/* @font-face rules live in js/data/assets.js now — they need ASSET_BASE
   to be correct for CDN deployments. See the IIFE at the top of that
   file. Aldrich = UI sans, Bombardier = headline/title display, Times
   Newer Roman = body serif. */

:root {
  /* Cool stone / gunmetal palette — matches the in-game hard-metal UI. */
  --bg:                 #0b0c0e;
  --bg-elev:            #131518;
  --panel:              #1b1d20;
  --panel-border:       #3c3f43;
  --panel-border-strong:#57595d;
  /* Unified component-interior colour — the plate that sits INSIDE
     the metal frame (national-spirits body, flag wells, row cards,
     etc.). Dark blue-grey rather than pure black so components read
     as part of the same chassis. Two shades so gradient-backed
     elements can vary between them. */
  --panel-interior:     #141922;
  --panel-interior-lo:  #0f131a;

  /* Riveted-metal frame — single source of truth.
     Every stage component picks these up via the
     `.superevent-stage > [id^="se-"]` selector in superevent-layout.css;
     change these three vars to resize or retint the frame EVERYWHERE
     at once. The thick variant is used by the big panels (music /
     biography / alliance / relations) that want the in-game heavy-duty
     look; everything else gets the thin 5px version.

     The frame image itself lives in --ui-tiled (set by assets.js) so
     that bakeUiBackgroundsToDataUrls() can inline it for PNG export
     without a second indirection layer to track. */
  --frame-slice:         22;
  --frame-width:         7px;
  --frame-width-thick:   16px;
  --text:               #dddcd5;
  --text-dim:           #8b8c89;
  --accent:             #d4d2ca;   /* bone-white, near-silver */
  --accent-dim:         #8a8a82;
  --accent-warm:        #b79a55;   /* reserved for ruling-party italic lines */
  --danger:             #c44a3a;

  /* --ui-* URL vars live in js/data/assets.js now (same reason as the
     @font-face rules — ASSET_BASE needs to apply). The vars are still
     injected onto :root, so every stylesheet that uses them works
     unchanged. */

  /* Typography — centralised. Reference with var(--font-*) anywhere a
     font-family stack used to repeat. Fallbacks only fire if the TNO
     font files fail to load. */
  --font-ui:          'Aldrich TNO', 'Aldrich', 'Segoe UI', 'Inter', system-ui, sans-serif;
  --font-title:       'Bombardier TNO', 'Garamond', 'EB Garamond', 'Cambria', 'Georgia', serif;
  --font-body:        'Times Newer Roman', 'Garamond', 'Times New Roman', Georgia, serif;
  --font-blackletter: 'UnifrakturMaguntia', 'Old English Text MT', 'Garamond', serif;
  --font-mono:        ui-monospace, 'Consolas', 'SF Mono', monospace;
}

* { box-sizing: border-box; }

html, body {
  /* Prevent iOS Safari "pull-to-refresh" from reloading the page when
     the user touches near the top during a long operation (bg-remove
     processing, model download, etc.). `contain` keeps overscroll
     inside the document so the refresh gesture is swallowed.
     Also stops Chrome-Android's pull-to-refresh bar. */
  overscroll-behavior: contain;
  /* Lock the viewport to its natural scroll — an accidental double-tap
     or pinch won't zoom the entire page away from under the user
     (individual zoomable canvases like the crop modal handle their own
     pinch via pointer events). */
  touch-action: manipulation;
}

body {
  margin: 0;
  font-family: var(--font-ui);
  background:
    radial-gradient(ellipse 130% 80% at 50% 0%, #17191c 0%, var(--bg) 55%, #050608 100%);
  color: var(--text);
  min-height: 100vh;
  background-attachment: fixed;
}

header.app-header {
  padding: 16px 32px;
  border-bottom: 1px solid var(--panel-border-strong);
  background: linear-gradient(180deg, #26282b 0%, #16181b 100%);
  display: flex; align-items: baseline; gap: 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.5);
  position: relative;
}
header.app-header::after {
  content: '';
  position: absolute;
  left: 0; right: 0; bottom: -1px; height: 1px;
  background: linear-gradient(90deg, transparent 0%, var(--accent) 50%, transparent 100%);
  opacity: 0.35;
}
header.app-header h1 {
  margin: 0;
  font-size: 17px;
  letter-spacing: 3.5px;
  color: var(--accent);
  text-transform: uppercase;
  font-weight: 700;
  text-shadow: 0 1px 2px rgba(0,0,0,0.7);
}
header.app-header .subtitle {
  color: var(--text-dim);
  font-size: 11.5px;
  letter-spacing: 2px;
  text-transform: uppercase;
  font-weight: 500;
}

/* Consistent nav across every page. The same four links in the same
   order everywhere; the active page is highlighted via .is-current. */
.app-nav {
  margin-left: auto;
  display: flex;
  gap: 4px;
  align-items: center;
}
.app-nav .header-link {
  color: var(--text-dim);
  font-size: 11px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  text-decoration: none;
  padding: 5px 11px;
  border: 1px solid transparent;
  border-radius: 2px;
  transition: color 0.12s, border-color 0.12s, background-color 0.12s;
}
.app-nav .header-link:hover {
  color: var(--accent);
  border-color: var(--panel-border);
}
.app-nav .header-link.is-current {
  color: var(--accent);
  border-color: var(--panel-border-strong);
  background: rgba(255, 255, 255, 0.03);
  font-weight: 600;
  cursor: default;
}

main {
  display: grid;
  grid-template-columns: minmax(420px, 1fr) minmax(360px, 1fr);
  gap: 24px;
  padding: 24px;
  max-width: 1280px;
  margin: 0 auto;
  align-items: start;
}

.left-column { display: flex; flex-direction: column; gap: 24px; }

.panel {
  background: linear-gradient(180deg, #1e2024 0%, #15171a 100%);
  border: 1px solid var(--panel-border);
  border-radius: 2px;
  padding: 18px 20px 18px;
  box-shadow:
    0 4px 16px rgba(0,0,0,0.35),
    inset 0 1px 0 rgba(255,255,255,0.03);
}
.panel h2 {
  margin: 0 0 16px;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 2.5px;
  color: var(--accent);
  font-weight: 700;
  border-bottom: 1px solid rgba(212,210,202,0.15);
  padding-bottom: 10px;
  text-shadow: 0 1px 0 rgba(0,0,0,0.6);
}

.toolbar {
  display: flex; gap: 10px; align-items: center;
  margin-bottom: 14px; flex-wrap: wrap;
  padding: 8px 10px;
  background: #131518;
  border: 1px solid var(--panel-border);
  border-radius: 2px;
}
.toolbar label {
  font-size: 10.5px; color: var(--text-dim);
  text-transform: uppercase; letter-spacing: 1.5px;
  font-weight: 600;
}
.toolbar .spacer { flex: 1; }

button, select, input[type=text], input[type=number], input[type=search], textarea {
  background: #0c0d0f;
  color: var(--text);
  border: 1px solid #2f3236;
  padding: 7px 11px;
  border-radius: 3px;
  font: inherit;
  font-size: 13px;
  transition: border-color 0.15s ease, background 0.15s ease,
              box-shadow 0.15s ease, transform 0.08s ease;
}
button { cursor: pointer; }
button:hover { border-color: var(--accent); background: #181a1d; }
button:active { background: #0a0b0d; transform: translateY(1px); }
button.primary {
  background: linear-gradient(180deg, #e3e1d8 0%, #8a8a82 100%);
  color: #15171a;
  border-color: #58595c;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  font-size: 12px;
  padding: 8px 15px;
  text-shadow: 0 1px 0 rgba(255,255,255,0.3);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.4),
    0 2px 6px rgba(0,0,0,0.45);
}
button.primary:hover {
  filter: brightness(1.08);
  border-color: var(--accent);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.45),
    0 4px 10px rgba(0,0,0,0.5);
  transform: translateY(-1px);
}
button.primary:active { transform: translateY(0); }
button:disabled { opacity: 0.5; cursor: not-allowed; transform: none !important; }

select:focus, input:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(212,210,202,0.14);
}

/* Keyboard focus on buttons — was missing entirely. */
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
button.primary:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 3px;
}

input[type=color] { padding: 0; height: 28px; width: 40px; border-radius: 2px; cursor: pointer; }

#pie-host {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 240px;
}

/* ────── Footer (author + disclaimer) + disclaimer modal ────── */
.site-footer {
  padding: 18px 24px 26px;
  text-align: center;
  color: var(--text-dim);
  font-size: 12px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.site-footer .footer-sep { color: #444; user-select: none; }
.site-footer a {
  color: var(--text-dim);
  text-decoration: none;
  border-bottom: 1px dotted #555;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.site-footer a:hover {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.disclaimer-modal[hidden] { display: none; }
.disclaimer-modal {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
}
.disclaimer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  cursor: pointer;
}
.disclaimer-panel {
  position: relative;
  max-width: 640px;
  max-height: 80vh;
  overflow-y: auto;
  margin: 20px;
  padding: 28px 32px 24px;
  background: #1a1a1a;
  color: #ddd;
  border: 1px solid #333;
  border-radius: 6px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
  font-size: 14px;
  line-height: 1.55;
}
.disclaimer-panel h2 {
  margin: 0 0 16px;
  font-size: 18px;
  color: #fff;
}
.disclaimer-panel p {
  margin: 0 0 12px;
}
.disclaimer-close {
  position: absolute;
  top: 8px;
  right: 10px;
  background: transparent;
  border: none;
  color: #888;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 10px;
}
.disclaimer-close:hover { color: #fff; }

/* ───────────────────────────────────────────────────────────────────────
   Polish pass — accessibility + theme-consistent niceties.
   ─────────────────────────────────────────────────────────────────────── */

/* Honour user OS-level "reduce motion". Kill transitions + animations
   for anyone who's set the preference (vestibular sensitivity, etc.). */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* Themed scrollbars — the default Chrome/Edge scrollbar is bright white
   on our dark theme and looks broken. Firefox uses scrollbar-color. */
* {
  scrollbar-width: thin;
  scrollbar-color: #3c3f43 transparent;
}
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: #3c3f43;
  border-radius: 5px;
  border: 2px solid var(--bg);
}
*::-webkit-scrollbar-thumb:hover { background: #57595d; }

/* Themed text selection — default blue clashes hard with the dark theme. */
::selection {
  background: rgba(212, 210, 202, 0.35);
  color: var(--text);
}

/* Skip-to-content link — invisible by default, jumps into view on focus.
   Lets keyboard users bypass the header nav. Wire by adding
   <a class="skip-link" href="#app-root">Skip to content</a> as the
   first body child where useful. */
.skip-link {
  position: absolute;
  top: 0;
  left: 0;
  padding: 8px 14px;
  background: var(--accent);
  color: var(--bg);
  font-weight: 700;
  font-size: 13px;
  z-index: 10000;
  transform: translateY(-150%);
  transition: transform 0.18s ease;
}
.skip-link:focus {
  transform: translateY(0);
  outline: none;
}

/* Subtler focus rings overall — was 2px outline + 2px offset, which
   reads as a chunky border on small buttons. Drop to 2px outline +
   1px offset, and tighten primary's bright white ring to a gentler
   off-white so it doesn't visually "shout". */
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-radius: 3px;
}
button.primary:focus-visible {
  outline: 2px solid #f5f3eb;
  outline-offset: 2px;
}

/* Lift muted-text contrast a touch — the original #8b8c89 was right at
   the WCAG AA edge against panel backgrounds. Bumping to make it a
   safer pass while still reading as "secondary." */
:root {
  --text-dim: #a0a19c;
}

/* Subtle hover lift for clickable cards / panel triggers that don't
   already have a hover state. Cosmetic, but makes the UI feel alive. */
.editor-tabs button,
.bg-toneify-check {
  transition: color 0.15s ease, background 0.15s ease, transform 0.08s ease;
}

/* Headings — slight letter-spacing tightening for better display feel. */
h1, h2, h3 { letter-spacing: -0.01em; }

/* Inputs — larger touch targets on small screens, plus font-size: 16px
   on text inputs (Mobile Safari zooms the viewport on focus for any
   input smaller than 16px — setting 16px defuses that). Minimum
   height of 44px on interactive elements matches the Apple HIG and
   Material tap-target guidance. */
@media (max-width: 720px) {
  button, select, input[type=text], input[type=number], input[type=search], textarea {
    padding: 10px 12px;
    font-size: 16px;
    min-height: 44px;
    box-sizing: border-box;
  }
  label { font-size: 13px; }
  .editor-tabs button {
    padding: 12px 14px;
    font-size: 12px;
    min-height: 44px;
  }
  /* Range sliders get a fatter thumb so they're actually draggable. */
  input[type=range] {
    height: 40px;
    min-height: 40px;
  }
  input[type=range]::-webkit-slider-thumb { width: 22px; height: 22px; }
  input[type=range]::-moz-range-thumb     { width: 22px; height: 22px; }
  /* Links in the header nav get larger hit area too. */
  .app-nav .header-link {
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
}

/* ────── Header "by Poliwave" pill + footer credit links ────── */
.header-poliwave {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  letter-spacing: 1px;
  text-transform: uppercase;
  text-decoration: none;
  color: var(--text-dim);
  padding: 4px 10px;
  margin-right: 12px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(127, 222, 255, 0.06) 0%, rgba(255, 175, 189, 0.06) 100%);
  transition: color 0.15s ease, border-color 0.15s ease, transform 0.08s ease;
}
.header-poliwave > span {
  font-weight: 700;
  color: var(--accent);
  background: linear-gradient(90deg, #ffafbd 0%, #7fdeff 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.header-poliwave:hover {
  border-color: rgba(127, 222, 255, 0.4);
  transform: translateY(-1px);
  color: var(--text);
}

/* Make the footer credit pieces visually distinct so author + Poliwave
   both stand out without being noisy. */
.footer-author {
  font-weight: 600;
}
.footer-poliwave {
  font-weight: 700;
  background: linear-gradient(90deg, #ffafbd 0%, #7fdeff 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  border-bottom: none !important;
}
.footer-poliwave:hover {
  filter: brightness(1.15);
}

/* On phones, drop the pill into the second nav row so it doesn't crowd
   the title. */
@media (max-width: 720px) {
  .header-poliwave {
    margin-right: 0;
    margin-bottom: 4px;
    font-size: 10px;
    padding: 3px 8px;
  }
}

/* "Open Editor" CTA — primary-styled link in preview header. More
   discoverable than the small "Editor" nav link for new users. */
.header-cta {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: 12px;
  padding: 7px 14px;
  background: linear-gradient(180deg, #e3e1d8 0%, #8a8a82 100%);
  color: #15171a;
  font-weight: 700;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  text-decoration: none;
  border-radius: 3px;
  border: 1px solid #58595c;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.3);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.4),
    0 2px 6px rgba(0, 0, 0, 0.45);
  transition: transform 0.08s ease, filter 0.15s ease, box-shadow 0.15s ease;
}
.header-cta:hover {
  filter: brightness(1.08);
  transform: translateY(-1px);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.45),
    0 4px 10px rgba(0, 0, 0, 0.5);
}
.header-cta:active { transform: translateY(0); }
@media (max-width: 720px) {
  .header-cta {
    margin-left: 0;
    width: 100%;
    justify-content: center;
    padding: 9px 14px;
  }
}
