/* Duplomaat Web: werkt van smalle smartphones (320 px) tot grote PC-schermen. */

:root {
  --bg: #f4f1e8;
  --ink: #1f2420;
  --muted: #66706a;
  --frame: #1d4f40;
  --sq: #cfdec5;          /* gewoon vakje */
  --dl: #a8d4ea;          /* letter x2 */
  --tl: #3b82c4;          /* letter x3 */
  --dw: #f2b8b1;          /* woord x2 */
  --tw: #cf4b43;          /* woord x3 */
  --tile: #f5e3b8;
  --tile-edge: #c9ad72;
  --blank-ink: #b23a24;
  --accent: #1d6b55;
  --accent-ink: #ffffff;
  --sel: #ffcf3f;
  --bad: #c62828;
  --good: #1b7a3a;
  --line: #d8d2c2;
  --panel: #ffffff;

  /* Celgrootte: 16 kolommen (15 + randlabels) passen in de schermbreedte */
  --cell: min(calc((100vw - 12px) / 16), 40px);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}

/* ---------- bovenbalk ---------- */
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 10px; padding-top: max(6px, env(safe-area-inset-top));
  background: var(--frame); color: #fff;
  position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 700; letter-spacing: .5px; }
.stats { display: flex; gap: 10px; flex: 1; font-size: 13px; flex-wrap: wrap; }
.stats b { font-variant-numeric: tabular-nums; }
.clock {
  font: 600 18px/1 ui-monospace, "SF Mono", Consolas, monospace;
  background: #0f3a2e; color: #fff; border: 1px solid #3f7d69; border-radius: 8px;
  padding: 6px 10px; min-width: 70px; cursor: pointer;
}
.clock.running { background: #145c45; }
.clock.warn { background: #b26a00; }
.clock.over { background: var(--bad); }

/* ---------- indeling ---------- */
.layout { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 6px; }
.side { width: 100%; max-width: 640px; display: flex; flex-direction: column; gap: 8px; }

@media (min-width: 980px) {
  :root { --cell: min(calc((100vh - 70px) / 16), 46px); }
  .layout { flex-direction: row; align-items: flex-start; justify-content: center; gap: 18px; padding: 14px; }
  .side { width: 420px; max-height: calc(100vh - 80px); }
  .panel { flex: 1; min-height: 0; overflow: auto; }
  .side { overflow: hidden; }
}

/* ---------- bord ---------- */
.board {
  display: grid;
  grid-template-columns: repeat(16, var(--cell));
  grid-auto-rows: var(--cell);
  gap: 1px;
  background: var(--frame);
  padding: 2px;
  border-radius: 6px;
  user-select: none; -webkit-user-select: none;
  touch-action: manipulation;
}
.lbl {
  display: flex; align-items: center; justify-content: center;
  color: #d8eadf; font-size: calc(var(--cell) * .38); font-weight: 600;
}
.cell {
  position: relative;
  display: flex; align-items: center; justify-content: center;
  background: var(--sq);
  font-size: calc(var(--cell) * .3); color: rgba(0,0,0,.45); font-weight: 600;
  cursor: pointer;
}
.cell.dl { background: var(--dl); }
.cell.tl { background: var(--tl); color: rgba(255,255,255,.8); }
.cell.dw { background: var(--dw); }
.cell.tw { background: var(--tw); color: rgba(255,255,255,.85); }
.cell.star::after { content: "★"; font-size: calc(var(--cell) * .55); color: rgba(120, 30, 30, .55); }

.tile {
  position: absolute; inset: 1px;
  display: flex; align-items: center; justify-content: center;
  background: var(--tile);
  border-radius: 3px;
  box-shadow: inset 0 -2px 0 var(--tile-edge);
  color: var(--ink);
  font-size: calc(var(--cell) * .6); font-weight: 700;
}
.tile .pt { position: absolute; right: 2px; bottom: 1px; font-size: calc(var(--cell) * .24); font-weight: 600; }
.tile.blank { color: var(--blank-ink); }
.tile.last { box-shadow: inset 0 -2px 0 var(--tile-edge), 0 0 0 2px var(--accent); }
.tile.preview { background: #fff7d6; opacity: .92; outline: 2px dashed var(--accent); outline-offset: -2px; }
.tile.preview.conflict { background: #ffd9d6; outline-color: var(--bad); }
.tile.hl { background: var(--sel); }

.cell.selected { outline: 3px solid var(--sel); outline-offset: -3px; z-index: 2; }
.cell .arrow {
  position: absolute; z-index: 3; color: var(--ink);
  font-size: calc(var(--cell) * .55); font-weight: 900; text-shadow: 0 0 3px #fff;
}

/* ---------- rekje ---------- */
.rack-row { display: flex; align-items: center; gap: 10px; min-height: 48px; }
.rack { display: flex; gap: 4px; }
.rack .rt {
  width: 40px; height: 44px; position: relative;
  display: flex; align-items: center; justify-content: center;
  background: var(--tile); border-radius: 5px; box-shadow: inset 0 -3px 0 var(--tile-edge);
  font-size: 24px; font-weight: 700;
}
.rack .rt .pt { position: absolute; right: 3px; bottom: 2px; font-size: 10px; }
.rack .rt.blank { color: var(--blank-ink); }
.rack .empty { color: var(--muted); font-size: 14px; }
.max-info { margin-left: auto; text-align: right; font-size: 13px; color: var(--muted); }
.max-info b { color: var(--ink); font-size: 18px; }

@media (max-width: 400px) {
  .rack .rt { width: 34px; height: 38px; font-size: 20px; }
}
@media (max-width: 520px) {
  .brand { display: none; }
  .stats { gap: 8px; font-size: 13px; flex-wrap: nowrap; white-space: nowrap; }
  .clock { font-size: 16px; padding: 5px 8px; min-width: 62px; }
}
@media (max-width: 979px) {
  /* smartphone/tablet: lijsten scrollen binnen het paneel, knoppen blijven bereikbaar */
  .panel { max-height: 58vh; overflow: auto; }
}

/* ---------- knoppen ---------- */
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.actions.primary .btn { flex: 1; }
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  border-radius: 8px; padding: 10px 12px; font-size: 15px; font-weight: 600; cursor: pointer;
  min-height: 42px;
}
.btn:hover { border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn.main { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.small { padding: 6px 10px; font-size: 13px; min-height: 34px; font-weight: 500; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.pulse { box-shadow: 0 0 0 3px var(--sel); }

/* ---------- woordingave ---------- */
.entry { display: flex; gap: 6px; }
.sel-info {
  flex: 0 0 auto; min-width: 92px; border: 1px solid var(--line); background: #fff; border-radius: 8px;
  font-weight: 700; font-size: 14px; cursor: pointer; padding: 0 8px;
}
#word {
  flex: 1; min-width: 0; font-size: 18px; font-weight: 600; letter-spacing: 1px;
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; text-transform: none;
}
.feedback { min-height: 20px; font-size: 14px; }
.feedback.good { color: var(--good); font-weight: 600; }
.feedback.bad { color: var(--bad); }

/* ---------- tabbladen en lijsten ---------- */
.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tab {
  flex: 1; background: none; border: none; padding: 8px; font-size: 14px; font-weight: 600;
  color: var(--muted); border-bottom: 3px solid transparent; cursor: pointer;
}
.tab.active { color: var(--ink); border-bottom-color: var(--accent); }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 6px; }
.panel.hidden, .hidden { display: none !important; }
.muted { color: var(--muted); font-size: 14px; margin: 6px; }

.moves { display: flex; flex-direction: column; }
.mv {
  display: grid; grid-template-columns: 34px 1fr 52px 44px; align-items: center;
  padding: 7px 6px; border-radius: 6px; cursor: pointer; font-variant-numeric: tabular-nums;
}
.mv:nth-child(even) { background: #f6f4ee; }
.mv.sel { background: var(--sel); }
.mv .rank { color: var(--muted); font-size: 12px; }
.mv .w { font-weight: 700; letter-spacing: .5px; overflow-wrap: anywhere; }
.mv .w .b { color: var(--blank-ink); }
.mv .c { color: var(--muted); }
.mv .s { text-align: right; font-weight: 700; }
.more { margin: 6px auto; }

table.turns { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
.turns th, .turns td { padding: 4px 3px; text-align: left; border-bottom: 1px solid #eee; }
.turns td:nth-child(n+5), .turns th:nth-child(n+5) { text-align: right; }
.turns tfoot td { font-weight: 700; border-top: 2px solid var(--line); }
.turns .w { font-weight: 700; }
.turns .top { color: var(--good); }

.bag { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 4px; }
.bag .bt { background: var(--tile); border-radius: 4px; text-align: center; padding: 4px 0; font-weight: 700; }
.bag .bt small { display: block; font-weight: 500; color: var(--muted); }

/* ---------- melding en dialogen ---------- */
.toast {
  position: fixed; left: 50%; bottom: max(16px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: #222; color: #fff; padding: 10px 14px; border-radius: 8px; max-width: 92vw; z-index: 20;
  font-size: 14px; box-shadow: 0 4px 16px rgba(0,0,0,.25);
}
dialog { border: none; border-radius: 12px; padding: 16px; max-width: min(92vw, 520px); width: 100%; }
dialog::backdrop { background: rgba(0,0,0,.35); }
dialog h2 { margin: 0 0 8px; font-size: 18px; }
dialog h3 { margin: 14px 0 4px; font-size: 15px; }
dialog input[type=text] { width: 100%; font-size: 20px; padding: 8px; border: 1px solid var(--line); border-radius: 8px; }
dialog input[type=number] { width: 80px; font-size: 15px; padding: 4px; margin-left: 6px; }
dialog .row { display: block; margin: 8px 0; font-size: 14px; }
dialog ol { padding-left: 20px; font-size: 14px; line-height: 1.45; }
dialog p { font-size: 14px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
.check-result { font-size: 16px; font-weight: 600; min-height: 22px; }
.at-list { max-height: 60vh; overflow: auto; }
