/* ============================================================================
   WHEN THE FIRE FADES - SHARED THEME
   Design tokens and the firelit "stage" world. Centralized so every page
   (landing, auth, lobby, gameplay) inherits the same fire. Pair with fire.js,
   which drives --fire-intensity live as the flame flickers.
   ========================================================================== */
:root {
  /* ---- FOREST / GROUND (the dark canvas) ------------------------------- */
  --c-void:        #07090a;   /* deepest night, outside the firelight       */
  --c-forest:      #0c0f0c;   /* page background, near-black moss            */
  --c-earth:       #12140f;   /* wet earth, base surface                     */
  --c-bark:        #1b1d16;   /* charred wood, raised surface                */
  --c-bark-2:      #24251c;   /* lifted surface / hover                      */
  --c-bark-line:   #34342a;   /* wood-grain hairline borders                 */

  /* ---- FIRE / ACCENT (alive - use sparingly so it glows) --------------- */
  --c-core:        #ffe7ab;   /* near-white hottest core, wisp of yellow     */
  --c-gold:        #ffb43d;   /* warm gold highlight, wordmark               */
  --c-ember:       #ff7a1f;   /* ember orange, primary CTA                   */
  --c-flame:       #ef4a23;   /* flame red                                   */
  --c-flame-deep:  #b22f17;   /* deep red, shadow side of the flame          */

  /* ---- ASH / SMOKE (muted, cold, inactive) ----------------------------- */
  --c-ash:         #cdbfa9;   /* primary readable text in firelight          */
  --c-ash-dim:     #9b9282;   /* secondary text                              */
  --c-ash-faint:   #6c665b;   /* tertiary text, placeholders                 */
  --c-smoke:       #423f38;   /* cold borders, dividers                      */

  /* ---- TYPOGRAPHY ------------------------------------------------------- */
  --font-display: "Cinzel", "Times New Roman", serif;     /* wordmark/heads  */
  --font-ui:      "Source Sans 3", system-ui, sans-serif; /* body & UI       */

  --fs-wordmark: clamp(1.8rem, 4.8vw, 3rem);
  --fs-h2:       clamp(1.4rem, 4vw, 2.1rem);
  --fs-lead:     clamp(1.05rem, 2.4vw, 1.3rem);
  --fs-body:     1rem;
  --fs-sm:       0.875rem;
  --fs-xs:       0.75rem;
  --tracking-display: 0.16em;
  --tracking-ui:      0.02em;

  /* ---- SPACING (8pt rhythm) -------------------------------------------- */
  --sp-1: 0.25rem; --sp-2: 0.5rem;  --sp-3: 0.75rem; --sp-4: 1rem;
  --sp-5: 1.5rem;  --sp-6: 2rem;    --sp-7: 3rem;    --sp-8: 4rem;

  /* ---- RADIUS ----------------------------------------------------------- */
  --r-sm: 4px; --r-md: 8px; --r-lg: 14px; --r-pill: 999px;

  /* ---- ELEVATION (soft, warm shadows - never hard) --------------------- */
  --shadow-card: 0 2px 8px rgba(0,0,0,0.5), 0 24px 60px -20px rgba(0,0,0,0.8);
  --shadow-soft: 0 1px 3px rgba(0,0,0,0.4);

  /* ---- GLOW (the firelight - driven live by JS via --fire-intensity) ---- */
  --fire-intensity: 1;        /* 0 = dead/cold, 1 = full blaze. Flickers.    */
  --glow-ember: 0 0 24px rgba(255,122,31,0.45), 0 0 60px rgba(239,74,35,0.25);
  --glow-soft:  0 0 18px rgba(255,180,61,0.30);

  /* ---- MOTION ----------------------------------------------------------- */
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
}

/* ============================================================================
   RESET / BASE
   ========================================================================== */
* { box-sizing: border-box; }
html { font-size: 16px; }            /* lock the rem scale; site.css drops html to 14px on small screens */
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-ui);
  font-size: var(--fs-body);
  color: var(--c-ash);
  background: var(--c-forest);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
  overflow-x: hidden;
}
a { color: var(--c-gold); text-decoration: none; }
button { font-family: inherit; }

/* ============================================================================
   STAGE - the firelit scene
   ========================================================================== */
.stage {
  position: relative;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  isolation: isolate;
  background:
    radial-gradient(120% 90% at 50% 118%,
      rgba(255,138,40, calc(0.20 * var(--fire-intensity))) 0%,
      rgba(120,40,12, calc(0.10 * var(--fire-intensity))) 26%,
      transparent 58%),
    radial-gradient(140% 120% at 50% 130%, #19150d 0%, var(--c-forest) 45%, var(--c-void) 100%);
  overflow: hidden;
}
/* Dark forest vignette - edges fall off into night */
.stage::after {
  content: "";
  position: absolute; inset: 0; z-index: 3; pointer-events: none;
  background:
    radial-gradient(115% 100% at 50% 116%, transparent 30%, rgba(4,5,4,0.55) 72%, rgba(2,3,2,0.92) 100%);
  mix-blend-mode: multiply;
}
/* Subtle soot / paper grain - never hurts legibility */
.stage::before {
  content: "";
  position: absolute; inset: 0; z-index: 2; pointer-events: none; opacity: 0.5;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.5'/%3E%3C/svg%3E");
  mix-blend-mode: overlay;
}

/* The flame canvas - the campfire itself, burning at the base of the scene */
#fireCanvas {
  display: block;
  width: min(520px, 92vw);
  height: clamp(190px, 26vh, 250px);
  margin: calc(var(--sp-4) * -1) auto 0;
  z-index: 1;
  pointer-events: none;
}

/* ============================================================================
   TOP NAV - shared across every firelit page (landing, lobby, ...)
   ========================================================================== */
.nav {
  position: relative; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--sp-4) var(--sp-5);
  gap: var(--sp-4);
}
.brand {
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: 0.1em;
  font-size: var(--fs-sm);
  color: var(--c-ash);
  text-transform: uppercase;
  display: flex; align-items: center; gap: var(--sp-2);
}
.brand .dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--c-ember);
  box-shadow: 0 0 10px var(--c-ember), 0 0 4px var(--c-core);
}
.nav-links { display: flex; align-items: center; gap: var(--sp-2); }
.nav-link {
  font-size: var(--fs-sm); color: var(--c-ash-dim);
  padding: var(--sp-2) var(--sp-3); border-radius: var(--r-sm);
  transition: color .2s var(--ease), background .2s var(--ease);
}
.nav-link:hover { color: var(--c-ash); background: rgba(255,255,255,0.03); }
/* min-width:0 + break-anywhere so an extreme (unbroken) viewer name breaks rather
   than running off the nav on a phone; multi-word names still wrap as before. */
.nav-link.user { color: var(--c-ash); min-width: 0; overflow-wrap: anywhere; }
.nav-divider { width:1px; height:18px; background: var(--c-smoke); }

/* the logout form should sit inline like a nav link, not a chunky button */
.nav-form { display: inline-flex; margin: 0; padding: 0; }
.nav-form .nav-link {
  background: none; border: none; cursor: pointer;
  font-family: inherit; line-height: inherit;
}

/* small carved label that sits above a heading */
.eyebrow {
  font-size: var(--fs-xs);
  letter-spacing: 0.42em;
  text-transform: uppercase;
  color: var(--c-ash-faint);
  padding-left: 0.42em;
}

/* ============================================================================
   BUTTONS
   ========================================================================== */
.btn {
  font-family: var(--font-ui);
  font-size: 1.02rem; font-weight: 600; letter-spacing: var(--tracking-ui);
  border-radius: var(--r-md);
  padding: var(--sp-4) var(--sp-5);
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-3);
  transition: transform .15s var(--ease), box-shadow .25s var(--ease), background .2s var(--ease), border-color .2s var(--ease), color .2s var(--ease);
  border: 1px solid transparent;
  width: 100%;
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--c-gold); outline-offset: 3px; }
.btn .ic { width: 18px; height: 18px; flex: none; }

/* primary - alive, warm, gently pulsing */
.btn-primary {
  color: #2a1405;
  background: linear-gradient(180deg, var(--c-gold) 0%, var(--c-ember) 70%, var(--c-flame) 100%);
  box-shadow: var(--glow-ember), inset 0 1px 0 rgba(255,255,255,0.35);
  border-color: rgba(255,210,140,0.5);
  animation: emberPulse 3.6s ease-in-out infinite;
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 0 30px rgba(255,122,31,0.6), 0 0 70px rgba(239,74,35,0.35), inset 0 1px 0 rgba(255,255,255,0.4); }
@keyframes emberPulse {
  0%, 100% { box-shadow: 0 0 22px rgba(255,122,31,0.40), 0 0 56px rgba(239,74,35,0.22), inset 0 1px 0 rgba(255,255,255,0.35); }
  50%      { box-shadow: 0 0 30px rgba(255,150,55,0.58), 0 0 72px rgba(239,74,35,0.34), inset 0 1px 0 rgba(255,255,255,0.4); }
}

/* secondary - cold ember, outlined, warms on hover */
.btn-secondary {
  color: var(--c-ash);
  background: rgba(255,255,255,0.02);
  border-color: var(--c-smoke);
}
.btn-secondary:hover {
  color: var(--c-core);
  border-color: rgba(255,150,55,0.55);
  background: rgba(255,120,40,0.06);
  box-shadow: var(--glow-soft);
}

/* ghost / text buttons for auth state */
.btn-ghost {
  background: transparent; border-color: var(--c-smoke); color: var(--c-ash);
}
.btn-ghost:hover { border-color: rgba(255,150,55,0.5); color: var(--c-core); }

/* danger - the flame turned destructive (leave / abandon) */
.btn-danger {
  color: #fff;
  background: linear-gradient(180deg, var(--c-flame), var(--c-flame-deep));
  border-color: rgba(239,74,35,.5);
}
.btn-danger:hover { box-shadow: 0 0 22px rgba(239,74,35,.4); transform: translateY(-1px); }

/* ============================================================================
   FORM FIELDS - the shared firelit text input, used by the landing/lobby dialogs
   and the auth pages. Page CSS adds only field-specific variants (e.g. the big
   code field on the landing).
   ========================================================================== */
.name-input {
  width: 100%;
  font-family: var(--font-ui);
  font-size: 1.05rem;
  text-align: center;
  color: var(--c-ash);
  background: #0c0d09;
  border: 1px solid var(--c-smoke);
  border-radius: var(--r-md);
  padding: var(--sp-4) var(--sp-4);
  transition: border-color .2s var(--ease), box-shadow .2s var(--ease);
}
.name-input::placeholder { color: var(--c-ash-faint); }
.name-input:focus { outline: none; border-color: rgba(255,150,55,0.6); box-shadow: var(--glow-soft); }

/* ============================================================================
   TOGGLE SWITCH - the shared firelit on/off control. Used by the lobby's
   leader-only settings (public/private game and phase timers). A bare checkbox
   styled into a sliding track; pair the <input> with a sibling .track inside a .switch.
   ========================================================================== */
.switch { display: flex; align-items: center; gap: var(--sp-4); cursor: pointer; text-align: left; }
.switch input { display: none; }
.track { width: 46px; height: 26px; border-radius: var(--r-pill); background: var(--c-smoke); position: relative; flex: none; transition: .22s var(--ease); }
.track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: var(--c-ash); transition: .22s var(--ease); }
.switch input:checked + .track { background: linear-gradient(180deg, var(--c-gold), var(--c-ember)); box-shadow: var(--glow-soft); }
.switch input:checked + .track::after { left: 23px; background: #2a1405; }
.switch-text { display: flex; flex-direction: column; }
.switch-title { font-size: .95rem; color: var(--c-ash); font-weight: 600; }
.switch-note { font-size: var(--fs-xs); color: var(--c-ash-faint); }

/* ============================================================================
   INLINE NOTICE / ERROR SLOT
   ========================================================================== */
.notice {
  display: none;
  align-items: center; gap: var(--sp-3);
  font-size: var(--fs-sm);
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-md);
  background: rgba(178,47,23,0.14);
  border: 1px solid rgba(239,74,35,0.4);
  color: #ffb59c;
}
.notice.show { display: flex; }
.notice .ic { width:16px; height:16px; flex:none; color: var(--c-flame); }

/* ============================================================================
   THEMED DIALOG SHELL - the firelit <dialog> used for join / leave / confirm.
   Page-specific contents (code field, confirm copy) live in the page CSS.
   ========================================================================== */
dialog.join {
  border: none; padding: 0; background: transparent;
  color: var(--c-ash);
  max-width: 92vw;
}
dialog.join::backdrop {
  background: radial-gradient(120% 120% at 50% 60%, rgba(20,10,2,0.55), rgba(2,3,2,0.86));
  backdrop-filter: blur(3px);
}
.join-card {
  width: 380px; max-width: 92vw;
  background: linear-gradient(180deg, #20211a, #14150f);
  border: 1px solid var(--c-bark-line);
  border-top-color: rgba(255,180,90,0.18);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-card);
  padding: var(--sp-6) var(--sp-5) var(--sp-5);
  text-align: center;
}
.join-card h3 {
  font-family: var(--font-display); font-weight: 600;
  font-size: var(--fs-h2); margin: 0 0 var(--sp-1); color: var(--c-ash);
  letter-spacing: 0.04em;
}
.join-card .sub { font-size: var(--fs-sm); color: var(--c-ash-dim); margin: 0 0 var(--sp-5); }
.join-actions { display: flex; gap: var(--sp-3); }
.join-actions .btn { font-size: 0.95rem; padding: var(--sp-3) var(--sp-4); }

/* ============================================================================
   RESPONSIVE (stage / flame)
   The decorative #fireCanvas is gated off globally on phones - one rule here
   drops it on every page that renders it (home, lobby, play, browse, login,
   register) to reclaim scarce vertical space. fire.js keeps driving
   --fire-intensity so the ambient firelight (wordmark glow, vignette, page
   warmth) still breathes, so there is no shared flame to resize here.
   ========================================================================== */
@media (max-width: 640px) {
  #fireCanvas { display: none; }
}

/* ============================================================================
   REDUCED MOTION - fall back to a calm, barely-breathing flame
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
  .btn-primary { animation: none; }
  * { scroll-behavior: auto; }
}
