:root {
  --bg: #f3ede1;
  --bg-2: #ebe3d3;
  --ink: #1f2a26;
  --ink-2: #5b655f;
  --ink-3: #8b928b;
  --line: #d8cdb8;
  --card: #fffcf5;
  --felt: #2f6a50;
  --felt-2: #24563f;
  --felt-ink: #eef6ef;
  --brass: #b07d1c;
  --brass-soft: #f1dfb4;
  --accent: #c2410c;
  --die: #fbf8f1;
  --die-edge: #d9d1c0;
  --pip: #1d2a26;
  --good: #2f7d4f;
  --pad-rule: #c9d8e6;
  --pad-margin: #e3a39b;
  --shadow: 0 1px 2px rgb(40 30 10 / .08), 0 8px 24px rgb(40 30 10 / .08);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0c1714; --bg-2: #10201b; --ink: #e9eee9; --ink-2: #a5b2ab; --ink-3: #6f7d76;
    --line: #23352f; --card: #13221d; --felt: #174535; --felt-2: #10352a; --felt-ink: #e9f3ec;
    --brass: #e0b04c; --brass-soft: #3a2f16; --accent: #ff8a5b; --die: #f3eee2; --die-edge: #b9b09e;
    --pip: #18221f; --good: #6fd39a; --pad-rule: #1f3a46; --pad-margin: #5a2e2a;
    --shadow: 0 1px 2px rgb(0 0 0 / .4), 0 10px 30px rgb(0 0 0 / .35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0c1714; --bg-2: #10201b; --ink: #e9eee9; --ink-2: #a5b2ab; --ink-3: #6f7d76;
  --line: #23352f; --card: #13221d; --felt: #174535; --felt-2: #10352a; --felt-ink: #e9f3ec;
  --brass: #e0b04c; --brass-soft: #3a2f16; --accent: #ff8a5b; --die: #f3eee2; --die-edge: #b9b09e;
  --pip: #18221f; --good: #6fd39a; --pad-rule: #1f3a46; --pad-margin: #5a2e2a;
  --shadow: 0 1px 2px rgb(0 0 0 / .4), 0 10px 30px rgb(0 0 0 / .35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}
button, input { font: inherit; color: inherit; }
.serif { font-family: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif; }

/* ---------- Kopf ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; max-width: 1240px; margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; }
.brand svg { width: 30px; height: 30px; }
.brand svg circle { fill: var(--pip); }
.brand .b-die { fill: var(--die); stroke: var(--brass); stroke-width: 2; }
.brand span { font: italic 700 1.45rem/1 "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif; letter-spacing: .01em; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.code-badge {
  font: 700 .95rem/1 ui-monospace, "SF Mono", Menlo, Consolas, monospace; letter-spacing: .18em;
  padding: 7px 10px 7px 12px; border-radius: 999px; background: var(--brass-soft); color: var(--ink);
  border: 1px solid color-mix(in srgb, var(--brass) 45%, transparent); cursor: pointer;
}
.icon-btn {
  width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--card); display: grid; place-items: center; cursor: pointer;
}
.icon-btn svg { width: 18px; height: 18px; }

main { max-width: 1240px; margin: 0 auto; padding: 0 16px 40px; }

/* ---------- Buttons & Felder ---------- */
.btn {
  appearance: none; border: 0; border-radius: 12px; padding: 12px 18px; cursor: pointer;
  font-weight: 650; background: var(--card); color: var(--ink); border: 1px solid var(--line);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 46px;
  transition: transform .08s, background .2s, opacity .2s;
}
.btn:active:not(:disabled) { transform: translateY(1px) scale(.99); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: #fff; border-color: transparent; }
.btn.brass { background: var(--brass); color: #1b1407; border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }
.field { display: grid; gap: 6px; }
.field label { font-size: .85rem; color: var(--ink-2); font-weight: 600; }
.input {
  width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg); min-height: 46px;
}
.input:focus, .btn:focus-visible, .cell:focus-visible, .die:focus-visible { outline: 3px solid color-mix(in srgb, var(--brass) 60%, transparent); outline-offset: 2px; }
.input.code { text-transform: uppercase; letter-spacing: .4em; font: 700 1.4rem/1 ui-monospace, Menlo, monospace; text-align: center; }
.muted { color: var(--ink-2); }
.small { font-size: .85rem; }
.err { color: var(--accent); font-size: .9rem; min-height: 1.2em; }

/* ---------- Startseite ---------- */
.hero { display: grid; gap: 28px; padding: 16px 0 8px; grid-template-columns: 1.1fr 1fr; align-items: center; }
.hero h1 { font: italic 800 clamp(2.6rem, 7vw, 4.6rem)/.95 "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif; margin: 0 0 14px; letter-spacing: -.01em; }
.hero h1 em { color: var(--brass); font-style: italic; }
.hero p.lead { font-size: 1.1rem; color: var(--ink-2); max-width: 30rem; margin: 0; }
.hero-dice { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 26px; }
.hero-dice .die { --s: 54px; cursor: default; }
.hero-dice .die:nth-child(odd) { transform: rotate(-6deg); }
.hero-dice .die:nth-child(even) { transform: rotate(5deg) translateY(4px); }
.cards { display: grid; gap: 14px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.card h2 { margin: 0 0 4px; font-size: 1.15rem; }
.card p { margin: 0 0 14px; }
.card form { display: grid; gap: 12px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* ---------- Lobby ---------- */
.lobby { display: grid; gap: 18px; grid-template-columns: 1fr 1fr; padding-top: 8px; }
.share-code {
  font: 800 clamp(2.8rem, 12vw, 4.5rem)/1 ui-monospace, Menlo, monospace; letter-spacing: .22em;
  text-align: center; padding: 18px 0 14px; color: var(--ink);
}
.player-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.player-list li { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 12px; background: var(--bg); border: 1px solid var(--line); }
.avatar { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 800; font-size: .9rem; flex: none; position: relative; }
.avatar.sm { width: 22px; height: 22px; font-size: .7rem; }
.avatar .dot { position: absolute; right: -2px; bottom: -2px; width: 10px; height: 10px; border-radius: 50%; background: var(--ink-3); border: 2px solid var(--card); }
.avatar .dot.on { background: #3ccf6e; }
.tag { font-size: .72rem; font-weight: 700; padding: 3px 8px; border-radius: 999px; background: var(--brass-soft); color: var(--ink); }
.spacer { flex: 1; }
.link-btn { background: none; border: 0; color: var(--ink-2); cursor: pointer; text-decoration: underline; padding: 4px; }

/* ---------- Spiel ---------- */
.game { display: grid; gap: 18px; grid-template-columns: minmax(320px, 420px) 1fr; align-items: start; }
.table {
  position: sticky; top: 8px; z-index: 5;
  background: radial-gradient(120% 90% at 30% 10%, var(--felt) 0%, var(--felt-2) 75%);
  color: var(--felt-ink); border-radius: 20px; padding: 16px; box-shadow: var(--shadow);
  border: 1px solid color-mix(in srgb, var(--brass) 30%, transparent);
}
.turn-line { display: flex; align-items: center; gap: 10px; min-height: 34px; }
.turn-line strong { font-size: 1.05rem; }
.turn-line .rolls { margin-left: auto; display: flex; gap: 5px; }
.turn-line .rolls i { width: 10px; height: 10px; border-radius: 50%; background: color-mix(in srgb, var(--felt-ink) 85%, transparent); display: block; }
.turn-line .rolls i.used { background: transparent; border: 1.5px solid color-mix(in srgb, var(--felt-ink) 45%, transparent); }
.dice { display: flex; justify-content: center; gap: clamp(8px, 2.6vw, 14px); padding: 22px 0 16px; }
.die {
  --s: clamp(48px, 14vw, 62px);
  width: var(--s); height: var(--s); border-radius: 22%; border: 0; padding: 0;
  background: linear-gradient(145deg, var(--die), color-mix(in srgb, var(--die) 82%, var(--die-edge)));
  box-shadow: inset 0 -3px 0 var(--die-edge), 0 4px 10px rgb(0 0 0 / .28);
  display: grid; grid-template: repeat(3, 1fr) / repeat(3, 1fr); padding: calc(var(--s) * .13); flex: none;
  cursor: pointer; position: relative; transition: transform .18s, box-shadow .18s;
}
.die .pip { width: 72%; aspect-ratio: 1; border-radius: 50%; background: var(--pip); place-self: center; visibility: hidden; }
.die.blank { background: color-mix(in srgb, var(--felt-ink) 10%, transparent); box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--felt-ink) 25%, transparent); cursor: default; }
.die.blank::after { content: "?"; position: absolute; inset: 0; display: grid; place-items: center; font-weight: 800; color: color-mix(in srgb, var(--felt-ink) 50%, transparent); font-size: 1.3rem; }
.die.held { transform: translateY(-8px); box-shadow: inset 0 -3px 0 var(--die-edge), 0 0 0 3px var(--brass), 0 10px 18px rgb(0 0 0 / .35); }
.die.held::before { content: "gehalten"; position: absolute; left: 50%; bottom: -24px; transform: translateX(-50%); font-size: .62rem; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--brass); white-space: nowrap; }
.die:disabled { cursor: default; }
.die.rolling { animation: tumble .62s cubic-bezier(.3,.7,.3,1); }
@keyframes tumble {
  0% { transform: translateY(-18px) rotate(-200deg) scale(.85); }
  60% { transform: translateY(3px) rotate(14deg) scale(1.03); }
  100% { transform: none; }
}
.f1 .p5, .f2 .p1, .f2 .p9, .f3 .p1, .f3 .p5, .f3 .p9,
.f4 .p1, .f4 .p3, .f4 .p7, .f4 .p9, .f5 .p1, .f5 .p3, .f5 .p5, .f5 .p7, .f5 .p9,
.f6 .p1, .f6 .p3, .f6 .p4, .f6 .p6, .f6 .p7, .f6 .p9 { visibility: visible; }
.f1 .pip.p5 { background: var(--accent); }
.controls { display: grid; gap: 10px; }
.controls .btn { min-height: 52px; font-size: 1.05rem; }
.hint { font-size: .85rem; text-align: center; min-height: 1.3em; opacity: .85; }
.joker-banner {
  background: var(--brass); color: #1b1407; border-radius: 12px; padding: 10px 12px; font-weight: 700;
  text-align: center; animation: pulse 1.6s ease-in-out infinite; margin-bottom: 10px;
}
@keyframes pulse { 50% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--brass) 30%, transparent); } }
.confirm { display: flex; gap: 8px; }
.confirm .btn { flex: 1; }

.log { margin-top: 14px; display: grid; gap: 6px; font-size: .85rem; max-height: 170px; overflow: auto; }
.log div { display: flex; gap: 8px; align-items: baseline; color: color-mix(in srgb, var(--felt-ink) 82%, transparent); }
.log div:first-child { color: var(--felt-ink); font-weight: 600; }
.log time { opacity: .55; font-variant-numeric: tabular-nums; flex: none; }

/* ---------- Kniffelblock ---------- */
.pad-wrap { background: var(--card); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); overflow: hidden; }
.pad-head { display: flex; align-items: baseline; gap: 10px; padding: 14px 16px 10px; border-bottom: 2px solid var(--pad-margin); }
.pad-head h2 { margin: 0; font: italic 700 1.3rem/1 "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif; }
.pad-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.pad { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
.pad th, .pad td { border-bottom: 1px solid var(--pad-rule); padding: 0; height: 40px; }
.pad thead th { height: auto; padding: 10px 6px; vertical-align: bottom; border-bottom: 2px solid var(--line); font-size: .85rem; }
.pad th.cat {
  text-align: left; font-weight: 600; padding: 0 12px; position: sticky; left: 0; background: var(--card); z-index: 1;
  white-space: nowrap; border-right: 2px solid var(--pad-margin); min-width: 128px; width: 170px;
}
.pad th.cat small { display: block; font-weight: 400; font-size: .7rem; color: var(--ink-3); line-height: 1.1; }
.pad .ph { text-align: center; min-width: 62px; }
.pad .ph .avatar { margin: 0 auto 4px; }
.pad .ph .nm { display: block; max-width: 86px; margin: 0 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pad .ph.active .nm { color: var(--accent); font-weight: 800; }
.pad td { text-align: center; min-width: 62px; }
.pad td.activecol, .pad th.activecol { background: color-mix(in srgb, var(--accent) 7%, transparent); }
.pad tr.sum th, .pad tr.sum td { background: var(--bg-2); font-weight: 700; height: 34px; font-size: .9rem; }
.pad tr.sum th.cat { background: var(--bg-2); }
.pad tr.total th, .pad tr.total td { font-size: 1.1rem; font-weight: 800; height: 48px; border-bottom: 0; background: var(--brass-soft); }
.pad tr.total th.cat { background: var(--brass-soft); }
.pad tr.gap td, .pad tr.gap th { height: 8px; border: 0; background: var(--bg-2); }
.val { font-size: 1.05rem; font-weight: 650; }
.val.zero { color: var(--ink-3); text-decoration: line-through; font-weight: 400; }
.val.fresh { animation: ink .9s ease-out; }
@keyframes ink { 0% { color: var(--accent); transform: scale(1.5); } 100% { transform: none; } }
.cell {
  width: 100%; height: 100%; min-height: 40px; border: 0; background: transparent; cursor: default;
  color: var(--ink-3); font-weight: 500; font-size: .95rem; position: relative;
}
.cell.mine { cursor: pointer; color: var(--ink-2); }
.cell.mine:hover { background: color-mix(in srgb, var(--brass) 14%, transparent); }
.cell.zero { opacity: .55; }
.cell.best { color: var(--good); font-weight: 800; }
.cell.best::after { content: "★"; font-size: .65rem; position: absolute; top: 3px; right: 5px; color: var(--brass); }
.cell.sel { background: var(--brass) !important; color: #1b1407 !important; font-weight: 800; border-radius: 6px; }
.bonus-prog { font-size: .7rem; color: var(--ink-3); font-weight: 500; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; z-index: 50;
  box-shadow: var(--shadow); max-width: calc(100% - 32px); font-weight: 600; text-align: center;
}

/* ---------- Sieger ---------- */
#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 60; }
.win-overlay {
  position: fixed; inset: 0; z-index: 55; display: grid; place-items: center; padding: 16px;
  background: color-mix(in srgb, var(--bg) 70%, transparent); backdrop-filter: blur(6px);
  animation: fade .4s ease-out;
}
@keyframes fade { from { opacity: 0; } }
.win-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 24px; box-shadow: var(--shadow);
  padding: 22px 22px 18px; width: min(440px, 100%); text-align: center; max-height: calc(100dvh - 32px); overflow: auto;
}
.trophy { width: 170px; height: 190px; margin: -6px auto 4px; display: block; animation: drop 1s cubic-bezier(.2,1.4,.4,1) both; }
@keyframes drop { 0% { transform: translateY(-80px) scale(.6) rotate(-8deg); opacity: 0; } 100% { transform: none; opacity: 1; } }
.trophy .shine { animation: shine 2.4s ease-in-out infinite 1s; transform-origin: center; }
@keyframes shine { 0%, 100% { opacity: .2; } 50% { opacity: .9; } }
.trophy .spark { animation: twinkle 1.6s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
.trophy .spark:nth-of-type(2) { animation-delay: .5s; }
.trophy .spark:nth-of-type(3) { animation-delay: 1s; }
@keyframes twinkle { 0%, 100% { transform: scale(.3); opacity: .2; } 50% { transform: scale(1); opacity: 1; } }
.win-card h2 { font: italic 800 2rem/1.05 "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif; margin: 6px 0 4px; }
.win-card .pts { color: var(--ink-2); margin-bottom: 14px; }
.ranking { list-style: none; margin: 0 0 16px; padding: 0; display: grid; gap: 6px; text-align: left; }
.ranking li { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 10px; background: var(--bg); }
.ranking li b { margin-left: auto; font-variant-numeric: tabular-nums; }
.ranking .place { width: 1.4em; font-weight: 800; color: var(--ink-3); }

/* ---------- Responsiv ---------- */
@media (max-width: 900px) {
  .hero, .lobby { grid-template-columns: 1fr; }
  .game { grid-template-columns: 1fr; }
  .table { top: 0; border-radius: 0 0 20px 20px; margin: 0 -16px; padding: 10px 14px 12px; }
  .dice { padding: 12px 0 18px; }
  .log { display: none; }
  .log-mobile { display: grid !important; }
}
@media (max-width: 420px) {
  .pad th.cat { min-width: 104px; padding: 0 8px; font-size: .9rem; }
  .pad td, .pad .ph { min-width: 50px; }
  .controls .btn { min-height: 48px; }
}
.log-mobile { display: none; margin-top: 14px; }
.log-mobile .log { display: grid; color: var(--ink-2); max-height: none; }
.log-mobile .log div { color: var(--ink-2); }
.log-mobile .log div:first-child { color: var(--ink); }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition: none !important; }
}
a.btn { text-decoration: none; }

.win-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.win-actions .btn.primary { grid-column: 1 / -1; }
.win-actions .btn.ghost { border-color: var(--line); }
.ranking li span:not(.place):not(.avatar) { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar { line-height: 1; overflow: hidden; }

.reclaim-box { display: grid; gap: 6px; margin-top: 12px; padding: 12px; border-radius: 12px; border: 1px dashed currentColor; text-align: left; }
.reclaim-box .small { opacity: .8; }
.reclaim-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.btn.reclaim { min-height: 40px; padding: 6px 12px 6px 8px; text-decoration: none; background: var(--card); color: var(--ink); }
.btn.reclaim .tag { margin-left: 2px; }
