
:root {
  /* Oberflächen, hell */
  --bg: #f2ece4;
  --surface: #ffffff;
  --raised: #e9e1d7;
  --hover: #ddd2c5;
  --well: #e6ddd2;
  --field: #ffffff;
  --text: #2a1f31;
  --muted: #5f5366;
  --line: rgba(42, 31, 49, 0.16);
  --accent: #2fb3a3;
  --accent-hover: #46cdbc;
  --accent-ink: #0b2420;
  --accent-text: #11695f;
  --accent-soft: rgba(47, 179, 163, 0.14);
  --quiet-hover: rgba(42, 31, 49, 0.06);
  --danger: #b3261e;
  --danger-soft: rgba(179, 38, 30, 0.1);
  --warn: #7a5200;
  --warn-soft: rgba(255, 183, 0, 0.18);
  --shadow: 0 12px 32px rgba(42, 31, 49, 0.2);
  --panel-shadow: 0 -1px 0 rgba(42, 31, 49, 0.12), 0 -10px 28px rgba(42, 31, 49, 0.14);
  --dialog-shadow: 0 24px 64px rgba(42, 31, 49, 0.28);
  --overlay: rgba(42, 31, 49, 0.5);
  /* Spielbrett, Ablage und Stifte: in beiden Modi dunkler Kunststoff */
  --board-top: #2a1f31;
  --board-bottom: #1b1320;
  --tray: #1b1320;
  --hole: #0e0a11;
  --board-text: #f3ead8;
  --board-muted: #b9adc2;
  --peg-size: 28px;
  --key: 11px;
  --font: "Avenir Next", Avenir, Futura, "Century Gothic", "Segoe UI", system-ui, -apple-system, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #231a2b;
    --surface: #2e2238;
    --raised: #3b2d47;
    --hover: #4a3a59;
    --well: #1b1320;
    --field: #1b1320;
    --text: #f3ead8;
    --muted: #b9adc2;
    --line: rgba(243, 234, 216, 0.14);
    --accent-text: #46cdbc;
    --quiet-hover: rgba(243, 234, 216, 0.07);
    --danger: #ff9a8f;
    --danger-soft: rgba(255, 154, 143, 0.12);
    --warn: #ffd27a;
    --warn-soft: rgba(255, 210, 122, 0.12);
    --shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
    --panel-shadow: 0 -1px 0 rgba(243, 234, 216, 0.14), 0 -12px 32px rgba(0, 0, 0, 0.45);
    --dialog-shadow: 0 24px 64px rgba(0, 0, 0, 0.55);
    --overlay: rgba(12, 8, 15, 0.74);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  overflow-wrap: break-word;
  overscroll-behavior-y: none;
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
button { touch-action: manipulation; }
:focus-visible { outline: 3px solid var(--accent-text); outline-offset: 2px; }
#app { max-width: 560px; margin: 0 auto; padding: 12px 12px 0; }

/* ---------- Setup ---------- */
.setup { display: flex; flex-direction: column; gap: 22px; padding-bottom: 28px; }
.brand { padding-top: 20px; text-align: center; }
.brand-title { margin: 0; font-size: clamp(2.6rem, 13vw, 3.6rem); font-weight: 800; letter-spacing: -0.035em; line-height: 1; }
.brand-mark { display: flex; justify-content: center; align-items: center; gap: 14px; margin-top: 16px; }
.brand-mark .peg { --peg-size: 24px; }
.brand-claim { max-width: 32ch; margin: 14px auto 0; color: var(--muted); }
.group { display: flex; flex-direction: column; gap: 12px; }
.group + .group { padding-top: 20px; border-top: 1px solid var(--line); }
.group-title { margin: 0; font-size: 1rem; font-weight: 700; }
.group-note { margin: 0; font-size: 0.875rem; color: var(--muted); }
.modes { display: grid; gap: 10px; }
.mode { display: flex; flex-direction: column; gap: 4px; padding: 14px 16px; border: 1.5px solid var(--line); border-radius: 16px; background: var(--surface); text-align: left; cursor: pointer; }
.mode-title { font-size: 1.05rem; font-weight: 800; }
.mode-text { font-size: 0.9rem; color: var(--muted); }
.mode.is-selected { border-color: var(--accent); background: var(--accent-soft); }
.segmented { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; padding: 4px; border-radius: 16px; background: var(--well); }
.seg { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 10px 4px; border: 0; border-radius: 12px; background: transparent; font-weight: 700; cursor: pointer; }
.seg small { font-size: 0.75rem; font-weight: 500; color: var(--muted); }
.seg.is-selected { background: var(--accent); color: var(--accent-ink); }
.seg.is-selected small { color: var(--accent-ink); }
.fields { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.fields.is-two { grid-template-columns: 1fr; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 0.875rem; color: var(--muted); }
.field input, .field select { width: 100%; min-height: 46px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--field); color: var(--text); font-size: 1rem; }
.check { display: flex; align-items: flex-start; gap: 12px; cursor: pointer; }
.check input { flex: none; width: 22px; height: 22px; margin: 1px 0 0; accent-color: var(--accent); }
.check small { display: block; margin-top: 2px; font-size: 0.825rem; color: var(--muted); }
.setup-actions { display: grid; gap: 8px; }
@media (min-width: 520px) {
  .modes, .fields.is-two { grid-template-columns: 1fr 1fr; }
}

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 46px; padding: 10px 16px; border: 1px solid var(--line); border-radius: 14px; background: var(--raised); color: var(--text); font-weight: 700; cursor: pointer; }
.btn:hover:not(:disabled) { background: var(--hover); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary { border-color: transparent; background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-quiet { background: transparent; }
.btn-quiet:hover:not(:disabled) { background: var(--quiet-hover); }
.btn-icon { flex: none; width: 46px; padding: 0; }
.btn-text { align-self: center; min-height: 40px; padding: 6px 10px; border: 0; background: none; color: var(--muted); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }
.btn-text:hover:not(:disabled) { background: none; color: var(--text); }
.btn-round { flex: none; width: 46px; height: 46px; padding: 0; border-radius: 50%; font-size: 1.4rem; line-height: 1; }
.btn-block { width: 100%; }

/* ---------- Spiel-Layout ---------- */
.game { display: flex; flex-direction: column; gap: 12px; min-height: calc(100vh - 12px); min-height: calc(100dvh - 12px); }
.topbar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; }
.topbar .btn { min-height: 38px; padding: 6px 12px; font-size: 0.9rem; }
.topbar .btn:first-child { justify-self: start; }
.topbar .btn:last-child { justify-self: end; }
.topbar-title { font-weight: 800; letter-spacing: -0.01em; }
.status { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, auto); align-items: baseline; gap: 2px 12px; padding: 0 6px; }
.status-main { font-size: 1.05rem; font-weight: 800; }
.status-side { text-align: right; font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; }
.status-side b { color: var(--accent-text); }
.status-sub { grid-column: 1 / -1; font-size: 0.9rem; color: var(--muted); }

/* ---------- Brett ---------- */
.board { padding: 10px 6px 12px; border-radius: 22px; background: linear-gradient(180deg, var(--board-top) 0%, var(--board-bottom) 100%); color: var(--board-text); box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06), inset 0 -2px 0 rgba(0, 0, 0, 0.4), var(--shadow); }
.rows { display: flex; flex-direction: column; gap: 2px; }
.row { display: grid; grid-template-columns: 2.5rem auto auto; justify-content: center; align-items: center; column-gap: 16px; padding: 5px 8px; border-radius: 12px; scroll-margin: 90px 0 330px; }
.row-num { padding-right: 2px; text-align: right; font-size: 0.75rem; color: var(--board-muted); font-variant-numeric: tabular-nums; }
.row.is-active { background: rgba(47, 179, 163, 0.13); box-shadow: inset 0 0 0 1.5px rgba(47, 179, 163, 0.6); }
.row.is-pending { background: rgba(255, 210, 122, 0.08); box-shadow: inset 0 0 0 1.5px rgba(255, 210, 122, 0.55); }
.row.is-future { opacity: 0.4; }
.row.secret { margin-bottom: 10px; padding-top: 10px; padding-bottom: 10px; border-radius: 14px; background: rgba(0, 0, 0, 0.28); box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.5); }
.row.secret .keys { visibility: hidden; }
.pegs { position: relative; display: flex; gap: 6px; }
.shield { position: absolute; inset: -5px; display: grid; place-items: center; border-radius: 12px; background: repeating-linear-gradient(135deg, #4b3c58 0 6px, #3e3149 6px 12px); box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.14), 0 3px 8px rgba(0, 0, 0, 0.45); color: var(--board-text); font-size: 0.8rem; font-weight: 700; }

/* ---------- Farbstifte ---------- */
.peg {
  --c: #888;
  --ink: #fff;
  display: inline-grid;
  place-items: center;
  flex: none;
  width: var(--peg-size);
  height: var(--peg-size);
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background:
    radial-gradient(circle at 35% 30%, rgba(255, 255, 255, 0.65) 0 8%, rgba(255, 255, 255, 0) 40%),
    radial-gradient(circle at 50% 125%, rgba(0, 0, 0, 0.35) 0 45%, rgba(0, 0, 0, 0) 70%),
    var(--c);
  box-shadow: 0 2px 3px rgba(0, 0, 0, 0.5);
  color: var(--ink);
  font-size: 0.7rem;
  font-weight: 800;
  line-height: 1;
  user-select: none;
  -webkit-user-select: none;
}
.peg.is-empty { background: var(--hole); box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.9), 0 1px 0 rgba(255, 255, 255, 0.06); }
.c0 { --c: #e53935; --ink: #ffffff; }
.c1 { --c: #fdd835; --ink: #3a2f00; }
.c2 { --c: #43a047; --ink: #ffffff; }
.c3 { --c: #1e88e5; --ink: #ffffff; }
.c4 { --c: #fb8c00; --ink: #2b1700; }
.c5 { --c: #8e24aa; --ink: #ffffff; }
.c6 { --c: #00acc1; --ink: #00262b; }
.c7 { --c: #f06292; --ink: #3b0016; }
button.peg { cursor: pointer; }
button.peg:hover:not(:disabled) { filter: brightness(1.1); }
button.peg:disabled { opacity: 0.25; cursor: not-allowed; }

/* ---------- Bewertungsstifte ---------- */
.keys { display: grid; grid-template-columns: repeat(2, var(--key)); gap: 4px; }
.keys.cols-3 { grid-template-columns: repeat(3, var(--key)); }
.key { width: var(--key); height: var(--key); border-radius: 50%; background: var(--hole); box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.9); }
.key.is-black { background: radial-gradient(circle at 35% 30%, #7a7a7a 0 10%, #161616 55%); box-shadow: 0 0 0 1.5px rgba(243, 234, 216, 0.7); }
.key.is-white { background: radial-gradient(circle at 35% 30%, #ffffff 0 25%, #d9d4cc 75%); box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.28), 0 1px 2px rgba(0, 0, 0, 0.5); }
.keys.is-pending .key.is-black, .keys.is-pending .key.is-white { opacity: 0.55; }

/* ---------- Eingabe-Panel ---------- */
.panel { position: sticky; bottom: 0; z-index: 5; display: flex; flex-direction: column; gap: 12px; max-height: calc(100vh - 120px); max-height: calc(100dvh - 120px); margin: auto -12px 0; padding: 14px 14px calc(16px + env(safe-area-inset-bottom)); overflow-y: auto; overscroll-behavior: contain; border-radius: 22px 22px 0 0; background: var(--surface); box-shadow: var(--panel-shadow); }
.panel-title { margin: 0; text-align: center; font-size: 1.125rem; font-weight: 800; }
.panel-hint { margin: -6px 0 0; text-align: center; font-size: 0.875rem; color: var(--muted); }
.kbd-hint { display: none; }
@media (hover: hover) and (pointer: fine) { .kbd-hint { display: block; } }
.draft { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 52px); justify-content: center; gap: 10px; }
.draft .peg { width: 100%; height: auto; aspect-ratio: 1; font-size: 1rem; }
.palette { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 46px); justify-content: center; gap: 7px; padding: 10px; border-radius: 18px; background: var(--tray); box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.5); }
.palette .peg { width: 100%; height: auto; aspect-ratio: 1; font-size: 0.95rem; }
.panel-actions { display: flex; gap: 8px; }
.panel-actions .btn-primary { flex: 1; }

/* ---------- Bewerten (Mensch gegen Mensch) ---------- */
.compare { display: grid; gap: 10px; padding: 12px; border-radius: 18px; background: var(--tray); color: var(--board-text); box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.5); }
.compare-row { display: grid; grid-template-columns: 4.25rem auto; justify-content: center; align-items: center; gap: 10px; }
.compare-label { font-size: 0.875rem; color: var(--board-muted); }
.compare .pegs { gap: 8px; }
.compare .peg { --peg-size: 38px; font-size: 0.9rem; }
.steppers { display: grid; gap: 8px; }
.stepper { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 8px 8px 14px; border-radius: 16px; background: var(--raised); }
.stepper-label { display: flex; align-items: center; gap: 12px; font-weight: 700; }
.stepper-label small { display: block; font-size: 0.8rem; font-weight: 500; color: var(--muted); }
.stepper-label .key { --key: 18px; flex: none; }
.stepper-controls { display: flex; align-items: center; gap: 8px; }
.stepper-value { min-width: 1.5em; text-align: center; font-size: 1.35rem; font-weight: 800; font-variant-numeric: tabular-nums; }

/* ---------- Meldungen und Ergebnisse ---------- */
.msg { margin: 0; padding: 10px 14px; border-radius: 12px; font-size: 0.9rem; }
.msg-error { background: var(--danger-soft); color: var(--danger); }
.msg-warn { background: var(--warn-soft); color: var(--warn); }
.result-title { margin: 0; text-align: center; font-size: 1.6rem; font-weight: 800; letter-spacing: -0.02em; }
.result-text { margin: 0; text-align: center; }
.result-score { margin: 0; text-align: center; font-size: 1.25rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.result-score b { color: var(--accent-text); }
.match { display: flex; flex-direction: column; gap: 16px; padding: 22px 16px; border-radius: 22px; background: var(--surface); box-shadow: var(--shadow); }
.table-wrap { overflow-x: auto; }
.history { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.history th, .history td { padding: 8px 5px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.history th { font-weight: 600; color: var(--muted); }
.history .num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Overlays ---------- */
.overlay { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px; background: var(--overlay); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); }
.overlay.is-solid { background: var(--bg); -webkit-backdrop-filter: none; backdrop-filter: none; }
.dialog { display: flex; flex-direction: column; gap: 14px; width: 100%; max-width: 440px; max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px); padding: 22px 20px; overflow-y: auto; border-radius: 22px; background: var(--surface); box-shadow: var(--dialog-shadow); }
.dialog p { margin: 0; }
.dialog-title { margin: 0; font-size: 1.5rem; font-weight: 800; letter-spacing: -0.02em; }
.confirm-text { font-size: 1.05rem; font-weight: 600; }
.handover { text-align: center; }
.handover-round { color: var(--muted); }
.handover-name { margin: 0; font-size: clamp(2rem, 10vw, 2.8rem); font-weight: 800; letter-spacing: -0.03em; line-height: 1.05; }
.rules { display: flex; flex-direction: column; gap: 10px; line-height: 1.5; }
.rules h3 { margin: 6px 0 0; font-size: 1rem; color: var(--accent-text); }
.rules p, .rules ul { margin: 0; }
.rules ul { padding-left: 1.2em; }

/* ---------- Aufdecken am Rundenende ---------- */
@keyframes peg-pop { from { transform: scale(0.3); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.secret.is-revealed .peg { animation: peg-pop 0.42s cubic-bezier(0.2, 0.9, 0.3, 1.25) both; }
.secret.is-revealed .peg:nth-child(2) { animation-delay: 0.07s; }
.secret.is-revealed .peg:nth-child(3) { animation-delay: 0.14s; }
.secret.is-revealed .peg:nth-child(4) { animation-delay: 0.21s; }
.secret.is-revealed .peg:nth-child(5) { animation-delay: 0.28s; }
.secret.is-revealed .peg:nth-child(6) { animation-delay: 0.35s; }
@media (prefers-reduced-motion: reduce) { .secret.is-revealed .peg { animation: none; } }

/* ---------- Selbsttest (#test) ---------- */
.test-banner { position: fixed; top: 8px; left: 8px; right: 8px; z-index: 100; padding: 10px 14px; border-radius: 12px; font-weight: 700; font-size: 0.9rem; color: #ffffff; }
.test-banner.is-ok { background: #1f6f4a; }
.test-banner.is-fail { background: #8e1f1f; }
