:root {
  --bg: #1b2224; --raise: #263033; --line: #3a474b; --ink: #f1f0e8; --soft: #b3c0bd;
  --light: #dfe3d8; --dark: #6f8f83; --accent: #f0b34a; --accent-ink: #2a1d05; --alert: #e0705a;
  --r: 12px;
  --st: env(safe-area-inset-top, 0px); --sb: env(safe-area-inset-bottom, 0px);
  --sl: env(safe-area-inset-left, 0px); --sr: env(safe-area-inset-right, 0px);
  color-scheme: dark;
}
* { box-sizing: border-box; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); overscroll-behavior: none; -webkit-text-size-adjust: 100%; }
body { color: var(--ink); font: 16px/1.4 ui-rounded, "SF Pro Rounded", system-ui, -apple-system, sans-serif; min-height: 100dvh; }
h1, h2, p { margin: 0; }
h2 { font-size: 20px; font-weight: 700; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-user-select: none; user-select: none; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.btn { min-height: 48px; padding: 0 16px; border: 1px solid var(--line); border-radius: var(--r); background: var(--raise); font-weight: 600; }
.btn:active { background: var(--line); }
.btn.main { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 700; }
.btn.main:active { filter: brightness(.9); }
.btn.danger { color: #f6a391; }
.btn:disabled { opacity: .45; cursor: default; }
.link { border: 0; background: none; padding: 12px 0; color: var(--soft); text-decoration: underline; text-underline-offset: 3px; align-self: flex-start; }
input:not([type=radio]) { width: 100%; min-height: 48px; padding: 0 14px; border: 1px solid var(--line); border-radius: var(--r); background: #141a1c; font-size: 16px; }
input::placeholder { color: #82918e; }

/* ---- start ---- */
.page { max-width: 480px; margin: 0 auto; min-height: 100dvh; padding: calc(var(--st) + 12px) calc(var(--sr) + 18px) calc(var(--sb) + 24px) calc(var(--sl) + 18px); display: flex; flex-direction: column; gap: 22px; }
.hero { position: relative; margin: calc(-1 * (var(--st) + 12px)) calc(-18px - var(--sr)) -6px calc(-18px - var(--sl)); padding-top: var(--st); overflow: hidden; background: #141a1c; }
#heroBoard { display: grid; grid-template-columns: repeat(8, 1fr); }
#heroBoard i { aspect-ratio: 1; display: block; }
#heroBoard i.l { background: var(--light); } #heroBoard i.d { background: var(--dark); }
.hero h1 { padding: 14px 18px 0; background: var(--bg); font-size: 36px; font-weight: 800; line-height: 1.1; }
form, .primary { display: flex; flex-direction: column; gap: 14px; }
.field { display: grid; gap: 5px; }
.field span, .legend, .codeform > label { font-size: 14px; color: var(--soft); padding: 0; }
.legend { margin-bottom: 5px; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; background: #141a1c; }
.seg label { position: relative; min-width: 0; }
.seg label + label { border-left: 1px solid var(--line); }
.seg input { position: absolute; inset: 0; opacity: 0; margin: 0; width: 100%; height: 100%; cursor: pointer; }
.seg span { display: grid; place-items: center; min-height: 46px; font-weight: 600; white-space: nowrap; }
.seg input:checked + span { background: var(--light); color: #1b2224; }
.seg input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: -3px; }
.codeform { gap: 5px; }
.codeform div { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
#code { text-transform: uppercase; letter-spacing: .2em; font-weight: 700; }
.offline { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.offline .btn { padding: 0 6px; font-size: 15px; }
.running { display: flex; gap: 8px; overflow-x: auto; margin: 8px -18px 0; padding: 0 18px 2px; scrollbar-width: none; }
.running::-webkit-scrollbar { display: none; }
.runitem { flex: 0 0 auto; display: flex; border: 1px solid var(--line); border-radius: var(--r); background: var(--raise); max-width: 290px; }
.runitem button { border: 0; background: none; }
.runopen { text-align: left; padding: 9px 4px 9px 14px; min-width: 0; }
.runopen b, .runopen small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.runopen small { color: var(--soft); font-size: 13px; }
.rundel { width: 44px; color: var(--soft); font-size: 20px; }
.center { gap: 16px; justify-content: flex-start; }
.center h1 { font-size: 28px; line-height: 1.15; }
.center p { color: var(--soft); overflow-wrap: anywhere; }
.center .codebig { font-size: 52px; font-weight: 800; letter-spacing: .14em; color: var(--accent); text-align: center; padding: 18px 0 18px .14em; -webkit-user-select: all; user-select: all; }
#inviteLink { color: var(--soft); font-size: 16px; }

/* ---- stukken en bord ---- */
.pc { display: block; width: 100%; height: 100%; overflow: visible; stroke-width: 4; stroke-linejoin: round; stroke-linecap: round; pointer-events: none; }
.pc-w { fill: #fffaf0; stroke: #28343a; }
.pc-b { fill: #27323a; stroke: #0d1316; }
.pc .d { fill: none; stroke-width: 4; }
.pc-w .d { stroke: #28343a; } .pc-b .d { stroke: #a8b9b8; }
.pc .e { stroke: none; } .pc-w .e { fill: #28343a; } .pc-b .e { fill: #dfe3d8; }
.board { width: var(--bs); height: var(--bs); touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; margin: 0 auto; background: var(--dark); }
.board * { touch-action: none; }
.row { display: grid; grid-template-columns: repeat(8, 1fr); height: 12.5%; }
.sq { position: relative; min-width: 0; padding: 4%; cursor: pointer; }
.sq:focus-visible { outline: 3px solid var(--accent); outline-offset: -3px; z-index: 2; }
.light { background: var(--light); color: #4e6d62; } .dark { background: var(--dark); color: #eef1e9; }
.sq.last.light { background: #efd79c; } .sq.last.dark { background: #b59a55; }
.sq.sel { background: var(--accent); }
.sq.check { background: radial-gradient(circle, #e0553c 25%, #e0705a 60%, #c9826f); }
.sq[data-rank]::before, .sq[data-file]::after { position: absolute; font-size: clamp(9px, calc(var(--bs) / 42), 13px); font-weight: 700; line-height: 1; pointer-events: none; }
.sq[data-rank]::before { content: attr(data-rank); left: 3px; top: 3px; }
.sq[data-file]::after { content: attr(data-file); right: 3px; bottom: 3px; }
.sq.last, .sq.sel { color: #40351a; }
.sq.dest { background-image: radial-gradient(circle, rgba(27,34,36,.5) 0 15%, transparent 16%); }
.sq.take { background-image: radial-gradient(circle, transparent 0 58%, rgba(27,34,36,.6) 60%); }
.sq.over { box-shadow: inset 0 0 0 4px var(--accent); }
.sq .pc { position: relative; z-index: 1; }
.pc.drag { z-index: 20; }
.sq:has(.drag) { z-index: 20; }

/* ---- partij ---- */
#game { --bs: min(100vw - var(--sl) - var(--sr), 100dvh - var(--st) - var(--sb) - 246px); height: 100dvh; overflow: hidden; padding: var(--st) var(--sr) var(--sb) var(--sl); display: flex; flex-direction: column; }
.bar { display: flex; align-items: center; height: 44px; flex: none; }
.bar h1 { flex: 1; min-width: 0; font-size: 16px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon { width: 44px; height: 44px; flex: none; display: grid; place-items: center; border: 0; background: none; border-radius: var(--r); }
.icon svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon:disabled { opacity: .3; }
.stage { flex: none; }
.player { display: flex; align-items: center; gap: 8px; height: 40px; padding: 0 12px; width: 100%; max-width: max(var(--bs), min(100vw, 480px)); margin: 0 auto; }
.player .chip { width: 14px; height: 14px; border-radius: 4px; flex: none; border: 2px solid #8fa09c; }
.chip.w { background: #fffaf0; } .chip.b { background: #0d1316; }
.player .pname { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 0 1 auto; min-width: 50px; }
.player.turn .pname { color: var(--accent); }
.player .pstate { font-size: 13px; color: var(--soft); white-space: nowrap; flex: none; }
.taken { display: flex; align-items: center; min-width: 0; overflow: hidden; flex: 1 1 0; color: var(--soft); font-size: 13px; }
.taken .pc { width: 17px; height: 17px; flex: none; margin-right: -6px; stroke-width: 5; }
.taken .pc-b { stroke: #8fa09c; }
.taken .plus { margin-left: 10px; }
.clock { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 700; font-size: 19px; padding: 1px 10px; border-radius: 8px; background: var(--raise); flex: none; }
.clock.run { background: var(--light); color: #1b2224; }
.clock.low { background: var(--alert); color: #1b0d09; }
.side { flex: 1; min-height: 0; display: flex; flex-direction: column; justify-content: space-between; width: 100%; max-width: 560px; margin: 0 auto; }
.status { min-height: 30px; padding: 2px 12px; display: flex; align-items: center; justify-content: center; gap: 8px; font-size: 15px; text-align: center; color: var(--soft); }
.status.strong { color: var(--ink); font-weight: 700; }
.movesrow { display: flex; align-items: center; height: 40px; flex: none; }
.movesrow .icon { height: 40px; }
.moves { list-style: none; display: flex; overflow-x: auto; margin: 0; padding: 0; flex: 1; min-width: 0; scrollbar-width: none; }
.moves::-webkit-scrollbar { display: none; }
.moves li { display: flex; align-items: center; flex: none; }
.moves .no { color: #92a29e; font-size: 13px; padding: 0 1px 0 7px; }
.moves button { border: 0; background: none; padding: 7px 6px; border-radius: 8px; font-size: 15px; }
.moves button.cur { background: var(--light); color: #1b2224; font-weight: 700; }
.actions { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 8px; padding: 2px 12px 6px; }
.actions .btn { min-height: 44px; padding: 0 6px; font-size: 15px; }

@media (min-width: 820px), (orientation: landscape) and (max-height: 520px) {
  #game { --bs: min(100dvh - var(--st) - var(--sb) - 148px, 100vw - 400px, 820px); display: grid; grid-template: 44px 1fr / auto minmax(260px, 340px); justify-content: center; align-content: center; column-gap: 32px; }
  .bar { grid-column: 1 / -1; width: 100%; }
  .stage { align-self: center; }
  .player { max-width: none; padding: 0 2px; }
  .side { justify-content: flex-start; align-self: center; height: calc(var(--bs) + 80px); margin: 0; gap: 12px; border-left: 1px solid var(--line); padding-left: 24px; }
  .status { justify-content: flex-start; text-align: left; padding: 8px 0; font-size: 18px; flex-wrap: wrap; }
  .movesrow { flex: 1; height: auto; min-height: 0; display: grid; grid-template: 1fr 44px / 1fr 1fr; }
  #prev { grid-area: 2 / 1; } #next { grid-area: 2 / 2; }
  .moves { grid-area: 1 / 1 / 2 / 3; display: block; overflow: auto; height: 100%; }
  .moves li { display: grid; grid-template-columns: 34px 1fr 1fr; }
  .moves button { text-align: left; }
  .movesrow .icon { width: 100%; }
  .actions { padding: 0; }
}
@media (orientation: landscape) and (max-height: 520px) {
  #game { --bs: min(100dvh - var(--st) - var(--sb) - 104px, 100vw - 330px); column-gap: 12px; grid-template-columns: auto minmax(240px, 340px); grid-template-rows: 36px 1fr; }
  .bar { height: 36px; } .player { height: 32px; }
  .side { height: calc(var(--bs) + 64px); gap: 2px; padding-left: 12px; }
  .status { font-size: 15px; padding: 0; }
}
@media (min-width: 820px) and (min-height: 521px) {
  #home { max-width: 560px; }
  .hero { margin: 0; border-radius: 0 0 var(--r) var(--r); }
  .hero h1 { padding-left: 0; }
}

/* ---- sheet en melding ---- */
dialog { border: 0; padding: 0; color: inherit; background: var(--raise); width: 100%; max-width: 440px; margin: auto auto 0; border-radius: 18px 18px 0 0; }
dialog::backdrop { background: rgba(10,14,15,.62); }
#sheetBody { padding: 22px 18px calc(var(--sb) + 18px); display: flex; flex-direction: column; gap: 12px; }
#sheetBody h2 { outline: 0; } #sheetBody p { color: var(--soft); }
.promo { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.promo button { min-width: 0; height: 84px; padding: 8px; border: 0; border-radius: var(--r); background: var(--dark); }
@media (min-width: 820px) { dialog { margin: auto; border-radius: 18px; } }
#toast { position: fixed; left: 50%; top: calc(var(--st) + 2px); transform: translateX(-50%); background: var(--light); color: #1b2224; font-weight: 600; padding: 10px 16px; border-radius: var(--r); max-width: calc(100vw - 32px); width: max-content; visibility: hidden; opacity: 0; transition: opacity .15s; pointer-events: none; z-index: 30; }
#toast.on { visibility: visible; opacity: 1; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
