:root {
  color-scheme: light dark;
  --bg: #f5f0e8;
  --surface: #ffffff;
  --text: #1a1a1a;
  --muted: #666;
  --accent: #c0392b;
  --accent-hover: #a93226;
  --grid-border: #333;
  --cell-bg: #fff;
  --cell-block: #1a1a1a;
  --cell-active: #fdebd0;
  --cell-highlight: #fef9e7;
  --cell-correct: #d5f5e3;
  --cell-wrong: #fadbd8;
  --cell-revealed: #ebf5fb;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  --radius: 8px;
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1c1e;
    --surface: #2c2c2e;
    --text: #f2f2f7;
    --muted: #98989d;
    --accent: #ff6b6b;
    --accent-hover: #ff5252;
    --grid-border: #636366;
    --cell-bg: #3a3a3c;
    --cell-block: #1c1c1e;
    --cell-active: #48484a;
    --cell-highlight: #3a3a3c;
    --cell-correct: #1e3a2f;
    --cell-wrong: #3a2020;
    --cell-revealed: #1e2a3a;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  }
}

*, *::before, *::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.hidden {
  display: none !important;
}

/* Site nav (uberbar) */
.uberbar {
  background: #1a1a1a;
  color: #f5f5f5;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
}

.uberbar header {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 3.25rem;
}

.uberbar .logo {
  color: #fff;
  font-weight: 700;
  font-size: 1.125rem;
  letter-spacing: 0.05em;
  text-decoration: none;
  padding: 0.5rem 0;
}

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

.nav-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.5rem;
}

.hamburger,
.hamburger::before,
.hamburger::after {
  display: block;
  width: 1.25rem;
  height: 2px;
  background: #fff;
  border-radius: 1px;
  position: relative;
  transition: transform 0.2s, opacity 0.2s;
}

.hamburger::before,
.hamburger::after {
  content: '';
  position: absolute;
  left: 0;
}

.hamburger::before { top: -6px; }
.hamburger::after { top: 6px; }

.nav-toggle[aria-expanded="true"] .hamburger {
  background: transparent;
}

.nav-toggle[aria-expanded="true"] .hamburger::before {
  top: 0;
  transform: rotate(45deg);
}

.nav-toggle[aria-expanded="true"] .hamburger::after {
  top: 0;
  transform: rotate(-45deg);
}

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

.nav__link {
  display: block;
  color: #e0e0e0;
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  padding: 0.5rem 0.75rem;
  border-radius: 4px;
  border: none;
  background: none;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
}

.nav__link:hover,
.nav__link:focus-visible {
  color: #fff;
  background: rgba(255, 255, 255, 0.08);
}

.nav__link--dropdown i {
  font-size: 0.65rem;
  margin-left: 0.25rem;
  transition: transform 0.2s;
}

.nav__item--dropdown {
  position: relative;
}

.nav__dropdown {
  list-style: none;
  margin: 0;
  padding: 0.35rem 0;
  position: absolute;
  top: 100%;
  right: 0;
  min-width: 11rem;
  background: #2a2a2a;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px);
  transition: opacity 0.15s, transform 0.15s, visibility 0.15s;
}

.nav__item--dropdown:hover .nav__dropdown,
.nav__item--dropdown:focus-within .nav__dropdown,
.nav__item--dropdown.is-open .nav__dropdown {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.nav__item--dropdown.is-open .nav__link--dropdown i {
  transform: rotate(180deg);
}

.nav__dropdown-link {
  display: block;
  color: #e0e0e0;
  text-decoration: none;
  font-size: 0.875rem;
  padding: 0.5rem 1rem;
}

.nav__dropdown-link:hover,
.nav__dropdown-link:focus-visible {
  color: #fff;
  background: rgba(255, 255, 255, 0.08);
}

@media (max-width: 768px) {
  .nav-toggle {
    display: block;
  }

  .nav {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #1a1a1a;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
  }

  .nav.is-open {
    max-height: 80vh;
    overflow-y: auto;
  }

  .uberbar header {
    position: relative;
    flex-wrap: wrap;
  }

  .nav__list {
    flex-direction: column;
    align-items: stretch;
    padding: 0.5rem 1rem 1rem;
    gap: 0;
  }

  .nav__link {
    padding: 0.75rem 0.5rem;
  }

  .nav__dropdown {
    position: static;
    opacity: 1;
    visibility: visible;
    transform: none;
    box-shadow: none;
    background: rgba(255, 255, 255, 0.05);
    margin-top: 0.25rem;
    display: none;
    border-radius: 4px;
  }

  .nav__item--dropdown.is-open .nav__dropdown {
    display: block;
  }
}

/* Puzzle page header */
.header {
  background: var(--surface);
  border-bottom: 1px solid var(--grid-border);
  padding: 1.25rem 1rem;
  box-shadow: var(--shadow);
}

.header-inner {
  max-width: 1100px;
  margin: 0 auto;
  text-align: center;
}

.header h1 {
  margin: 0;
  font-size: 1.75rem;
  letter-spacing: -0.02em;
}

.subtitle {
  margin: 0.25rem 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.date {
  margin: 0.5rem 0 0;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--accent);
}

.locale {
  margin: 0.25rem 0 0;
  font-size: 0.8rem;
  color: var(--muted);
}

/* Main */
.main {
  flex: 1;
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem 1rem 2rem;
  width: 100%;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  position: relative;
  z-index: 10;
}

.difficulty-selector {
  display: flex;
  gap: 0.25rem;
  background: var(--surface);
  padding: 0.25rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.diff-btn {
  border: none;
  background: transparent;
  color: var(--text);
  padding: 0.5rem 1rem;
  border-radius: calc(var(--radius) - 2px);
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}

.diff-btn:hover {
  background: var(--cell-highlight);
}

.diff-btn.active {
  background: var(--accent);
  color: #fff;
}

.diff-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.controls {
  display: flex;
  gap: 0.5rem;
}

.ctrl-btn {
  border: 1px solid var(--grid-border);
  background: var(--surface);
  color: var(--text);
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  transition: background 0.15s, border-color 0.15s;
}

.ctrl-btn:hover {
  border-color: var(--accent);
  background: var(--cell-highlight);
}

.loading, .error {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--muted);
}

.error {
  color: var(--accent);
}

/* Game layout */
.game {
  display: grid;
  grid-template-columns: 1fr;
  gap: 2rem;
}

@media (min-width: 768px) {
  .game {
    grid-template-columns: auto 1fr;
    align-items: start;
  }
}

.grid-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

.grid {
  display: inline-grid;
  gap: 0;
  border: 2px solid var(--grid-border);
  background: var(--grid-border);
  user-select: none;
}

.cell {
  width: clamp(28px, 8vw, 36px);
  height: clamp(28px, 8vw, 36px);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--cell-bg);
  border: none;
  outline: none;
  text-align: center;
  font-size: clamp(0.75rem, 3vw, 1rem);
  font-weight: 700;
  text-transform: uppercase;
  font-family: var(--font);
  color: var(--text);
  padding: 0;
  cursor: pointer;
}

.cell.block {
  background: var(--cell-block);
  cursor: default;
  pointer-events: none;
}

.cell.active {
  background: var(--cell-active);
}

.cell.highlight {
  background: var(--cell-highlight);
}

.cell.correct {
  background: var(--cell-correct);
}

.cell.wrong {
  background: var(--cell-wrong);
}

.cell.revealed {
  background: var(--cell-revealed);
  color: var(--muted);
}

.cell-number {
  position: absolute;
  top: 1px;
  left: 2px;
  font-size: 0.45rem;
  font-weight: 600;
  line-height: 1;
  pointer-events: none;
  color: var(--muted);
}

.completion {
  font-weight: 600;
  color: var(--accent);
  text-align: center;
  animation: fadeIn 0.4s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Clues */
.clues-section {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.clue-group h2 {
  margin: 0 0 0.75rem;
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.clue-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.clue-item {
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.9rem;
  line-height: 1.4;
  transition: background 0.15s;
}

.clue-item:hover {
  background: var(--cell-highlight);
}

.clue-item.active {
  background: var(--cell-active);
  font-weight: 500;
}

.clue-item.completed {
  color: var(--muted);
  text-decoration: line-through;
}

.clue-num {
  font-weight: 700;
  margin-right: 0.35rem;
}

.clue-source {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 0.15rem;
}

.clue-source a {
  color: var(--accent);
  text-decoration: none;
}

.clue-source a:hover {
  text-decoration: underline;
}

/* Footer */
.footer {
  text-align: center;
  padding: 1rem;
  font-size: 0.8rem;
  color: var(--muted);
  border-top: 1px solid var(--grid-border);
}

.footer a {
  color: var(--accent);
}
