/**
 * Reef Tycoon - Design-System der Spielansicht (D61).
 *
 * Leitbild: MAD-TV-Haptik ("Spielzeugkiste", nicht Admin-Panel) mit der
 * Lesbarkeit der Two-Point-Reihe. Konkret heisst das hier:
 *   - dicke Radien, sichtbare Kanten, glaenzende Innenlichter -> alles wirkt
 *     wie ein gespritztes Kunststoffteil, das man anfassen kann,
 *   - jeder Druck gibt nach (`:active` skaliert), nichts fuehlt sich tot an,
 *   - Zahlen sind fett und tabellarisch, damit sie beim Ticken nicht springen,
 *   - Touch-Ziele mindestens 48 px (--tap).
 *
 * Warum handgeschriebenes CSS und kein Tailwind: das Projekt hat bewusst keinen
 * Build-Schritt und keine Laufzeit-Abhaengigkeiten (D2), und externe CDNs sind
 * wegen Offline-/Capacitor-Betrieb ausgeschlossen (D60). Die Token-Ebene unten
 * uebernimmt die Rolle, die in Tailwind die Konfiguration haette.
 */

:root {
  /* --- Flaechen: Wassertiefe von unten (Abgrund) nach oben (Riffdach) --- */
  --abyss: #061520;
  --deep: #0b2130;
  --shelf: #123246;
  --shelf-2: #19445f;
  --edge: #24597f;
  --edge-soft: rgba(120, 190, 235, 0.16);

  /* --- Schrift --- */
  --foam: #eaf6ff;
  --foam-dim: #93b5cf;
  --foam-faint: #5f819b;

  /* --- Signalfarben --- */
  --coral: #ff6f5b;      /* Hauptaktion, Markenfarbe */
  --coral-deep: #d4442f;
  --gold: #ffc63d;       /* Muenzen */
  --gem: #8b7bff;        /* Edelsteine */
  --kelp: #2fdd8f;       /* gut */
  --amber: #ffb224;      /* Achtung */
  --alarm: #ff4d5e;      /* kritisch */
  --cyan: #35cdf2;       /* Technik / Hinweis */

  /* --- Form --- */
  --r-sm: 10px;
  --r-md: 16px;
  --r-lg: 22px;
  --r-xl: 28px;
  --tap: 48px;           /* Mindestgroesse fuer Touch-Ziele */

  /* --- Tiefe: zwei Schatten plus ein Innenlicht = Kunststoff-Anmutung --- */
  --lift-1: 0 2px 0 rgba(0, 0, 0, 0.45), 0 6px 14px rgba(0, 0, 0, 0.35);
  --lift-2: 0 3px 0 rgba(0, 0, 0, 0.5), 0 12px 26px rgba(0, 0, 0, 0.45);
  --gloss: inset 0 1px 0 rgba(255, 255, 255, 0.18);

  /* --- Sicherheitsabstaende fuer Notch und Home-Indicator --- */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  --hud-h: 62px;
  --nav-h: 66px;

  /* Wie viel Platz die Bildschirmtastatur gerade nimmt (D134).
     Wird vom Skript aus `visualViewport` gesetzt, ist sonst 0. */
  --kb: 0px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;                 /* gescrollt wird nur die Buehne */
  overscroll-behavior: none;
}

body {
  background: var(--abyss);
  color: var(--foam);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-weight: 500;
  user-select: none;
  -webkit-user-select: none;
}

h1, h2, h3 { margin: 0; font-weight: 800; letter-spacing: -0.01em; }

/* Zahlen laufen tabellarisch, sonst zappeln sie beim Hochzaehlen. */
.num { font-variant-numeric: tabular-nums; }

/* ==========================================================================
   Grundgeruest: HUD oben, scrollende Buehne, feste Navigation unten
   ========================================================================== */

.app {
  /* Die Tastatur verkuerzt die App, statt das Eingabefeld zu verdecken (D134).
     Ohne `--kb` waere das auf iOS nicht loesbar: der Layout-Viewport schrumpft
     dort beim Oeffnen der Tastatur nicht, und `overflow: hidden` auf `body`
     laesst sich auch nicht wegscrollen. */
  height: calc(100% - var(--kb));
  display: grid;
  /* HUD, Buehne, Chat-Eingabe, Navigation. Die dritte Zeile ist meist leer
     (`hidden`) und kostet dann nichts. */
  grid-template-rows: auto 1fr auto auto;
  max-width: 720px;                 /* auf dem Desktop wie ein Handy zentriert */
  margin: 0 auto;
  position: relative;
  background: radial-gradient(120% 70% at 50% 0%, #0f2c3f 0%, var(--abyss) 70%);
  transition: height 0.12s ease-out;
}

.stage {
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 12px 14px 22px;
  scrollbar-width: none;
}
.stage::-webkit-scrollbar { display: none; }

/* ==========================================================================
   HUD (oben): Guthaben, Edelsteine, Beckenfuellstand
   ========================================================================== */

.hud {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(var(--safe-top) + 8px) 12px 8px;
  min-height: var(--hud-h);
  background: linear-gradient(180deg, rgba(6, 21, 32, 0.96), rgba(6, 21, 32, 0.72));
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--edge-soft);
  position: relative;
  z-index: 20;
}

/* Waehrungsanzeige: gepraegtes Plaettchen mit Symbol links. */
.purse {
  display: flex;
  align-items: center;
  gap: 7px;
  height: 38px;
  padding: 0 12px 0 7px;
  border-radius: 999px;
  background: linear-gradient(180deg, var(--shelf-2), var(--shelf));
  border: 1px solid var(--edge);
  box-shadow: var(--lift-1), var(--gloss);
}
.purse .sym {
  width: 24px; height: 24px;
  display: grid; place-items: center;
  border-radius: 50%;
  font-size: 13px; font-weight: 900;
  flex: 0 0 auto;
}
.purse .val { font-size: 16px; font-weight: 900; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }

.purse.coins .sym { background: radial-gradient(circle at 35% 30%, #ffe9a3, var(--gold) 60%, #b3820f); color: #4a3300; }
.purse.coins .val { color: var(--gold); }
.purse.gems .sym { background: radial-gradient(circle at 35% 30%, #cfc7ff, var(--gem) 60%, #4a3ab8); color: #1b1140; }
.purse.gems .val { color: #c3b9ff; }

/* Wenn Geld dazukommt, pulst das Plaettchen einmal auf. */
.purse.blitz { animation: purse-blitz 620ms ease-out; }
@keyframes purse-blitz {
  0% { transform: scale(1); }
  35% { transform: scale(1.14); box-shadow: var(--lift-2), var(--gloss), 0 0 18px currentColor; }
  100% { transform: scale(1); }
}

/* Beckenfuellstand: ein Glaszylinder, der sich sichtbar fuellt. */
.fill {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  height: 38px;
  padding: 0 12px;
  border-radius: 999px;
  background: linear-gradient(180deg, var(--shelf-2), var(--shelf));
  border: 1px solid var(--edge);
  box-shadow: var(--lift-1), var(--gloss);
}
.fill .glas {
  position: relative;
  width: 46px; height: 20px;
  border-radius: 6px;
  background: rgba(4, 16, 26, 0.85);
  border: 1.5px solid rgba(150, 210, 245, 0.45);
  overflow: hidden;
}
.fill .glas i {
  position: absolute; left: 0; bottom: 0; top: 0;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.35), transparent 40%), var(--pegel, var(--kelp));
  transition: width 420ms cubic-bezier(0.22, 1, 0.36, 1), background 300ms;
}
/* Glanzlicht ueber dem Glas - macht aus dem Balken ein Objekt. */
.fill .glas::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(105deg, rgba(255, 255, 255, 0.22) 0 30%, transparent 55%);
  pointer-events: none;
}
/**
 * Reservierungsmarke (D93): wie voll die Ablegerplatte GEOMETRISCH ist.
 * Der Pegel darunter misst Gewebe (daran haengt das Gedraenge, D21) - beides
 * ist dieselbe Platte, aber nicht dieselbe Zahl, und vorher sah man nur eine.
 * Als schmale Marke statt als zweitem Balken: der Streifen ist 46 px breit.
 */
.fill .glas .marke {
  position: absolute; top: -1px; bottom: -1px; width: 2px;
  margin-left: -1px;
  background: var(--gold, #ffc758);
  box-shadow: 0 0 4px rgba(255, 199, 88, 0.8);
  transition: left 420ms cubic-bezier(0.22, 1, 0.36, 1);
  pointer-events: none;
}
.fill .txt { font-size: 12px; font-weight: 800; color: var(--foam-dim); font-variant-numeric: tabular-nums; }
.fill .txt em { font-style: normal; color: var(--gold, #ffc758); }

/* ==========================================================================
   Bottom-Navigation
   ========================================================================== */

.navbar {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 2px;
  padding: 6px 8px calc(var(--safe-bottom) + 6px);
  min-height: var(--nav-h);
  background: linear-gradient(180deg, rgba(9, 28, 42, 0.94), rgba(4, 14, 22, 0.99));
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--edge-soft);
  position: relative;
  z-index: 20;
}

.navbtn {
  position: relative;               /* traegt Kappe und Merkpunkt */
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--foam-faint);
  min-height: var(--tap);
  padding: 4px 2px;
  border-radius: var(--r-md);
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 2px;
  font: inherit;
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: color 160ms, transform 120ms;
}
.navbtn svg { width: 24px; height: 24px; display: block; }
.navbtn:active { transform: scale(0.92); }
.navbtn[aria-selected="true"] { color: var(--foam); }

/* Aktiver Reiter bekommt eine leuchtende Kappe statt eines Rahmens. */
.navbtn[aria-selected="true"]::before {
  content: "";
  position: absolute;
  top: -6px; left: 50%;
  transform: translateX(-50%);
  width: 34px; height: 4px;
  border-radius: 0 0 4px 4px;
  background: var(--coral);
  box-shadow: 0 0 12px var(--coral);
}
/* Merkpunkt, wenn auf einem Reiter etwas zu tun ist. */
.navbtn .dot {
  position: absolute;
  top: 4px; left: 50%;
  margin-left: 8px;
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--coral);
  border: 2px solid var(--deep);
}

/* ==========================================================================
   Knoepfe
   ========================================================================== */

.btn {
  appearance: none;
  font: inherit;
  font-weight: 800;
  min-height: var(--tap);
  padding: 0 18px;
  border-radius: var(--r-md);
  border: 1px solid var(--edge);
  background: linear-gradient(180deg, var(--shelf-2), var(--shelf));
  color: var(--foam);
  box-shadow: var(--lift-1), var(--gloss);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 110ms cubic-bezier(0.22, 1, 0.36, 1), filter 160ms;
}
/* Der Druck faehrt den Knopf auf seinen Sockel - das ist das haptische Signal. */
.btn:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 0 0 rgba(0,0,0,0.4), var(--gloss); }
.btn:disabled { opacity: 0.38; cursor: not-allowed; box-shadow: none; }

.btn.primary {
  background: linear-gradient(180deg, #ff8a72, var(--coral) 55%, var(--coral-deep));
  border-color: #ff9d88;
  color: #37110a;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.25);
}
.btn.gold {
  background: linear-gradient(180deg, #ffe08a, var(--gold) 55%, #c08d12);
  border-color: #ffe9a8;
  color: #3c2b00;
}
.btn.silver {
  background: linear-gradient(180deg, #e8f0f7, #a8b8c6 55%, #6d7f8e);
  border-color: #f0f6fb;
  color: #1a2530;
}
.btn.ghost { background: rgba(255, 255, 255, 0.05); box-shadow: none; }
.btn.sm { min-height: 38px; padding: 0 13px; font-size: 13px; border-radius: var(--r-sm); }
.btn.wide { width: 100%; }

/* ==========================================================================
   Panels, Abschnitte, Hinweise
   ========================================================================== */

.panel {
  background: linear-gradient(180deg, rgba(25, 68, 95, 0.55), rgba(18, 50, 70, 0.35));
  border: 1px solid var(--edge-soft);
  border-radius: var(--r-lg);
  padding: 14px;
  box-shadow: var(--lift-1);
}
.panel + .panel { margin-top: 12px; }

.sect {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin: 18px 2px 10px;
}
.sect:first-child { margin-top: 4px; }
.sect h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.09em; color: var(--foam-dim); }
.sect .hint { font-size: 12px; color: var(--foam-faint); margin-left: auto; }

.hinweis {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 12px 14px;
  border-radius: var(--r-md);
  background: rgba(53, 205, 242, 0.1);
  border: 1px solid rgba(53, 205, 242, 0.3);
  font-size: 13.5px;
  line-height: 1.4;
  margin-bottom: 12px;
}
.hinweis .ico { font-size: 18px; line-height: 1.1; flex: 0 0 auto; }
.hinweis.bad { background: rgba(255, 77, 94, 0.12); border-color: rgba(255, 77, 94, 0.42); }
.hinweis.good { background: rgba(47, 221, 143, 0.11); border-color: rgba(47, 221, 143, 0.38); }
.hinweis.warn { background: rgba(255, 178, 36, 0.12); border-color: rgba(255, 178, 36, 0.4); }
.hinweis b { color: #fff; }

.leer { padding: 24px 12px; text-align: center; color: var(--foam-faint); font-size: 13px; }

/* Kleine Statusmarke. */
.marke {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 9px; border-radius: 999px;
  font-size: 11px; font-weight: 800; letter-spacing: 0.02em;
  background: rgba(255, 255, 255, 0.08); color: var(--foam-dim);
  border: 1px solid var(--edge-soft);
}
.marke.good { color: var(--kelp); border-color: rgba(47, 221, 143, 0.45); background: rgba(47, 221, 143, 0.12); }
.marke.warn { color: var(--amber); border-color: rgba(255, 178, 36, 0.45); background: rgba(255, 178, 36, 0.12); }
.marke.bad { color: var(--alarm); border-color: rgba(255, 77, 94, 0.45); background: rgba(255, 77, 94, 0.12); }
.marke.gold { color: var(--gold); border-color: rgba(255, 198, 61, 0.5); background: rgba(255, 198, 61, 0.13); }

/* ==========================================================================
   Ziel-Leiste (naechster Meilenstein)
   ========================================================================== */

.ziel {
  display: flex; align-items: center; gap: 11px;
  width: 100%;
  padding: 11px 14px;
  margin-bottom: 12px;
  border-radius: var(--r-md);
  border: 1px solid rgba(255, 198, 61, 0.4);
  background: linear-gradient(100deg, rgba(255, 198, 61, 0.18), rgba(255, 111, 91, 0.1));
  color: var(--foam);
  font: inherit;
  text-align: left;
  cursor: pointer;
  box-shadow: var(--lift-1);
}
.ziel:active { transform: translateY(1px); }
.ziel .ring { flex: 0 0 auto; }
.ziel .txt { flex: 1; min-width: 0; }
.ziel .lbl { font-size: 10px; font-weight: 900; letter-spacing: 0.1em; text-transform: uppercase; color: var(--gold); }
.ziel .tit { font-size: 13.5px; font-weight: 800; }
.ziel .lohn { font-size: 13px; font-weight: 900; color: var(--gold); white-space: nowrap; }
.ziel.fertig { border-color: rgba(47, 221, 143, 0.45); background: rgba(47, 221, 143, 0.12); justify-content: center; }

/* ==========================================================================
   Bottom-Sheet (Preisdialog, Details) und Toasts
   ========================================================================== */

.sheet-bg {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(3, 10, 16, 0.66);
  backdrop-filter: blur(3px);
  opacity: 0;
  transition: opacity 200ms;
}
.sheet-bg.auf { opacity: 1; }

.sheet {
  position: fixed;
  left: 50%; bottom: 0;
  width: min(720px, 100%);
  transform: translate(-50%, 100%);
  z-index: 61;
  background: linear-gradient(180deg, var(--shelf), var(--deep));
  border: 1px solid var(--edge);
  border-bottom: 0;
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  padding: 10px 18px calc(var(--safe-bottom) + 20px);
  box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.6);
  transition: transform 300ms cubic-bezier(0.22, 1, 0.36, 1);
  max-height: 88%;
  overflow-y: auto;
}
.sheet.auf { transform: translate(-50%, 0); }
.sheet .griff { width: 44px; height: 5px; border-radius: 999px; background: var(--foam-faint); margin: 0 auto 14px; opacity: 0.5; }
.sheet h3 { font-size: 18px; margin-bottom: 4px; }
.sheet .unter { color: var(--foam-dim); font-size: 13px; margin-bottom: 16px; }

.toasts {
  position: fixed;
  left: 50%; transform: translateX(-50%);
  top: calc(var(--safe-top) + var(--hud-h) + 8px);
  z-index: 70;
  display: grid;
  gap: 8px;
  width: min(420px, calc(100% - 28px));
  pointer-events: none;
}
.toast {
  padding: 11px 15px;
  border-radius: var(--r-md);
  background: linear-gradient(180deg, var(--shelf-2), var(--shelf));
  border: 1px solid var(--edge);
  box-shadow: var(--lift-2), var(--gloss);
  font-size: 13.5px;
  font-weight: 700;
  animation: toast-rein 260ms cubic-bezier(0.22, 1, 0.36, 1);
}
.toast.good { border-color: rgba(47, 221, 143, 0.6); }
.toast.bad { border-color: rgba(255, 77, 94, 0.6); }
.toast.gold { border-color: rgba(255, 198, 61, 0.6); }
.toast.weg { animation: toast-raus 240ms ease-in forwards; }
@keyframes toast-rein { from { opacity: 0; transform: translateY(-14px) scale(0.96); } }
@keyframes toast-raus { to { opacity: 0; transform: translateY(-10px) scale(0.97); } }

/* Regler (Technik). */
input[type="range"] {
  width: 100%;
  height: var(--tap);
  appearance: none;
  background: transparent;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 10px; border-radius: 999px;
  background: linear-gradient(90deg, var(--cyan), rgba(53, 205, 242, 0.18));
  border: 1px solid var(--edge);
}
input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 28px; height: 28px; margin-top: -10px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff, #cfe6f5 45%, #7c9db3);
  border: 2px solid var(--deep);
  box-shadow: var(--lift-1);
}
input[type="range"]::-moz-range-track { height: 10px; border-radius: 999px; background: rgba(53, 205, 242, 0.35); }
input[type="range"]::-moz-range-thumb { width: 26px; height: 26px; border-radius: 50%; background: #e8f4fb; border: 2px solid var(--deep); }

/* Wer Bewegung reduziert haben will, bekommt die Zustaende ohne Animation. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

/* ==========================================================================
   Anmeldetor (D137)
   ========================================================================== */

/* Liegt ueber HUD und Navigation (z-index 20) und ueber den Bottom-Sheets
   (60/61), aber unter den Toasts (70) - Fehlermeldungen bleiben sichtbar.
   Die Tastaturregel ist dieselbe wie bei `.app` (D134): auf iOS schrumpft der
   Layout-Viewport nicht, also verkuerzen wir selbst. */
.tor {
  position: fixed;
  inset: 0;
  z-index: 65;
  height: calc(100% - var(--kb));
  display: grid;
  align-content: center;
  gap: 14px;
  padding: calc(var(--safe-top) + 24px) 22px calc(var(--safe-bottom) + 24px);
  max-width: 720px;
  margin: 0 auto;
  background: radial-gradient(120% 70% at 50% 0%, #0f2c3f 0%, var(--abyss) 70%);
  overflow-y: auto;
  transition: height 0.12s ease-out;
}
.tor[hidden] { display: none; }

.tor h1 {
  font-size: 26px;
  letter-spacing: -0.02em;
  text-align: center;
  margin-bottom: 2px;
}
.tor .tor-unter {
  text-align: center;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--foam-dim);
  margin-bottom: 6px;
}
.tor .tor-fehler {
  min-height: 18px;
  font-size: 12.5px;
  font-weight: 800;
  color: var(--alarm);
  text-align: center;
}
.tor .tor-fuss {
  display: flex;
  justify-content: center;
  gap: 14px;
  font-size: 12.5px;
  font-weight: 700;
  margin-top: 4px;
}
.tor .tor-fuss button {
  border: 0;
  background: none;
  color: var(--cyan);
  font: inherit;
  cursor: pointer;
  padding: 6px 2px;
  text-decoration: underline;
}
.tor .rechtliches {
  font-size: 11px;
  font-weight: 600;
  color: var(--foam-faint);
  text-align: center;
  line-height: 1.5;
}
.tor .rechtliches a { color: var(--foam-dim); }

/* Eingabefelder: 16px ist Pflicht, nicht Geschmack - darunter zoomt iOS beim
   Fokussieren hinein, und `user-scalable=no` verhindert das seit iOS 10 nicht
   mehr zuverlaessig. */
.tor input {
  width: 100%;
  min-height: var(--tap);
  padding: 0 14px;
  margin-bottom: 10px;
  border-radius: var(--r-md);
  border: 1px solid var(--edge);
  background: rgba(255, 255, 255, 0.06);
  color: inherit;
  font: inherit;
  font-size: 16px;
  user-select: text;
  -webkit-user-select: text;
}
.tor input:focus { outline: 2px solid var(--cyan); outline-offset: 1px; }
