/* Layout: top bar, then a two-pane workspace (bot roster | spell table), collapsing to one column on phones. */
:root {
  --bg: #eef2f6;
  --surface: #ffffff;
  --raised: #f5f8fb;
  --ink: #172130;
  --muted: #5a6879;
  --line: #d5dde6;
  --accent: #1d7a8d;
  --accent-ink: #ffffff;
  --accent-soft: #dcf0f4;
  --off: #9aa6b4;
  --danger: #b03a2e;
  --focus: #2f7fd1;
  --font-display: "Marcellus SC", "Palatino Linotype", Georgia, serif;
  --font-body: "Source Sans 3", "Segoe UI", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e141e; --surface: #151d2a; --raised: #1b2535; --ink: #e3eaf3; --muted: #93a1b5; --line: #273246;
    --accent: #6cc6d6; --accent-ink: #0b1a20; --accent-soft: #173640; --off: #5d6a7d; --danger: #e27c6f; --focus: #7ab8ff;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
/* the JS shows/hides views with the hidden attribute; class rules like .login { display: grid } would otherwise beat it */
[hidden] { display: none !important; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font-family: var(--font-body); font-size: 15px; line-height: 1.5; }
code { font-family: var(--font-mono); font-size: 0.92em; background: var(--raised); border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; }
h1, h2, h3 { font-family: var(--font-display); font-weight: 400; letter-spacing: 0.02em; margin: 0; text-wrap: balance; }
button { font: inherit; cursor: pointer; }
button:focus-visible, input:focus-visible, .bot-btn:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 20px; border-bottom: 1px solid var(--line); background: var(--surface); }
.brand { display: flex; align-items: baseline; gap: 12px; }
.wordmark { font-family: var(--font-display); font-size: 22px; letter-spacing: 0.04em; }
.section { color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: 0.12em; }
.who { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 14px; }
.link { background: none; border: none; color: var(--accent); padding: 0; font-weight: 600; }

.login { display: grid; place-items: center; padding: 48px 16px; }
.login-card { width: min(420px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 28px; display: grid; gap: 12px; }
.login-card h1 { font-size: 28px; }
.login-card p { margin: 0; color: var(--muted); }
.login-card label { font-weight: 600; font-size: 14px; margin-top: 6px; }
#code { font-family: var(--font-mono); font-size: 22px; letter-spacing: 0.18em; text-transform: uppercase; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--raised); color: var(--ink); }
.primary { background: var(--accent); color: var(--accent-ink); border: none; border-radius: 8px; padding: 10px 16px; font-weight: 700; }
.primary:disabled { opacity: 0.6; cursor: wait; }
.error { color: var(--danger); min-height: 1.2em; font-size: 14px; }

.app { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: 0; min-height: calc(100vh - 57px); }
.roster { border-right: 1px solid var(--line); padding: 20px 16px; background: var(--surface); }
.roster h2 { font-size: 18px; margin-bottom: 12px; }
.char-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.char { border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.char[open] { border-color: var(--accent); }
.char > summary { cursor: pointer; list-style: none; display: grid; grid-template-columns: 1em minmax(0, 1fr); column-gap: 6px; padding: 10px 12px; border-radius: 7px; }
.char > summary::-webkit-details-marker { display: none; }
.char > summary::before { content: "▸"; grid-column: 1; grid-row: 1; color: var(--muted); text-align: center; transition: transform 0.15s; }
.char[open] > summary::before { transform: rotate(90deg); }
.char > summary:hover { background: var(--raised); }
.char > summary:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.char .cn { grid-column: 2; font-weight: 700; overflow-wrap: anywhere; }
.char .cm { grid-column: 2; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.char .bot-list { padding: 2px 8px 8px 20px; }
.char .none { margin: 0; padding: 0 12px 10px 30px; }
.bot-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.bot-btn { width: 100%; text-align: left; background: var(--raised); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; color: var(--ink); display: grid; gap: 2px; }
.bot-btn:hover { border-color: var(--accent); }
.bot-btn[aria-current="true"] { border-color: var(--accent); background: var(--accent-soft); }
.bot-btn .n { font-weight: 700; }
.bot-btn .m { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.bot-btn .c { font-size: 12px; color: var(--accent); font-weight: 600; }

.panel { padding: 24px clamp(16px, 3vw, 32px) 64px; min-width: 0; }
.placeholder { max-width: 60ch; }
.placeholder h2 { font-size: 26px; margin-bottom: 8px; }
.placeholder p { color: var(--muted); }
.bot-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 12px 24px; }
.bot-head h2 { font-size: 30px; }
.bot-head p { margin: 2px 0 0; }
.bot-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; color: var(--muted); }
.danger { background: none; border: 1px solid var(--line); border-radius: 8px; padding: 7px 12px; color: var(--danger); font-weight: 600; }
.danger.confirm { border-color: var(--danger); background: var(--danger); color: var(--surface); }
.hint { color: var(--muted); font-size: 14px; margin: 14px 0 6px; max-width: 75ch; }

.group { margin-top: 22px; }
.group h3 { font-size: 18px; display: flex; align-items: baseline; gap: 8px; padding-bottom: 6px; border-bottom: 1px solid var(--line); }
.group h3 .count { font-family: var(--font-body); font-size: 13px; color: var(--muted); letter-spacing: 0; }
.rows { list-style: none; margin: 0; padding: 0; }
.row { display: grid; grid-template-columns: 52px minmax(0, 1fr) 130px 84px 64px 112px 150px; align-items: center; gap: 8px 12px; padding: 9px 4px; border-bottom: 1px solid var(--line); }
.row.off .name, .row.off .type, .row.off .num { color: var(--off); }
.row.locked { opacity: 0.55; }
.row .name { font-weight: 600; overflow-wrap: anywhere; }
.row .type { font-size: 13px; color: var(--muted); }
.row .num { font-family: var(--font-mono); font-size: 13px; font-variant-numeric: tabular-nums; color: var(--muted); }
.row .lvl-note { display: block; font-size: 12px; color: var(--muted); font-weight: 400; }
.prio { width: 100%; font-family: var(--font-mono); font-size: 14px; padding: 5px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--raised); color: var(--ink); }
.status { display: flex; align-items: center; gap: 8px; justify-content: flex-end; }
.chip { font-size: 11px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; border-radius: 999px; padding: 2px 8px; }
.chip.custom { background: var(--accent-soft); color: var(--accent); }
.chip.default { color: var(--muted); border: 1px solid var(--line); }
.reset { background: none; border: none; color: var(--accent); font-size: 13px; font-weight: 600; padding: 0; }
.head-row { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); border-bottom: none; padding-bottom: 0; }

/* on/off switch */
.switch { position: relative; width: 40px; height: 22px; display: inline-block; }
.switch input { opacity: 0; width: 100%; height: 100%; margin: 0; position: absolute; inset: 0; cursor: pointer; }
.switch .track { position: absolute; inset: 0; border-radius: 999px; background: var(--off); transition: background 0.15s; pointer-events: none; }
.switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: var(--surface); transition: transform 0.15s; }
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(18px); }
.switch input:focus-visible + .track { outline: 2px solid var(--focus); outline-offset: 2px; }

/* tabs */
.tabs { display: flex; gap: 4px; margin-top: 18px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs [role="tab"] { background: none; border: none; border-bottom: 3px solid transparent; padding: 8px 14px; color: var(--muted); font-weight: 600; white-space: nowrap; margin-bottom: -1px; }
.tabs [role="tab"][aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
.tabs [role="tab"]:hover { color: var(--ink); }
.tabs [role="tab"]:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.tab-bar { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 8px 24px; margin-top: 6px; }
.tab-bar .hint { margin: 14px 0 0; }
h3.sub { font-size: 20px; margin-top: 22px; }
.note { background: var(--accent-soft); border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; margin: 16px 0 0; max-width: 75ch; }

/* stance picker */
.stances { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; margin-top: 10px; }
.stance { text-align: left; background: var(--raised); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; color: var(--ink); display: grid; gap: 2px; }
.stance:hover { border-color: var(--accent); }
.stance.on { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.stance .sn { font-weight: 700; }
.stance .sd { font-size: 13px; color: var(--muted); }

/* setting rows (behavior + spell types) */
.settings { display: grid; }
.setting { display: grid; grid-template-columns: minmax(0, 1fr) auto 170px; align-items: center; gap: 6px 16px; padding: 10px 4px; border-bottom: 1px solid var(--line); }
.setting .ln { display: block; font-weight: 600; }
.setting .lh { display: block; font-size: 13px; color: var(--muted); max-width: 60ch; }
.setting .ctl { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.setting .unit, .setting .to { font-size: 13px; color: var(--muted); }
.setting .dflt { display: flex; align-items: center; justify-content: flex-end; gap: 10px; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.setting .row-reset { display: none; }
.setting.custom .row-reset { display: inline; }
.setting.custom .ln::after { content: "Custom"; margin-left: 8px; font-size: 11px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; border-radius: 999px; padding: 1px 7px; background: var(--accent-soft); color: var(--accent); vertical-align: 2px; }
.num-in { width: 84px; font-family: var(--font-mono); font-size: 14px; padding: 5px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--raised); color: var(--ink); }
.num-in:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }

/* spell type cards */
.type-card { border: 1px solid var(--line); border-radius: 8px; background: var(--surface); margin-top: 8px; }
.type-card > summary { cursor: pointer; list-style: none; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; padding: 10px 14px; }
.type-card > summary::-webkit-details-marker { display: none; }
.type-card > summary::before { content: "▸"; color: var(--muted); width: 1em; transition: transform 0.15s; }
.type-card[open] > summary::before { transform: rotate(90deg); }
.type-card > summary:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 8px; }
.type-card .tn { font-weight: 700; }
.type-card .chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip.off { background: var(--off); color: var(--surface); }
.type-body { padding: 0 14px 12px; }
.type-body h4 { margin: 12px 0 0; font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 700; }
.more { margin-top: 10px; }
.more > summary { cursor: pointer; color: var(--accent); font-weight: 600; font-size: 14px; padding: 4px 0; }
.bot-btn .c:empty { display: none; }

.orphan-list { list-style: none; padding: 0; margin: 8px 0 0; display: grid; gap: 6px; }
.orphan-list li { display: flex; gap: 12px; align-items: center; }
#orphans { margin-top: 28px; }
#orphans h3 { font-size: 18px; }

.toast { position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); max-width: min(420px, calc(100vw - 32px)); background: var(--ink); color: var(--bg); border-radius: 8px; padding: 10px 14px; font-size: 14px; box-shadow: 0 6px 24px rgba(0,0,0,0.25); }
.toast.bad { background: var(--danger); color: #fff; }

@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .roster { border-right: none; border-bottom: 1px solid var(--line); }
  .bot-list { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
  .row { grid-template-columns: 52px minmax(0, 1fr) 96px; }
  .row .type, .row .lvl, .row .num.mana { display: none; }
  .row .status { grid-column: 2 / -1; justify-content: flex-start; }
  .head-row { display: none; }
  .setting { grid-template-columns: 1fr; }
  .setting .dflt { justify-content: flex-start; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
