/* ═══════════════════════════════════════════════════════════════════
   The Empty Throne — redesign theme (shared chrome + tokens)
   Loaded on every page by base.html.
   ═══════════════════════════════════════════════════════════════════ */

:root {
    --paper:  #F3F5F8;
    --ink:    #0E1726;
    --red:    #E0352B;
    --gold:   #FFC531;
    --blue:   #1A47B8;
    --mist:   #DCE2EB;
    --slate:  #4A5568;
    --white:  #FFFFFF;
    --line:   rgba(14, 23, 38, .15);
    --line-inv:  rgba(243, 245, 248, .15);
    --paper-70:  rgba(243, 245, 248, .7);
    --paper-60:  rgba(243, 245, 248, .6);
    --ink-hover: #1d2a40;
    --green:  #1E8A4C;
    --purple: #7A3E9D;
    --yellow: #A87A00;

    --font-display: 'Archivo', system-ui, sans-serif;
    --font-body:    'Instrument Sans', system-ui, sans-serif;
    --font-mono:    'JetBrains Mono', ui-monospace, monospace;

    --gutter: clamp(16px, 4.5vw, 64px);
    --max:    1440px;

    color-scheme: light;
}

/* ─── DARK THEME ───
   Same ink/paper system, flipped: page is deep ink, text is paper.
   data-theme is set on <html> by the head script in base.html. */
:root[data-theme="dark"] {
    --paper:  #0B1220;
    --ink:    #E6EAF0;
    --red:    #F0473C;
    --blue:   #6A8FF0;
    --mist:   #1D283B;
    --slate:  #9AA6B8;
    --white:  #131C2D;
    --line:   rgba(230, 234, 240, .14);
    --line-inv:  rgba(11, 18, 32, .15);
    --paper-70:  rgba(11, 18, 32, .7);
    --paper-60:  rgba(11, 18, 32, .6);
    --ink-hover: #C5CDD9;
    --green:  #3FB873;
    --purple: #B07CD6;
    --yellow: #E0AE2A;

    color-scheme: dark;
}

/* Feature bands (footer, study-modes band, sealed card…) stay dark in dark
   mode instead of flipping to bright slabs: re-scope the light-mode tokens
   inside them, with a lifted ink as the band surface. */
:root[data-theme="dark"] :is(.v2-footer, .band) {
    --ink:    #16213A;
    --paper:  #F3F5F8;
    --red:    #E0352B;
    --blue:   #1A47B8;
    --mist:   #24314A;
    --slate:  #A9B4C4;
    --white:  #FFFFFF;
    --line:   rgba(243, 245, 248, .15);
    --line-inv:  rgba(243, 245, 248, .15);
    --paper-70:  rgba(243, 245, 248, .7);
    --paper-60:  rgba(243, 245, 248, .6);
    --ink-hover: #1E2B47;
}
:root[data-theme="dark"] .v2-footer { --ink: #070C16; border-top: 1px solid rgba(243, 245, 248, .1); }

/* Gold surfaces (tips, saved state) keep dark ink text. */
:root[data-theme="dark"] :is(.tip, .action.saved, .drill-btn) {
    --ink:   #0E1726;
    --slate: #4A5568;
    --line:  rgba(14, 23, 38, .15);
    color: var(--ink);
}
/* Gold accents on pills that flip to light paper need a deeper gold. */
:root[data-theme="dark"] :is(.tab.active .count, .chip.active .n, .cta-primary .icon) { color: #A87A00; }

:root[data-theme="dark"] mark { background: rgba(255, 197, 49, .3); }

.theme-swap { transition: none !important; }
.theme-swap *, .theme-swap *::before, .theme-swap *::after { transition: none !important; }

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

body.v2 {
    font-family: var(--font-body);
    background: var(--paper);
    color: var(--ink);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

:where(.v2) a { color: inherit; }
.v2 .icon { flex-shrink: 0; display: block; }

.wrap {
    max-width: var(--max);
    margin: 0 auto;
    padding-left: var(--gutter);
    padding-right: var(--gutter);
}

.mono { font-family: var(--font-mono); }

.eyebrow {
    font: 600 14px var(--font-body);
    color: var(--red);
}

/* ─── BUTTONS ─── */
.btn-ink {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 18px;
    border-radius: 2px;
    background: var(--ink);
    color: var(--paper) !important;
    font: 600 14px var(--font-body);
    text-decoration: none;
    border: none;
    cursor: pointer;
    white-space: nowrap;
    transition: background .15s;
}
.btn-ink:hover { background: var(--ink-hover); }

.link-underline {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding-bottom: 4px;
    border-bottom: 1.5px solid currentColor;
    font: 600 17px var(--font-body);
    text-decoration: none;
    white-space: nowrap;
}
.link-underline .icon { transition: transform .15s; }
.link-underline:hover .icon { transform: translateY(2px); }

/* ─── NAV ─── */
.v2-nav {
    position: sticky;
    top: 0;
    z-index: 200;
    background: var(--paper);
    border-bottom: 1.5px solid var(--ink);
}

.v2-nav-inner {
    height: 74px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.v2-brand {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    font: 700 23px/1 var(--font-display);
    letter-spacing: -.4px;
    white-space: nowrap;
}
.v2-brand .logo { width: 26px; height: 36px; color: var(--ink); }

.v2-links { display: flex; align-items: center; gap: 8px; }

.v2-link {
    display: inline-flex;
    align-items: baseline;
    gap: 6px;
    padding: 8px 14px;
    border-radius: 2px;
    text-decoration: none;
    font: 500 15px var(--font-body);
    color: var(--ink);
    white-space: nowrap;
    transition: background .15s;
}
.v2-link:hover { background: var(--mist); }
.v2-link.active { background: var(--ink); color: var(--paper); }

.v2-account { display: flex; align-items: center; gap: 20px; }

.v2-support {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font: 500 15px var(--font-body);
    text-decoration: none;
    white-space: nowrap;
}
.v2-support:hover { text-decoration: underline; text-underline-offset: 3px; }

.v2-user {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font: 600 14px var(--font-body);
    white-space: nowrap;
}
.v2-user .avatar {
    width: 28px;
    height: 28px;
    border-radius: 2px;
    background: var(--gold);
    color: var(--ink);
    display: grid;
    place-items: center;
    font: 700 12px var(--font-body);
}
.v2-user .logout {
    font: 400 12px var(--font-body);
    color: var(--slate);
    text-decoration: none;
}
.v2-user .logout:hover { color: var(--red); }

.v2-toggle {
    display: none;
    background: none;
    border: 1.5px solid var(--ink);
    border-radius: 2px;
    padding: 7px;
    color: var(--ink);
    cursor: pointer;
}

.v2-drawer {
    display: none;
    flex-direction: column;
    border-top: 1px solid var(--line);
    padding: 8px var(--gutter) 16px;
}
.v2-drawer.open { display: flex; }
.v2-drawer a {
    display: flex;
    align-items: baseline;
    gap: 8px;
    padding: 12px 0;
    border-bottom: 1px solid var(--line);
    font: 500 16px var(--font-body);
    text-decoration: none;
}

.v2-theme {
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    background: none;
    border: 1.5px solid var(--ink);
    border-radius: 2px;
    color: var(--ink);
    cursor: pointer;
    transition: background .15s;
}
.v2-theme:hover { background: var(--mist); }
.v2-theme .sun, :root[data-theme="dark"] .v2-theme .moon { display: none; }
:root[data-theme="dark"] .v2-theme .sun { display: block; }
.v2-tools { display: flex; align-items: center; gap: 16px; }
@media (max-width: 1080px) { .v2-tools { gap: 10px; } }

@media (max-width: 1080px) {
    .v2-links, .v2-account { display: none; }
    .v2-toggle { display: block; }
}
@media (max-width: 400px) {
    .v2-brand { font-size: 19px; }
}

/* ─── FOOTER ─── */
.v2-footer {
    background: var(--ink);
    color: var(--paper);
    padding: 72px 0 40px;
}

.v2-footer-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 40px 24px;
    flex-wrap: wrap;
}

.v2-footer-mark {
    display: flex;
    align-items: center;
    gap: 12px;
}
.v2-footer-mark .logo {
    width: 29px;
    height: 40px;
    color: var(--white);
}
.v2-footer-word {
    font: 700 28px/1 var(--font-display);
    letter-spacing: -.5px;
    white-space: nowrap;
}

.v2-footer-links {
    display: flex;
    gap: 56px;
    padding-bottom: 14px;
}
.v2-footer-col { display: flex; flex-direction: column; gap: 12px; }
.v2-footer-col .head {
    font: 400 12px var(--font-body);
    color: var(--paper-60);
}
.v2-footer-col a {
    font: 400 15px var(--font-body);
    text-decoration: none;
}
.v2-footer-col a:hover { color: var(--gold); }

.v2-footer-rule {
    height: 1px;
    background: rgba(243, 245, 248, .2);
    margin: 48px 0 40px;
}

.v2-footer-bottom {
    display: flex;
    justify-content: space-between;
    gap: 24px 48px;
    flex-wrap: wrap;
}
.v2-footer-disclaimer {
    max-width: 760px;
    font: 400 12px/19px var(--font-body);
    color: var(--paper-60);
}
.v2-footer-legal { display: flex; gap: 24px; }
.v2-footer-legal a { font: 400 13px var(--font-body); text-decoration: none; }
.v2-footer-legal a:hover { color: var(--gold); }

@media (max-width: 600px) {
    .v2-footer { padding-top: 56px; }
    .v2-footer-links { gap: 40px; }
}

/* ─── SHARED PAGE PIECES (legal, auth, errors) ─── */
.page-head { display: flex; flex-direction: column; gap: 16px; padding-top: 64px; padding-bottom: 48px; }
.page-head .headline { font: 800 clamp(44px, 6.1vw, 88px)/.98 var(--font-display); letter-spacing: -.03em; }
.page-head .sub { max-width: 640px; font: 400 18px/1.5 var(--font-body); color: var(--slate); }

.legal { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 64px; padding-bottom: 96px; border-top: 1.5px solid var(--ink); padding-top: 40px; }
.legal-toc { position: sticky; top: 104px; align-self: start; display: flex; flex-direction: column; gap: 2px; }
.legal-toc .head { font: 400 12px var(--font-body); color: var(--slate); margin-bottom: 10px; }
.legal-toc a { padding: 6px 0; font: 500 14px var(--font-body); color: var(--slate); text-decoration: none; }
.legal-toc a:hover { color: var(--ink); }
.legal-toc a .n { display: inline-block; width: 26px; font: 400 11px var(--font-mono); color: var(--red); }
.legal-body { max-width: 720px; }
.legal-note {
    margin-bottom: 40px;
    padding: 18px 20px;
    border-left: 4px solid var(--red);
    background: var(--white);
    font: 500 15px/1.6 var(--font-body);
}
.legal-section { padding: 28px 0; border-top: 1px solid var(--line); scroll-margin-top: 96px; }
.legal-section:first-of-type { border-top: none; padding-top: 0; }
.legal-section h2 { display: flex; gap: 14px; align-items: baseline; margin-bottom: 12px; font: 700 24px/1.2 var(--font-display); letter-spacing: -.5px; }
.legal-section h2 .n { font: 700 13px var(--font-mono); color: var(--red); }
.legal-section p, .legal-section li { font: 400 16px/1.7 var(--font-body); color: #2c3648; }
.legal-section p + p, .legal-section ul + p { margin-top: 12px; }
.legal-section ul { margin: 10px 0 0; padding-left: 20px; }
.legal-section li { margin-bottom: 6px; }
.legal-section li::marker { color: var(--red); }
.legal-section a { color: var(--blue); }

@media (max-width: 900px) {
    .legal { grid-template-columns: 1fr; gap: 24px; }
    .legal-toc { display: none; }
}
@media (max-width: 720px) {
    .page-head { padding-top: 40px; padding-bottom: 32px; }
    .page-head .sub { font-size: 16px; }
}

.center-page { display: flex; align-items: center; justify-content: space-between; gap: 48px 64px; flex-wrap: wrap; min-height: calc(100vh - 76px - 360px); padding-top: 72px; padding-bottom: 96px; }
.center-copy { display: flex; flex-direction: column; gap: 18px; max-width: 620px; }
.center-copy .headline { font: 800 clamp(44px, 6.1vw, 88px)/.98 var(--font-display); letter-spacing: -.03em; }
.center-copy .headline em { font-style: normal; color: var(--red); }
.center-copy p { font: 400 18px/1.5 var(--font-body); color: var(--slate); }
.center-copy .actions { display: flex; align-items: center; gap: 16px 28px; flex-wrap: wrap; margin-top: 8px; }
.big-code { font: 800 clamp(120px, 20vw, 280px)/.8 var(--font-display); letter-spacing: -.05em; color: var(--ink); position: relative; }
.big-code span { color: var(--red); }
.btn-ink.lg { padding: 14px 20px; font-size: 16px; }
.notice-box { padding: 14px 18px; border-left: 4px solid var(--gold); background: var(--white); font: 500 15px/1.5 var(--font-body); }

/* ─── CARD REFERENCES (static/js/card-refs.js) ─── */
.ref-link {
    display: inline;
    padding: 0;
    border: none;
    background: none;
    color: inherit;
    font: inherit;
    letter-spacing: inherit;
    white-space: nowrap;
    text-decoration: underline;
    text-decoration-color: var(--red);
    text-decoration-thickness: 2px;
    text-underline-offset: .18em;
    cursor: pointer;
}
.ref-link:hover, .ref-link[aria-expanded="true"] { color: var(--red); }

.card-pop {
    position: fixed;
    z-index: 400;
    width: 440px;
    max-width: calc(100vw - 24px);
    max-height: calc(100vh - 24px);
    overflow: auto;
    padding: 16px;
    border-radius: 6px;
    background: var(--white);
    color: var(--ink);
    outline: 1.5px solid var(--ink);
    box-shadow: 0 6px 20px rgba(0, 0, 0, .25);
}
.card-pop[hidden] { display: none; }
.card-pop-close {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 32px;
    height: 32px;
    border: none;
    background: none;
    color: var(--slate);
    font: 400 22px/1 var(--font-body);
    cursor: pointer;
}
.card-pop-close:hover { color: var(--red); }
.card-pop-body { display: flex; gap: 16px; align-items: flex-start; }
.card-pop-img { flex: 0 0 170px; width: 170px; aspect-ratio: 600 / 838; border-radius: 6px; background: var(--mist); }
.card-pop-info { min-width: 0; display: flex; flex-direction: column; gap: 6px; padding-right: 20px; }
.card-pop-id { font: 700 13px var(--font-mono); color: var(--red); }
.card-pop-name { font: 700 20px/1.2 var(--font-display); }
.card-pop-spec { font: 400 13px/1.4 var(--font-body); color: var(--slate); }
.card-pop-text { margin: 4px 0 0; font: 400 14px/1.45 var(--font-body); white-space: pre-line; }
.card-pop-loading { padding: 8px 32px 8px 0; font: 400 14px var(--font-body); color: var(--slate); }
@media (max-width: 560px) {
    .card-pop { left: 12px; right: 12px; bottom: 12px; width: auto; max-height: 75vh; }
    .card-pop-img { flex-basis: 120px; width: 120px; }
    .card-pop-name { font-size: 18px; }
}
