/* ==========================================================================
   AgentQuest theme: "dark grimoire". Shared by public pages and the portal.
   Fonts: Cinzel (display), EB Garamond (narrative), Inter (interface). OFL.
   ========================================================================== */
@font-face { font-family: "Cinzel"; font-weight: 500; font-display: swap; src: url(/static/fonts/cinzel-latin-500-normal.woff2) format("woff2"); }
@font-face { font-family: "Cinzel"; font-weight: 600; font-display: swap; src: url(/static/fonts/cinzel-latin-600-normal.woff2) format("woff2"); }
@font-face { font-family: "Cinzel"; font-weight: 700; font-display: swap; src: url(/static/fonts/cinzel-latin-700-normal.woff2) format("woff2"); }
@font-face { font-family: "EB Garamond"; font-weight: 400; font-display: swap; src: url(/static/fonts/eb-garamond-latin-400-normal.woff2) format("woff2"); }
@font-face { font-family: "EB Garamond"; font-weight: 400; font-style: italic; font-display: swap; src: url(/static/fonts/eb-garamond-latin-400-italic.woff2) format("woff2"); }
@font-face { font-family: "EB Garamond"; font-weight: 500; font-display: swap; src: url(/static/fonts/eb-garamond-latin-500-normal.woff2) format("woff2"); }
@font-face { font-family: "EB Garamond"; font-weight: 600; font-display: swap; src: url(/static/fonts/eb-garamond-latin-600-normal.woff2) format("woff2"); }
@font-face { font-family: "EB Garamond"; font-weight: 600; font-style: italic; font-display: swap; src: url(/static/fonts/eb-garamond-latin-600-italic.woff2) format("woff2"); }
@font-face { font-family: "Inter"; font-weight: 400; font-display: swap; src: url(/static/fonts/inter-latin-400-normal.woff2) format("woff2"); }
@font-face { font-family: "Inter"; font-weight: 500; font-display: swap; src: url(/static/fonts/inter-latin-500-normal.woff2) format("woff2"); }
@font-face { font-family: "Inter"; font-weight: 600; font-display: swap; src: url(/static/fonts/inter-latin-600-normal.woff2) format("woff2"); }

:root {
  color-scheme: dark;
  --ink-0: #0b0907;          /* deepest background */
  --ink-1: #120e0b;          /* page */
  --ink-2: #1a1410;          /* panel */
  --ink-3: #241b15;          /* raised */
  --ink-4: #302419;          /* hover */
  --line: #3a2d20;
  --line-gold: #6e5631;
  --parch: #ecdfc3;          /* main text */
  --parch-2: #cdbd9c;        /* secondary */
  --muted: #8f7f63;
  --gold: #d4a64a;
  --gold-hi: #f1d38a;
  --gold-lo: #8a6a2c;
  --crimson: #a3262a;
  --crimson-hi: #c9383a;
  --ember: #d9773a;
  --verdigris: #5fae8c;
  --arcane: #8f74d8;
  --sky: #5d9ad6;
  --r: 6px;
  --shadow: 0 10px 30px rgba(0,0,0,.45), 0 2px 6px rgba(0,0,0,.35);
  --font-display: "Cinzel", "Trajan Pro", Georgia, serif;
  --font-story: "EB Garamond", "Garamond", Georgia, serif;
  --font-ui: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --noise: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .9 0 0 0 0 .8 0 0 0 0 .6 0 0 0 .05 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  --corner: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Cg fill='none' stroke='%23b8903f' stroke-width='1.4'%3E%3Cpath d='M2 38V12Q2 2 12 2h26'/%3E%3Cpath d='M7 38V16q0-9 9-9h22' opacity='.55'/%3E%3Cpath d='M2 12q6 0 8 4' opacity='.7'/%3E%3Ccircle cx='12' cy='12' r='2.2' fill='%23d4a64a' stroke='none'/%3E%3C/g%3E%3C/svg%3E");
  --flourish: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 240 24'%3E%3Cg fill='none' stroke='%23b8903f' stroke-width='1.2'%3E%3Cpath d='M0 12h92'/%3E%3Cpath d='M148 12h92'/%3E%3Cpath d='M92 12c8-10 18-10 22 0 4-10 14-10 22 0-8 10-18 10-22 0-4 10-14 10-22 0z'/%3E%3Cpath d='M114 12l6-7 6 7-6 7z' fill='%23d4a64a'/%3E%3Ccircle cx='86' cy='12' r='2' fill='%23d4a64a'/%3E%3Ccircle cx='154' cy='12' r='2' fill='%23d4a64a'/%3E%3C/g%3E%3C/svg%3E");
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; min-height: 100vh; color: var(--parch); font: 16px/1.6 var(--font-ui); background: var(--ink-0); position: relative; isolation: isolate; }
/* Atmosphere layer: fixed to the viewport so long pages never show seams. */
body::before {
  content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(212,166,74,.10), transparent 60%),
    radial-gradient(900px 500px at 100% 0%, rgba(163,38,42,.10), transparent 60%),
    radial-gradient(800px 800px at 0% 100%, rgba(95,174,140,.05), transparent 60%),
    var(--noise), linear-gradient(180deg, var(--ink-1), var(--ink-0));
}
::selection { background: rgba(212,166,74,.35); color: #fff; }
a { color: var(--gold); text-decoration: none; transition: color .15s; }
a:hover { color: var(--gold-hi); }
img, svg { max-width: 100%; }
.icon { width: 1.1em; height: 1.1em; display: inline-block; vertical-align: -.18em; flex: none; }

/* ---------- typography ---------- */
h1, h2, h3, h4, .display { font-family: var(--font-display); font-weight: 600; letter-spacing: .04em; line-height: 1.2; margin: 0 0 .5em; color: var(--parch); }
h1 { font-size: clamp(1.9rem, 4vw, 2.9rem); font-weight: 700; }
h2 { font-size: clamp(1.35rem, 2.6vw, 1.75rem); }
h3 { font-size: 1.12rem; }
.gilded { background: linear-gradient(180deg, var(--gold-hi) 10%, var(--gold) 55%, var(--gold-lo)); -webkit-background-clip: text; background-clip: text; color: transparent; text-shadow: none; }
.eyebrow { font: 600 .72rem/1 var(--font-ui); letter-spacing: .22em; text-transform: uppercase; color: var(--gold); }
.story { font-family: var(--font-story); font-size: 1.16rem; line-height: 1.7; color: var(--parch); }
.story p { margin: 0 0 .9em; }
.dropcap > p:first-of-type::first-letter, p.dropcap::first-letter {
  font-family: var(--font-display); font-weight: 700; float: left; font-size: 3.3em; line-height: .82; padding: .08em .1em 0 0; color: var(--gold);
  text-shadow: 0 0 18px rgba(212,166,74,.35);
}
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.lead { font-family: var(--font-story); font-size: 1.28rem; color: var(--parch-2); line-height: 1.6; }
code, pre, kbd { font-family: ui-monospace, "JetBrains Mono", Menlo, monospace; font-size: .86em; }
.divider { height: 24px; margin: 28px auto; max-width: 320px; background: var(--flourish) center/contain no-repeat; opacity: .9; border: 0; }

/* ---------- layout ---------- */
.container { width: 100%; max-width: 1120px; margin: 0 auto; padding-inline: 20px; }
.narrow { max-width: 880px; }
.stack > * + * { margin-top: 16px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.grid { display: grid; gap: 18px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.grid-2 { display: grid; gap: 18px; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.section { padding-block: 40px; }

/* ---------- header / footer ---------- */
.topbar { position: sticky; top: 0; z-index: 20; backdrop-filter: blur(10px); background: linear-gradient(180deg, rgba(11,9,7,.92), rgba(11,9,7,.78)); border-bottom: 1px solid var(--line); }
.topbar::after { content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 1px; background: linear-gradient(90deg, transparent, var(--gold-lo), transparent); }
.topbar .container { display: flex; align-items: center; gap: 22px; height: 64px; }
.brand { display: flex; align-items: center; gap: 10px; font: 700 1.25rem/1 var(--font-display); letter-spacing: .08em; color: var(--parch); }
.brand .crest { width: 34px; height: 34px; color: var(--gold); filter: drop-shadow(0 0 8px rgba(212,166,74,.35)); }
.brand b { color: var(--gold); font-weight: 700; }
.nav { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.nav a { font: 500 .86rem var(--font-ui); color: var(--parch-2); padding: 8px 12px; border-radius: var(--r); letter-spacing: .02em; }
.nav a:hover, .nav a.active { color: var(--gold-hi); background: rgba(212,166,74,.08); }
.footer { margin-top: 64px; border-top: 1px solid var(--line); padding-block: 28px 40px; color: var(--muted); font-size: .8rem; line-height: 1.6; }
.footer a { color: var(--parch-2); }
@media (max-width: 760px) {
  .topbar .container { height: auto; padding-block: 10px; flex-wrap: wrap; gap: 8px; }
  .nav a { padding: 6px 8px; }
}

/* ---------- panels ---------- */
.panel {
  position: relative; background: linear-gradient(180deg, rgba(36,27,21,.92), rgba(23,18,14,.94)), var(--noise);
  border: 1px solid var(--line); border-radius: var(--r); padding: 22px; box-shadow: var(--shadow), inset 0 1px 0 rgba(241,211,138,.05);
}
.panel.ornate { border-color: var(--line-gold); padding: 28px; }
.panel.ornate::before, .panel.ornate::after {
  content: ""; position: absolute; width: 34px; height: 34px; background: var(--corner) no-repeat center/contain; pointer-events: none; opacity: .95;
}
.panel.ornate::before { top: 5px; left: 5px; }
.panel.ornate::after { bottom: 5px; right: 5px; transform: rotate(180deg); }
.panel-title { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.panel-title h2, .panel-title h3 { margin: 0; }
.panel-title .icon { color: var(--gold); width: 1.4em; height: 1.4em; }
.card { display: block; color: inherit; transition: transform .18s ease, border-color .18s ease, box-shadow .18s ease; }
a.card:hover, .card.clickable:hover { transform: translateY(-3px); border-color: var(--gold-lo); box-shadow: 0 16px 40px rgba(0,0,0,.55), 0 0 0 1px rgba(212,166,74,.15); color: inherit; }

/* ---------- buttons ---------- */
.btn, button.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; cursor: pointer; text-decoration: none;
  font: 600 .82rem/1 var(--font-ui); letter-spacing: .12em; text-transform: uppercase; padding: 12px 20px; border-radius: 4px;
  color: #fff4dd; border: 1px solid #d07a55; background: linear-gradient(180deg, var(--crimson-hi), var(--crimson) 60%, #7c1b1f);
  box-shadow: 0 1px 0 rgba(255,220,180,.25) inset, 0 6px 16px rgba(163,38,42,.25); transition: filter .15s, transform .15s;
}
.btn:hover { filter: brightness(1.12); color: #fff; transform: translateY(-1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; filter: none; }
.btn.gold { color: #1c140b; border-color: var(--gold-hi); background: linear-gradient(180deg, var(--gold-hi), var(--gold) 55%, #a87e2e); box-shadow: 0 1px 0 rgba(255,255,255,.4) inset, 0 6px 16px rgba(212,166,74,.2); }
.btn.ghost { color: var(--gold); background: transparent; border-color: var(--line-gold); box-shadow: none; }
.btn.ghost:hover { background: rgba(212,166,74,.08); color: var(--gold-hi); }
.btn.sm { padding: 8px 12px; font-size: .72rem; }
.btn.lg { padding: 16px 28px; font-size: .9rem; }
.btn .icon { width: 1.2em; height: 1.2em; }

/* ---------- forms ---------- */
label.field { display: block; }
label.field > span, .label { display: block; font: 600 .7rem/1 var(--font-ui); letter-spacing: .16em; text-transform: uppercase; color: var(--parch-2); margin: 0 0 8px; }
input, select, textarea {
  width: 100%; font: 400 .95rem var(--font-ui); color: var(--parch); background: rgba(11,9,7,.6); border: 1px solid var(--line); border-radius: 4px;
  padding: 11px 12px; outline: none; transition: border-color .15s, box-shadow .15s;
}
textarea { font-family: var(--font-story); font-size: 1.05rem; min-height: 96px; resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus { border-color: var(--gold-lo); box-shadow: 0 0 0 3px rgba(212,166,74,.15); }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--gold) 50%), linear-gradient(135deg, var(--gold) 50%, transparent 50%); background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 32px; }
input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--gold); }
.hint { font-size: .8rem; color: var(--muted); margin-top: 6px; }
.error { color: #f08a7e; }
.success { color: var(--verdigris); }
.notice { border-left: 3px solid var(--gold); background: rgba(212,166,74,.07); padding: 12px 14px; border-radius: 0 4px 4px 0; font-size: .9rem; }
.notice.danger { border-color: var(--crimson-hi); background: rgba(163,38,42,.1); }

/* ---------- badges, chips ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; font: 600 .66rem/1 var(--font-ui); letter-spacing: .14em; text-transform: uppercase; padding: 5px 8px; border-radius: 3px; border: 1px solid var(--line-gold); color: var(--gold); background: rgba(212,166,74,.07); }
.badge.crimson { color: #f3a39b; border-color: rgba(201,56,58,.6); background: rgba(163,38,42,.14); }
.badge.green { color: #9fe0c3; border-color: rgba(95,174,140,.5); background: rgba(95,174,140,.1); }
.badge.dim { color: var(--muted); border-color: var(--line); background: transparent; }
.rarity-common { --rc: #b9ad97; } .rarity-uncommon { --rc: #6fc49b; } .rarity-rare { --rc: #6aa8ea; } .rarity-epic { --rc: #b08cf0; } .rarity-legendary { --rc: #f1c45c; } .rarity-very_rare { --rc: #b08cf0; }
[class*="rarity-"] .rc, .rc { color: var(--rc, var(--gold)); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { font: 500 .82rem/1 var(--font-ui); padding: 9px 13px; border-radius: 999px; border: 1px solid var(--line); background: rgba(11,9,7,.5); color: var(--parch-2); cursor: pointer; transition: all .15s; }
.chip:hover { border-color: var(--line-gold); color: var(--parch); }
.chip.on { color: #1c140b; background: linear-gradient(180deg, var(--gold-hi), var(--gold)); border-color: var(--gold-hi); }
.chip:disabled { opacity: .35; cursor: not-allowed; }
.chip.locked { color: var(--gold); border-style: dashed; border-color: var(--line-gold); cursor: default; }

/* ---------- medallion (class / avatar) ---------- */
.medallion { --size: 64px; width: var(--size); height: var(--size); flex: none; border-radius: 50%; display: grid; place-items: center; color: var(--gold-hi);
  background: radial-gradient(circle at 35% 30%, #4a3825, #1b140e 70%); border: 2px solid var(--gold-lo);
  box-shadow: 0 0 0 3px rgba(11,9,7,.9), 0 0 0 4px var(--line-gold), 0 8px 18px rgba(0,0,0,.5), inset 0 2px 8px rgba(241,211,138,.15); }
.medallion .icon { width: 56%; height: 56%; filter: drop-shadow(0 2px 3px rgba(0,0,0,.6)); }
.medallion.lg { --size: 104px; }
.medallion.sm { --size: 40px; }
.medallion.dead { filter: grayscale(1) brightness(.7); }

/* ---------- ability score blocks ---------- */
.abilities { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 720px) { .abilities { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.ability { position: relative; text-align: center; padding: 14px 6px 22px; border: 1px solid var(--line-gold); border-radius: 10px 10px 40% 40% / 10px 10px 18px 18px;
  background: linear-gradient(180deg, rgba(48,36,25,.9), rgba(18,14,11,.95)); box-shadow: inset 0 1px 0 rgba(241,211,138,.08); }
.ability .abbr { font: 700 .78rem/1 var(--font-display); letter-spacing: .18em; color: var(--gold); }
.ability .score { font: 700 2rem/1.1 var(--font-display); color: var(--parch); margin-top: 6px; }
.ability .mod { position: absolute; left: 50%; bottom: -13px; transform: translateX(-50%); min-width: 40px; padding: 4px 8px; border-radius: 999px; font: 600 .82rem/1 var(--font-ui);
  background: var(--ink-0); border: 1px solid var(--gold-lo); color: var(--gold-hi); }
.ability.primary { border-color: var(--gold); box-shadow: 0 0 0 1px rgba(212,166,74,.25), inset 0 0 20px rgba(212,166,74,.08); }
.ability .adjust { display: flex; justify-content: center; gap: 6px; margin-top: 8px; }
.ability .adjust button { width: 28px; height: 28px; border-radius: 50%; border: 1px solid var(--line-gold); background: transparent; color: var(--gold); cursor: pointer; font: 600 1rem/1 var(--font-ui); }
.ability .adjust button:disabled { opacity: .3; cursor: not-allowed; }
.ability .base { font-size: .72rem; color: var(--muted); }

/* ---------- bars ---------- */
.bar { position: relative; height: 10px; border-radius: 999px; background: rgba(11,9,7,.8); border: 1px solid var(--line); overflow: hidden; }
.bar > i { position: absolute; inset: 0 auto 0 0; border-radius: inherit; background: linear-gradient(90deg, var(--gold-lo), var(--gold-hi)); box-shadow: 0 0 12px rgba(212,166,74,.4); }
.bar.hp > i { background: linear-gradient(90deg, #7c1b1f, var(--crimson-hi)); box-shadow: 0 0 12px rgba(201,56,58,.4); }
.stat-line { display: flex; justify-content: space-between; font-size: .78rem; color: var(--parch-2); margin-bottom: 5px; }

/* ---------- KPIs ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(118px, 1fr)); gap: 12px; }
.kpi { padding: 14px 16px; border: 1px solid var(--line); border-radius: var(--r); background: rgba(11,9,7,.45); }
.kpi b { display: block; font: 700 1.6rem/1.1 var(--font-display); color: var(--gold-hi); }
.kpi span { font: 600 .66rem/1.2 var(--font-ui); letter-spacing: .16em; text-transform: uppercase; color: var(--muted); }
.kpi .icon { float: right; color: var(--gold-lo); width: 22px; height: 22px; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table.grim { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.grim th { font: 600 .66rem/1 var(--font-ui); letter-spacing: .16em; text-transform: uppercase; color: var(--muted); text-align: left; padding: 12px 10px; border-bottom: 1px solid var(--line-gold); }
table.grim td { padding: 12px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.grim tr:hover td { background: rgba(212,166,74,.04); }
.rank { font: 700 1.05rem var(--font-display); color: var(--muted); width: 48px; }
.rank.r1 { color: #f1c45c; } .rank.r2 { color: #cfd6dd; } .rank.r3 { color: #d39363; }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 2px; flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; border-bottom: 1px solid var(--line); margin-bottom: 18px; }
.tabs a, .tabs button { font: 600 .72rem/1 var(--font-ui); letter-spacing: .1em; white-space: nowrap; flex: 0 0 auto; text-transform: uppercase; color: var(--muted); padding: 12px 10px; border: 0; background: none; border-bottom: 2px solid transparent; cursor: pointer; margin-bottom: -1px; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a:hover, .tabs button:hover { color: var(--parch); }
.tabs .on { color: var(--gold-hi); border-bottom-color: var(--gold); }

/* ---------- dice ---------- */
.roll { display: inline-flex; align-items: center; gap: 6px; font: 500 .78rem/1 var(--font-ui); padding: 5px 9px 5px 6px; border-radius: 999px; border: 1px solid var(--line); background: rgba(11,9,7,.6); color: var(--parch-2); white-space: nowrap; }
.roll .icon { width: 18px; height: 18px; color: var(--parch-2); }
.roll b { font-weight: 600; color: var(--parch); }
.roll.crit_success { border-color: #b8903f; color: var(--gold-hi); box-shadow: 0 0 14px rgba(241,196,92,.35); }
.roll.crit_success .icon { color: var(--gold-hi); }
.roll.success { border-color: rgba(95,174,140,.55); } .roll.success .icon { color: var(--verdigris); }
.roll.fail { border-color: rgba(217,119,58,.45); } .roll.fail .icon { color: var(--ember); }
.roll.crit_fail { border-color: rgba(201,56,58,.7); color: #f3a39b; box-shadow: 0 0 14px rgba(201,56,58,.3); } .roll.crit_fail .icon { color: var(--crimson-hi); }

/* ---------- code scroll ---------- */
pre.scroll { position: relative; margin: 0; padding: 16px 18px; border-radius: 4px; border: 1px solid var(--line); background: #0a0806; color: #e8d9b6; overflow-x: auto; line-height: 1.7; white-space: pre-wrap; word-break: break-word; }
pre.scroll .c { color: var(--muted); }

/* ---------- utility ---------- */
.hide-sm { } @media (max-width: 760px) { .hide-sm { display: none !important; } }
.center { text-align: center; }
.mt-0 { margin-top: 0; } .mb-0 { margin-bottom: 0; }
.glow-gold { text-shadow: 0 0 22px rgba(212,166,74,.45); }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
@media (max-width: 760px) {
  .topbar .nav { order: 3; width: 100%; overflow-x: auto; flex-wrap: nowrap; }
  .topbar .nav a { white-space: nowrap; }
}
.center .medallion, .medallion.center { margin-inline: auto; }
