*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: #1d1030;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: #3a2540;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  display: grid;
  place-items: center;
  background:
    radial-gradient(1200px 700px at 50% -10%, #5a2f7a 0%, #1d1030 60%),
    #1d1030;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}

#stage {
  position: fixed;
  inset: 0;
  overflow: hidden;
  user-select: none;
}

/* touch-action:none NUR auf Spielfeld + Touch-Steuerung (nicht auf #stage), damit
   Menü-Overlays (.screen) weiterhin per Wisch scrollbar bleiben. */
#game { display: block; width: 100%; height: 100%; cursor: crosshair; touch-action: none; }

/* Weißer Schleier, wenn der Weg durch ein Wolkenband führt (Sicht getrübt) */
#cloud-veil {
  position: absolute;
  inset: 0;
  background: radial-gradient(120% 100% at 50% 45%, #ffffff, #eef2ff);
  opacity: 0;
  pointer-events: none;
  transition: opacity .15s linear;
}

/* ---------------------------------------------------- HUD im Spiel */
#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  font-weight: 800;
  color: #fff;
  text-shadow: 0 2px 6px rgba(0, 0, 0, .45);
}
.hearts { position: absolute; top: 14px; left: 16px; display: flex; gap: 4px; font-size: 24px; }
.heart { color: #ff4d6a; }
.heart.aus { color: rgba(255, 255, 255, .3); }

.level-tag {
  position: absolute;
  top: 16px; left: 50%;
  transform: translateX(-50%);
  font-size: 19px;
  letter-spacing: .04em;
}
.time-tag {
  position: absolute;
  top: 42px; left: 50%;
  transform: translateX(-50%);
  font-size: 15px;
  font-weight: 800;
  color: #fff;
  opacity: .85;
  font-variant-numeric: tabular-nums;
}
.coin-tag {
  /* Mittig unter der Zeit – nicht mehr oben rechts, wo der „Menü"-Knopf sitzt. */
  position: absolute;
  top: 66px; left: 50%;
  transform: translateX(-50%);
  display: flex; align-items: center; gap: 7px;
  font-size: 21px;
}
.coin-dot {
  width: 18px; height: 18px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffe07a, #ffc61a 60%, #c99312);
  box-shadow: 0 1px 4px rgba(0, 0, 0, .3);
}

.bar {
  position: absolute;
  /* Weiter unten starten (+ Safe-Area), damit das 🏆 oben nicht unter dem
     „Menü"-Knopf oben rechts liegt. */
  right: 20px;
  top: calc(env(safe-area-inset-top, 0px) + 100px);
  bottom: 60px;
  width: 9px;
  border-radius: 5px;
  background: rgba(255, 255, 255, .28);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .35);
}
.bar-fill {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  border-radius: 5px;
  background: linear-gradient(180deg, #ff5fa2, #ff1f6d);
  transition: height .12s linear;
}
.bar-top { position: absolute; top: -24px; left: 50%; transform: translateX(-50%); font-size: 16px; }

.lock-tip {
  position: absolute;
  bottom: 18px; left: 50%;
  transform: translateX(-50%);
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  color: rgba(255, 255, 255, .95);
  background: rgba(0, 0, 0, .3);
  border-radius: 20px;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.crosshair {
  position: absolute;
  top: 50%; left: 50%;
  width: 5px; height: 5px;
  margin: -2.5px 0 0 -2.5px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .6);
  box-shadow: 0 0 0 1.5px rgba(0, 0, 0, .3);
}

/* ---------------------------------------------------- Touch-Steuerung */
#touch-ui {
  position: absolute;
  inset: 0;
  pointer-events: none;   /* Zonen liegen auf dem Canvas; nur die Knöpfe fangen Touches */
  z-index: 6;
  touch-action: none;
}
/* Virtueller Joystick (erscheint, wo der linke Daumen tippt) */
.joy {
  position: absolute;
  width: 130px; height: 130px;
  margin: -65px 0 0 -65px;      /* per JS an die Touch-Position gesetzt */
  border-radius: 50%;
  background: rgba(255, 255, 255, .14);
  border: 2px solid rgba(255, 255, 255, .5);
  pointer-events: none;
}
#joy-knob {
  position: absolute;
  top: 50%; left: 50%;
  width: 60px; height: 60px;
  margin: -30px 0 0 -30px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffffff, #ff8fc4 70%, #ff2d7a);
  box-shadow: 0 3px 10px rgba(0, 0, 0, .35);
}
/* Springen-Knopf rechts unten */
#jump-btn {
  position: absolute;
  right: 22px; bottom: 26px;
  width: 96px; height: 96px;
  border-radius: 50%;
  font-size: 34px;
  font-weight: 900;
  color: #fff;
  background: radial-gradient(circle at 40% 32%, #ff7fb2, #ff2d7a 72%, #cc1f60);
  box-shadow: 0 5px 0 #b31a53, 0 8px 20px rgba(255, 45, 122, .4);
  pointer-events: auto;
  -webkit-user-select: none;
  user-select: none;
  transition: transform .06s, box-shadow .06s;
}
#jump-btn:active { transform: translateY(4px); box-shadow: 0 1px 0 #b31a53, 0 4px 10px rgba(255, 45, 122, .35); }

/* Auf Touch-Geräten den Maus-Hinweis ausblenden */
body.touch .lock-tip { display: none; }

/* Hilfetexte je nach Gerät: Touch-Hinweise nur am Handy, Tasten-Hinweise nur am PC.
   Selektoren bewusst mit .help-row, damit sie das display:flex von .help-row schlagen. */
.help-row.touch-only { display: none; }
body.touch .help-row.touch-only { display: flex; }
body.touch .help-row.desk-only { display: none; }

/* ---------------------------------------------------- Overlays */
.screen {
  position: absolute;
  inset: 0;
  z-index: 20;              /* immer über HUD, Touch-Steuerung (6) und Menü-Knopf (7) */
  display: grid;
  place-items: center;
  padding: 16px;
  background: linear-gradient(180deg, rgba(40, 16, 52, .55), rgba(40, 16, 52, .78));
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  overflow-y: auto;
  /* WICHTIG: #stage hat touch-action:none (fürs Spiel). In Menüs/Overlays muss
     man aber wischen können, sonst sind bei hohen Panels (z. B. Spiel-vorbei auf
     kleinen/queren Handys) die unteren Knöpfe unerreichbar. */
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
  animation: fade .18s ease-out;
}
/* Utility-Klasse: schlägt bewusst per !important konkurrierende display-Regeln
   (z. B. .board-levels{display:flex}), damit „hidden" immer wirklich versteckt. */
.screen.hidden, .hidden { display: none !important; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.panel {
  width: 100%;
  max-width: 340px;
  background: linear-gradient(180deg, #fffdfe, #fff0f7);
  border-radius: 20px;
  padding: 22px 20px;
  text-align: center;
  box-shadow: 0 14px 40px rgba(0, 0, 0, .35);
  animation: pop .22s cubic-bezier(.2, 1.5, .4, 1);
}
.panel.wide { max-width: 400px; padding: 18px 16px; }
@keyframes pop { from { transform: scale(.9); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ---------------------------------------------------- Logo */
.logo { line-height: .92; margin-bottom: 6px; }
.logo-1 {
  display: block;
  font-size: 30px;
  font-weight: 800;
  letter-spacing: .22em;
  color: #8a4dff;
  text-indent: .22em;
}
.logo-2 {
  display: block;
  font-size: 54px;
  font-weight: 900;
  letter-spacing: .02em;
  background: linear-gradient(180deg, #ff5fa2, #ff2d7a);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 3px 0 rgba(255, 45, 122, .18);
}
.logo-3 {
  display: inline-block;
  margin-top: 2px;
  padding: 2px 10px;
  font-size: 14px;
  font-weight: 900;
  letter-spacing: .18em;
  color: #fff;
  background: linear-gradient(180deg, #a86bff, #8a4dff);
  border-radius: 6px;
  box-shadow: 0 2px 0 #6a34d0;
}
.tag { margin: 4px 0 16px; font-size: 13px; color: #7a6480; line-height: 1.45; }

h2 { margin: 0 0 4px; font-size: 24px; font-weight: 800; color: #ff2d7a; }
.sub { margin: 0 0 12px; font-size: 14px; color: #7a6480; }
.hint { margin: 12px 0 4px; font-size: 12.5px; color: #7a6480; }
.hint.new { color: #ff2d7a; font-weight: 800; font-size: 15px; }
.trophy { font-size: 46px; line-height: 1; margin-bottom: 4px; }

/* ---------------------------------------------------- Buttons */
button { font-family: inherit; cursor: pointer; border: 0; }

.big {
  display: block;
  width: 100%;
  margin: 10px 0 0;
  padding: 14px;
  font-size: 18px;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(180deg, #ff5fa2, #ff2d7a);
  border-radius: 14px;
  box-shadow: 0 4px 0 #cc1f60, 0 8px 18px rgba(255, 45, 122, .35);
  transition: transform .06s, box-shadow .06s;
}
.big:active { transform: translateY(3px); box-shadow: 0 1px 0 #cc1f60, 0 4px 10px rgba(255, 45, 122, .3); }

.ghost {
  display: block;
  width: 100%;
  margin: 8px 0 0;
  padding: 11px;
  font-size: 15px;
  font-weight: 700;
  color: #8a4dff;
  background: #f2ebff;
  border-radius: 12px;
  transition: background .12s, transform .06s;
}
.ghost:active { transform: translateY(2px); background: #e6dbff; }
.ghost.small { width: auto; padding: 8px 12px; font-size: 13px; margin-top: 6px; }

/* Unter den Herzen, damit nichts die Level-Anzeige verdeckt.
   Safe-Area beachten, damit die Knöpfe nicht unter Notch/Statusleiste liegen. */
.mute {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 40px);
  left: calc(env(safe-area-inset-left, 0px) + 8px);
  width: 30px;
  height: 30px;
  font-size: 13px;
  background: rgba(255, 255, 255, .5);
  border-radius: 50%;
  z-index: 5;
  line-height: 1;
  opacity: .75;
}
.mute:active { transform: scale(.9); }

/* Pause-/Menü-Knopf (oben rechts, während des Spiels) – deutlich sichtbar. */
.pause {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 10px);
  right: calc(env(safe-area-inset-right, 0px) + 10px);
  display: flex;
  align-items: center;
  gap: 5px;
  width: auto;
  height: 44px;
  padding: 0 15px 0 13px;
  font-size: 15px;
  font-weight: 800;
  color: #8a4dff;
  background: rgba(255, 255, 255, .92);
  border-radius: 22px;
  z-index: 7;
  line-height: 1;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .22);
}
.pause:active { transform: scale(.94); }

.meta { margin: 14px 0 0; font-size: 12.5px; color: #7a6480; }
.meta b { color: #3a2540; }

/* ---------------------------------------------------- Hilfe-Liste */
.help {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px dashed #f0d5e4;
  text-align: left;
}
.help-row {
  display: flex;
  align-items: flex-start;  /* Symbol oben, Text bricht sauber daneben um */
  gap: 8px;
  font-size: 11.5px;
  line-height: 1.45;
  color: #7a6480;
  padding: 3px 0;
  overflow-wrap: anywhere;  /* nichts läuft mehr aus dem Panel heraus */
}
.k {
  flex: none;
  min-width: 34px;
  text-align: center;
  font-weight: 800;
  color: #8a4dff;
}

/* Kleiner Hinweis ganz unten im Hauptmenü */
.credit {
  margin: 14px 0 0;
  padding-top: 11px;
  border-top: 1px dashed #f0d5e4;
  font-size: 11.5px;
  color: #9a86a8;
  text-align: center;
}
.credit b { color: #8a4dff; font-weight: 800; }

/* ---------------------------------------------------- Figuren-Editor (Vollbild) */
/* Editor überschreibt das zentrierende Grid der .screen-Basis: fester Vollbild-
   Rahmen, nur die Optionsspalte scrollt. */
.creator-screen {
  display: block;
  padding: 0;
  overflow: hidden;
  background: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}
.creator-layout {
  display: flex;
  width: 100%;
  height: 100%;
}
/* Große Bühne links mit der Figur in voller Größe */
.creator-stage {
  position: relative;
  flex: 1 1 58%;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background:
    radial-gradient(120% 90% at 50% 8%, #fff2f8 0%, #ffe3f0 45%, #e7d5ff 100%);
}
/* Absolut positioniert, damit die Canvas-Puffergröße die Flex-Höhe nicht aufbläht */
#preview {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}
.creator-title {
  position: absolute;
  top: 18px; left: 0; right: 0;
  text-align: center;
  font-size: 26px;
  font-weight: 900;
  color: #ff2d7a;
  letter-spacing: .01em;
  pointer-events: none;
}
.creator-hint {
  position: absolute;
  bottom: 16px; left: 0; right: 0;
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  color: #b088b0;
  pointer-events: none;
}
/* Scrollbare Optionen rechts */
/* Die Figur steht IMMER links und ganz im Bild; nur die Optionen rechts scrollen. */
.creator-side {
  flex: 1 1 46%;
  min-height: 0;
  overflow-y: auto;
  padding: 16px 16px 22px;
  background: linear-gradient(180deg, #fffdfe, #fff0f7);
  box-shadow: -6px 0 24px rgba(0, 0, 0, .18);
}
.name-row { display: flex; gap: 8px; }
.name-row #name-input { flex: 1; }
.name-row .ghost.small { width: auto; margin-top: 0; padding: 0 14px; font-size: 18px; flex: none; }

/* Sehr schmale Fenster: Optionsspalte etwas breiter, Figur bleibt links */
@media (max-width: 640px) {
  .creator-stage { flex: 1 1 42%; }
  .creator-side { flex: 1 1 58%; padding: 12px 12px 20px; }
  .creator-title { font-size: 20px; top: 10px; }
}

.name-box { text-align: left; margin-bottom: 12px; }
.name-box label {
  display: block;
  font-size: 11px;
  font-weight: 800;
  color: #8a4dff;
  text-transform: uppercase;
  letter-spacing: .08em;
  margin-bottom: 4px;
}
#name-input {
  width: 100%;
  padding: 9px 10px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  color: #3a2540;
  background: #fff;
  border: 2px solid #f0d5e4;
  border-radius: 10px;
  outline: none;
}
#name-input:focus { border-color: #ff5fa2; }

.row { margin-bottom: 9px; text-align: left; }
.row-label {
  font-size: 10.5px;
  font-weight: 800;
  color: #8a4dff;
  text-transform: uppercase;
  letter-spacing: .07em;
  margin-bottom: 4px;
}
.opts { display: flex; flex-wrap: wrap; gap: 5px; }

.opt {
  border-radius: 9px;
  transition: transform .08s, box-shadow .08s;
  padding: 0;
}
.opt:active { transform: scale(.92); }

.swatch {
  width: 27px;
  height: 27px;
  border-radius: 50%;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .5), 0 1px 3px rgba(0, 0, 0, .2);
}
.swatch.sel {
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .9), 0 0 0 3px #ff2d7a;
  transform: scale(1.06);
}

.chip {
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 700;
  color: #7a6480;
  background: #f4eef8;
}
.chip.sel { color: #fff; background: linear-gradient(180deg, #ff5fa2, #ff2d7a); }

/* ---------------------------------------------------- Regler */
.slider-box {
  margin: 14px 0 6px;
  padding: 12px;
  background: #f7f2fb;
  border-radius: 12px;
  text-align: left;
}
.slider-box label { display: block; font-size: 12.5px; font-weight: 700; color: #7a6480; margin-bottom: 8px; }
.slider-box label b { color: #ff2d7a; }
.slider-box input[type="range"] {
  width: 100%;
  accent-color: #ff2d7a;
  cursor: pointer;
}
.slider-ends {
  display: flex;
  justify-content: space-between;
  margin-top: 2px;
  font-size: 10px;
  color: #a695ad;
}

/* ---------------------------------------------------- Figuren-Übersicht */
.figuren-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 9px;
  margin: 12px 0 10px;
  max-height: 320px;
  overflow-y: auto;
  padding: 2px;
}
.figur-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 4px 6px;
  background: #f5eefc;
  border-radius: 14px;
  cursor: pointer;
  transition: transform .08s, box-shadow .08s;
}
.figur-card img { width: 100%; height: auto; border-radius: 10px; background: linear-gradient(180deg, #fff2f8, #e7d5ff); }
.figur-card span { font-size: 12px; font-weight: 800; color: #7a6480; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.figur-card:active { transform: scale(.95); }
.figur-card.aktiv { box-shadow: 0 0 0 3px #ff2d7a; background: #fff; }
.figur-card.aktiv span { color: #ff2d7a; }
.figur-card.neu { justify-content: center; color: #8a4dff; min-height: 120px; background: #efe6fb; }
.figur-card.neu .plus { font-size: 30px; font-weight: 900; line-height: 1; }
.figur-card.neu span { color: #8a4dff; }

/* ---------------------------------------------------- Level-Auswahl */
.level-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 7px;
  margin: 14px 0 4px;
  max-height: 250px;
  overflow-y: auto;
}
.lvl {
  aspect-ratio: 1;
  font-size: 15px;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(180deg, #a86bff, #8a4dff);
  border-radius: 10px;
  box-shadow: 0 3px 0 #6a34d0;
  transition: transform .06s, box-shadow .06s;
}
.lvl:active { transform: translateY(2px); box-shadow: 0 1px 0 #6a34d0; }
.lvl.neu {
  background: linear-gradient(180deg, #ff5fa2, #ff2d7a);
  box-shadow: 0 3px 0 #cc1f60, 0 0 0 2px #ffd23a;
}

/* ---------------------------------------------------- Weltweite Rangliste */
.board-levels {
  display: flex; flex-wrap: wrap; justify-content: center;
  gap: 6px; margin: 12px 0 10px;
}
.lvpick {
  min-width: 34px; padding: 6px 9px;
  font-size: 14px; font-weight: 800; color: #8a4dff;
  background: #efe6fb; border-radius: 9px;
  transition: transform .06s;
}
.lvpick.on { color: #fff; background: linear-gradient(180deg, #ff5fa2, #ff2d7a); box-shadow: 0 2px 0 #cc1f60; }
.lvpick:active { transform: translateY(1px); }
.board-list {
  min-height: 90px; max-height: 46vh; overflow-y: auto;
  margin: 4px 0 12px;
  display: flex; flex-direction: column; gap: 4px;
  font-size: 14px; color: #5a4560;
}
.board-row {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; background: #fff; border-radius: 10px;
}
.board-row.mine { background: #fff0f7; box-shadow: 0 0 0 2px #ff8fc4; }
.br-rank { flex: none; width: 26px; font-weight: 900; color: #ff2d7a; text-align: right; }
.board-row:nth-child(1) .br-rank { color: #e8a400; }
.br-name { flex: 1; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.br-time { flex: none; font-weight: 800; font-variant-numeric: tabular-nums; }
.board-note, .board-empty { text-align: center; color: #7a6480; font-size: 13px; padding: 10px; }

/* Tabs der Rangliste (Schnellste je Level / Am weitesten) */
.board-tabs { display: flex; gap: 6px; margin: 12px 0 6px; }
.board-tab {
  flex: 1; padding: 10px 6px;
  font-size: 13px; font-weight: 800; color: #8a4dff;
  background: #efe6fb; border-radius: 10px;
  transition: transform .06s;
}
.board-tab.on { color: #fff; background: linear-gradient(180deg, #a86bff, #8a4dff); box-shadow: 0 2px 0 #6a34d0; }
.board-tab:active { transform: translateY(1px); }

/* Konto-Bildschirm */
.acc-fields { display: flex; flex-direction: column; gap: 9px; margin: 12px 0; }
.acc-fields input {
  width: 100%; padding: 13px 15px;
  font-size: 16px;                 /* ≥16px: iOS zoomt beim Fokus nicht rein */
  font-family: inherit;
  border-radius: 12px; border: 2px solid #e6dbf5;
  background: #fff; color: #3a2b45;
}
.acc-fields input:focus { outline: none; border-color: #ff5fa2; }
.acc-fields input::placeholder { color: #b3a6c2; }
.acc-msg { min-height: 18px; margin: 6px 0 2px; font-size: 13px; font-weight: 700; color: #d81b60; }
.acc-msg.good { color: #1f9d55; }
.acc-msg.info { color: #6a4dc0; }

/* ---------------------------------------------------- Statistik */
.stats {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin: 14px 0 2px;
}
.stats > div {
  flex: 1;
  background: #fff;
  border-radius: 12px;
  padding: 9px 4px;
  box-shadow: 0 2px 8px rgba(255, 45, 122, .1);
}
.stats span {
  display: block;
  font-size: 22px;
  font-weight: 900;
  color: #ff2d7a;
  line-height: 1.1;
}
.stats small {
  display: block;
  font-size: 9.5px;
  color: #7a6480;
  margin-top: 2px;
}
