/*
 * CounterGames Web · Designsystem "Spieltisch" v2
 * Alle Farbwerte sind 1:1 aus handoff/new/frontend/src/design/theme.ts
 * uebernommen. Neue Hex-Werte NUR dort eintragen, dann hier spiegeln.
 *
 * Regel 1: accent ("Glut") markiert ausschliesslich Tippbares.
 * Regel 2: money (gruen), ranking (gold), cash (blau) sind nie interaktiv.
 */

:root {
  color-scheme: light dark;

  /* Grundflaechen */
  --bg: #F7F3EC;
  --card: #FFFFFF;
  --line: #E2DACB;
  --sunken: #EFE9DF;

  /* Text */
  --text: #17140F;
  --muted: #6B655B;

  /* Glut · die EINZIGE Aktionsfarbe */
  --accent: #B03D14;
  --on-accent: #FFF7F2;
  --soft: #FBE6DB;

  /* Filz · Geld */
  --money: #14624A;
  --money-soft: #DCEDE3;
  --on-money: #FBF8F2;

  /* Tinte · Kasse */
  --cash: #2B5877;
  --cash-soft: #E1EBF2;
  --on-cash: #F2F7FA;

  /* Messing · Punkte, Rang */
  --ranking: #8A6114;
  --ranking-soft: #F7EBD2;
  --on-ranking: #FDF7EA;

  /* Zustaende */
  --danger: #B23A20;
  --on-danger: #FFFFFF;
  --disabled: #F0EADF;
  --on-disabled: #A69E90;

  /* Tokens (tokens.ts) */
  --space-micro: 4px;
  --space-tight: 8px;
  --space-related: 12px;
  --space-inset: 16px;
  --space-page: 20px;
  --space-section: 24px;
  --space-spacious: 32px;
  --space-chapter: 48px;

  --radius-field: 14px;
  --radius-action: 16px;
  --radius-card: 22px;
  --radius-feature: 28px;
  --radius-tile: 12px;
  --radius-pill: 999px;

  --control-touch: 44px;
  --control-field: 52px;
  --control-action: 52px;
  --control-row: 72px;
  --control-row-compact: 60px;
  --control-row-rich: 88px;
  --control-dock: 64px;
  --control-action-dock: 76px;

  --font-text: -apple-system, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-rounded: "SF Pro Rounded", ui-rounded, -apple-system, "Segoe UI", Roboto, sans-serif;

  --glass-fill: rgba(255, 255, 255, 0.62);
  --glass-border: rgba(0, 0, 0, 0.08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121010;
    --card: #1D1A17;
    --line: #322D27;
    --sunken: #262119;
    --text: #F5F0E6;
    --muted: #A39C8E;
    --accent: #FF7A45;
    --on-accent: #20100A;
    --soft: #3A2115;
    --money: #5FC79B;
    --money-soft: #14291F;
    --on-money: #0B1A13;
    --cash: #7FB6DC;
    --cash-soft: #16242E;
    --on-cash: #0C1720;
    --ranking: #E8BC5E;
    --ranking-soft: #2E2415;
    --on-ranking: #1C1508;
    --danger: #FF9074;
    --on-danger: #2A1009;
    --disabled: #2A251F;
    --on-disabled: #6E675C;
    --glass-fill: rgba(29, 26, 23, 0.62);
    --glass-border: rgba(255, 255, 255, 0.08);
  }
}

/* Erhoehter Kontrast (highContrastOverrides) */
@media (prefers-contrast: more) {
  :root { --muted: #4A443B; --line: #C9BFAC; }
  @media (prefers-color-scheme: dark) {
    :root { --muted: #C9C2B4; --line: #4A433A; }
  }
  .tile, .chip, .soft-surface { border: 1px solid currentColor; }
}

/* ─── Grundlayout ───────────────────────────────────────────── */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-text);
  font-size: 17px;
  line-height: 24px;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}
a { color: var(--accent); text-decoration: none; }
a:hover, a:focus-visible { text-decoration: underline; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

#app {
  max-width: 640px;
  margin: 0 auto;
  padding: var(--space-page) var(--space-inset);
  padding-bottom: calc(var(--control-dock) + var(--space-inset) * 3 + env(safe-area-inset-bottom));
}
#app.with-action {
  padding-bottom: calc(var(--control-action-dock) + var(--control-dock) + var(--space-inset) + env(safe-area-inset-bottom));
}

/* ─── Typografie (typography.ts) ────────────────────────────── */
.metric, .metric-small, .value {
  font-family: var(--font-rounded);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}
.metric { font-size: clamp(40px, 12vw, 52px); line-height: 1.04; overflow-wrap: anywhere; }
.metric-small { font-size: 32px; line-height: 36px; }
.value { font-size: 18px; line-height: 23px; }
.hero { font-size: 34px; line-height: 41px; font-weight: 700; margin: 0; }
.title { font-size: 22px; line-height: 28px; font-weight: 600; margin: 0; }
.headline { font-size: 17px; line-height: 22px; font-weight: 600; margin: 0; }
.body { font-size: 17px; line-height: 24px; }
.secondary { font-size: 15px; line-height: 20px; color: var(--muted); }
.label { font-size: 15px; line-height: 20px; font-weight: 500; }
.caption { font-size: 13px; line-height: 18px; color: var(--muted); }
.eyebrow {
  font-size: 11px; line-height: 13px; font-weight: 700;
  letter-spacing: 1px; text-transform: uppercase; color: var(--muted);
  display: block; margin-bottom: var(--space-micro);
}
.muted { color: var(--muted); }

/* Domaenenfarben auf Text: nie interaktiv */
.t-money { color: var(--money); }
.t-ranking { color: var(--ranking); }
.t-cash { color: var(--cash); }
.t-danger { color: var(--danger); }

/* ─── Flaechen ───────────────────────────────────────────────── */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  padding: var(--space-inset);
}
.feature {
  border-radius: var(--radius-feature);
  padding: var(--space-section) var(--space-page);
}
.feature.money { background: var(--money); color: var(--on-money); }
.feature.cash { background: var(--cash); color: var(--on-cash); }
.feature.ranking { background: var(--ranking); color: var(--on-ranking); }
.feature .eyebrow { color: inherit; opacity: 0.85; }
.feature .secondary { color: inherit; opacity: 0.85; }

.soft-surface { border-radius: var(--radius-card); padding: var(--space-inset); }
.soft-surface.money { background: var(--money-soft); }
.soft-surface.cash { background: var(--cash-soft); }
.soft-surface.ranking { background: var(--ranking-soft); }
.soft-surface.sunken { background: var(--sunken); }

.stack > * + * { margin-top: var(--space-related); }
.section { margin-top: var(--space-section); }
.chapter { margin-top: var(--space-chapter); }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: var(--space-related); }

/* ─── Zeilen (round-list-row / Personenzeile) ────────────────── */
.list { list-style: none; margin: 0; padding: 0; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-card); overflow: hidden; }
.list > li + li { border-top: 1px solid var(--line); }
.row {
  display: flex; align-items: center; gap: var(--space-related);
  min-height: var(--control-row); padding: var(--space-related) var(--space-inset);
  width: 100%; text-align: left; background: none; border: 0; color: inherit; cursor: pointer;
}
.row.compact { min-height: var(--control-row-compact); }
.row.rich { min-height: var(--control-row-rich); }
.row.static { cursor: default; }
button.row:hover:not(.static) { background: var(--sunken); }
.row .grow { flex: 1; min-width: 0; }
.row .title-line { font-weight: 600; overflow-wrap: anywhere; }
.row .right { text-align: right; flex-shrink: 0; }
.row .chev { color: var(--accent); flex-shrink: 0; }
@media (max-width: 380px) {
  .row { flex-wrap: wrap; }
  .row .right { text-align: left; width: 100%; padding-left: 52px; }
}

.tile {
  width: 40px; height: 40px; border-radius: var(--radius-tile); flex-shrink: 0;
  display: grid; place-items: center; font-weight: 700; font-size: 14px;
  font-family: var(--font-rounded);
}
.tile.money { background: var(--money-soft); color: var(--money); }
.tile.cash { background: var(--cash-soft); color: var(--cash); }
.tile.ranking { background: var(--ranking-soft); color: var(--ranking); }
.tile.neutral { background: var(--sunken); color: var(--muted); }

.avatar {
  width: 40px; height: 40px; border-radius: var(--radius-pill); flex-shrink: 0;
  display: grid; place-items: center; background: var(--sunken); color: var(--text);
  font-weight: 700; font-size: 14px;
}

/* ─── Aktionen (accent = tippbar) ───────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-tight);
  min-height: var(--control-action); padding: 0 var(--space-page);
  border-radius: var(--radius-action); border: 0; cursor: pointer;
  font-size: 17px; font-weight: 600; line-height: 22px; width: 100%;
}
.btn.primary { background: var(--accent); color: var(--on-accent); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.secondary { background: var(--soft); color: var(--accent); }
.btn.quiet { background: transparent; color: var(--accent); }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.btn:disabled, .btn[aria-disabled="true"] {
  background: var(--disabled); color: var(--on-disabled); cursor: not-allowed; filter: none; border-color: transparent;
}
.btn.inline { width: auto; min-height: var(--control-touch); padding: 0 var(--space-inset); font-size: 15px; }
.link-btn { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; font-weight: 600; min-height: var(--control-touch); }
.actions { display: flex; flex-direction: column; gap: var(--space-tight); }
.actions.inline { flex-direction: row; flex-wrap: wrap; }
.actions.inline .btn { width: auto; flex: 1; }

/* Chips: Filter, tippbar → accent nur im aktiven Zustand als Rahmen/Text */
.chips { display: flex; flex-wrap: wrap; gap: var(--space-tight); }
.chip {
  min-height: 36px; padding: 0 14px; border-radius: var(--radius-pill);
  background: var(--sunken); border: 1px solid transparent; color: var(--text);
  font-size: 15px; font-weight: 500; cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
}
.chip[aria-pressed="true"] { background: var(--soft); color: var(--accent); border-color: var(--accent); }
.chip .x { font-weight: 700; }

/* ─── Formulare ─────────────────────────────────────────────── */
.field { display: block; margin-bottom: var(--space-inset); }
.field > span { display: block; font-size: 15px; font-weight: 500; margin-bottom: var(--space-micro); }
.field input, .field select, .field textarea {
  width: 100%; min-height: var(--control-field); padding: 12px 14px;
  border: 1px solid var(--line); border-radius: var(--radius-field);
  background: var(--card); color: var(--text); font: inherit;
}
.field textarea { min-height: 88px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--soft); }
.field .hint { font-size: 13px; color: var(--muted); margin-top: var(--space-micro); }
.field.amount input { font-family: var(--font-rounded); font-size: 32px; font-weight: 700; min-height: 68px; font-variant-numeric: tabular-nums; }
.segment { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-tight); }
.segment button {
  min-height: var(--control-touch); border-radius: var(--radius-field); border: 1px solid var(--line);
  background: var(--card); cursor: pointer; font-weight: 500;
}
.segment button[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); background: var(--soft); }

/* ─── Feedback (Regel 14, 15) ───────────────────────────────── */
.feedback { border-radius: var(--radius-card); padding: var(--space-inset); border: 1px solid var(--line); background: var(--card); }
.feedback.error { border-color: var(--danger); }
.feedback.error .headline { color: var(--danger); }
.feedback.notice { background: var(--sunken); }
.feedback p { margin: var(--space-micro) 0 0; }
.empty { text-align: center; padding: var(--space-spacious) var(--space-inset); color: var(--muted); }
.empty .headline { color: var(--text); }
.loading { color: var(--muted); padding: var(--space-inset) 0; }

/* ─── Details (Regel 12: nur Nachschlagbares einklappen) ────── */
details { border: 1px solid var(--line); border-radius: var(--radius-card); background: var(--card); }
details summary { cursor: pointer; padding: var(--space-related) var(--space-inset); font-weight: 600; min-height: var(--control-touch); display: flex; align-items: center; justify-content: space-between; list-style: none; }
details summary::-webkit-details-marker { display: none; }
details summary::after { content: "›"; color: var(--accent); font-size: 22px; transform: rotate(90deg); }
details[open] summary::after { transform: rotate(-90deg); }
details .inner { padding: 0 var(--space-inset) var(--space-inset); }

/* ─── Kopfzeile / Toolbar ───────────────────────────────────── */
.topbar { display: flex; align-items: center; gap: var(--space-related); margin-bottom: var(--space-inset); min-height: var(--control-touch); }
.topbar .back { color: var(--accent); background: none; border: 0; font-size: 17px; font-weight: 600; cursor: pointer; padding: 0; min-height: var(--control-touch); }
.topbar .spacer { flex: 1; }

/* ─── Glas: Tab-Dock und Aktions-Dock (genau diese beiden hier) ─ */
.dock {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--space-inset) + env(safe-area-inset-bottom));
  width: min(640px - 32px, calc(100vw - 32px));
  height: var(--control-dock);
  border-radius: var(--radius-pill);
  background: var(--glass-fill); border: 1px solid var(--glass-border);
  -webkit-backdrop-filter: blur(30px) saturate(1.8); backdrop-filter: blur(30px) saturate(1.8);
  display: grid; grid-auto-flow: column; align-items: stretch; z-index: 20;
  box-shadow: 0 8px 30px rgba(0,0,0,0.08);
}
.dock a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); font-size: 11px; font-weight: 600; text-decoration: none; border-radius: var(--radius-pill);
}
.dock a[aria-current="page"] { color: var(--accent); }
.dock a svg { width: 22px; height: 22px; }
.action-dock {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--control-dock) + var(--space-inset) * 2 + env(safe-area-inset-bottom));
  width: min(640px - 32px, calc(100vw - 32px));
  min-height: var(--control-action-dock); padding: var(--space-related);
  border-radius: var(--radius-feature);
  background: var(--glass-fill); border: 1px solid var(--glass-border);
  -webkit-backdrop-filter: blur(30px) saturate(1.8); backdrop-filter: blur(30px) saturate(1.8);
  z-index: 19; box-shadow: 0 8px 30px rgba(0,0,0,0.08);
}
@media (prefers-reduced-transparency: reduce) {
  .dock, .action-dock { background: var(--card); -webkit-backdrop-filter: none; backdrop-filter: none; border-color: var(--line); }
}

/* ─── Bewegung: Saldo zaehlt hoch (350 ms) ──────────────────── */
@keyframes countup { from { opacity: 0.4; } to { opacity: 1; } }
.counting { animation: countup 350ms ease-out; }
@media (prefers-reduced-motion: reduce) {
  .counting { animation-duration: 150ms; }
}

/* Karten zur Typwahl (Erstellen) */
.type-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-related); }
@media (max-width: 420px) { .type-grid { grid-template-columns: 1fr; } }
.type-card { text-align: left; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-card); padding: var(--space-inset); cursor: pointer; }
.type-card[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 3px var(--soft); }

/* Spielercode als Held */
.player-code { font-family: var(--font-rounded); font-size: 40px; letter-spacing: 4px; font-weight: 700; font-variant-numeric: tabular-nums; }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ─── Sheet (Glasfläche 3: fährt ein) ───────────────────────── */
dialog.sheet {
  border: 1px solid var(--line); border-radius: var(--radius-feature) var(--radius-feature) 0 0;
  background: var(--card); color: var(--text); padding: var(--space-inset) var(--space-page) calc(var(--space-section) + env(safe-area-inset-bottom));
  width: min(640px, 100vw); max-width: 100vw; max-height: 88vh; overflow: auto;
  margin: auto auto 0; box-shadow: 0 -8px 40px rgba(0,0,0,0.18);
  animation: sheet-in 260ms ease-out;
}
dialog.sheet::backdrop { background: rgba(0,0,0,0.38); }
@media (min-width: 700px) { dialog.sheet { border-radius: var(--radius-feature); margin: auto; } }
@keyframes sheet-in { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { dialog.sheet { animation: none; } }
.sheet-head { display: flex; align-items: center; gap: var(--space-related); margin-bottom: var(--space-related); }
.sheet-head .title { flex: 1; margin: 0; }
.sheet-close { min-height: var(--control-touch); padding: 0 8px; width: auto; flex: 0 0 auto; }

/* QR-Code und Scanner */
svg.qr { display: block; margin: 0 auto; width: min(240px, 70vw); height: auto; border-radius: 16px; }
.qr-wrap { background: #FFFFFF; padding: 12px; border-radius: 20px; align-self: center; }
.scanner { position: relative; border-radius: var(--radius-card); overflow: hidden; background: #000; aspect-ratio: 1 / 1; max-height: 50vh; margin: 0 auto; width: 100%; }
.scanner video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scan-frame { position: absolute; inset: 18%; border: 3px solid rgba(255,255,255,0.9); border-radius: 18px; box-shadow: 0 0 0 999px rgba(0,0,0,0.25); }

/* Avatar mit Bild, grosse Variante */
.avatar img { width: 100%; height: 100%; border-radius: inherit; object-fit: cover; display: block; }
.avatar.large { width: 64px; height: 64px; font-size: 22px; }
.avatar { overflow: hidden; }

/* Reiter (Spielstände / Verlauf) */
.tabs { display: flex; gap: var(--space-micro); border-bottom: 1px solid var(--line); margin-top: var(--space-section); align-items: flex-end; }
.tabs [role="tab"] { background: none; border: 0; border-bottom: 2px solid transparent; padding: 10px 12px; min-height: var(--control-touch); font: inherit; font-weight: 500; color: var(--muted); cursor: pointer; }
.tabs [role="tab"][aria-selected="true"] { color: var(--text); font-weight: 600; border-bottom-color: var(--accent); }
.tabs .spacer { flex: 1; }
.tabs .link-btn { margin-bottom: 10px; }

/* Personen mit Verwaltungsaktionen */
.person-actions { display: flex; gap: var(--space-tight); flex-wrap: wrap; justify-content: flex-end; }
.person-actions .btn { min-height: 36px; padding: 0 12px; font-size: 14px; width: auto; }
.list li .row.static .person-actions { margin-left: auto; }

/* Umschalter (Checkbox als Zeile) */
.toggle { display: flex; align-items: center; gap: var(--space-related); padding: var(--space-tight) 0; cursor: pointer; }
.toggle input { width: 22px; height: 22px; accent-color: var(--accent); flex-shrink: 0; }
.toggle .grow { flex: 1; }

/* Profil-Kopf */
.profile-head { display: flex; align-items: center; gap: var(--space-inset); padding: var(--space-inset); border-radius: var(--radius-card); background: var(--sunken); }
.faq details + details { margin-top: var(--space-tight); }
.faq p { margin: 0; }
.row.static.has-actions { flex-wrap: wrap; row-gap: var(--space-tight); }
.row.static.has-actions .grow { min-width: 0; flex: 1 1 140px; }
@media (max-width: 520px) { .row.static.has-actions .person-actions { flex-basis: 100%; justify-content: flex-start; padding-left: 52px; } }
