:root {
  --bg: #f2ebdd;
  --bg-2: #e9dfcc;
  --ink: #241b12;
  --ink-2: #6b5d4c;
  --ink-3: #9a8b77;
  --line: #ddd0b8;
  --card: #fffaf0;
  --accent: #a8321f;
  --accent-ink: #fff;
  --brass: #a87518;
  --brass-soft: #f0e0b8;
  --good: #2f7d4f;
  --wood-1: #e6c493;
  --wood-2: #c4914f;
  --wood-edge: #8a5a2b;
  --inlay: #4a2f17;
  --grain: .22;
  --mill: #f4c64e;
  --st-w1: #ffffff; --st-w2: #e8dfcf; --st-w-edge: #a8987c;
  --st-b1: #57514b; --st-b2: #141210; --st-b-edge: #000;
  --shadow: 0 1px 2px rgb(40 25 10 / .08), 0 10px 30px rgb(40 25 10 / .10);
  --radius: 16px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16120e; --bg-2: #1d1812; --ink: #efe6d6; --ink-2: #b5a68f; --ink-3: #7c6f5d;
    --line: #362c21; --card: #211b15; --accent: #ff7a5c; --accent-ink: #1b0d08; --brass: #e2b257; --brass-soft: #3b2f17;
    --good: #6fd39a; --wood-1: #6e4626; --wood-2: #3f2613; --wood-edge: #2a190c; --inlay: #e8cf9e; --grain: .35;
    --mill: #ffd86b;
    --shadow: 0 1px 2px rgb(0 0 0 / .4), 0 12px 34px rgb(0 0 0 / .4);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #16120e; --bg-2: #1d1812; --ink: #efe6d6; --ink-2: #b5a68f; --ink-3: #7c6f5d;
  --line: #362c21; --card: #211b15; --accent: #ff7a5c; --accent-ink: #1b0d08; --brass: #e2b257; --brass-soft: #3b2f17;
  --good: #6fd39a; --wood-1: #6e4626; --wood-2: #3f2613; --wood-edge: #2a190c; --inlay: #e8cf9e; --grain: .35;
  --mill: #ffd86b;
  --shadow: 0 1px 2px rgb(0 0 0 / .4), 0 12px 34px rgb(0 0 0 / .4);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background:
    radial-gradient(1200px 600px at 85% -10%, color-mix(in srgb, var(--brass) 10%, transparent), transparent 60%),
    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, select { font: inherit; color: inherit; }

/* ---------- Kopf ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; max-width: 1180px; margin: 0 auto; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; }
.brand img { display: block; }
.brand span { font: italic 700 1.55rem/1 var(--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: 8px 10px 8px 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; padding: 0; }
.icon-btn svg { width: 18px; height: 18px; }
main { max-width: 1180px; margin: 0 auto; padding: 0 16px 48px; }

/* ---------- Buttons & Felder ---------- */
.btn {
  appearance: none; border-radius: 12px; padding: 11px 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; text-decoration: none;
  transition: transform .08s, background .2s, opacity .2s, border-color .2s;
}
.btn:hover:not(:disabled) { border-color: color-mix(in srgb, var(--ink) 30%, var(--line)); }
.btn:active:not(:disabled) { transform: translateY(1px) scale(.99); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.brass { background: var(--brass); color: #1b1407; border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }
.btn.sm { min-height: 38px; padding: 7px 12px; font-size: .9rem; }
.btn svg { width: 18px; height: 18px; flex: none; }
.field { display: grid; gap: 6px; }
.field > label, .label { font-size: .82rem; color: var(--ink-2); font-weight: 650; letter-spacing: .01em; }
.input { width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); min-height: 46px; }
.input:focus-visible, .btn:focus-visible, .seg button:focus-visible, .hit:focus-visible, .icon-btn: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; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 4px; border-radius: 12px; background: var(--bg); border: 1px solid var(--line); }
.seg button { border: 0; background: transparent; border-radius: 9px; padding: 8px 6px; cursor: pointer; font-weight: 600; font-size: .92rem; color: var(--ink-2); display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.seg button[aria-pressed="true"] { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgb(0 0 0 / .12); }
.chk { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; font-size: .92rem; }
.chk input { width: 18px; height: 18px; margin: 2px 0 0; accent-color: var(--accent); flex: none; }
.chk small { display: block; color: var(--ink-2); font-size: .8rem; }

.mini { width: 16px; height: 16px; border-radius: 50%; display: inline-block; flex: none; vertical-align: -3px; }
.mini.w { background: radial-gradient(circle at 35% 30%, var(--st-w1), var(--st-w2) 70%); box-shadow: inset 0 0 0 1px var(--st-w-edge); }
.mini.b { background: radial-gradient(circle at 35% 30%, var(--st-b1), var(--st-b2) 70%); box-shadow: inset 0 0 0 1px #000; }
.mini.r { background: conic-gradient(var(--st-w2) 0 50%, var(--st-b2) 0); box-shadow: inset 0 0 0 1px var(--st-w-edge); }

/* ---------- Startseite ---------- */
.hero { display: grid; gap: 34px; padding: 14px 0 6px; grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr); align-items: center; }
.hero h1 { font: italic 800 clamp(2.5rem, 6.4vw, 4.4rem)/.98 var(--serif); margin: 0 0 16px; letter-spacing: -.01em; }
.hero h1 em { color: var(--accent); }
.hero .lead { font-size: 1.08rem; color: var(--ink-2); max-width: 31rem; margin: 0 0 22px; }
.hero-board { max-width: 460px; }
.hero-board .board { filter: drop-shadow(0 18px 30px rgb(40 20 0 / .25)); transform: rotate(-3deg); }
.modes { 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: italic 700 1.35rem/1.2 var(--serif); display: flex; align-items: center; gap: 10px; }
.card h2 .num { font: 700 .72rem/1 ui-sans-serif, system-ui, sans-serif; letter-spacing: .08em; color: var(--brass); font-style: normal; border: 1px solid color-mix(in srgb, var(--brass) 50%, transparent); border-radius: 999px; padding: 4px 7px; }
.card > p { margin: 0 0 14px; }
.card form, .stack { display: grid; gap: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stats { display: flex; gap: 14px; font-size: .85rem; color: var(--ink-2); flex-wrap: wrap; }
.stats b { color: var(--ink); font-variant-numeric: tabular-nums; }
.or { display: flex; align-items: center; gap: 10px; color: var(--ink-3); font-size: .8rem; text-transform: uppercase; letter-spacing: .1em; margin: 4px 0; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.join-row { display: grid; grid-template-columns: 1fr 1.4fr; gap: 10px; }
.rules { margin-top: 26px; }
.rules summary { cursor: pointer; font: italic 700 1.2rem/1.3 var(--serif); list-style: none; display: flex; align-items: center; gap: 8px; }
.rules summary::-webkit-details-marker { display: none; }
.rules summary::before { content: "›"; transition: transform .2s; display: inline-block; color: var(--brass); font-style: normal; }
.rules[open] summary::before { transform: rotate(90deg); }
.rules ol { margin: 12px 0 0; padding-left: 1.3em; color: var(--ink-2); display: grid; gap: 6px; max-width: 60rem; }
.rules ol b { color: var(--ink); }

/* ---------- Spiel ---------- */
.play { display: grid; gap: 22px; grid-template-columns: minmax(0, 1fr) minmax(290px, 360px); align-items: start; padding-top: 4px; }
.board-col { display: grid; gap: 12px; justify-items: center; }
.banner {
  width: 100%; max-width: 640px; display: flex; align-items: center; gap: 12px; min-height: 58px;
  padding: 10px 16px; border-radius: 14px; background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow);
}
.banner .who { width: 26px; height: 26px; }
.banner strong { font: italic 700 1.18rem/1.2 var(--serif); display: block; }
.banner .hint { font-size: .86rem; color: var(--ink-2); }
.banner.alert { border-color: color-mix(in srgb, var(--accent) 55%, var(--line)); background: color-mix(in srgb, var(--accent) 8%, var(--card)); }
.banner.alert strong { color: var(--accent); }
.banner.win { border-color: color-mix(in srgb, var(--brass) 60%, var(--line)); background: color-mix(in srgb, var(--brass) 10%, var(--card)); }
.banner .spacer { flex: 1; }
.thinking i { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: currentColor; margin-left: 3px; animation: blink 1s infinite; opacity: .3; }
.thinking i:nth-child(2) { animation-delay: .15s; } .thinking i:nth-child(3) { animation-delay: .3s; }
@keyframes blink { 40% { opacity: 1; } }
.board-wrap { width: 100%; max-width: min(640px, max(320px, calc((100dvh - 150px) * 102 / 131))); }

.panel { display: grid; gap: 14px; position: sticky; top: 10px; }
.players { display: grid; gap: 8px; }
.pl {
  display: grid; grid-template-columns: auto 1fr auto; gap: 4px 12px; align-items: center;
  padding: 12px 14px; border-radius: 14px; background: var(--card); border: 1px solid var(--line); position: relative;
  transition: border-color .25s, box-shadow .25s;
}
.pl.cur { border-color: color-mix(in srgb, var(--brass) 70%, transparent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brass) 18%, transparent); }
.pl.cur::after { content: "am Zug"; position: absolute; right: 12px; top: -9px; font-size: .66rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; background: var(--brass); color: #1b1407; padding: 2px 7px; border-radius: 999px; }
.pl .mini { width: 26px; height: 26px; grid-row: span 2; }
.pl .nm { font-weight: 700; display: flex; gap: 6px; align-items: center; min-width: 0; }
.pl .nm span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pl .sub { font-size: .8rem; color: var(--ink-2); grid-column: 2; }
.pl .score { grid-row: span 2; font: 800 1.5rem/1 var(--serif); font-variant-numeric: tabular-nums; color: var(--ink-2); }
.pl .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-3); flex: none; }
.pl .dot.on { background: #3ccf6e; }
.hand { display: flex; gap: 3px; flex-wrap: wrap; }
.hand i { width: 9px; height: 9px; border-radius: 50%; display: block; }
.hand.w i { background: var(--st-w2); box-shadow: inset 0 0 0 1px var(--st-w-edge); }
.hand.b i { background: var(--st-b1); }
.hand i.gone { background: transparent !important; box-shadow: inset 0 0 0 1px var(--ink-3) !important; opacity: .5; }

.actions { display: grid; gap: 8px; grid-template-columns: 1fr 1fr; }
.actions .wide { grid-column: 1 / -1; }
.moves { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; max-height: 240px; overflow: auto; font-size: .86rem; }
.moves h3 { margin: 0 0 6px; font-size: .74rem; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-3); }
.moves ol { margin: 0; padding: 0; list-style: none; display: grid; gap: 2px; counter-reset: mv; }
.moves li { display: grid; grid-template-columns: 2.2em 1fr 1fr; gap: 6px; font-variant-numeric: tabular-nums; padding: 2px 4px; border-radius: 6px; }
.moves li:last-child { background: var(--bg); }
.moves li .n { color: var(--ink-3); }
.moves li .x { color: var(--accent); font-weight: 700; }
.log { display: grid; gap: 4px; }
.log div { display: flex; gap: 8px; color: var(--ink-2); }
.log div:first-child { color: var(--ink); font-weight: 600; }
.log time { opacity: .6; font-variant-numeric: tabular-nums; flex: none; }
.legend { font-size: .78rem; color: var(--ink-3); text-align: center; }

/* ---------- Brett ---------- */
.board { width: 100%; height: auto; display: block; user-select: none; -webkit-user-select: none; touch-action: manipulation; overflow: visible; }
.board .frame { stroke: var(--wood-edge); stroke-width: .6; }
.board .grain { opacity: var(--grain); mix-blend-mode: multiply; pointer-events: none; }
.board .bevel { fill: none; stroke: rgb(255 255 255 / .25); stroke-width: .5; }
.board .lines { stroke: var(--inlay); stroke-width: .95; fill: none; stroke-linecap: square; }
.board .node { fill: var(--inlay); }
.board .coord { fill: var(--inlay); opacity: .5; font: 600 2.4px/1 ui-sans-serif, system-ui, sans-serif; text-anchor: middle; dominant-baseline: middle; }
.board .tray { fill: color-mix(in srgb, var(--wood-2) 55%, transparent); stroke: color-mix(in srgb, var(--wood-edge) 50%, transparent); stroke-width: .3; }
.board .slot { fill: none; stroke: var(--ink-3); stroke-width: .25; stroke-dasharray: .7 .7; opacity: .55; }
.board .mill { stroke: var(--mill); stroke-width: 2.6; stroke-linecap: round; fill: none; filter: drop-shadow(0 0 1.6px var(--mill)); stroke-dasharray: 100; stroke-dashoffset: 100; animation: drawmill .45s ease-out forwards, millglow 2.4s ease-in-out .5s; opacity: .9; }
.board .mill.old { animation: none; stroke-dashoffset: 0; opacity: .35; filter: none; stroke-width: 1.6; }
@keyframes drawmill { to { stroke-dashoffset: 0; } }
@keyframes millglow { 30% { stroke-width: 3.4; } }

.board .target { fill: var(--inlay); opacity: .35; transition: opacity .2s; }
.board .target.go { fill: var(--good); opacity: .9; animation: breathe 1.4s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
@keyframes breathe { 50% { transform: scale(1.35); } }
.board .from-mark { fill: none; stroke: var(--brass); stroke-width: .6; stroke-dasharray: 1.2 1; opacity: .9; }
.board .rem-mark { stroke: var(--accent); stroke-width: .7; stroke-linecap: round; opacity: .7; }
.board .hint-ring { fill: none; stroke: var(--brass); stroke-width: .9; animation: hintp 1s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
@keyframes hintp { 50% { transform: scale(1.18); opacity: .5; } }

.stone { transition: transform .42s cubic-bezier(.3, .8, .25, 1); }
.stone.fast { transition-duration: .28s; }
.stone .in { transition: transform .18s ease-out; }
.stone .shadow { fill: rgb(0 0 0 / .32); }
.stone .groove { fill: none; stroke-width: .35; }
.stone.w .face { stroke: var(--st-w-edge); stroke-width: .3; }
.stone.w .groove { stroke: rgb(120 100 70 / .35); }
.stone.b .face { stroke: #000; stroke-width: .3; }
.stone.b .groove { stroke: rgb(255 255 255 / .12); }
.stone .shine { fill: #fff; opacity: .55; }
.stone.b .shine { opacity: .22; }
.stone .lastdot { fill: var(--accent); opacity: 0; transition: opacity .3s; }
.stone.last .lastdot { opacity: .9; }
.stone.moving .in { transform: scale(1.12); }
.stone.sel .in { transform: translateY(-1px) scale(1.12); }
.stone .ring { fill: none; stroke-width: .8; opacity: 0; }
.stone.sel .ring { stroke: var(--brass); opacity: 1; }
.stone.can .ring { stroke: var(--brass); opacity: .75; animation: canp 1.6s ease-in-out infinite; }
.stone.rem .ring { stroke: var(--accent); opacity: 1; stroke-width: 1; animation: canp .9s ease-in-out infinite; }
.stone.rem .in { animation: shake 2.4s ease-in-out infinite; }
@keyframes canp { 50% { opacity: .25; } }
@keyframes shake { 0%, 86%, 100% { transform: none; } 90% { transform: rotate(-8deg); } 95% { transform: rotate(8deg); } }
.stone.gone { transition: transform .5s ease-in, opacity .5s ease-in; opacity: 0; }
.stone.gone .in { transform: scale(1.6) translateY(-4px); transition: transform .5s ease-in; }
.stone.tray .in { transform: scale(.66); }
.stone.dim { opacity: .55; }

.board .hit { fill: transparent; cursor: default; outline: none; }
.board .hit.on { cursor: pointer; }
.board .hit:focus-visible { stroke: var(--brass); stroke-width: .8; }

/* ---------- Ende ---------- */
#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 60; }
.over {
  position: fixed; inset: 0; z-index: 55; display: grid; place-items: center; padding: 16px;
  background: color-mix(in srgb, var(--bg) 66%, transparent); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  animation: fade .35s ease-out;
}
@keyframes fade { from { opacity: 0; } }
.over-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 24px; box-shadow: var(--shadow);
  padding: 28px 24px 22px; width: min(420px, 100%); text-align: center; animation: pop .45s cubic-bezier(.2, 1.4, .4, 1);
}
@keyframes pop { from { transform: translateY(16px) scale(.95); opacity: 0; } }
.over-card .medal { width: 120px; height: 120px; margin: -2px auto 6px; display: block; }
.over-card h2 { font: italic 800 2rem/1.1 var(--serif); margin: 0 0 6px; }
.over-card p { margin: 0 0 16px; color: var(--ink-2); }
.over-card .tally { display: flex; justify-content: center; gap: 18px; margin: 0 0 18px; font-size: .9rem; color: var(--ink-2); }
.over-card .tally b { display: block; font: 800 1.6rem/1.1 var(--serif); color: var(--ink); }
.over-card .btns { display: grid; gap: 8px; }

/* ---------- Lobby ---------- */
.lobby { display: grid; gap: 18px; grid-template-columns: 1fr 1fr; padding-top: 6px; }
.share-code { font: 800 clamp(2.8rem, 12vw, 4.4rem)/1 ui-monospace, Menlo, monospace; letter-spacing: .22em; text-align: center; padding: 18px 0 14px; }
.seats { display: grid; gap: 8px; margin: 10px 0 14px; }
.seat { display: flex; align-items: center; gap: 10px; padding: 12px; border-radius: 12px; background: var(--bg); border: 1px dashed var(--line); }
.seat.full { border-style: solid; }
.seat .mini { width: 22px; height: 22px; }
.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; }
.reclaim-box { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); display: grid; gap: 8px; }
.reclaim-list { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- 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: 70;
  box-shadow: var(--shadow); max-width: calc(100% - 32px); font-weight: 600; text-align: center;
}

/* ---------- Mobil ---------- */
@media (max-width: 900px) {
  .hero { grid-template-columns: 1fr; gap: 18px; }
  .hero-board { max-width: 360px; margin: 0 auto; order: -1; }
  .play { grid-template-columns: 1fr; gap: 14px; }
  .panel { position: static; }
  .lobby { grid-template-columns: 1fr; }
}
@media (max-width: 520px) {
  main { padding: 0 10px 40px; }
  .banner { padding: 8px 12px; min-height: 52px; }
  .banner strong { font-size: 1.05rem; }
  .players { grid-template-columns: 1fr 1fr; }
  .pl { padding: 10px; gap: 2px 8px; }
  .pl .mini { width: 20px; height: 20px; }
  .pl .score { font-size: 1.2rem; }
  .grid2 { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
