/* Shared design tokens, page chrome (header / nav / footer), and base
   typography. Used by index.html (Lens), dreamer.html, and any future
   pages (rankings.html, etc.). Page-specific styles stay inline in each
   HTML file. */

:root {
  --accent: #C061AE;
  --accent-strong: #8a3f7d;
  --accent-soft: rgba(192, 97, 174, 0.10);
  --rarity: 217, 119, 6;          /* amber, used as rgba(var(--rarity), α) */
  --bg: #f6f1e6;                  /* warm cream — replaces clinical white */
  --bg-grid: rgba(26, 26, 31, 0.05);
  --card: #fffefb;
  --text: #1a1a1f;
  --muted: #6b7280;
  --border: #d9cfb9;              /* warm beige border */
  --border-soft: rgba(217, 207, 185, 0.5);
  --shadow: 0 1px 0 rgba(26,26,31,0.05), 0 2px 8px rgba(26,26,31,0.04);
  --font-display: 'VT323', ui-monospace, monospace;
  --font-body: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  /* Brand wordmark always uses VT323 even in zh mode (pixel-art identity
     stays English). All other VT323 callers use --font-display, which the
     html[lang="zh"] block below swaps to a CJK-capable font. */
  --font-brand: 'VT323', ui-monospace, monospace;
}

/* When Chinese is active, swap display + body fonts to ones that actually
   render CJK glyphs. VT323 has no CJK coverage, so leaving it would render
   tofu boxes for every label. Brand is exempt (uses --font-brand). */
html[lang="zh"] {
  --font-display: 'Noto Sans SC', 'PingFang SC', 'Microsoft YaHei', system-ui, sans-serif;
  --font-body:    'Noto Sans SC', 'PingFang SC', 'Microsoft YaHei', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
/* Phase G: the footer's castle pseudo-elements use left/right
   negative offsets to push past the viewport edges (so they hug
   the corners and can extend slightly outward for a cleaner
   silhouette). Without overflow-x: hidden here, that overflow
   produces a phantom horizontal scrollbar at the bottom of the
   page. Clipping at the html level is safe — no sticky/fixed
   element on any page relies on horizontal body scroll. */
html { overflow-x: hidden; }
body {
  font-family: var(--font-body);
  font-size: 13px;
  line-height: 1.5;
  background-color: var(--bg);
  background-image: radial-gradient(circle at 1px 1px, var(--bg-grid) 1px, transparent 0);
  background-size: 24px 24px;
  background-attachment: fixed;
  color: var(--text);
  padding: 20px 24px 64px;
  /* Phase G: sticky-footer pattern so the footer (and its
     castle bookends) actually lands at the viewport bottom even
     when page content is shorter than viewport. body fills at
     least viewport height; <main> grows to fill leftover space;
     <footer> sits at the very bottom. */
  min-height: 100vh;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
}
body > main { flex: 1 0 auto; }

/* ---- Site header (UNIPEG wordmark + nav tabs) ---- */
.site-header {
  display: flex; align-items: center; gap: 24px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}
.brand {
  display: inline-flex; align-items: center; gap: 12px;
  font-family: var(--font-brand);
  font-size: 56px; line-height: 0.85;
  color: var(--text); text-decoration: none;
}
.brand img {
  width: 44px; height: 44px;
  border: 1.5px solid var(--text);
  border-radius: 4px;
  padding: 2px;
  background: var(--card);
  image-rendering: pixelated;
}
.site-nav { display: inline-flex; gap: 4px; align-items: center; padding-top: 8px; }
.nav-tab {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  text-decoration: none;
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.10em;
  color: var(--muted);
  border: 1.5px solid transparent;
  transition: color 0.1s ease, background 0.1s ease;
}
.nav-tab svg { width: 14px; height: 14px; }
.nav-tab:hover:not(.nav-tab--active) { color: var(--text); }
.nav-tab--active {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: rgba(192,97,174,0.30);
}
/* Tiny "BETA" badge inside the BATTLE nav tab — marks the link as
   gated (form-application, not direct game access) without losing
   the standard nav-tab silhouette. Inline border + 8px size mirrors
   the Game-View toggle BETA pill on Lens so the visual vocabulary
   for "beta surface" is consistent across the site. */
.nav-tab__beta {
  font-size: 8px;
  padding: 1px 4px;
  border: 1px solid currentColor;
  border-radius: 3px;
  line-height: 1;
  letter-spacing: 0.08em;
  margin-left: 2px;
}

/* ---- Right-edge cluster: lang toggle + (on Lens) auth pill ---- */
.site-auth {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 10px;
}
/* Auth-pill slot is empty on dreamer/rankings (only Lens uses it). */
#auth-pill:empty { display: none; }
.auth-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: var(--accent);
  color: #fff;
  border: 1.5px solid var(--accent);
  border-radius: 999px;
  font: inherit;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  cursor: pointer;
  transition: filter 0.08s ease;
}
.auth-btn:hover:not(:disabled) { filter: brightness(1.05); }
.auth-btn:disabled { opacity: 0.6; cursor: wait; }
.auth-btn svg { width: 14px; height: 14px; }
.auth-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 4px 5px 12px;
  background: var(--accent-soft);
  border: 1.5px solid rgba(192, 97, 174, 0.45);
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.auth-pill__dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #16a34a;
  animation: auth-breathe 2.4s ease-in-out infinite;
  flex-shrink: 0;
}
@keyframes auth-breathe {
  0%, 100% { opacity: 1;   transform: scale(1); }
  50%      { opacity: 0.5; transform: scale(0.85); }
}
.auth-pill__signout {
  display: inline-flex;
  align-items: center; justify-content: center;
  width: 22px; height: 22px;
  background: transparent;
  border: 0;
  font-size: 16px;
  cursor: pointer;
  color: var(--accent);
  border-radius: 50%;
  line-height: 1;
}
.auth-pill__signout:hover { background: rgba(192, 97, 174, 0.18); }
/* Edit-profile button — same shape as signout but with a pencil glyph
   so the two actions read as a paired toolbar inside the pill. */
.auth-pill__edit {
  display: inline-flex;
  align-items: center; justify-content: center;
  width: 22px; height: 22px;
  background: transparent;
  border: 0;
  cursor: pointer;
  color: var(--accent);
  border-radius: 50%;
  line-height: 1;
}
.auth-pill__edit svg { width: 12px; height: 12px; }
.auth-pill__edit:hover { background: rgba(192, 97, 174, 0.18); }

/* Truncated address swap. Lens renders both spans; the @media at the
   bottom of this file flips which one is visible at narrow widths. */
.auth-pill__addr--tiny { display: none; }

/* Compact language toggle. Lives in `.site-auth` next to the auth pill;
   wraps with it on mobile. Two characters max ("EN" / "中") so it stays
   tiny regardless of the active language. */
.lang-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0;
  border: 1.5px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
  background: var(--card);
}
.lang-toggle button {
  appearance: none;
  background: transparent;
  border: 0;
  padding: 5px 9px;
  font: inherit;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--muted);
  cursor: pointer;
  font-family: var(--font-body);
}
.lang-toggle button:hover { color: var(--text); }
.lang-toggle button.active {
  background: var(--text);
  color: var(--bg);
}

/* ---- Common micro-elements ---- */
.lab {
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 700;
}

/* ---- Site footer ---- BASE rules (Lens dashboard / Dreamer / Rankings).
   Original layout: flex-wrap row with community attribution + links +
   security disclaimer underneath. No castles, no sticky-footer
   negatives. The uPEGDuel game footer's Phase G chrome (castles, grid
   1-col, pipe seps, max-width caps) is opted into via the
   .site-footer--game modifier further down. */
footer.site-footer {
  margin-top: 36px;
  padding: 20px 4px 8px;
  border-top: 1.5px dashed var(--border);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
footer.site-footer b { color: var(--text); font-weight: 600; }
.footer-disclaimer {
  flex-basis: 100%;
  margin-top: 4px;
  padding-top: 8px;
  border-top: 1px dotted var(--border);
  color: var(--muted);
  font-style: italic;
  font-size: 10.5px;
  letter-spacing: 0.02em;
  text-transform: none;
  line-height: 1.55;
}
.footer-disclaimer b { color: var(--text); font-style: normal; }
footer.site-footer .links {
  display: inline-flex; align-items: center; gap: 14px;
}
footer.site-footer a, footer.site-footer .footer-link {
  background: none; border: 0;
  color: var(--text);
  text-decoration: none;
  font: inherit; font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0 0 1px 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
footer.site-footer a:hover, footer.site-footer .footer-link:hover {
  border-bottom-color: var(--accent);
  color: var(--accent);
}

/* ---- Site footer (.site-footer--game) ----
   uPEGDuel game.html only. Phase G chrome: castles bookending the ©
   row, grid 1-col layout so each row claims its own line, pipe
   separators between links, max-width caps to keep text clear of the
   castle silhouettes. Combined with the body sticky-footer flex
   (set higher up) so the footer hugs the viewport bottom. */
footer.site-footer.site-footer--game {
  position: relative;
  margin: 36px -24px -64px;
  padding: 28px 24px 24px;
  border-top: 0;
  flex-shrink: 0;
  display: grid;
  grid-template-columns: 1fr;
  justify-items: center;
  row-gap: 8px;
}
footer.site-footer.site-footer--game::before,
footer.site-footer.site-footer--game::after {
  content: '';
  position: absolute;
  width: 300px;
  height: 160px;
  background: url('../assets/pool-castle.png') center bottom / contain no-repeat;
  pointer-events: none;
}
footer.site-footer.site-footer--game::before { left: -64px; top: 7px; transform: scaleX(-1); }
footer.site-footer.site-footer--game::after  { right: -64px; top: 7px; }
/* Game footer: switch link chrome from border-bottom to
   text-decoration so the underline only paints under text glyphs
   (the inline-block pipe pseudo stays outside the underlined run). */
footer.site-footer--game a,
footer.site-footer--game .footer-link {
  border-bottom: 0;
  padding: 0;
  text-decoration: underline;
  text-decoration-color: var(--border);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}
footer.site-footer--game a:hover,
footer.site-footer--game .footer-link:hover {
  text-decoration-color: var(--accent);
  color: var(--accent);
}
footer.site-footer--game .footer-disclaimer {
  margin: 8px auto 0;
  padding-top: 0;
  border-top: 0;
  max-width: min(720px, calc(100% - 540px));
  text-align: center;
}
footer.site-footer--game .links {
  display: inline-flex; align-items: center; gap: 14px;
  flex-wrap: wrap;
}
/* Pipe separators between every flex child after the first. */
footer.site-footer--game .links > *:nth-child(n+2)::before {
  content: "|";
  display: inline-block;
  color: var(--border);
  font-weight: 400;
  letter-spacing: 0;
  margin-right: 14px;
  text-transform: none;
  border-bottom: 0;
}
footer.site-footer--game .footer-copy {
  color: var(--muted);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
footer.site-footer--game .footer-attribution {
  flex-basis: 100%;
  font-size: 10.5px;
  letter-spacing: 0.02em;
  text-transform: none;
  color: var(--muted);
  margin: 4px auto 0;
  max-width: min(720px, calc(100% - 540px));
  text-align: center;
}
@media (max-width: 540px) {
  /* Castles read poorly at phone widths and overlap footer text on
     standalone pages (docs.html). Hide them entirely on mobile —
     desktop keeps the decoration. */
  footer.site-footer--game::before,
  footer.site-footer--game::after { display: none; }
  /* When body.m-app is active (mobile in-game shell), the footer is
     relocated by applyMobileMode() into the trainer view's
     scrollable content. Reset the desktop sticky chrome so it
     flows as a normal section inside that scroll area. */
  body.m-app footer.site-footer--game {
    margin: 0;
    padding: 24px 16px 28px;
    border-top: 1px dashed var(--border);
  }
  /* Two-row links: © takes its own row, links wrap below with dots. */
  body.m-app footer.site-footer--game .footer-copy {
    flex-basis: 100%;
    text-align: center;
    margin-bottom: 4px;
  }
  body.m-app footer.site-footer--game .links > *:nth-child(n+2)::before {
    content: '·';
    color: var(--border);
    margin-right: 8px;
    font-weight: 400;
    letter-spacing: 0;
    text-transform: none;
  }
  body.m-app footer.site-footer--game .links > .footer-copy + *::before {
    content: '';
    margin: 0;
  }
  footer.site-footer--game .footer-disclaimer,
  footer.site-footer--game .footer-attribution {
    max-width: 100%;
  }
}

/* Footer freshness row — full-width, sits above the credits/links rows
   on Lens (only page that populates it). Empty on Dreamer/Rankings. */
.footer-freshness {
  width: 100%;
  flex-basis: 100%;
  order: -1;                 /* render before the credits + links */
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  text-transform: none;
  letter-spacing: 0;
}
.footer-freshness:empty { display: none; }

/* Compact timestamp — visible only on phone-portrait widths. */
.ts-narrow { display: none; }
@media (max-width: 480px) {
  .ts-full   { display: none; }
  .ts-narrow { display: inline; }
}

/* ---- Mobile site-chrome tweaks ---- */
@media (max-width: 720px) {
  body { padding: 14px 12px 48px; }
  .site-header { gap: 8px 14px; row-gap: 8px; }
  .brand { font-size: 40px; gap: 10px; }
  .brand img { width: 36px; height: 36px; }
  /* Reorder so the wrap pattern is visually balanced:
       row 1: brand + auth pill (left-aligned, both items flow naturally)
       row 2: nav (3 tabs, full-width)
     Without `order`, flex-wrap puts nav between brand and auth, leaving
     a lonely right-aligned auth pill on its own row with a wide empty
     gutter on the left. Bumping nav to a higher order keeps it after
     site-auth in the wrap order. We also DROP `margin-left: auto` on
     mobile because at narrower widths brand+auth still don't always fit
     on the same row — when auth wraps to row 2 alone, the auto-margin
     pinned it right, giving the same lonely-pill look on the new row.
     Without auto-margin, auth flows left wherever it lands. */
  .site-nav { order: 3; width: 100%; }
  .site-auth { order: 2; margin-left: 0; }
}
/* Phone-portrait widths — collapse the auth-pill address to its tiny
   form (0x..35fd) so the pill doesn't push the lang toggle off-row.
   Threshold sits a hair above iPhone SE (375px) so even the smallest
   modern phones get the compact layout. */
@media (max-width: 480px) {
  .auth-pill__addr--full { display: none; }
  .auth-pill__addr--tiny { display: inline; }
}
@media (max-width: 420px) {
  .brand { font-size: 32px; }
  .brand img { width: 28px; height: 28px; }
  .nav-tab { padding: 5px 10px; font-size: 11px; }
}
