/* Five Dice Trainer — felt table, ivory dice, paper score pad. */
:root {
  --felt: #0f3b2e;
  --felt-2: #164c3c;
  --felt-3: #1d5e4a;
  --ink: #f2eee2;
  --muted: #a8bdb2;
  --paper: #fbf7ec;
  --paper-line: #e6dcc4;
  --pad-ink: #1f2a25;
  --amber: #f0b03f;
  --blue: #4d8fe0;     /* optimal player / good */
  --orange: #e9772e;   /* you / mistakes */
  --radius: 14px;
  --serif: ui-serif, "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 16px/1.45 var(--sans);
  color: var(--ink);
  background:
    radial-gradient(ellipse at 50% 0%, var(--felt-3) 0%, transparent 60%),
    repeating-linear-gradient(45deg, rgba(255,255,255,.012) 0 2px, transparent 2px 4px),
    var(--felt);
  min-height: 100vh;
  font-variant-numeric: tabular-nums;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: not-allowed; }
:focus-visible { outline: 3px solid var(--amber); outline-offset: 2px; }
kbd { font: 600 11px var(--sans); padding: 1px 5px; border-radius: 4px; border: 1px solid currentColor; opacity: .6; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- header ---------- */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 14px clamp(16px, 4vw, 40px);
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand h1 { font: 600 22px/1.1 var(--serif); margin: 0; letter-spacing: .2px; }
.brand p { margin: 2px 0 0; font-size: 13px; color: var(--muted); }
.top-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.ghost {
  background: transparent; border: 1px solid rgba(255,255,255,.22); border-radius: 999px;
  padding: 7px 14px; font-size: 14px;
}
.ghost:hover { background: rgba(255,255,255,.07); }
.chip { background: var(--felt-3); border: 1px solid rgba(255,255,255,.18); border-radius: 999px; padding: 7px 14px; font-weight: 600; font-size: 14px; }
.chip::before { content: "●"; color: var(--amber); margin-right: 6px; font-size: 10px; vertical-align: 2px; }
.lang { min-width: 48px; font-weight: 600; }
.primary {
  background: var(--amber); color: #2a1d05; border: 0; border-radius: 999px;
  padding: 12px 28px; font-weight: 700; font-size: 17px; letter-spacing: .3px;
  box-shadow: 0 3px 0 #b77d1f, 0 8px 18px rgba(0,0,0,.25);
  transition: transform .08s, box-shadow .08s;
}
.primary:hover:not(:disabled) { filter: brightness(1.05); }
.primary:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 #b77d1f, 0 4px 10px rgba(0,0,0,.25); }
.primary:disabled { background: #6f7f77; color: #dfe6e2; box-shadow: none; }
.wide { width: 100%; margin-top: 16px; }

/* ---------- layout ---------- */
.layout {
  display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: clamp(16px, 3vw, 36px);
  max-width: 1100px; margin: 0 auto; padding: clamp(16px, 3vw, 32px);
}
@media (max-width: 820px) { .layout { grid-template-columns: 1fr; } }
.table { display: flex; flex-direction: column; align-items: center; gap: 18px; position: relative; }

.status { display: flex; align-items: center; gap: 14px; font-size: 15px; color: var(--muted); }
.rollpips { display: inline-flex; gap: 5px; }
.rp { width: 10px; height: 10px; border-radius: 50%; border: 1.5px solid var(--muted); }
.rp.on { background: var(--amber); border-color: var(--amber); }
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .6px; padding: 3px 10px; border-radius: 999px; background: rgba(255,255,255,.08); color: var(--ink); }
.badge.mode-test { background: rgba(233,119,46,.2); color: #ffc39a; }

/* ---------- dice ---------- */
.dice { display: flex; gap: clamp(8px, 2.2vw, 18px); padding: 26px 8px 34px; }
.die {
  --s: clamp(54px, 13vw, 78px);
  width: var(--s); height: var(--s); padding: calc(var(--s) * .14);
  position: relative; border: 0; border-radius: calc(var(--s) * .2);
  background: linear-gradient(145deg, #fffdf6 0%, #efe7d3 100%);
  box-shadow: inset 0 -4px 0 rgba(0,0,0,.08), inset 0 2px 0 #fff, 0 6px 14px rgba(0,0,0,.35);
  transition: transform .15s ease, box-shadow .15s ease;
}
.die .face { display: grid; grid-template: repeat(3, 1fr) / repeat(3, 1fr); width: 100%; height: 100%; place-items: center; }
.pip { width: 68%; aspect-ratio: 1; border-radius: 50%; }
.pip.on { background: radial-gradient(circle at 35% 35%, #4b4b4b, #111 70%); }
.die.blank { opacity: .35; }
.die[aria-disabled="true"] { cursor: default; }
.die:not([aria-disabled="true"]):hover { transform: translateY(-3px); }
.die.held { transform: translateY(-12px); box-shadow: 0 0 0 3px var(--amber), 0 14px 22px rgba(0,0,0,.4); }
.die.suggest { outline: 3px dashed var(--blue); outline-offset: 5px; }
.die .held-tag {
  position: absolute; left: 50%; bottom: -24px; transform: translateX(-50%);
  font-size: 11px; font-weight: 800; letter-spacing: 1px; color: var(--amber); opacity: 0;
}
.die.held .held-tag { opacity: 1; }
.die kbd { position: absolute; top: -20px; left: 50%; transform: translateX(-50%); color: var(--muted); border-color: transparent; }
.die.rolling { animation: tumble .45s cubic-bezier(.3,.7,.4,1); }
@keyframes tumble {
  0% { transform: translateY(-26px) rotate(-200deg) scale(.85); }
  60% { transform: translateY(4px) rotate(12deg); }
  100% { transform: none; }
}

.actions { display: flex; gap: 12px; align-items: center; }

/* ---------- coach ---------- */
.coach {
  width: 100%; max-width: 560px; min-height: 120px;
  background: rgba(0,0,0,.2); border: 1px solid rgba(255,255,255,.08); border-radius: var(--radius);
  padding: 16px 18px;
}
.coach:empty { display: none; }
.coach p { margin: 6px 0; }
.coach h4 { margin: 14px 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }
.fb-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.loss { font-weight: 800; color: #ffb38a; }
.why { color: #e6efe9; font-style: italic; }
.best-line { font-size: 18px; }
.faces { font-size: 1.25em; letter-spacing: 1px; }
.badge.grade-optimal { background: rgba(77,143,224,.25); color: #b9d4ff; }
.badge.grade-good { background: rgba(77,143,224,.14); color: #cfe0f8; }
.badge.grade-inaccuracy { background: rgba(240,176,63,.22); color: #ffd98f; }
.badge.grade-mistake { background: rgba(233,119,46,.3); color: #ffc39a; }
.badge.hint { background: rgba(77,143,224,.25); color: #b9d4ff; }
.opts { list-style: none; margin: 0; padding: 0; font-size: 14px; }
.opts li { display: flex; justify-content: space-between; gap: 12px; padding: 5px 8px; border-radius: 8px; }
.opts li:first-child { background: rgba(77,143,224,.16); }
.opts li.mine { outline: 1.5px solid var(--orange); }
.opts .ev { white-space: nowrap; font-weight: 600; }
.opts small { color: #ffb38a; font-weight: 600; margin-left: 4px; }
.loading { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(15,59,46,.85); border-radius: var(--radius); font-weight: 600; }
.loading[hidden] { display: none; }

/* ---------- score pad ---------- */
.pad {
  background: var(--paper); color: var(--pad-ink); border-radius: 6px;
  box-shadow: 0 1px 0 #d8cdb1, 0 2px 0 var(--paper), 0 3px 0 #d8cdb1, 0 14px 30px rgba(0,0,0,.35);
  padding: 14px 16px 18px; align-self: start;
}
#scorecard { width: 100%; border-collapse: collapse; }
#scorecard th { text-align: left; font-weight: 500; padding: 0 6px; }
#scorecard td { text-align: right; width: 84px; padding: 2px 0; }
#scorecard tr { border-bottom: 1px solid var(--paper-line); }
#scorecard tr.sec th { font: 700 12px var(--sans); text-transform: uppercase; letter-spacing: .8px; color: #7c6f52; padding: 12px 6px 4px; }
#scorecard tr.sum th, #scorecard tr.sum td { font-size: 14px; color: #5d5440; padding: 5px 6px; }
#scorecard tr.grand { border-bottom: 0; border-top: 2px solid var(--pad-ink); }
#scorecard tr.grand th, #scorecard tr.grand td { font: 700 20px var(--serif); padding: 10px 6px 0; }
.cell {
  width: 100%; min-height: 34px; border: 1.5px solid transparent; border-radius: 8px; background: transparent;
  font-weight: 600; font-size: 16px; text-align: right; padding: 4px 10px;
}
.cell.filled { font: 700 18px var(--serif); color: #173a8a; }
.cell.preview { color: #6c7a72; border-color: #d9cfb6; background: #fff; }
.cell.preview:hover { border-color: var(--pad-ink); color: var(--pad-ink); background: #fffdf5; }
.cell.preview.zero { color: #b2a891; }
.cell.suggest { border: 2px dashed var(--blue); color: var(--pad-ink); }
.meter { height: 4px; background: var(--paper-line); border-radius: 2px; margin-top: 3px; }
.meter span { display: block; height: 100%; background: var(--amber); border-radius: 2px; }

.credit { text-align: center; font-size: 12px; color: var(--muted); padding: 8px 16px 28px; }

/* ---------- dialogs ---------- */
dialog {
  border: 0; border-radius: 18px; padding: 24px 26px; width: min(520px, 94vw); max-height: 90vh;
  background: #123f32; color: var(--ink); box-shadow: 0 30px 80px rgba(0,0,0,.6);
}
dialog.wide-dlg { width: min(760px, 96vw); }
dialog::backdrop { background: rgba(4,18,13,.7); backdrop-filter: blur(2px); }
dialog h2 { font: 600 24px var(--serif); margin: 0 0 14px; }
dialog h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); margin: 18px 0 8px; }
.players { display: flex; flex-wrap: wrap; gap: 8px; }
.pl { display: inline-flex; align-items: center; gap: 8px; padding: 8px 14px; border-radius: 999px; background: rgba(255,255,255,.07); cursor: pointer; }
.pl input { accent-color: var(--amber); }
.pl small { color: var(--muted); }
.pl:has(input:checked) { background: rgba(240,176,63,.2); outline: 1.5px solid var(--amber); }
.addrow { display: flex; gap: 8px; margin-top: 12px; }
.addrow input { flex: 1; padding: 9px 14px; border-radius: 999px; border: 1px solid rgba(255,255,255,.25); background: rgba(0,0,0,.2); color: var(--ink); font: inherit; }
.mode { display: flex; gap: 12px; align-items: flex-start; padding: 10px 12px; border-radius: 12px; cursor: pointer; }
.mode:has(input:checked) { background: rgba(255,255,255,.07); }
.mode input { accent-color: var(--amber); margin-top: 4px; }
.mode span { display: flex; flex-direction: column; }
.mode small { color: var(--muted); }
.dlg-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 20px; }
.dlg-actions form { margin-left: auto; }

.final { display: flex; align-items: baseline; justify-content: space-between; margin: 0 0 14px; }
.final strong { font: 700 52px/1 var(--serif); color: var(--amber); }
.split { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
.tile { background: rgba(0,0,0,.2); border-radius: 12px; padding: 10px 12px; display: flex; flex-direction: column; }
.tile span { font-size: 12px; color: var(--muted); }
.tile strong { font-size: 22px; }
.tile small { color: var(--muted); }
.pos { color: #b9d4ff; }
.neg { color: #ffb38a; }
.eq { font-size: 13px; color: var(--muted); }
.scroll { max-height: 40vh; overflow: auto; }
.errs { width: 100%; border-collapse: collapse; font-size: 14px; }
.errs th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 4px 6px; position: sticky; top: 0; background: #123f32; }
.errs td { padding: 6px; border-top: 1px solid rgba(255,255,255,.08); vertical-align: top; }

.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: rgba(255,255,255,.1); }
.chart .tick { fill: var(--muted); font-size: 11px; }
.chart .opt-line { stroke: var(--blue); stroke-width: 2; stroke-dasharray: 6 4; }
.chart .run { fill: none; stroke: var(--orange); stroke-width: 2.5; }
.chart .dot { fill: #ffd2b3; }
.chart .bar-opt { fill: var(--blue); opacity: .8; }
.chart .bar-you { fill: var(--orange); }
.legend { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin: 6px 0 0; }
.k { display: inline-block; width: 14px; height: 4px; border-radius: 2px; margin-left: 8px; }
.k.you { background: var(--orange); }
.k.opt { background: var(--blue); }
.bars { display: flex; flex-direction: column; gap: 8px; }
.brow { display: grid; grid-template-columns: minmax(140px, 1.2fr) 2fr 52px; gap: 10px; align-items: center; font-size: 14px; }
.btrack { height: 10px; background: rgba(255,255,255,.07); border-radius: 5px; }
.bfill { height: 100%; background: var(--orange); border-radius: 5px; }
.brow b { text-align: right; color: #ffb38a; }

@media (hover: none) { kbd { display: none; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
