/* The Nest: colours, fonts, and the light/dark themes, then the shared base (reset, masthead, buttons, cards, form fields, banners, toast, chips, meters)
   that the Character Generator, the Ref Screen, and the accounts site all start from. Shared by all three; each section file adds only what differs.
   The tabletop styles live in table.css (Character Generator and Ref Screen only). */
:root {
  --paper: #f4efe6;
  --card: #fffdf8;
  --ink: #1f1d1e;
  --muted: #6b645c;
  --line: #d6cfc4;
  --accent: #8c1c13;
  --accent-ink: #ffffff;
  --soft: #ece5d9;
  --ok: #2f6b3a;
  --warn: #9a5b00;
  --bad: #a3231a;
  --slot: #f7f3ec;
  --slot-hover: #efe6d6;
  --sel: #d9a441;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(60,40,20,.07), 0 8px 20px -10px rgba(60,40,20,.22);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", "URW Palladio L", "P052", Georgia, "Times New Roman", serif;
  --ease: cubic-bezier(.2,.8,.2,1);
  --glow: color-mix(in srgb, var(--sel) 24%, transparent);   /* the soft gold halo round a focused control */
}
/* Dark: follows the device unless the theme toggle (theme.js) sets data-theme on <html>. */
:root { color-scheme: light dark; }
:root[data-theme="light"] { color-scheme: light; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #161415; --card: #211e1f; --ink: #ece6dc; --muted: #a79f94; --line: #3a3536;
    --accent: #c2412f; --soft: #2c2829; --slot: #1b191a; --slot-hover: #2b2627;
    --ok: #6fbf7c; --warn: #e0a84a; --bad: #ff7b6e; --sel: #d9a441;
    --shadow: 0 1px 2px rgba(0,0,0,.45), 0 10px 24px -12px rgba(0,0,0,.7);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #161415; --card: #211e1f; --ink: #ece6dc; --muted: #a79f94; --line: #3a3536;
  --accent: #c2412f; --soft: #2c2829; --slot: #1b191a; --slot-hover: #2b2627;
  --ok: #6fbf7c; --warn: #e0a84a; --bad: #ff7b6e; --sel: #d9a441;
  --shadow: 0 1px 2px rgba(0,0,0,.45), 0 10px 24px -12px rgba(0,0,0,.7);
}

/* ============================================================================
   Shared base: the rules the Character Generator (app.css), the Ref Screen (ref.css), and the accounts
   portal (portal.css) all start from. Each section file loads after this one and keeps only what differs
   (a one-line override) or what only it uses. Because this loads first, an override must come after the
   rule it adjusts in the section file, and equal-specificity section rules always win.
   ============================================================================ */

/* Reset and page */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; color: var(--ink); font: 15px/1.45 var(--font);
  /* paper, with lamplight falling from the top of the page */
  background: var(--paper) radial-gradient(120% 70% at 50% 0, color-mix(in srgb, var(--sel) 9%, transparent), transparent 70%) fixed no-repeat; }
::selection { background: color-mix(in srgb, var(--sel) 45%, transparent); }
* { scrollbar-color: color-mix(in srgb, var(--muted) 50%, transparent) transparent; }
h1, h2, h3 { font-family: var(--serif); margin: 0 0 .5rem; text-wrap: balance; }
/* a card's heading sits on a short rule that runs from oxblood to gold */
.card > h2 { padding-bottom: .45rem; background: linear-gradient(90deg, var(--accent), var(--sel) 70%, transparent) left bottom / 3.4rem 2px no-repeat; }
button, input, select, textarea { font: inherit; color: inherit; }
textarea { width: 100%; resize: vertical; }
.hint { color: var(--muted); margin: 0 0 .8rem; font-size: .9rem; }
.fine { color: var(--muted); font-size: .8rem; }
.muted { color: var(--muted); }
.spacer { flex: 1; }

/* Masthead */
.masthead { background: linear-gradient(180deg, #292526, #1a1819); color: #f4efe6; position: sticky; top: 0; z-index: 20; border-bottom: 4px solid var(--accent);
  box-shadow: 0 1px 0 rgba(217,164,65,.6), 0 8px 18px -12px rgba(0,0,0,.7); }   /* a gold hairline under the oxblood band */
.masthead-inner { margin: 0 auto; padding: .6rem clamp(16px, 2vw, 40px); display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.brand { display: flex; align-items: baseline; gap: .7rem; }
.brand-mark { font: bold 1.8rem/1 var(--serif); letter-spacing: .08em; }
.brand-glyph { width: 1.55rem; height: 1.55rem; align-self: center; flex: none; color: var(--sel); margin-right: -.2rem; transition: transform .5s var(--ease); transform-origin: 20% 90%; }
.brand:hover .brand-glyph { transform: rotate(-9deg); }
.brand-sub { font-family: var(--serif); font-style: italic; opacity: .85; }
.actions { display: flex; gap: .4rem; flex-wrap: wrap; }
.masthead .btn-ghost { color: #f4efe6; border-color: #5a5354; }
.masthead .btn:hover:not([disabled]) { border-color: var(--sel); }

/* Masthead tab bar (Character Generator and Ref Screen) */
.tabbar { margin: 0 auto; padding: 0 clamp(16px, 2vw, 40px); }
.tabbar-inner { display: flex; flex-wrap: wrap; gap: 2px; }
.tabbar button { background: transparent; color: #f4efe6; border: 0; border-radius: 6px 6px 0 0; padding: .45rem .9rem; cursor: pointer; font-weight: 600; min-height: 38px; white-space: nowrap; opacity: .8;
  transition: opacity .15s, background-color .15s, box-shadow .2s; }
.tabbar button:hover { opacity: 1; background: #2c292a; }
.tabbar button[aria-selected="true"] { background: var(--accent); color: #fff; opacity: 1; box-shadow: inset 0 2px 0 var(--sel); }
.tabbar button:focus-visible { outline: 2px solid var(--sel); outline-offset: -2px; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .3rem; padding: .45rem .8rem; border-radius: 6px;
  border: 1px solid var(--line); background: var(--soft); color: var(--ink); cursor: pointer; white-space: nowrap; min-height: 36px;
  transition: background-color .15s, border-color .15s, box-shadow .15s, filter .15s, transform .08s; }
.btn:hover { filter: brightness(.96); }
.btn:hover:not([disabled]) { border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); }
.btn:active:not([disabled]) { transform: translateY(1px); }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--sel); outline-offset: 1px; box-shadow: 0 0 0 5px var(--glow); }
.btn-primary { background: var(--accent) linear-gradient(180deg, rgba(255,255,255,.12), rgba(0,0,0,.1)); color: var(--accent-ink); border-color: var(--accent); font-weight: 600;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.2), 0 1px 2px rgba(0,0,0,.22); }
.btn-primary:hover:not([disabled]) { border-color: var(--accent); filter: brightness(1.1); }
.btn-ghost { background: transparent; }
.btn-small { padding: .25rem .55rem; min-height: 30px; font-size: .85rem; }
.btn.wide { width: 100%; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.file-btn { position: relative; overflow: hidden; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; }

/* Cards, form fields, banners, toast */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; box-shadow: var(--shadow); min-width: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: .7rem 1rem; }
.span2 { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: .25rem; font-size: .85rem; font-weight: 600; min-width: 0; }
.banner { border-radius: 6px; padding: .5rem .7rem; background: var(--soft); margin: .6rem 0; font-size: .9rem; }
.banner.warn { border-left: 4px solid var(--warn); }
.banner.bad { border-left: 4px solid var(--bad); }
.banner.ok { border-left: 4px solid var(--ok); }
.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%) translateY(150%); background: var(--ink); color: var(--paper); padding: .6rem 1rem; border-radius: 8px; border-left: 3px solid var(--sel);
  box-shadow: 0 12px 30px -8px rgba(0,0,0,.5); transition: transform .35s var(--ease); z-index: 50; max-width: 90vw; }
.toast.show { transform: translateX(-50%) translateY(0); }

/* Chips, progress meter, tier badge, use-pips (sizes and spacing are set per section) */
.chip { background: var(--soft); border-radius: 999px; padding: .05rem .55rem; font-size: .78rem; font-weight: 600; }
.chip.accent { background: var(--accent); color: var(--accent-ink); }
.chip.warn { background: var(--warn); color: #fff; }
.chip.ok { background: var(--ok); color: #fff; }
.meter { height: 8px; background: var(--soft); border-radius: 4px; overflow: hidden; }
.meter span { display: block; height: 100%; background: var(--ok) linear-gradient(180deg, rgba(255,255,255,.28), transparent 70%); }
.tier { display: inline-block; border-radius: 999px; font-weight: 700; color: #fff; }
.tier.t1 { background: var(--bad); } .tier.t2 { background: var(--warn); } .tier.t3 { background: var(--ok); }
.upip { border-radius: 50%; border: 2px solid var(--ink); background: var(--ink); cursor: pointer; padding: 0; }
.upip.used { background: transparent; border-style: dashed; opacity: .6; }

/* Flourishes any section can use.
   .empty-state: what a list says when it has nothing in it. .rule: a divider with a gold lozenge. .ink-in: a new result landing (add the class
   only to something just made, never on a plain re-render). */
.empty-state { border: 1px dashed var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; text-align: center; color: var(--muted); font: italic .98rem/1.45 var(--serif); background: color-mix(in srgb, var(--soft) 35%, transparent); }
.empty-state::before { content: '\2766'; display: block; font: normal 1.25rem/1 var(--serif); color: var(--sel); margin-bottom: .3rem; }
.empty-state .btn { font: 600 .9rem var(--font); margin-top: .6rem; }
.rule { position: relative; border: 0; height: 1px; margin: 1rem 0; overflow: visible; background: linear-gradient(90deg, transparent, var(--line) 18%, var(--line) 82%, transparent); }
.rule::after { content: ''; position: absolute; left: 50%; top: 50%; width: 7px; height: 7px; background: var(--sel); transform: translate(-50%, -50%) rotate(45deg); box-shadow: 0 0 0 4px var(--card); }
.ink-in { animation: ink-in .45s var(--ease) both; }
@keyframes ink-in { from { opacity: 0; transform: scale(1.18); filter: blur(2px); } to { opacity: 1; transform: none; filter: none; } }
@media (prefers-reduced-motion: reduce) {
  .btn, .tabbar button, .toast, .brand-glyph { transition: none; }
  .ink-in { animation: none; }
}
