/* The Dungeon Master's portal (W6-A15). Built on the style guide's tokens,
   copied verbatim from mockups/style-guide.html and checked by
   scripts/check-theme-parity.mjs: a raw value below that is not a token
   is a defect (Law I). Night chrome always; the page is a vellum surface
   that re-anchors the light tokens on itself (Law II). Mockup 21. */

/* The exact faces (Law III), served from here so no third party sits
   between the Dungeon Master and the page. Same files as the app's
   (app-rn/assets/fonts), under the OFL beside them. */
@font-face { font-family: 'Cormorant Garamond'; font-weight: 700; font-style: normal; font-display: swap; src: url(fonts/CormorantGaramond-Bold.ttf) format('truetype'); }
@font-face { font-family: 'EB Garamond'; font-weight: 400; font-style: normal; font-display: swap; src: url(fonts/EBGaramond-Regular.ttf) format('truetype'); }
@font-face { font-family: 'EB Garamond'; font-weight: 500 600; font-style: normal; font-display: swap; src: url(fonts/EBGaramond-SemiBold.ttf) format('truetype'); }
@font-face { font-family: 'EB Garamond'; font-weight: 400; font-style: italic; font-display: swap; src: url(fonts/EBGaramond-Italic.ttf) format('truetype'); }

:root {
  /* dark mode (default): night chrome */
  --bg:        #161820;  /* background · night ink */
  --surface:   #2A2530;  /* surface · deep binding */
  --field:     #1E222C;  /* field (inputs) · recessed ink */
  --ink:       #E4DCD0;  /* primary ink · 13.0:1 on bg */
  --ink-2:     #A89F92;  /* secondary ink · 6.8:1 */
  --muted:     #8A8478;  /* muted · 4.8:1 */
  --accent:    #B89358;  /* THE accent · gilt · 6.2:1 */
  --accent-ink:#161820;  /* text set on accent fills */
  --success:   #8CA867;  /* verdant · 6.7:1 */
  --warning:   #D97B2E;  /* flame · 5.8:1 */
  --danger:    #CE6B6F;  /* ember blood · 5.0:1 */
  --danger-deep:#6E2832; /* oxblood · fills, depletion bars */
  --info:      #6E9BC8;  /* wizard blue · 6.1:1 */
  --narration: rgba(184,147,88,0.78); /* DM voice · gilt at ~78% */
  --hairline:  rgba(184,147,88,0.26);
  --shadow-card: 0 1px 2px rgba(0,0,0,.45), 0 6px 16px rgba(0,0,0,.35);
  --shadow-modal: 0 2px 4px rgba(0,0,0,.5), 0 16px 40px rgba(0,0,0,.5);
  --glow: 0 0 0 1px rgba(184,147,88,.4), 0 0 14px rgba(184,147,88,.28);
  --seg-shadow: 0 1px 3px rgba(0,0,0,.4);
  /* class heraldry (mode-independent) */
  --class-fighter: #922830;
  --class-wizard:  #1A4A7A;
  --class-cleric:  #F0E8D8;
  --class-rogue:   #28282A;
  /* the portal's own measures */
  --side-w: 232px;
  --radius: 12px;
  --radius-sm: 8px;
  --pill: 999px;
  --touch: 44px;
  --dur-quick: 120ms;
  --dur-settle: 220ms;
  --ease: cubic-bezier(0.2, 0, 0, 1);
}
[data-mode="light"] {
  /* light mode: vellum pages */
  --bg:        #F8F4EC;  /* background · ivory vellum */
  --surface:   #FFFCF4;  /* surface · bright vellum */
  --field:     #EFE8D8;  /* field · pressed vellum */
  --ink:       #1E2028;  /* primary ink · 14.8:1 on bg */
  --ink-2:     #3A3830;  /* secondary ink · iron ink · 10.7:1 */
  --muted:     #7E7668;  /* muted · 4.1:1 */
  --accent:    #8A6D3A;  /* deep gilt · 4.4:1 · AA large text and icons */
  --accent-small-text: #5A4228; /* body-size gilt on vellum */
  --accent-ink:#F8F4EC;
  --success:   #4A6B38;  /* 5.6:1 */
  --warning:   #9C4F12;  /* 5.4:1 */
  --danger:    #6E2832;  /* oxblood · 9.5:1 */
  --danger-deep:#6E2832;
  --info:      #1A4A7A;  /* royal blue · 8.3:1 */
  --narration: #5A4228;  /* small-text gilt on vellum */
  --hairline:  rgba(90,66,40,0.24);
  --shadow-card: 0 1px 2px rgba(58,56,48,.10), 0 6px 16px rgba(58,56,48,.12);
  --shadow-modal: 0 2px 4px rgba(58,56,48,.12), 0 16px 40px rgba(58,56,48,.18);
  --glow: 0 0 0 1px rgba(138,109,58,.45), 0 0 12px rgba(138,109,58,.22);
  --seg-shadow: 0 1px 3px rgba(58,56,48,.18);
  color: var(--ink);
}

/* ---------- Document chrome ---------- */
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body.portal {
  background: var(--bg); color: var(--ink);
  font: 400 15px/1.5 'EB Garamond', Georgia, serif;
  display: flex; min-height: 100vh;
}
h1, h2, h3, .display { font-family: 'Cormorant Garamond', 'Times New Roman', serif; font-weight: 700; }
.num { font-family: 'Cormorant Garamond', 'Times New Roman', serif; font-weight: 700; font-variant-numeric: lining-nums tabular-nums; }
a { color: var(--accent); }
button { font: inherit; color: inherit; }
button.link { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; text-decoration: none; min-height: 0; }
button.link:hover { text-decoration: underline; }
[hidden] { display: none !important; }

/* ---------- Type ---------- */
.t-title     { font: 700 28px/1.2  'Cormorant Garamond', serif; letter-spacing: .01em; }
.t-heading   { font: 700 22px/1.25 'Cormorant Garamond', serif; letter-spacing: .01em; }
.t-body      { font: 400 15px/1.45 'EB Garamond', serif; }
.t-narration { font: italic 400 15px/1.4 'EB Garamond', serif; color: var(--narration); }
.t-caption   { font: 400 13px/1.4  'EB Garamond', serif; color: var(--ink-2); }
.t-label     { font: 600 11px/1.3  'EB Garamond', serif; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-2); }
.t-numeral   { font: 700 17px/1.2 'Cormorant Garamond', serif; font-variant-numeric: lining-nums tabular-nums; }
.wordmark { font-family: 'Cormorant Garamond', serif; font-weight: 700; font-size: 26px; letter-spacing: .06em; line-height: 1; }
.wordmark .mob { color: var(--accent); }

/* ---------- Components (the style guide's) ---------- */
.btn {
  font: 600 15px 'EB Garamond', serif; letter-spacing: .02em;
  border-radius: var(--radius-sm); padding: 11px 20px; cursor: pointer; border: 1px solid transparent;
  min-height: var(--touch); transition: box-shadow var(--dur-quick) var(--ease);
}
/* Two treatments only (ruled 2026-09-08): gold fill is clickable, flat is not. */
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { box-shadow: var(--glow); }
.btn-primary:disabled, .btn-disabled { background: var(--field); color: var(--muted); cursor: not-allowed; box-shadow: none; }
.btn-sm { font-size: 13px; padding: 8px 14px; }
.input {
  width: 100%; font: 400 15px 'EB Garamond', serif; color: var(--ink);
  background: var(--field); border: 1px solid var(--hairline);
  border-radius: var(--radius-sm); padding: 11px 14px; outline: none; min-height: var(--touch);
}
.input::placeholder { color: var(--muted); font-style: italic; }
.input:focus { border-color: var(--accent); box-shadow: var(--glow); }
.input[readonly], .input:disabled { color: var(--ink-2); }
.select { appearance: none; -webkit-appearance: none; padding-right: 34px;
  background-image: linear-gradient(45deg, transparent 50%, var(--accent) 50%), linear-gradient(135deg, var(--accent) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; }
.badge {
  display: inline-block; font: 600 11px/1 'EB Garamond', serif;
  letter-spacing: .08em; text-transform: uppercase;
  border-radius: var(--pill); padding: 5px 10px; border: 1px solid transparent;
}
.badge-success { color: var(--success); background: color-mix(in srgb, var(--success) 14%, transparent); border-color: color-mix(in srgb, var(--success) 38%, transparent); }
.badge-warning { color: var(--warning); background: color-mix(in srgb, var(--warning) 14%, transparent); border-color: color-mix(in srgb, var(--warning) 38%, transparent); }
.badge-danger  { color: var(--danger);  background: color-mix(in srgb, var(--danger) 14%, transparent);  border-color: color-mix(in srgb, var(--danger) 38%, transparent); }
.card { background: var(--surface); border: 1px solid var(--hairline); border-radius: var(--radius); box-shadow: var(--shadow-card); padding: 16px 18px; }
.card .t-label { color: var(--accent-small-text); }

/* ---------- The shell ---------- */
.side { width: var(--side-w); flex: none; display: flex; flex-direction: column; padding: 28px 22px 22px; border-right: 1px solid var(--hairline); position: sticky; top: 0; height: 100vh; }
.side .t-label { display: block; color: var(--accent); margin-top: 8px; }
.nav { margin-top: 28px; display: flex; flex-direction: column; gap: 4px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: var(--radius-sm); color: var(--ink-2); font: 500 15px 'EB Garamond', serif; text-decoration: none; min-height: var(--touch); transition: background var(--dur-quick) var(--ease); }
.nav a svg { stroke: currentColor; flex: none; }
.nav a:hover { background: color-mix(in srgb, var(--accent) 8%, transparent); }
.nav a.active { background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent); }
.side-foot { margin-top: auto; }
.side-foot .t-caption { color: var(--ink-2); }
.side-foot .who { font: 600 14px 'EB Garamond', serif; color: var(--ink); min-height: 1.4em; }
.page { flex: 1; min-width: 0; min-height: 100vh; background: var(--bg); color: var(--ink); padding: 28px 32px; display: flex; flex-direction: column; overflow: auto; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.page-head .t-label { display: block; color: var(--accent-small-text); }
.page-head h1 { font-size: 30px; line-height: 1.15; margin-top: 4px; }
.page-head .t-caption { margin-top: 6px; max-width: 620px; }
.actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.actions .select { width: auto; min-width: 200px; }
.cols { display: flex; gap: 20px; margin-top: 22px; flex: 1; min-height: 0; align-items: flex-start; }

/* ---------- The ledger ---------- */
.ledger { width: 340px; flex: none; display: flex; flex-direction: column; gap: 8px; }
.boss-row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border: 1px solid var(--hairline); border-radius: 10px; background: var(--surface); min-height: 56px; width: 100%; text-align: left; cursor: pointer; transition: box-shadow var(--dur-quick) var(--ease); }
.boss-row:hover { box-shadow: var(--glow); }
.boss-row.open { border-color: var(--accent); box-shadow: var(--glow); }
.boss-row .name { font: 700 17px/1.2 'Cormorant Garamond', serif; }
.boss-row .sub { font: 400 12.5px/1.3 'EB Garamond', serif; color: var(--ink-2); }
.boss-row .grow { flex: 1; min-width: 0; }
.sheet { flex: 1; min-width: 0; }
.sheet h2 { font-size: 26px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.sheet h2 svg { stroke: var(--accent); flex: none; }
.fields { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px 16px; margin-top: 14px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field .t-label { color: var(--ink-2); }
.field .input { padding: 8px 12px; font-size: 14px; }
.field .hint { font: 400 12px/1.3 'EB Garamond', serif; color: var(--muted); }
.field.wide { grid-column: span 3; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.chip { display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 4px 6px 4px 10px; border-radius: var(--pill); border: 1px solid var(--hairline); background: var(--field); font: 600 12px/1.3 'EB Garamond', serif; letter-spacing: .03em; color: var(--ink); white-space: nowrap; }
.chip .n { color: var(--accent-small-text); font: 700 12px 'Cormorant Garamond', serif; }
.chip.still { padding-right: 10px; }
.chip .x { width: 24px; height: 24px; border-radius: var(--pill); border: 0; background: transparent; color: var(--ink-2); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; font-size: 14px; line-height: 1; }
.chip .x:hover { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.chip-add { display: inline-flex; align-items: center; gap: 6px; }
.chip-add .input, .chip-add .select { width: auto; min-width: 140px; min-height: 32px; padding: 4px 10px; font-size: 13px; border-radius: var(--pill); }
.chip-add .select { padding-right: 30px; }
.chip-add .btn { min-height: 32px; padding: 4px 12px; font-size: 13px; border-radius: var(--pill); }
.lines { display: flex; flex-direction: column; gap: 8px; margin-top: 6px; }
.line { display: flex; align-items: center; gap: 10px; }
.line .input { flex: 1; padding: 8px 12px; font-size: 14px; }
.line .count { font: 700 13px 'Cormorant Garamond', serif; font-variant-numeric: lining-nums tabular-nums; color: var(--ink-2); width: 62px; text-align: right; flex: none; }
.line .count.over { color: var(--danger); }
.slot { color: var(--accent-small-text); font-weight: 600; }
.foot-actions { display: flex; align-items: center; gap: 12px; margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--hairline); flex-wrap: wrap; }
.foot-actions .spacer { flex: 1; }
.empty { color: var(--muted); font-style: italic; padding: 12px 0; }

/* ---------- The world ---------- */
.map-wrap { flex: 1; min-width: 0; align-self: stretch; min-height: 560px; position: relative; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--hairline); background: var(--bg); }
.map-wrap #map { position: absolute; inset: 0; }
.maplibregl-ctrl-attrib { background: color-mix(in srgb, var(--bg) 70%, transparent) !important; }
.maplibregl-ctrl-attrib, .maplibregl-ctrl-attrib a { color: var(--muted) !important; font: 9px serif; }
.maplibregl-popup-content { background: var(--surface); color: var(--ink); border-radius: var(--radius-sm); box-shadow: var(--shadow-card); font: 400 13px/1.4 'EB Garamond', serif; padding: 10px 14px; }
.maplibregl-popup-content .name { font: 700 16px/1.2 'Cormorant Garamond', serif; }
.maplibregl-popup-tip { border-top-color: var(--surface) !important; border-bottom-color: var(--surface) !important; }
.rail { width: 360px; flex: none; display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.rail-list { padding: 6px 6px; }
.seat-row { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-bottom: 1px solid var(--hairline); width: 100%; background: none; border-left: 0; border-right: 0; border-top: 0; text-align: left; cursor: pointer; min-height: var(--touch); }
.seat-row:last-child { border-bottom: 0; }
.seat-row:hover .name { color: var(--accent-small-text); }
.seat-row .grow { flex: 1; min-width: 0; }
.seat-row .name { font: 700 16px/1.2 'Cormorant Garamond', serif; }
.seat-row .sub { font: 400 12.5px/1.3 'EB Garamond', serif; color: var(--ink-2); }
.seat-row .map-link { font: 400 13px 'EB Garamond', serif; color: var(--accent-small-text); text-decoration: none; }
.dot { width: 9px; height: 9px; border-radius: var(--pill); flex: none; }
.dot.standing { background: var(--success); }
.dot.fallen { background: transparent; border: 1.5px solid var(--muted); }
/* The world pin, as the phone draws it (mockup 20a): the doubled gilt ring,
   the crown, the name. A fallen one is hollow and muted. */
.wpin { position: relative; width: 46px; height: 46px; cursor: pointer; }
.wpin svg { display: block; }
.wpin .crown { position: absolute; left: 50%; top: -16px; transform: translateX(-50%); }
.wpin .label { position: absolute; left: 50%; top: 100%; transform: translateX(-50%); margin-top: 2px; white-space: nowrap; font: 600 11px 'EB Garamond', serif; letter-spacing: .1em; text-transform: uppercase; color: var(--accent); }
.wpin.fallen .label { color: var(--muted); }

/* ---------- The door ---------- */
body.door { display: block; }
.gate { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.gate-card { width: 440px; max-width: 100%; padding: 34px 36px 30px; text-align: center; }
.gate-card .wordmark { font-size: 40px; }
.gate-card .t-label { display: block; color: var(--accent-small-text); margin-top: 8px; }
.gate-card h1 { font-size: 26px; margin-top: 18px; }
.gate-card .t-caption { margin-top: 8px; }
/* Apple's own button: its guidelines require Apple's mark and one of its two colours. */
.apple-btn { margin: 22px auto 0; display: inline-flex; align-items: center; gap: 10px; background: #000; color: #fff; border: 0; border-radius: var(--radius-sm); padding: 12px 22px; font: 600 16px -apple-system, 'Helvetica Neue', Helvetica, Arial, sans-serif; min-height: var(--touch); cursor: pointer; }
.apple-btn:hover { box-shadow: var(--glow); }
.gate-card .grant { margin-top: 20px; padding-top: 14px; border-top: 1px solid var(--hairline); }

/* ---------- The toast: the book's one line back ---------- */
.toast { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); background: var(--surface); color: var(--ink); border: 1px solid var(--hairline); border-radius: var(--radius-sm); box-shadow: var(--shadow-modal); padding: 10px 16px; font: 400 14px 'EB Garamond', serif; animation: rise var(--dur-settle) var(--ease); max-width: 80vw; }
.toast.danger { border-color: var(--danger); color: var(--danger); }
@keyframes rise { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }
@media (prefers-reduced-motion: reduce) { .toast { animation: none; } .btn, .nav a, .boss-row { transition: none; } }

@media (max-width: 980px) {
  body.portal { flex-direction: column; }
  .side { width: 100%; height: auto; position: static; flex-direction: row; align-items: center; gap: 16px; padding: 14px 18px; flex-wrap: wrap; }
  .nav { margin-top: 0; flex-direction: row; flex-wrap: wrap; }
  .side-foot { margin-top: 0; margin-left: auto; }
  .cols { flex-direction: column; }
  .ledger, .rail { width: 100%; }
  .fields { grid-template-columns: 1fr 1fr; }
  .field.wide { grid-column: span 2; }
  .map-wrap { min-height: 420px; width: 100%; }
}
