/* ── Reset & base ───────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* Dark mode (default) — navy-first palette */
:root {
  --bg:        #0b0e1a;
  --bg-card:   #111827;
  --bg-mid:    #1a2235;
  --border:    #1e2d4a;
  --border-hi: #2a3f68;
  --text:      #f0f4ff;
  --muted:     #8ba3cc;
  --subtle:    #4a6490;
  --red:       #e8334a;
  --red-soft:  rgba(232,51,74,0.15);
  --blue:      #3b82f6;
  --blue-soft: rgba(59,130,246,0.15);
  --gold:      #60a5fa;
  --emerald:   #34d399;
  --radius:    16px;
  --radius-sm: 10px;
  --header-bg: rgba(11, 14, 26, 0.88);
  --shadow-img: 0 24px 48px rgba(0,0,0,0.55);
}

/* Light mode — crisp white with patriotic accents */
@media (prefers-color-scheme: light) {
  :root {
    --bg:        #f5f7ff;
    --bg-card:   #ffffff;
    --bg-mid:    #e8edf8;
    --border:    #c8d3ec;
    --border-hi: #a0b0d8;
    --text:      #0d1b3e;
    --muted:     #2d4a8a;
    --subtle:    #6b85b8;
    --red:       #b91c1c;
    --red-soft:  rgba(185,28,28,0.08);
    --blue:      #1d4ed8;
    --blue-soft: rgba(29,78,216,0.08);
    --gold:      #1d4ed8;
    --emerald:   #047857;
    --header-bg: rgba(245, 247, 255, 0.92);
    --shadow-img: 0 8px 32px rgba(13,27,62,0.12);
  }
}

html { font-size: 16px; }
body {
  font-family: "Inter", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Header ─────────────────────────────────────────────── */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--header-bg);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.header-inner {
  max-width: 1600px;
  width: 100%;
  margin: 0 auto;
  padding: 0.9rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.header-left { display: flex; align-items: center; gap: 0.75rem; }
.flag-icon { font-size: 1.8rem; }
.site-header h1 {
  font-family: "Playfair Display", serif;
  font-size: 1.35rem;
  font-weight: 900;
  letter-spacing: 0.01em;
  color: var(--text);
}

.title-250 {
  color: var(--red);
  -webkit-text-fill-color: var(--red);
  font-style: italic;
}

.subtitle {
  font-size: 0.7rem;
  color: var(--muted);
  font-weight: 400;
}

.header-stats {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.72rem;
  color: var(--muted);
}
.stats-item { display: flex; align-items: center; gap: 0.3rem; }
.stats-item i { font-size: 0.65rem; }
.streak-fire { color: var(--muted); transition: color 0.2s; }
.streak-fire.active { color: var(--gold); }
.stats-divider { color: var(--border-hi); }

.date-chip {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.75rem;
  color: var(--muted);
  background: var(--bg-mid);
  padding: 0.3rem 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--border-hi);
}

/* ── Main layout ─────────────────────────────────────────── */
.main-content {
  flex: 1;
  width: 100%;
  max-width: 1600px;
  margin: 0 auto;
  padding: 1.5rem 2rem;
  display: grid;
  grid-template-columns: 240px 1fr 300px;
  grid-template-areas: "archive image quiz"
                       "archive context quiz";
  gap: 1.75rem;
  align-items: start;
}

.main-content.no-image {
  grid-template-columns: 240px 1fr;
  grid-template-areas: "archive quiz";
}

@media (max-width: 1100px) {
  .main-content {
    grid-template-columns: 200px 1fr;
    grid-template-areas: "archive image" "archive quiz" "archive context";
  }
  .main-content.no-image {
    grid-template-areas: "archive quiz";
  }
}

@media (max-width: 700px) {
  .main-content {
    grid-template-columns: 1fr;
    grid-template-areas: "image" "quiz" "context" "archive";
  }
  .main-content.no-image {
    grid-template-columns: 1fr;
    grid-template-areas: "quiz" "context" "archive";
  }
  .zoom-controls { display: none; }
}

/* ── Image panel ─────────────────────────────────────────── */
.image-section {
  grid-area: image;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.quiz-section { grid-area: quiz; }
.context-section { grid-area: context; }

.image-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-img);
}

.image-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem 0.9rem;
  background: var(--bg-mid);
  border-bottom: 1px solid var(--border);
  font-size: 0.72rem;
  font-family: "SF Mono", monospace;
}
.year-label { color: var(--gold); font-weight: 700; letter-spacing: 0.08em; }
.zoom-hint  { color: var(--muted); }

.image-frame {
  background: transparent;
  overflow: hidden;
  position: relative;
  cursor: grab;
  user-select: none;
}

.image-shimmer {
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, var(--bg-mid) 25%, var(--bg-card) 50%, var(--bg-mid) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  z-index: 1;
}

@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
.image-frame:active { cursor: grabbing; }

#puzzle-img {
  width: 100%;
  height: auto;
  display: block;
  transform-origin: 0 0;
  pointer-events: none;
}

.zoom-controls {
  position: absolute;
  bottom: 0.6rem;
  right: 0.6rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  z-index: 10;
}
.zoom-controls button {
  width: 2.1rem;
  height: 2.1rem;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 8px;
  color: rgba(255,255,255,0.9);
  font-size: 1.1rem;
  cursor: pointer;
  line-height: 1;
  transition: background 0.15s, color 0.15s;
}
.zoom-controls button:hover {
  background: rgba(0,0,0,0.8);
  color: #fff;
}


/* ── Image footer ────────────────────────────────────────── */
.ai-badge {
  position: absolute;
  top: 1rem;
  left: 1rem;
  z-index: 2;
  font-size: 0.6rem;
  font-family: "JetBrains Mono", monospace;
  color: rgba(255,255,255,0.85);
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  letter-spacing: 0.05em;
  pointer-events: none;
}

/* ── Quiz panel ──────────────────────────────────────────── */
.quiz-section { display: flex; flex-direction: column; gap: 1.25rem; }

.quiz-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow-img);
  position: relative;
}

.week-date {
  display: block;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.62rem;
  color: var(--muted);
  letter-spacing: 0.06em;
  margin-bottom: 0.25rem;
}

.challenge-label {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--blue);
  font-family: monospace;
  margin-bottom: 0.5rem;
  display: block;
}

.riddle {
  font-family: "Inter", sans-serif;
  font-size: 1rem;
  font-weight: 400;
  line-height: 1.8;
  color: var(--text);
  margin-bottom: 1.25rem;
}

.options-form {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.option-btn {
  width: 100%;
  background: var(--bg-mid);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  font-family: "Inter", sans-serif;
  font-size: 0.9rem;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
.option-btn:hover {
  background: var(--bg-card);
  border-color: var(--gold);
  transform: translateX(3px);
  color: var(--text);
}
.option-btn:hover .opt-letter {
  background: var(--gold);
  color: #fff;
  border-color: var(--gold);
}

.opt-letter {
  width: 1.6rem;
  height: 1.6rem;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  border: 1.5px solid var(--border-hi);
  font-family: "JetBrains Mono", monospace;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--muted);
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

/* ── Spinner ─────────────────────────────────────────────── */
.spinner { display: none; color: var(--muted); font-size: 0.85rem; padding: 0.5rem 0; }
.htmx-request .spinner { display: block; }
.htmx-request .options-form { opacity: 0.35; pointer-events: none; }

/* ── Result state ────────────────────────────────────────── */
.result-area {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  box-shadow: var(--shadow-img);
}

.result-banner {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.95rem;
  font-weight: 600;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}
.result-icon { font-size: 1.3rem; }
.result-correct .result-icon { color: var(--emerald); }
.result-wrong   .result-icon { color: var(--red); }

/* highlight correct/wrong options after submission */
/* Frozen option state after answer */
.option-frozen {
  pointer-events: none;
  cursor: default;
  transform: none !important;
  box-shadow: none !important;
}

.opt-icon {
  font-size: 1rem;
  flex-shrink: 0;
}
.opt-correct .opt-icon { color: var(--emerald); }
.opt-wrong   .opt-icon { color: var(--red); }

.option-btn.opt-correct {
  border-color: rgba(52,211,153,0.5) !important;
  background: rgba(52,211,153,0.08) !important;
  color: var(--emerald) !important;
  opacity: 1 !important;
}
.option-btn.opt-correct .opt-letter {
  background: var(--emerald);
  border-color: var(--emerald);
  color: #000;
}
.option-btn.opt-wrong {
  border-color: rgba(232,51,74,0.5) !important;
  background: rgba(232,51,74,0.08) !important;
  color: var(--red) !important;
}
.option-btn.opt-wrong .opt-letter {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
}
.option-btn.opt-dim { opacity: 0.4; cursor: not-allowed; }
.option-btn.option-focused { outline: 2px solid var(--gold); outline-offset: 2px; }

.context-card {
  background: var(--bg-card);
  border: 1px solid rgba(96,165,250,0.25);
  border-radius: var(--radius);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  box-shadow: var(--shadow-img);
}

.context-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--gold);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-family: monospace;
}

.year-reveal {
  margin-left: auto;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.75rem;
  color: var(--bg);
  background: var(--gold);
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  letter-spacing: 0.05em;
}

.context-text {
  font-family: "Inter", sans-serif;
  font-size: 0.9rem;
  line-height: 1.8;
  color: var(--text);
}

.context-divider { border: none; border-top: 1px solid var(--border); }

.context-books-header {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.65rem;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 0.25rem 0;
}

.prompt-label {
  font-size: 0.65rem;
  font-family: monospace;
  color: var(--subtle);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.4rem;
  display: block;
}
.prompt-debug {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.75rem;
  font-size: 0.72rem;
  font-family: "JetBrains Mono", monospace;
  color: var(--muted);
  overflow-x: auto;
  max-height: 7rem;
  white-space: pre-wrap;
  word-break: break-word;
  cursor: text;
  user-select: all;
}

.come-back {
  font-size: 0.8rem;
  color: var(--muted);
}

.quiz-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.how-to-play {
  position: relative;
}
.how-btn {
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 50%;
  border: 1.5px solid var(--border-hi);
  background: transparent;
  color: var(--muted);
  font-family: "JetBrains Mono", monospace;
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s, color 0.15s;
}
.how-btn:hover { border-color: var(--gold); color: var(--gold); }
.how-btn.active { border-color: var(--gold); color: var(--gold); }

.how-tooltip {
  display: none;
  position: fixed;
  width: 300px;
  background: var(--bg-card);
  border: 1px solid var(--gold);
  border-radius: var(--radius-sm);
  padding: 0.75rem 0.9rem;
  z-index: 100;
  box-shadow: 0 12px 40px rgba(0,0,0,0.55), 0 2px 8px rgba(0,0,0,0.3);
  font-size: 0.78rem;
  color: var(--text);
}
.how-tooltip.open { display: block; }
.how-tooltip strong {
  display: block;
  margin-bottom: 0.5rem;
  font-size: 0.8rem;
  color: var(--gold);
  letter-spacing: 0.04em;
}
.how-tooltip ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.how-tooltip li { color: var(--muted); line-height: 1.4; }
.how-tooltip li::before { content: "→ "; color: var(--gold); }
.how-tooltip kbd {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.68rem;
  background: var(--bg-mid);
  border: 1px solid var(--border-hi);
  border-radius: 3px;
  padding: 0.05rem 0.3rem;
}
.how-close {
  position: absolute;
  top: 0.35rem;
  right: 0.4rem;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
}
.how-close:hover { color: var(--text); }

.share-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--gold);
  background: transparent;
  border: 1px solid var(--gold);
  border-radius: 999px;
  padding: 0.35rem 0.9rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.share-btn:hover {
  background: var(--gold);
  color: #fff;
}

/* ── Sidebar ─────────────────────────────────────────────── */
.sidebar-left {
  grid-area: archive;
  position: sticky;
  top: 5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.sidebar-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.sidebar-card-header {
  padding: 0.75rem 1rem;
  background: var(--bg-mid);
  border-bottom: 1px solid var(--border);
  font-family: "JetBrains Mono", monospace;
  font-size: 0.65rem;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

/* Archive tree */
.archive-tree {
  padding: 0.75rem 0;
  list-style: none;
}

.archive-year {
  padding: 0;
}

.archive-year-toggle {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  width: 100%;
  background: none;
  border: none;
  color: var(--text);
  font-family: "Inter", sans-serif;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.4rem 1rem;
  cursor: pointer;
  text-align: left;
  transition: background 0.12s;
}
.archive-year-toggle:hover { background: var(--bg-mid); }
.archive-year-toggle .caret { font-size: 0.6rem; color: var(--subtle); transition: transform 0.2s; display: inline-block; }
.archive-year-toggle.open .caret { transform: rotate(90deg); }

.archive-months {
  list-style: none;
  display: none;
  padding-left: 0;
}
.archive-months.open { display: block; }

.archive-month-toggle {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  width: 100%;
  background: none;
  border: none;
  color: var(--muted);
  font-family: "Inter", sans-serif;
  font-size: 0.8rem;
  font-weight: 500;
  padding: 0.35rem 1rem 0.35rem 1.75rem;
  cursor: pointer;
  text-align: left;
  transition: background 0.12s;
}
.archive-month-toggle:hover { background: var(--bg-mid); color: var(--text); }
.archive-month-toggle .caret { font-size: 0.6rem; color: var(--subtle); transition: transform 0.2s; }
.archive-month-toggle.open .caret { transform: rotate(90deg); }

.archive-days {
  list-style: none;
  display: none;
  padding-left: 0;
}
.archive-days.open { display: block; }

.archive-day-link {
  display: block;
  padding: 0.3rem 1rem 0.3rem 2.75rem;
  font-size: 0.75rem;
  color: var(--subtle);
  text-decoration: none;
  font-family: "Inter", sans-serif;
  transition: color 0.12s, background 0.12s;
  line-height: 1.5;
}
.archive-day-link:hover { color: var(--text); background: var(--bg-mid); }
.archive-day-link.active { color: var(--gold); font-weight: 600; }
.archive-day-link .day-title {
  display: block;
  font-size: 0.7rem;
  color: var(--subtle);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.archive-played {
  margin-left: auto;
  font-size: 0.65rem;
  font-weight: 700;
  flex-shrink: 0;
}
.archive-played-correct { color: var(--emerald); }
.archive-played-wrong   { color: var(--red); }

.archive-empty {
  padding: 1rem;
  font-size: 0.75rem;
  color: var(--muted);
  line-height: 1.5;
}

/* Books section */
.books-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.book-item {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.875rem;
  padding: 0.75rem 0.875rem;
  background: var(--bg-mid);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--text);
  transition: border-color 0.15s, background 0.15s;
}
.book-item:hover {
  border-color: var(--gold);
  background: var(--bg-card);
}

.book-info { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.book-title {
  font-size: 0.85rem;
  font-weight: 600;
  font-family: "Inter", sans-serif;
  color: var(--text);
  line-height: 1.4;
}
.book-author {
  font-size: 0.75rem;
  color: var(--muted);
  font-family: "Inter", sans-serif;
}
.book-cta {
  font-size: 0.7rem;
  color: var(--gold);
  font-family: "Inter", sans-serif;
  margin-top: 4px;
}

.book-cover {
  width: 48px;
  height: auto;
  border-radius: 3px;
  flex-shrink: 0;
  object-fit: cover;
  box-shadow: 0 2px 6px rgba(0,0,0,0.25);
  margin-left: auto;
}

/* ── No puzzle ───────────────────────────────────────────── */
.no-puzzle {
  text-align: center;
  padding: 5rem 1rem;
  color: var(--muted);
}
.no-puzzle h2 { font-size: 1.4rem; margin-bottom: 0.5rem; }

/* ── Footer ──────────────────────────────────────────────── */
.site-footer {
  text-align: center;
  padding: 1.25rem;
  font-size: 0.72rem;
  font-family: monospace;
  color: var(--muted);
  border-top: 1px solid var(--border);
  margin-top: 2rem;
  background: var(--bg-mid);
}
