/* Shared design tokens + components (derived from the student UI prototype). */
:root {
  --bg: #f7f6f3; --surface: #ffffff; --surface-2: #f0efe9; --border: #e0ddd4;
  --fg: #1a1916; --fg-2: #5c5a52; --fg-3: #9b9789;
  --accent: #1e6b3c; --gold: #b8860b;
  --accent-light: color-mix(in srgb, var(--accent) 12%, var(--surface));
  --accent-dark: color-mix(in srgb, var(--accent) 78%, #000);
  --gold-light: color-mix(in srgb, var(--gold) 12%, var(--surface));
  --warn: #c45c1a; --warn-light: #fdf0e8;
  --critical: #b91c1c; --critical-light: #fef2f2;
  --ok: #1e6b3c; --on-accent: #fff; --accent-fg: var(--accent);
  --nav-h: 52px;
  --ff: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --ff-mono: 'IBM Plex Mono', ui-monospace, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:#111110; --surface:#1c1c1a; --surface-2:#252522; --border:#2e2e2a;
    --fg:#f0ede6; --fg-2:#a8a49a; --fg-3:#7a776d;
    --warn:#e07a3a; --warn-light:#2a1a0d; --critical:#ef4444; --critical-light:#2a0d0d; --ok:#4dc876;
    --accent-fg: color-mix(in srgb, var(--accent) 55%, #fff);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg:#111110; --surface:#1c1c1a; --surface-2:#252522; --border:#2e2e2a;
  --fg:#f0ede6; --fg-2:#a8a49a; --fg-3:#7a776d;
  --warn:#e07a3a; --warn-light:#2a1a0d; --critical:#ef4444; --critical-light:#2a0d0d; --ok:#4dc876;
  --accent-fg: color-mix(in srgb, var(--accent) 55%, #fff);
  color-scheme: dark;
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body { font-family: var(--ff); background: var(--bg); color: var(--fg); font-size: 14px; line-height: 1.5; }
[hidden] { display: none !important; }
a { color: var(--accent-fg); }
h1 { font-size: 22px; letter-spacing: -0.02em; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
.muted { color: var(--fg-2); } .faint { color: var(--fg-3); } .small { font-size: 12px; } .tiny { font-size: 11px; }
.mono { font-family: var(--ff-mono); } .tnum { font-variant-numeric: tabular-nums; }
.right { text-align: right; } .center { text-align: center; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; } .grow { flex: 1; min-width: 0; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.mt { margin-top: 12px; } .mt2 { margin-top: 20px; } .mb { margin-bottom: 12px; }

/* top nav */
.topnav { position: fixed; top: 0; left: 0; right: 0; height: var(--nav-h); background: var(--accent); color: var(--on-accent); display: flex; align-items: center; padding: 0 14px; gap: 10px; z-index: 200; border-bottom: 1px solid var(--accent-dark); }
.topnav-logo { font-weight: 700; font-size: 15px; letter-spacing: -0.02em; flex: none; }
.topnav-logo span { opacity: .75; font-weight: 400; font-size: 11px; margin-left: 6px; }
.nav-sep { width: 1px; height: 24px; background: currentColor; opacity: .25; flex: none; }
.nav-spacer { flex: 1; }
.nav-btn { background: color-mix(in srgb, currentColor 14%, transparent); border: 1px solid color-mix(in srgb, currentColor 30%, transparent); border-radius: 6px; color: inherit; padding: 5px 11px; font: inherit; font-size: 12px; font-weight: 600; cursor: pointer; white-space: nowrap; text-decoration: none; }
.nav-btn:hover { background: color-mix(in srgb, currentColor 26%, transparent); }
.topnav .who { font-size: 12px; opacity: .9; }

/* buttons + forms */
.btn { background: var(--accent); color: var(--on-accent); border: 1px solid transparent; border-radius: 6px; padding: 7px 14px; font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--accent-dark); }
.btn:disabled { background: var(--border); color: var(--fg-3); cursor: not-allowed; }
.btn.sec { background: var(--surface-2); color: var(--fg); border-color: var(--border); }
.btn.sec:hover { background: var(--accent-light); color: var(--accent-fg); }
.btn.danger { background: var(--critical); } .btn.danger:hover { filter: brightness(.9); }
.btn.gold { background: var(--gold-light); color: var(--gold); border-color: var(--gold); }
.btn.sm { padding: 4px 10px; font-size: 12px; }
.input, .select, .textarea { width: 100%; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 8px 11px; font: inherit; font-size: 13px; color: var(--fg); outline: none; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-light); }
.textarea { resize: vertical; min-height: 80px; }
.input.sm, .select.sm { padding: 4px 8px; font-size: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field > label, .lbl { font-size: 12px; font-weight: 600; color: var(--fg-2); }
.field .hint { font-size: 11px; color: var(--fg-3); }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }

/* cards, tables, chips */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 16px; }
.card.flat { padding: 0; overflow: hidden; }
.card-h { background: var(--surface-2); border-bottom: 1px solid var(--border); padding: 11px 14px; display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 13px; }
.card-b { padding: 14px; }
.sec-h { font-size: 13px; font-weight: 600; margin: 4px 0 10px; display: flex; align-items: center; gap: 8px; }
.cnt { font-size: 11px; font-weight: 600; background: var(--surface-2); border-radius: 10px; padding: 1px 8px; color: var(--fg-2); }
table.t { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.t th { text-align: left; padding: 6px 10px; font-size: 10px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--fg-3); border-bottom: 1px solid var(--border); white-space: nowrap; }
table.t td { padding: 9px 10px; border-bottom: 1px solid var(--border); color: var(--fg-2); vertical-align: top; }
table.t tr:last-child td { border-bottom: none; }
table.t td.strong { color: var(--fg); font-weight: 600; }
.chip { display: inline-block; font-size: 11px; font-weight: 600; border-radius: 4px; padding: 2px 8px; background: var(--surface-2); color: var(--fg-2); }
.chip.ok { background: var(--accent-light); color: var(--accent-fg); }
.chip.warn { background: var(--warn-light); color: var(--warn); }
.chip.bad { background: var(--critical-light); color: var(--critical); }
.chip.gold { background: var(--gold-light); color: var(--gold); }
.pos { color: var(--ok); font-weight: 600; } .neg { color: var(--critical); font-weight: 600; }

/* Formatted game text (see richtext.js): bold, italic, underline, colours, lists, quotes, tables */
.rt p { margin: 0 0 .6em; } .rt > :last-child { margin-bottom: 0; }
.rt ul, .rt ol { margin: 0 0 .6em 1.3em; } .rt li { margin-bottom: .15em; }
.rt h3, .rt h4, .rt h5 { margin: .8em 0 .3em; line-height: 1.3; } .rt h3 { font-size: 1.15em; } .rt h4 { font-size: 1.05em; } .rt h5 { font-size: 1em; }
.rt blockquote { border-left: 3px solid var(--border); padding-left: 10px; margin: 0 0 .6em; color: var(--fg-2); }
.rt hr { border: 0; border-top: 1px solid var(--border); margin: .8em 0; }
.rt table { border-collapse: collapse; margin: 0 0 .6em; } .rt th, .rt td { border: 1px solid var(--border); padding: 3px 9px; text-align: left; } .rt th { background: var(--surface-2); }
.rt-red { color: var(--critical); } .rt-green { color: var(--ok); } .rt-amber { color: var(--warn); } .rt-blue { color: #1d4ed8; } .rt-grey { color: var(--fg-3); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .rt-blue { color: #60a5fa; } }
:root[data-theme="dark"] .rt-blue { color: #60a5fa; }
.notice { border: 1px solid var(--border); background: var(--surface-2); border-radius: 8px; padding: 10px 13px; font-size: 12.5px; }
.notice.warn { background: var(--warn-light); border-color: var(--warn); color: var(--warn); }
.notice.ok { background: var(--accent-light); border-color: var(--accent); }
.notice.bad { background: var(--critical-light); border-color: var(--critical); color: var(--critical); }
.empty { padding: 28px 16px; text-align: center; color: var(--fg-3); font-size: 13px; }
.err { color: var(--critical); font-size: 12.5px; min-height: 18px; }
.rte-body table { border-collapse: collapse; } .rte-body td, .rte-body th { border: 1px solid var(--border); padding: 4px 8px; }

/* modals + toast */
.modal-bd { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 300; display: flex; align-items: center; justify-content: center; padding: 20px; overflow-y: auto; }
.modal { background: var(--surface); border-radius: 12px; width: 100%; max-width: 480px; overflow: hidden; max-height: 92vh; display: flex; flex-direction: column; }
.modal.wide { max-width: 760px; }
.modal-h { padding: 15px 18px; border-bottom: 1px solid var(--border); font-weight: 600; font-size: 15px; display: flex; align-items: center; gap: 8px; flex: none; }
.modal-body { padding: 18px; display: flex; flex-direction: column; gap: 12px; overflow-y: auto; }
.modal-foot { padding: 13px 18px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; flex: none; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(90px); background: var(--fg); color: var(--bg); border-radius: 8px; padding: 10px 18px; font-size: 13px; font-weight: 500; z-index: 400; transition: transform .3s; pointer-events: none; max-width: 90vw; }
.toast.show { transform: translateX(-50%) translateY(0); }
.toast.bad { background: var(--critical); color: #fff; }

/* tabs */
.tabs { display: flex; border-bottom: 1px solid var(--border); background: var(--surface); padding: 0 14px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { padding: 11px 13px; font: inherit; font-size: 12.5px; font-weight: 500; color: var(--fg-2); border: none; background: none; cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; margin-bottom: -1px; }
.tab:hover { color: var(--fg); }
.tab.active { color: var(--accent-fg); border-bottom-color: var(--accent); font-weight: 600; }
.tab .badge { background: var(--critical); color: #fff; border-radius: 9px; font-size: 10px; padding: 0 6px; margin-left: 5px; }

@media (max-width: 640px) { .topnav .who { display: none; } .hide-narrow { display: none !important; } .topnav-logo span { display: none; } .topnav-logo { max-width: 38vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } }

/* alerts stay until dismissed */
.alerts { position: fixed; top: calc(var(--nav-h, 48px) + 10px); left: 50%; transform: translateX(-50%); z-index: 450; display: grid; gap: 8px; width: min(560px, calc(100vw - 24px)); }
.alert-b { display: flex; align-items: center; gap: 10px; background: var(--surface); color: var(--fg); border: 1px solid var(--accent); border-left-width: 5px; border-radius: 8px; padding: 10px 10px 10px 14px; box-shadow: 0 6px 24px rgba(0,0,0,.25); font-size: 14px; font-weight: 500; }
.alert-b.bad { border-color: var(--critical); }
.alert-t { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.alert-x { flex: none; width: 28px; height: 28px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface-2); color: var(--fg); cursor: pointer; font-size: 14px; line-height: 1; }
.alert-x:hover { background: var(--border); }

.toast.good { background: #1e7a3c; color: #fff; }
