/**
 * TICKET-303/306: Global Premium Chrome
 *
 * Applied on all pages via inc/codeword-enqueue.php.
 * Covers: base typography, site header, site footer, theme toggle,
 *         primary nav (TICKET-311), focus states, skip link.
 *
 * Token source: css/tokens.css (loaded before this file).
 * Dark mode is default. Light mode via html.light-mode.
 *
 * Does NOT contain page-specific styles — those live in premium-{surface}.css.
 */

/* ─── Base typography ────────────────────────────────────────────────────────── */

body,
input,
textarea,
button,
select,
.result-ledger,
.solver-grid {
  font-family: var(--font-logic);
}

h1 {
  font-family: var(--font-gnosis);
  font-size: clamp(2rem, 4vw, 3.5rem);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  line-height: 1.1;
  color: var(--text-primary);
}

h2 {
  font-family: var(--font-gnosis);
  font-size: clamp(1.25rem, 2.6vw, 2rem);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  line-height: 1.15;
  color: var(--text-primary);
}

h3 {
  font-family: var(--font-logic);
  color: var(--text-primary);
}

p {
  color: var(--text-color);
}

a {
  color: var(--accent);
  transition: color var(--dur-fast);
}

a:hover {
  color: var(--accent);
  opacity: 0.8;
  text-decoration: underline;
}

/* ─── Body ───────────────────────────────────────────────────────────────────── */

body {
  background-color: var(--bg-page);
  color: var(--text-primary);
}

/* ─── Container — TICKET-336: pure layout primitive ──────────────────────────── */
/*
 * .container is now a pure centering/width primitive — no card treatment.
 * The base styles.css has max-width: 800px and margin: 1rem (never centred).
 * This override widens it to 1080px, properly centres it, and strips the
 * card styling (background, border, shadow, radius) so that secondary pages
 * sit on the open canvas rather than floating inside a narrow boxed card.
 *
 * Card treatment is applied ONLY where explicitly intended:
 *   - Solver pages: .cws-page--solver .container  (see premium-solver.css)
 *   - Puzzle pages: .puzzle-page / .puzzle-archive-page .container (see premium-puzzle.css)
 *
 * Header and footer containers are further reset by their own rules below.
 * The homepage uses .hp-main for its primary layout so is unaffected.
 */

.container {
  max-width: 1080px;
  width: 92%;
  margin: 1.5rem auto;
  background: transparent;
  border: none;
  box-shadow: none;
  border-radius: 0;   /* reset the 8px radius from styles.css */
}

/* ─── Site header ────────────────────────────────────────────────────────────── */
/*
 * Adds premium treatment on top of the existing .site-header rules in styles.css.
 * Because --card-background and --border-color are now mapped to dark theme
 * values via tokens.css, the header already picks up the dark palette.
 * These rules add the layout fixes and font treatment.
 */

.site-header {
  align-self: stretch;   /* full-width in body flex context */
  width: 100%;
  position: sticky;
  top: 0;
  z-index: 200;
  background-color: var(--bg-page);
  border-bottom: 1px solid var(--border-subtle);
  padding: 0.5rem 1.5rem; /* TICKET-335: tighter vertical rhythm vs styles.css 16px 32px */
  transition:
    background-color var(--dur-mid) var(--ease-shutter),
    border-color      var(--dur-mid) var(--ease-shutter);
}

/* TICKET-335: Strip the card treatment from the .container inside the header.
 * The base .container rule applies background, border, shadow, 32px padding,
 * and 1rem margin — all of which make the header look like a nested boxed card.
 * Reset it to a transparent pass-through so .site-header__inner controls layout. */
.site-header .container {
  background: transparent;
  border: none;
  box-shadow: none;
  border-radius: 0;
  padding: 0;
  margin: 0 auto;
  width: 100%;
  max-width: none;
}

.site-header__inner {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

/* ─── Site branding ──────────────────────────────────────────────────────────── */

.site-title {
  font-family: var(--font-gnosis);
  font-size: 0.95rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  margin: 0;
  white-space: nowrap;
}

.site-title a {
  color: var(--text-primary);
  text-decoration: none;
  transition: color var(--dur-fast);
}

.site-title a:hover {
  color: var(--accent);
  text-decoration: none;
  opacity: 1;
}

/* ─── Primary navigation (TICKET-311) ───────────────────────────────────────── */

.site-nav {
  flex: 1;
  display: flex;
  justify-content: flex-end;
}

.site-nav__list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  align-items: center;
  gap: 0.125rem;
  flex-wrap: nowrap;
}

.site-nav__link {
  font-family: var(--font-logic);
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  text-decoration: none;
  white-space: nowrap; /* TICKET-377A: prevent multi-word labels wrapping to 2 lines */
  padding: 0.375rem 0.5rem;
  border-radius: 3px;
  border-bottom: 2px solid transparent;
  transition:
    color            var(--dur-fast),
    border-color     var(--dur-fast),
    background-color var(--dur-fast);
}

.site-nav__link:hover {
  color: var(--text-primary);
  text-decoration: none;
  opacity: 1;
}

.site-nav__link--active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ─── Theme toggle (TICKET-301 / TICKET-371B) ───────────────────────────────── */
/*
 * Pill-shaped button that shows the current theme state as visible text.
 * Icon is decorative; the label span carries the state copy.
 *
 * Visible copy:     Theme: Dark | Theme: Light
 * Accessible label: Switch to light mode | Switch to dark mode
 *
 * JS (theme-toggle.js) keeps both in sync with the active theme.
 */

.theme-toggle {
  flex-shrink: 0;
  background: transparent;
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  padding: 0.25rem 0.625rem;
  border-radius: 1rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.8rem;
  line-height: 1;
  white-space: nowrap;
  transition:
    color            var(--dur-fast),
    border-color     var(--dur-fast),
    background-color var(--dur-fast);
}

.theme-toggle:hover {
  color: var(--text-primary);
  border-color: var(--accent);
  background-color: var(--accent-glow);
}

.theme-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  color: var(--text-primary);
  border-color: var(--accent);
}

.theme-toggle__icon {
  font-size: 0.9rem;
  line-height: 1;
  flex-shrink: 0;
}

.theme-toggle__icon::before {
  content: "◐";
}

html.light-mode .theme-toggle__icon::before {
  content: "●";
}

.theme-toggle__label {
  font-size: 0.75rem;
  letter-spacing: 0.01em;
}

/* ─── Skip link ──────────────────────────────────────────────────────────────── */

.skip-link {
  position: absolute;
  top: -100px;
  left: 0.5rem;
  z-index: 999;
  background: var(--bg-surface);
  color: var(--text-primary);
  font-family: var(--font-logic);
  font-size: 0.875rem;
  padding: 0.5rem 1rem;
  border: 1px solid var(--border-subtle);
  border-radius: 0 0 4px 4px;
  text-decoration: none;
  transition: top var(--dur-fast);
}

.skip-link:focus {
  top: 0;
}

/* ─── Focus visible ──────────────────────────────────────────────────────────── */

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ─── Site footer (TICKET-306/312) ───────────────────────────────────────────── */

.site-footer {
  align-self: stretch;
  width: 100%;
  margin-top: auto;
  background-color: var(--bg-page);
  border-top: 1px solid var(--border-subtle);
  padding: 2rem 1.5rem;
  transition:
    background-color var(--dur-mid) var(--ease-shutter),
    border-color      var(--dur-mid) var(--ease-shutter);
}

/* TICKET-335: Footer container — transparent, centred, no card treatment.
 * The base .container gives 32px padding and 1rem all-side margin which
 * creates gaps from the footer edges. Override to flush+centred. */
.site-footer .container {
  max-width: 1100px;
  width: 100%;
  background: transparent;
  box-shadow: none;
  border: none;
  border-radius: 0;
  padding: 0;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* Trust nav — primary footer element */
.footer-trust-nav__list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem 1.25rem;
}

.footer-trust-nav__list a {
  font-family: var(--font-logic);
  font-size: 0.8rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  text-decoration: none;
  transition: color var(--dur-fast);
}

.footer-trust-nav__list a:hover {
  color: var(--accent);
  text-decoration: none;
  opacity: 1;
}

/* ─── Footer link groups (TICKET-312) ────────────────────────────────────── */

.footer-groups {
  display: flex;
  flex-wrap: wrap;
  gap: 2rem 3.5rem;
}

.footer-group__heading {
  font-family: var(--font-gnosis);
  font-size: 0.6875rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-muted);
  opacity: 0.55;
  margin: 0 0 0.625rem;
}

.footer-group__list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.footer-group__link {
  font-family: var(--font-logic);
  font-size: 0.8rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  text-decoration: none;
  transition: color var(--dur-fast);
}

.footer-group__link:hover {
  color: var(--accent);
  text-decoration: none;
  opacity: 1;
}

html.light-mode .footer-group__link:hover {
  color: var(--amber-logic);
}

/* Credits — visually secondary to trust nav */
.footer-meta {
  opacity: 0.45;
  font-family: var(--font-logic);
  font-size: 0.75rem;
  color: var(--text-muted);
}

.footer-meta p {
  margin: 0 0 0.25rem;
  color: var(--text-muted);
}

.footer-meta a {
  color: var(--text-muted);
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* ─── Continuation buttons (shared across surfaces) ─────────────────────────── */

.puzzle-continuation__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border-subtle);
}

.puzzle-continuation__btn {
  font-family: var(--font-logic);
  font-size: 0.85rem;
  letter-spacing: 0.04em;
  padding: 0.5rem 1.25rem;
  border-radius: 3px;
  border: 1px solid transparent;
  text-decoration: none;
  transition:
    background-color var(--dur-fast),
    color            var(--dur-fast),
    border-color     var(--dur-fast);
  cursor: pointer;
}

.puzzle-continuation__btn--primary {
  background-color: var(--accent);
  color: var(--ink-nocturnal);
  border-color: var(--accent);
}

html.light-mode .puzzle-continuation__btn--primary {
  color: #fff;
}

.puzzle-continuation__btn--primary:hover {
  background-color: var(--primary-dark);
  border-color: var(--primary-dark);
  text-decoration: none;
  opacity: 1;
}

.puzzle-continuation__btn--secondary {
  background-color: transparent;
  color: var(--accent);
  border-color: var(--border-subtle);
}

.puzzle-continuation__btn--secondary:hover {
  border-color: var(--accent);
  text-decoration: none;
  opacity: 1;
}

.puzzle-continuation__btn--ghost {
  background-color: transparent;
  color: var(--text-muted);
  border-color: var(--border-subtle);
  font-size: 0.8rem;
}

.puzzle-continuation__btn--ghost:hover {
  color: var(--text-primary);
  border-color: var(--accent);
  text-decoration: none;
  opacity: 1;
}

/* ─── Puzzle help aside (shared) ────────────────────────────────────────────── */

.puzzle-help {
  margin-top: 2rem;
  padding: 1rem 1.25rem;
  background-color: var(--bg-panel);
  border-left: 3px solid var(--border-subtle);
  border-radius: 0 4px 4px 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.puzzle-help__text {
  font-family: var(--font-logic);
  font-size: 0.875rem;
  color: var(--text-muted);
  margin: 0;
  line-height: 1.6;
}

.puzzle-help__text strong {
  color: var(--text-primary);
}

.puzzle-help__link {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* ─── Hamburger toggle (TICKET-341) ─────────────────────────────────────────── */
/*
 * Hidden on desktop. Revealed below the 960px breakpoint.
 * Three-bar icon built from .nav-toggle__bar spans — no SVG dependency.
 */

.nav-toggle {
  display: none;          /* desktop: invisible */
  flex-shrink: 0;
  order: 3;               /* sits after .site-nav in flex row */
  width: 2.25rem;
  height: 2.25rem;
  padding: 0.375rem;
  background: transparent;
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  cursor: pointer;
  flex-direction: column;
  justify-content: space-between;
  align-items: stretch;
  transition: border-color var(--dur-fast);
}

.nav-toggle:hover,
.nav-toggle:focus-visible {
  border-color: var(--accent);
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.nav-toggle__bar {
  display: block;
  height: 2px;
  border-radius: 2px;
  background-color: var(--text-primary);
  transition:
    transform var(--dur-fast) var(--ease-shutter),
    opacity   var(--dur-fast);
}

/* × state when menu is open */
.nav-toggle[aria-expanded="true"] .nav-toggle__bar:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}
.nav-toggle[aria-expanded="true"] .nav-toggle__bar:nth-child(2) {
  opacity: 0;
}
.nav-toggle[aria-expanded="true"] .nav-toggle__bar:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

/* ─── Mid-desktop compact nav (TICKET-377A) ─────────────────────────────────── */
/*
 * At 961–1100px the 7-item nav + branding + theme toggle is snug.
 * Tighten horizontal link padding and the header inner gap so all items
 * remain on one row without overflow before the hamburger breakpoint at 960px.
 */

@media (min-width: 961px) and (max-width: 1100px) {
  .site-header__inner {
    gap: 1rem;
  }

  .site-nav__link {
    padding-left: 0.3rem;
    padding-right: 0.3rem;
  }
}

/* ─── Mobile / tablet nav (TICKET-341) ──────────────────────────────────────── */
/*
 * Below 960px the inline nav is replaced by the hamburger pattern.
 *
 * Closed:  .site-nav has display:none → links not reachable by keyboard.
 * Open:    .site-nav--open restores display as a full-width dropdown panel.
 */

@media (max-width: 960px) {
  /* Show the hamburger button */
  .nav-toggle {
    display: flex;
  }

  /* Anchor point for the absolute dropdown */
  .site-header__inner {
    position: relative;
  }

  /* Hide the nav by default — removes links from tab order when closed */
  .site-nav {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 199;
    background-color: var(--bg-page);
    border-bottom: 1px solid var(--border-subtle);
    padding: 1rem 1.5rem 1.25rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
  }

  /* Open state — toggled by nav-hamburger.js */
  .site-nav--open {
    display: block;
  }

  /* Stack links vertically */
  .site-nav__list {
    flex-direction: column;
    align-items: flex-start;
    gap: 0;
  }

  .site-nav__list li {
    width: 100%;
  }

  .site-nav__link {
    display: block;
    width: 100%;
    font-size: 0.8rem;
    padding: 0.65rem 0.5rem;
    border-bottom: 1px solid var(--border-subtle);
    border-radius: 0;
    border-left: 3px solid transparent;
  }

  /* Active state: left-border accent replaces bottom-border accent */
  .site-nav__link--active {
    border-bottom-color: var(--border-subtle);
    border-left-color: var(--accent);
    color: var(--accent);
  }

  .site-nav__list li:last-child .site-nav__link {
    border-bottom: none;
  }

  /* Footer layout adjustments */
  .footer-trust-nav__list {
    gap: 0.375rem 1rem;
  }

  .footer-groups {
    gap: 1.5rem 2.5rem;
  }

  .puzzle-continuation__actions {
    flex-direction: column;
  }

  .puzzle-continuation__btn {
    text-align: center;
  }
}

/* ─── Phone-only fine-tuning (≤480px) ───────────────────────────────────────── */

@media (max-width: 480px) {
  .site-nav {
    padding: 0.75rem 1rem 1rem;
  }

  .site-nav__link {
    font-size: 0.75rem;
    padding: 0.6rem 0.5rem;
  }
}
