/* Theme tokens — paired with theme.js (data-theme on <html>) */

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Main site header — markup from site-nav.js */
.nav {
  position: sticky;
  top: 0;
  z-index: 100;
  flex-shrink: 0;
  min-height: var(--nav-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  row-gap: 0.65rem;
  padding: 0.65rem clamp(1rem, 4vw, 3rem);
  background: var(--nav-bg);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}

.logo {
  font-family: "Fraunces", Georgia, serif;
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text);
  text-decoration: none;
}

.logo span {
  color: var(--accent);
}

.nav-links {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.35rem 0.5rem;
  list-style: none;
  justify-content: flex-end;
}

.nav-links a {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.95rem;
  font-weight: 500;
  padding: 0.5rem 1rem;
  border-radius: 999px;
  transition: color 0.2s, background 0.2s;
}

.nav-links a:hover {
  color: var(--text);
  background: var(--nav-link-hover-bg);
}

.nav-links a.primary {
  color: var(--primary-pill-fg);
  background: linear-gradient(135deg, var(--accent), #818cf8);
  box-shadow: 0 4px 20px var(--accent-soft);
  pointer-events: none;
}

.nav-brand {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  min-width: 0;
}

.nav-actions .nav-links {
  justify-content: flex-end;
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
  justify-content: flex-end;
  flex-shrink: 0;
}

.nav-overflow {
  position: relative;
}

.nav-overflow-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--key-bg);
  color: var(--text);
  cursor: pointer;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}

.nav-overflow-btn:hover {
  background: var(--nav-link-hover-bg);
  color: var(--accent);
}

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

.nav-overflow-btn[aria-expanded="true"] {
  background: var(--nav-link-hover-bg);
  color: var(--accent);
}

.nav-overflow-menu {
  position: absolute;
  top: calc(100% + 0.35rem);
  left: 0;
  right: auto;
  min-width: 12rem;
  margin: 0;
  padding: 0.35rem;
  list-style: none;
  background: var(--surface-card-strong);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-elevated);
  z-index: 200;
}

.nav-overflow-menu[hidden] {
  display: none !important;
}

.nav-overflow-menu a {
  display: block;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  padding: 0.55rem 0.85rem;
  border-radius: calc(var(--radius) - 4px);
  transition: color 0.15s, background 0.15s;
}

.nav-overflow-menu a:hover {
  color: var(--text);
  background: var(--nav-link-hover-bg);
}

.nav-overflow-menu a.primary {
  color: var(--primary-pill-fg);
  background: linear-gradient(135deg, var(--accent), #818cf8);
  box-shadow: 0 2px 12px var(--accent-soft);
  pointer-events: none;
}

html[data-theme="dark"] {
  --bg: #0f1419;
  --bg-elevated: #1a222c;
  --text: #e8eef4;
  --text-muted: #94a3b8;
  --accent: #38bdf8;
  --accent-soft: rgba(56, 189, 248, 0.15);
  --border: rgba(148, 163, 184, 0.12);
  --nav-bg: rgba(15, 20, 25, 0.75);
  --nav-link-hover-bg: rgba(255, 255, 255, 0.06);
  --primary-pill-fg: #0f1419;
  --surface-card: rgba(26, 34, 44, 0.9);
  --surface-card-mid: rgba(26, 34, 44, 0.65);
  --surface-card-strong: rgba(26, 34, 44, 0.95);
  --key-bg: rgba(255, 255, 255, 0.06);
  --key-hover: rgba(255, 255, 255, 0.1);
  --key-muted: rgba(255, 255, 255, 0.08);
  --key-muted-hover: rgba(255, 255, 255, 0.12);
  --cell-hover: rgba(255, 255, 255, 0.08);
  --grid-wrap-outer-shadow: 0 24px 80px rgba(0, 0, 0, 0.35);
  --key-op-hover: rgba(56, 189, 248, 0.25);
  --inset-highlight: rgba(255, 255, 255, 0.06);
  --shadow-elevated: 0 16px 48px rgba(0, 0, 0, 0.3);
  --shadow-strong: 0 24px 80px rgba(0, 0, 0, 0.45);
  --frame-bg: #121820;
  --frame-outer-shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
  --paint-frame-border: rgba(71, 85, 105, 0.95);
  --paint-frame-outline: rgba(15, 23, 42, 0.8);
  --found: rgba(56, 189, 248, 0.35);
  --select: rgba(129, 140, 248, 0.4);
  --game-accent-ring: rgba(56, 189, 248, 0.35);
  --game-accent-fill: rgba(56, 189, 248, 0.08);
  --game-focus-shadow: 0 0 0 1px var(--accent-soft), 0 12px 40px rgba(0, 0, 0, 0.25);
  --game-input-focus-border: rgba(56, 189, 248, 0.4);
  --game-input-hover-bg: rgba(255, 255, 255, 0.06);
  --radius: 14px;
  --nav-h: 72px;
}

html[data-theme="light"] {
  --bg: #f1f5f9;
  --bg-elevated: #ffffff;
  --text: #0f172a;
  --text-muted: #64748b;
  --accent: #0284c7;
  --accent-soft: rgba(2, 132, 199, 0.14);
  --border: rgba(15, 23, 42, 0.12);
  --nav-bg: rgba(255, 255, 255, 0.88);
  --nav-link-hover-bg: rgba(15, 23, 42, 0.06);
  --primary-pill-fg: #ffffff;
  --surface-card: rgba(255, 255, 255, 0.94);
  --surface-card-mid: rgba(241, 245, 249, 0.92);
  --surface-card-strong: #ffffff;
  --key-bg: rgba(15, 23, 42, 0.06);
  --key-hover: rgba(15, 23, 42, 0.1);
  --key-muted: rgba(15, 23, 42, 0.06);
  --key-muted-hover: rgba(15, 23, 42, 0.1);
  --cell-hover: rgba(15, 23, 42, 0.06);
  --grid-wrap-outer-shadow: 0 24px 80px rgba(15, 23, 42, 0.1);
  --key-op-hover: rgba(2, 132, 199, 0.22);
  --inset-highlight: rgba(255, 255, 255, 0.9);
  --shadow-elevated: 0 16px 48px rgba(15, 23, 42, 0.1);
  --shadow-strong: 0 24px 80px rgba(15, 23, 42, 0.08);
  --frame-bg: #e2e8f0;
  --frame-outer-shadow: 0 24px 80px rgba(15, 23, 42, 0.12);
  --paint-frame-border: rgba(100, 116, 139, 0.4);
  --paint-frame-outline: rgba(15, 23, 42, 0.06);
  --found: rgba(2, 132, 199, 0.3);
  --select: rgba(99, 102, 241, 0.35);
  --game-accent-ring: rgba(2, 132, 199, 0.35);
  --game-accent-fill: rgba(2, 132, 199, 0.08);
  --game-focus-shadow: 0 0 0 1px var(--accent-soft), 0 12px 40px rgba(15, 23, 42, 0.12);
  --game-input-focus-border: rgba(2, 132, 199, 0.45);
  --game-input-hover-bg: rgba(15, 23, 42, 0.06);
  --radius: 14px;
  --nav-h: 72px;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  margin-left: 0;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--key-bg);
  color: var(--text);
  cursor: pointer;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}

.theme-toggle:hover {
  background: var(--nav-link-hover-bg);
  color: var(--accent);
}

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

.theme-toggle .icon-sun,
.theme-toggle .icon-moon {
  display: block;
  width: 1.15rem;
  height: 1.15rem;
}

html[data-theme="dark"] .theme-toggle .icon-sun {
  display: block;
}

html[data-theme="dark"] .theme-toggle .icon-moon {
  display: none;
}

html[data-theme="light"] .theme-toggle .icon-sun {
  display: none;
}

html[data-theme="light"] .theme-toggle .icon-moon {
  display: block;
}

@media (max-width: 768px) {
  /* Keep burger + logo + theme on one row on phones (don't wrap theme to next line). */
  .nav {
    flex-wrap: nowrap;
    column-gap: 0.35rem;
  }

  .nav-brand {
    flex: 1 1 auto;
    min-width: 0;
    flex-wrap: nowrap;
  }

  .nav-actions {
    flex: 0 0 auto;
    justify-content: flex-end;
  }

  .nav-links {
    justify-content: flex-start;
  }

  .logo {
    font-size: 1.1rem;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .nav-overflow-btn {
    width: 2.35rem;
    height: 2.35rem;
    flex-shrink: 0;
  }

  .nav-links a {
    font-size: 0.85rem;
    padding: 0.45rem 0.75rem;
  }

  .theme-toggle {
    width: 2.35rem;
    height: 2.35rem;
    flex-shrink: 0;
  }
}

@media (max-width: 400px) {
  .nav-links a {
    font-size: 0.78rem;
    padding: 0.4rem 0.6rem;
  }
}
