/* Tavern Draft: warm tavern wood, candlelight and toy clay. The page around the table follows
   light and dark; the table itself (the canvas) keeps its candlelit warmth in both. */
:root {
  --bg: #F3E7D3;          /* parchment */
  --card: #FFF8EC;
  --ink: #2B1D14;         /* the clay toys' ink */
  --muted: #6E5847;
  --line: #DCC7A8;
  --wood: #4A3428;        /* the table's dark wood, behind the canvas */
  --accent: #B4521C;      /* candle flame, toasted */
  --on-accent: #FFF8EC;
  --accent-soft: #F7DCC2;
  --gold: #A87412;
  --coin: #E8B63A;
  --good: #3F7A3A;
  --err: #A8321F;
  --shadow: 0 1px 0 rgb(74 52 40 / 12%), 0 10px 24px -14px rgb(74 52 40 / 45%);
  --knight: #7D8EA6; --barbarian: #D9782C; --rogue: #5B4872; --ranger: #4F9A4A; --mage: #7656C4; --cleric: #D9A62C;
  --display: "Fraunces", ui-serif, Georgia, serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1B130E;
    --card: #2A1E16;
    --ink: #F3E6D3;
    --muted: #BDA68E;
    --line: #47362A;
    --wood: #4A3428;
    --accent: #F0A04B;
    --on-accent: #1B130E;
    --accent-soft: #4A2E17;
    --gold: #F2C14E;
    --good: #8FCB7A;
    --err: #FF9C86;
    --shadow: 0 1px 0 rgb(0 0 0 / 30%), 0 10px 24px -14px rgb(0 0 0 / 70%);
    --rogue: #9C86BC;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.5 ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 8px; }
h1, h2, h3 { font-family: var(--display); font-variation-settings: "SOFT" 100; margin: 0; line-height: 1.15; }
h1 { font-size: clamp(34px, 8vw, 52px); font-weight: 800; }
h2 { font-size: 24px; font-weight: 700; }
h3 { font-size: 19px; font-weight: 700; }
h2:focus, h2:focus-visible { outline: none; }
p { margin: 0; }

main { width: 100%; max-width: 980px; margin: 0 auto; flex: 1; }

/* ---- the table ---- */
.table { background: var(--wood); }
.table canvas {
  display: block; width: 100%;
  height: clamp(220px, min(44vh, 76vw), 520px);
  background: var(--wood);
  touch-action: pan-y;
}
.no3d { color: #F3E6D3; padding: 18px 16px; font-size: 16px; }
@media (min-width: 720px) {
  main { padding: 16px 16px 0; }
  .table { border-radius: 18px; overflow: hidden; box-shadow: var(--shadow); }
}

.panel { padding: 16px 16px 8px; display: grid; gap: 20px; }
@media (min-width: 720px) { .panel { padding: 20px 4px 8px; } }
.screen { display: grid; gap: 14px; }
.loading { color: var(--muted); }

/* ---- buttons ---- */
button {
  font: inherit; font-size: 16px; color: var(--ink);
  min-height: 44px; padding: 0 16px;
  border-radius: 12px; border: 2px solid var(--line); background: var(--card);
  cursor: pointer;
  transition: transform .12s ease, background-color .12s ease, border-color .12s ease;
}
button:active:not(:disabled):not([aria-disabled="true"]) { transform: translateY(1px) scale(.98); }
button:disabled, button[aria-disabled="true"] { opacity: .55; cursor: default; }
button.go {
  background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 700;
  box-shadow: 0 3px 0 color-mix(in srgb, var(--accent) 60%, #000);
}
button.go:active:not(:disabled):not([aria-disabled="true"]) { box-shadow: 0 1px 0 color-mix(in srgb, var(--accent) 60%, #000); transform: translateY(2px); }
button.big { min-height: 54px; font-size: 18px; padding: 0 24px; justify-self: start; }
button.quiet { background: transparent; border-color: transparent; text-decoration: underline; text-underline-offset: 3px; padding: 0 8px; color: var(--muted); }
button[aria-pressed="true"]:not(.card):not(.slot) { background: var(--accent-soft); border-color: var(--accent); }
.cost { color: var(--muted); font-size: 14px; margin-left: 4px; }

.lede { font-size: 18px; max-width: 34em; }
.hint { color: var(--muted); font-size: 15px; }
.err { color: var(--err); font-weight: 600; }

/* ---- the bar: status line ---- */
.status { display: flex; align-items: center; gap: 12px 16px; flex-wrap: wrap; }
.status h2 { margin-right: auto; }
.gold { display: inline-flex; align-items: center; gap: 6px; font-size: 17px; }
.gold b { font-size: 20px; color: var(--gold); font-variant-numeric: tabular-nums; }
.gold svg { width: 22px; height: 22px; fill: var(--coin); stroke: color-mix(in srgb, var(--coin) 55%, #000); stroke-width: 1.4; }
.gold svg .rim { fill: none; }
#fight { min-width: 110px; font-size: 18px; }

.cleared { background: var(--card); border: 2px solid var(--line); border-left: 6px solid var(--good); border-radius: 12px; padding: 12px 14px; display: grid; gap: 6px; }
.cleared b { color: var(--good); }
.log summary { cursor: pointer; color: var(--muted); font-size: 15px; min-height: 32px; display: flex; align-items: center; }
.log summary::before { content: "▸"; margin-right: 6px; }
.log[open] summary::before { content: "▾"; }
.log summary::-webkit-details-marker { display: none; }
.log ol { margin: 6px 0 0; padding-left: 22px; font-size: 15px; max-height: 260px; overflow: auto; }

/* ---- the party: the table's slots as buttons ---- */
.party { display: grid; gap: 10px; }
@media (min-width: 720px) {
  .party { grid-template-columns: minmax(0, 420px) minmax(0, 1fr); align-items: start; column-gap: 20px; }
  .party h3 { grid-column: 1 / -1; }
}
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; max-width: 460px; }
.row-head { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); text-align: center; }
.slot {
  min-height: 52px; padding: 4px 10px; display: grid; align-content: center; justify-items: start; gap: 0;
  text-align: left; border-style: dashed; background: transparent;
}
.slot .who { font-weight: 700; font-size: 16px; line-height: 1.2; }
.slot .sub { font-size: 14px; color: var(--muted); }
.slot.empty { justify-items: center; }
.slot.filled { border-style: solid; background: var(--card); border-left: 6px solid var(--cls, var(--line)); }
.slot.target { border-color: var(--accent); border-style: dashed; background: var(--accent-soft); }
.slot.target .sub { color: var(--ink); }
.slot.picked { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent) inset; }

.picked { display: grid; gap: 8px; background: var(--card); border-radius: 12px; padding: 10px 14px; border: 2px solid var(--line); max-width: 640px; font-size: 16px; }
.picked .actions button { min-height: 40px; }
.picked.compact { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; }
.picked:has(> .hint:only-child) { background: transparent; border: 0; padding: 0; }
.picked .bio { font-style: italic; }
.meanings { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; font-size: 16px; flex-basis: 100%; }
.meanings li { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; }

/* ---- the bar: starting over ---- */
.leave { display: grid; gap: 8px; justify-items: start; margin-top: 8px; padding-top: 12px; border-top: 1px dashed var(--line); font-size: 16px; }
.leave p { margin: 0; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* ---- the bar: recruit cards ---- */
.bar-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-top: 6px; }
.cards {
  display: grid; gap: 10px;
  grid-template-columns: repeat(5, minmax(0, 1fr));
}
@media (max-width: 860px) {
  /* A row you swipe along, so the table stays in view while you pick. */
  .cards {
    grid-template-columns: none; grid-auto-flow: column; grid-auto-columns: min(78%, 250px);
    overflow-x: auto; scroll-snap-type: x mandatory; scroll-padding: 0 16px;
    margin: 0 -16px; padding: 2px 16px 10px;
  }
  .card { scroll-snap-align: start; }
}
.cards .empty { color: var(--muted); grid-column: 1 / -1; }
.card {
  display: grid; align-content: start; gap: 6px; text-align: left; height: auto; min-height: 200px;
  padding: 12px 12px 12px 14px; background: var(--card); border: 2px solid var(--line);
  border-top: 6px solid var(--cls, var(--line)); box-shadow: var(--shadow);
}
.card[aria-pressed="true"] { border-color: var(--accent); border-top-color: var(--cls); box-shadow: 0 0 0 3px var(--accent); transform: translateY(-3px); }
.card-top { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 0 8px; }
.card .who { font-family: var(--display); font-variation-settings: "SOFT" 100; font-size: 19px; font-weight: 700; }
.card .cls { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--cls); }
.card .role { font-size: 13px; color: var(--muted); line-height: 1.3; }
.card .bio { font-size: 15px; line-height: 1.4; font-style: italic; }
.merge { font-size: 13px; font-weight: 700; color: var(--good); }
.merge::before { content: "★ "; }

.traits { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 14px; }
.trait { display: inline-flex; align-items: center; gap: 4px; }
.ticon { width: 16px; height: 16px; fill: currentColor; stroke: currentColor; stroke-width: 1.6; stroke-linejoin: round; }
.ticon .pupil { stroke: none; }
.t-courage { color: #C4561E; }
.t-kindness { color: #C2405F; }
.t-focus { color: #2F6F9E; }
.trait.lvl-0 .ticon { fill: none; }
.trait.lvl-0 .ticon .pupil { fill: none; }
.trait.lvl-1 .ticon { fill-opacity: .4; }
@media (prefers-color-scheme: dark) {
  .t-courage { color: #F3965F; }
  .t-kindness { color: #F38AA4; }
  .t-focus { color: #7FBDEB; }
}

.cls-knight { --cls: var(--knight); }
.cls-barbarian { --cls: var(--barbarian); }
.cls-rogue { --cls: var(--rogue); }
.cls-ranger { --cls: var(--ranger); }
.cls-mage { --cls: var(--mage); }
.cls-cleric { --cls: var(--cleric); }

/* ---- the fight ---- */
.caption { min-height: 3em; font-size: 17px; }

/* ---- the end ---- */
.depth { font-size: 20px; }
.depth b { font-family: var(--display); font-variation-settings: "SOFT" 100; font-size: 44px; color: var(--gold); display: block; line-height: 1.1; }
.saga:empty { display: none; }
.saga .told {
  background: var(--card); border: 2px solid var(--line); border-radius: 12px; padding: 14px 16px;
  font-family: var(--display); font-variation-settings: "SOFT" 100; font-weight: 600; font-size: 18px; line-height: 1.5;
  max-width: 36em; animation: fade-in 1.2s ease both;
}
#standing:empty { display: none; }
@keyframes fade-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ---- the board ---- */
.board { background: var(--card); border: 2px solid var(--line); border-radius: 16px; padding: 14px 16px; display: grid; gap: 10px; max-width: 520px; }
.board-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.tabs { display: inline-flex; gap: 4px; }
.tabs button { min-height: 38px; padding: 0 12px; font-size: 15px; }
.board .tabs button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 700; }
.scores { margin: 0; padding: 0; list-style: none; counter-reset: rank; display: grid; gap: 2px; }
.scores li { display: flex; gap: 10px; padding: 6px 4px; border-bottom: 1px dashed var(--line); counter-increment: rank; }
.scores li::before { content: counter(rank); width: 1.6em; color: var(--muted); font-variant-numeric: tabular-nums; }
.scores li.empty { color: var(--muted); border: 0; }
.scores li.empty::before { content: none; }
.scores .who { flex: 1; overflow-wrap: anywhere; }
.scores .pts { font-variant-numeric: tabular-nums; color: var(--muted); }
.scores li.mine { font-weight: 700; }
.scores li.mine .pts { color: var(--gold); }
.resets { font-size: 13px; color: var(--muted); }
.you { font-size: 15px; }
.name-form { display: grid; gap: 6px; }
.name-form label { font-weight: 600; }
.name-form .row { display: flex; flex-wrap: wrap; gap: 8px; }
.name-form input {
  font: inherit; font-size: 16px; min-height: 44px; padding: 0 12px; flex: 1 1 160px; min-width: 0;
  border-radius: 12px; border: 2px solid var(--line); background: var(--bg); color: var(--ink);
}

footer {
  max-width: 980px; width: 100%; margin: 0 auto;
  padding: 20px 16px max(24px, env(safe-area-inset-bottom));
  color: var(--muted); font-size: 14px;
  display: flex; flex-wrap: wrap; gap: 6px 18px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
  .card[aria-pressed="true"] { transform: none; }
}
