/* TableKeeper deck builder: matches design/builder.figcraft */
:root {
  --bg: #f3ecdc; --panel: #fffaf0; --line: #e0d3b8; --field: #cbbd9f; --row: #ece2cc;
  --ink: #2c241c; --muted: #6f6353; --faint: #9a8d78; --gold: #b08f55; --bronze: #7a5f32;
  --board: #1f2d2e; --cream: #f6edd9; --hl: #f3e5c8; --group: #f3ead6;
  --ok-bg: #e3ebdc; --ok: #2f4a2c; --over-bg: #f6e2bf; --over: #7a4b0c;
  --ui: "IBM Plex Sans Condensed", system-ui, sans-serif; --sc: "Alegreya SC", Georgia, serif; --serif: "Alegreya", Georgia, serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.4 var(--ui); font-synthesis: none; }
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--bronze); }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 20px 0; }
.hint { color: var(--muted); font-size: 13px; line-height: 18px; margin: 6px 0 0; }
.hint.italic, .italic { font-style: italic; }
.center { text-align: center; }
.field-label { display: block; color: var(--muted); font-size: 13px; font-weight: 500; margin: 16px 0 6px; }
.link { background: none; border: 0; padding: 0; color: inherit; text-decoration: underline; text-underline-offset: 3px; }
.wordmark { font: 800 36px/1.1 var(--sc); margin: 0; color: var(--ink); }
.wordmark.small { font-size: 28px; color: var(--cream); }
.tagline { font: italic 400 18px var(--serif); color: var(--gold); }

/* ---------- unlock ---------- */
.unlock { min-height: 100vh; background: var(--board); display: grid; place-items: center; position: relative; overflow: hidden; padding: 24px 16px 80px; }
.unlock-card { position: relative; z-index: 1; width: min(440px, 100%); background: var(--panel); border-radius: 12px; padding: 40px; box-shadow: 0 12px 32px rgba(0,0,0,.35); text-align: left; }
.unlock-card .wordmark, .unlock-card .tagline { display: block; text-align: center; }
.unlock-card .tagline { color: var(--bronze); font-size: 20px; margin: 4px 0 0; }
.lede { text-align: center; font-size: 16px; line-height: 23px; margin: 20px 0 24px; }
.code-input { width: 100%; height: 52px; border: 2px solid var(--gold); border-radius: 6px; padding: 0 16px; font-size: 20px; font-weight: 500; letter-spacing: 2px; text-transform: uppercase; background: #fff; }
.error { color: #9b2c1e; font-size: 14px; margin: 8px 0 0; }
.btn-primary { width: 100%; height: 52px; margin-top: 20px; border: 0; border-radius: 8px; background: var(--board); color: var(--cream); font-size: 18px; font-weight: 600; }
.btn-primary:hover { background: #2b3d3e; }
.btn-primary:disabled { opacity: .6; cursor: progress; }
.btn-primary.big { height: 54px; }
.deco { position: absolute; top: 50%; width: 200px; transform: translateY(-50%) rotate(-6deg); border-radius: 6px; box-shadow: 0 10px 28px rgba(0,0,0,.4); opacity: .9; }
.deco-l { left: calc(50% - 470px); }
.deco-r { right: calc(50% - 470px); transform: translateY(-50%) rotate(6deg); }
@media (max-width: 980px) { .deco { display: none; } }

/* ---------- builder ---------- */
.topbar { height: 64px; background: var(--board); display: flex; align-items: center; gap: 18px; padding: 0 32px; }
.topbar nav { margin-left: auto; display: flex; gap: 28px; }
.topbar nav a, .topbar nav .link { color: var(--cream); font-weight: 500; text-decoration: none; }
.topbar nav a:hover, .topbar nav .link:hover { text-decoration: underline; }
.grid { display: grid; grid-template-columns: 320px minmax(0, 1fr) 392px; gap: 24px; padding: 24px; max-width: 1600px; margin: 0 auto; align-items: start; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 20px 24px 24px; }
.panel h2 { font: 700 20px/1.2 var(--sc); margin: 0; }
.panel h2 .num { margin-right: 4px; }
select, .search { width: 100%; height: 40px; border: 1px solid var(--field); border-radius: 6px; background: #fff; padding: 0 12px; font-size: 16px; }
select:disabled { background: #f7f2e7; color: var(--faint); }
.level-row { display: flex; align-items: center; gap: 14px; }
.level-row .hint { margin: 0; }
.stepper { display: flex; width: 124px; height: 40px; border: 1px solid var(--field); border-radius: 6px; background: #fff; flex: none; }
.stepper button { width: 40px; border: 0; background: none; font-size: 18px; }
.stepper input { width: 42px; border: 0; text-align: center; font-size: 18px; font-weight: 600; -moz-appearance: textfield; }
.stepper input::-webkit-inner-spin-button { -webkit-appearance: none; }
.styles { display: flex; gap: 8px; margin-top: 16px; }
.styles button { padding: 0; border: 2.5px solid transparent; border-radius: 5px; background: none; line-height: 0; }
.styles button[aria-checked="true"] { border-color: var(--gold); }
.styles img { width: 48px; height: 67px; border-radius: 2px; }
.style-name { font-weight: 600; margin: 12px 0 0; }
.seg { display: flex; border: 1px solid var(--field); border-radius: 6px; overflow: hidden; background: #fff; }
.seg button { flex: 1; height: 40px; border: 0; border-left: 1px solid var(--line); background: none; font-weight: 500; }
.seg button:first-child { border-left: 0; }
.seg button[aria-checked="true"] { background: var(--board); color: var(--cream); }
.seg.small button { height: 30px; padding: 0 12px; font-size: 14px; }
.check { display: flex; gap: 10px; align-items: flex-start; margin-top: 20px; }
.check input { width: 18px; height: 18px; margin: 2px 0 0; accent-color: var(--board); flex: none; }
.check small { display: block; color: var(--muted); font-size: 13px; }

.spells-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.counters { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.pill { height: 28px; border-radius: 14px; padding: 0 14px; display: inline-flex; align-items: center; font-weight: 500; font-size: 14px; background: var(--ok-bg); color: var(--ok); }
.pill.over { background: var(--over-bg); color: var(--over); }
.pill.under { background: #efe8d8; color: var(--muted); }
.tabs { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0 0; }
.tabs button { height: 32px; padding: 0 16px; border-radius: 16px; border: 1px solid var(--field); background: #fff; font-weight: 500; font-size: 14px; }
.tabs button[aria-selected="true"] { background: var(--board); border-color: var(--board); color: var(--cream); }
.toggle { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-weight: 500; font-size: 14px; margin-top: 12px; }
.toggle input { accent-color: var(--board); }
.list-head, .row { display: grid; grid-template-columns: 34px minmax(0, 1fr) 120px 104px 92px; align-items: center; }
.list-head { margin-top: 12px; padding-bottom: 6px; border-bottom: 1px solid var(--field); color: var(--faint); font-size: 11px; font-weight: 600; letter-spacing: 1px; text-transform: uppercase; }
.list-head span:first-child { grid-column: 2; }
.group { display: flex; align-items: baseline; gap: 12px; width: 100%; margin-top: 6px; padding: 6px 10px; border: 0; border-radius: 4px; background: none; text-align: left; color: var(--bronze); }
.group:hover, .group.collapsed { background: var(--group); }
.group b { font: 700 16px var(--sc); white-space: nowrap; }
.group b::before { content: "▾"; display: inline-block; width: 16px; font-size: 12px; }
.group.collapsed b::before { content: "▸"; }
.group span { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row { min-height: 38px; border-bottom: 1px solid var(--row); cursor: pointer; position: relative; }
.row:hover { background: #faf3e4; }
.row.current { background: var(--hl); border-radius: 4px; box-shadow: inset 3px 0 0 var(--gold); }
.row input { width: 18px; height: 18px; margin: 0 0 0 8px; accent-color: var(--board); }
.row .name { font: 400 18px/1.2 var(--serif); padding: 6px 8px 6px 6px; }
.row.current .name { font-weight: 700; }
.row .school, .row .time { color: var(--muted); font-size: 14px; }
.row .tags { color: var(--bronze); font-size: 13px; font-weight: 500; }
.row .tags .sub { color: var(--ok); }
.row.locked input { opacity: .5; }
.empty-list { color: var(--muted); padding: 24px 8px; }

.stage { display: flex; align-items: center; justify-content: center; gap: 6px; margin-top: 4px; }
.nav { width: 32px; height: 60px; border: 0; background: none; color: var(--faint); font-size: 32px; }
.nav:disabled { opacity: .3; cursor: default; }
.card-frame { width: 260px; height: 363px; position: relative; flex: none; border-radius: 8px; overflow: hidden; box-shadow: 0 6px 16px rgba(44,36,28,.25); background: #e9e0cc; }
.card-frame iframe { position: absolute; left: 0; top: 0; border: 0; width: 63mm; height: 88mm; transform-origin: 0 0; background: transparent; }
.card-frame .empty { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 24px; color: var(--muted); margin: 0; }
.caption { text-align: center; color: var(--muted); font-size: 14px; margin: 12px 0 0; min-height: 20px; }
.cardnav { text-align: center; color: var(--muted); font-size: 14px; }
.summary p { margin: 6px 0 0; }
.summary .warn { color: #9b2c1e; }
.status { color: var(--muted); font-size: 13px; min-height: 18px; margin: 8px 0 0; }
.guide-link { font-weight: 500; font-size: 14px; }
.legal { max-width: 1100px; margin: 0 auto; padding: 8px 24px 32px; color: var(--muted); font-size: 12px; line-height: 17px; text-align: center; }
.legal.on-dark { position: absolute; bottom: 0; left: 0; right: 0; color: var(--gold); }
.offscreen { position: absolute; left: -20000px; top: 0; width: 1200px; height: 800px; border: 0; }

@media (max-width: 1200px) {
  .grid { grid-template-columns: 320px minmax(0, 1fr); }
  .preview { grid-column: 1 / -1; display: grid; grid-template-columns: auto 1fr; column-gap: 32px; }
  .preview > * { grid-column: 2; }
  .preview > .spells-head, .preview > .stage, .preview > .caption, .preview > .cardnav { grid-column: 1; }
  .preview > .spells-head { grid-row: 1; } .preview > .stage { grid-row: 2 / span 6; align-self: start; }
  .preview > hr { display: none; }
}
@media (max-width: 820px) {
  .topbar { padding: 0 16px; gap: 10px; } .topbar .tagline { display: none; } .topbar nav { gap: 16px; font-size: 14px; }
  .grid { grid-template-columns: minmax(0, 1fr); padding: 16px; gap: 16px; }
  .preview { display: block; }
  .panel { padding: 16px; }
  .list-head, .row { grid-template-columns: 34px minmax(0, 1fr) 84px; }
  .list-head span:nth-child(2), .list-head span:nth-child(3), .row .school, .row .time { display: none; }
  .row .tags { font-size: 12px; }
}

/* wide screens: the list scrolls inside its panel; settings and preview stay in view */
@media (min-width: 1201px) {
  .settings, .preview { position: sticky; top: 24px; }
  .spells { display: flex; flex-direction: column; height: calc(100vh - 112px); min-height: 640px; position: sticky; top: 24px; }
  .spells .list { flex: 1 1 auto; overflow-y: auto; min-height: 0; margin-right: -12px; padding-right: 12px; }
}
.seg button { white-space: nowrap; padding: 0 6px; font-size: 15px; }
.spells > * { flex: none; }
.spells > .list { flex: 1 1 auto; }
.styles { gap: 4px; }
.styles img { width: 44px; height: 61px; }
