/* Public pages rendered by the worker: /puzzles, /puzzles/<slug>, /teachers,
   and the 404 page. Tokens match src/index.css. */

:root {
  --paper: #F6F4EF;
  --paper-alt: #ECE9E1;
  --card: #FFFFFF;
  --ink: #1A1612;
  --ink-soft: #4A4036;
  --muted: #8C8170;
  --rule: #E4E0D6;
  --accent: #FF6B47;
  --accent-soft: #FFE2D7;
  --butter: #FFD66B;
  --font-display: 'Bricolage Grotesque', 'Geist', system-ui, sans-serif;
  --font-ui: 'Geist', system-ui, sans-serif;
  --font-mono: 'Geist Mono', ui-monospace, monospace;
}

* { box-sizing: border-box; }

body.site {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--ink); text-decoration-color: var(--accent); text-underline-offset: 3px; }
a:hover { color: var(--accent); }

h1, h2 { font-family: var(--font-display); letter-spacing: -0.03em; line-height: 1.1; }
h1 { font-size: clamp(32px, 6vw, 48px); margin: 0 0 12px; }
h2 { font-size: 22px; margin: 36px 0 12px; }

/* ── Header and footer ── */

/* The app's header (src/components/AppNav.jsx, .desktop-nav and
   .mobile-topbar in src/index.css): full width with a rule under it, the
   same sizes and the same links, so nothing moves going between these pages
   and the app. Change one, change the other. */
.site-header {
  display: flex;
  align-items: center;
  gap: 36px;
  padding: 20px 48px;
  background: var(--paper);
  border-bottom: 1px solid var(--rule);
}
@media (max-width: 1099px) { .site-header { padding: 18px 28px; } }
@media (max-width: 767px) { .site-header { justify-content: space-between; padding: 12px 18px 10px; border-bottom: 0; } }

.brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; }
.brand img { display: block; }
.brand-word {
  font-family: var(--font-display);
  font-size: 26px;
  line-height: 1;
  font-weight: 700;
  letter-spacing: -0.035em;
  color: var(--ink);
}
/* On phones, and in the menu, the app's smaller logo */
@media (max-width: 767px) {
  .brand { gap: 8px; }
  .brand img { width: 30px; height: 30px; }
  .brand-word { font-size: 21px; }
}
.brand-md { gap: 8px; }
.brand-md img { width: 30px; height: 30px; }
.brand-md .brand-word { font-size: 21px; }
.brand-ai { color: var(--accent); }
.brand-i { position: relative; }
.brand-i::after {
  content: '';
  position: absolute;
  top: -0.02em;
  left: 50%;
  width: 0.2em;
  height: 0.2em;
  border-radius: 50%;
  background: var(--butter);
  transform: translateX(-50%);
}

/* Where to go, beside the brand */
.site-nav { display: flex; align-items: center; gap: 22px; flex: 1; }
.site-nav a { font-family: var(--font-display); font-size: 14px; font-weight: 600; letter-spacing: -0.005em; text-decoration: none; color: var(--ink-soft); white-space: nowrap; }
.site-nav a:hover { color: var(--ink); }

/* Yours, on the right: links into the app's panels, then Play today */
.site-actions { display: flex; align-items: center; gap: 16px; }
.site-more { display: flex; align-items: center; gap: 18px; }
.site-more a, .site-more button {
  font: 600 13px/1.2 var(--font-display);
  color: var(--ink-soft);
  text-decoration: none;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  white-space: nowrap;
}
.site-more a:hover, .site-more button:hover { color: var(--ink); }
.site-more [hidden] { display: none; }
/* The app's small button (cit-btn-sm); scoped to win over .btn and .btn-small below */
.site-actions .site-play { padding: 11px 16px; border: 0; font-size: 13px; line-height: 1.2; white-space: nowrap; }

.menu-btn {
  display: none;
  width: 42px;
  height: 42px;
  border-radius: 999px;
  cursor: pointer;
  background: var(--card);
  border: 1px solid var(--rule);
  flex-direction: column;
  gap: 5px;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.menu-btn span { width: 16px; height: 2px; border-radius: 2px; background: var(--ink); display: block; }
/* Under 1100px the right side's links move into the menu; on phones the
   rest go too, leaving the brand and the menu button */
@media (max-width: 1099px) {
  .site-more { display: none; }
  .menu-btn { display: flex; }
}
@media (max-width: 767px) {
  .site-nav, .site-actions .site-play { display: none; }
}
.menu-btn[hidden] { display: none; }

/* The menu (NavDrawer in the app, .nav-drawer-* in src/index.css) */
.nav-drawer-overlay { position: fixed; inset: 0; z-index: 120; pointer-events: none; }
.nav-drawer-overlay.open { pointer-events: auto; }
.nav-drawer-backdrop { position: absolute; inset: 0; background: rgba(26,22,18,0.4); backdrop-filter: blur(2px); opacity: 0; transition: opacity 0.22s ease; }
.nav-drawer-overlay.open .nav-drawer-backdrop { opacity: 1; }
.nav-drawer-panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 76%;
  max-width: 380px;
  background: var(--paper);
  box-shadow: -12px 0 40px rgba(26,22,18,0.2);
  transform: translateX(100%);
  transition: transform 0.26s cubic-bezier(0.22,0.61,0.36,1);
  display: flex;
  flex-direction: column;
  padding: 20px 22px;
  overflow-y: auto;
}
.nav-drawer-overlay.open .nav-drawer-panel { transform: translateX(0); }
.nav-drawer-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 26px; }
.nav-drawer-close {
  width: 38px;
  height: 38px;
  border-radius: 999px;
  cursor: pointer;
  background: var(--card);
  border: 1px solid var(--rule);
  color: var(--ink);
  font: 700 18px/1 var(--font-display);
  display: flex;
  align-items: center;
  justify-content: center;
}
.nav-drawer-close:hover { background: var(--paper-alt); }
.nav-drawer-item {
  display: block;
  font: 700 24px/1.5 var(--font-display);
  letter-spacing: -0.03em;
  color: var(--ink);
  text-decoration: none;
  padding: 14px 0;
  border-bottom: 1px solid var(--rule);
  transition: color 0.12s;
}
.nav-drawer-item:hover { color: var(--accent); }
.nav-drawer-item:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.nav-drawer-item[hidden] { display: none; }
.nav-drawer-footer { margin-top: auto; padding-top: 20px; display: flex; flex-direction: column; gap: 10px; }
.nav-drawer-footer .nav-drawer-play { padding: 16px 26px; font-size: 16px; }
.nav-drawer-user-email { text-align: center; font: 500 13px var(--font-display); color: var(--ink-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-drawer-signin { display: block; text-align: center; font: 600 14px var(--font-display); color: var(--muted); background: none; border: 0; padding: 8px; cursor: pointer; text-decoration: none; }
.nav-drawer-signin:hover { color: var(--ink); }
.nav-drawer-footer [hidden] { display: none; }
@media (prefers-reduced-motion: reduce) {
  .nav-drawer-backdrop, .nav-drawer-panel { transition: none; }
}

.site-main { max-width: 1040px; margin: 0 auto; padding: 8px 20px 48px; }

.site-foot {
  border-top: 1px solid var(--rule);
  padding: 20px;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
}
.site-foot nav { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px 18px; margin-bottom: 8px; }
.site-foot a { color: var(--muted); text-decoration: none; }
.site-foot a:hover { color: var(--ink); }
.site-foot p { margin: 0; }

/* ── Buttons ── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 18px;
  border-radius: 999px;
  border: 1px solid var(--rule);
  background: var(--card);
  color: var(--ink);
  font: 600 15px/1 var(--font-display);
  letter-spacing: -0.01em;
  text-decoration: none;
  cursor: pointer;
}
.btn:hover { color: var(--ink); border-color: var(--muted); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { color: #fff; background: #f25a35; border-color: #f25a35; }
.btn-small { padding: 8px 14px; font-size: 14px; }
.btn[hidden] { display: none; }

/* ── Page heads, prose, lists ── */

.page-head { max-width: 680px; margin: 24px 0 28px; }
.lead { font-size: 19px; color: var(--ink-soft); margin: 0 0 16px; }
.updated { font-size: 14px; color: var(--muted); margin: 0; }
.prose ul { padding-left: 22px; }

.prose { max-width: 680px; }
.prose ol { padding-left: 22px; }
.prose li { margin-bottom: 6px; }
.levels { display: grid; grid-template-columns: max-content 1fr; gap: 8px 18px; margin: 0; }
.levels dt { font-family: var(--font-display); font-weight: 700; }
.levels dd { margin: 0; }

.card-list {
  list-style: none;
  padding: 0;
  margin: 16px 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
}
.card {
  display: flex;
  align-items: center;
  gap: 14px;
  height: 100%;
  padding: 16px 18px;
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 16px;
  text-decoration: none;
}
.card:hover { border-color: var(--accent); color: var(--ink); }
.card-text { display: flex; flex-direction: column; gap: 4px; min-width: 0; overflow-wrap: anywhere; }
.card-title { font-family: var(--font-display); font-weight: 700; font-size: 18px; letter-spacing: -0.02em; }
.card-meta { font-size: 13px; color: var(--muted); }

.link-list { font-size: 18px; line-height: 2; }

.cta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 40px;
  padding: 22px 24px;
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 22px;
}
.cta p { margin: 0 auto 0 0; font-family: var(--font-display); font-weight: 700; font-size: 20px; letter-spacing: -0.02em; }

/* ── Puzzle page ── */

.crumbs { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0 8px; font-size: 14px; color: var(--muted); }
.crumbs a { color: var(--muted); }

.puzzle-head { margin-bottom: 24px; }
.kicker {
  margin: 0 0 8px;
  font: 700 12px/1.2 var(--font-display);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
}
.puzzle-meta { margin: 0; font-weight: 600; color: var(--ink-soft); }
.byline { margin: 6px 0 0; color: var(--ink-soft); font-style: italic; }

/* Curator avatars (avatarHtml in backend/pages.js): a photo or initials */
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border-radius: 50%;
  object-fit: cover;
  vertical-align: middle;
  background: var(--paper-alt);
  color: #fff;
  font: 700 10px/1 var(--font-display);
  letter-spacing: 0.02em;
}
.avatar-sm { width: 24px; height: 24px; margin: -3px 8px 0 0; }
.avatar-md { width: 36px; height: 36px; font-size: 13px; }
.avatar-lg { width: 96px; height: 96px; font-size: 32px; }
@media print { .puzzle-meta .avatar { display: none; } }

/* Curators on /about */
.curator-list {
  list-style: none;
  padding: 0;
  margin: 8px 0 12px;
  max-width: 680px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}
.curator {
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 16px;
  padding: 16px;
}
.curator-name { margin: 0; font-family: var(--font-display); font-weight: 700; font-size: 18px; letter-spacing: -0.02em; }
.curator-bio { margin: 4px 0 0; color: var(--ink-soft); }
.howto { margin: 12px 0 0; color: var(--ink-soft); }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }
.online-note { margin: 10px 0 0; font-size: 14px; color: var(--muted); }

.ws-grid {
  display: grid;
  /* minmax(0, 1fr): square cells must not take a minimum width from their
     line height, or wide grids overflow narrow screens */
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  width: min(100%, 600px);
  line-height: 1;
  background: var(--card);
  border: 2px solid var(--ink);
  border-radius: 8px;
  padding: 6px;
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: clamp(10px, calc(min(560px, 100vw - 56px) / var(--cols) * 0.52), 22px);
}
.ws-grid span { aspect-ratio: 1; display: flex; align-items: center; justify-content: center; }

.words-head {
  margin: 28px 0 12px;
  font: 700 13px/1.2 var(--font-display);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.words {
  list-style: none;
  padding: 0;
  margin: 0;
  columns: 4 140px;
  column-gap: 24px;
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: 0.01em;
}
.words li { break-inside: avoid; margin-bottom: 8px; }

.answer-key { margin-top: 28px; }
.answer-key summary { cursor: pointer; font-weight: 600; color: var(--ink-soft); }
.answer-key .ws-key { margin-top: 12px; }

.ws-key { display: block; width: min(100%, 600px); height: auto; background: var(--card); border: 2px solid var(--ink); border-radius: 8px; }
.ws-key text { font-family: var(--font-mono); font-size: 5.2px; font-weight: 500; text-anchor: middle; dominant-baseline: central; fill: var(--ink); }

.related { margin-top: 48px; }

.print-only { display: none; }

/* Too narrow for the brand, links and button in one row: the links take
   their own row under the brand */
@media (max-width: 560px) {
  .cta p { flex-basis: 100%; }
}

/* ── Print: one letter page, plus an answer key page on request ── */

@page { size: letter portrait; margin: 0.5in; }

@media print {
  body.site { background: #fff; font-size: 11pt; line-height: 1.4; }
  .site-header, .site-foot, .nav-drawer-overlay, .no-print { display: none !important; }
  .print-only { display: block; }
  .site-main { padding: 0; max-width: none; }
  h1 { font-size: 22pt; margin-bottom: 4pt; }
  .kicker { margin-bottom: 4pt; }
  .byline { margin-top: 2pt; }
  .puzzle-head { margin-bottom: 12pt; }
  .howto { margin-top: 4pt; }
  /* --pw: the grid's width budget; a grid taller than it is wide shrinks
     so its height stays within the same budget */
  .ws-grid { --pw: 6in; }
  .ws-grid.ws-m { --pw: 5.5in; }
  .ws-grid.ws-l { --pw: 4.9in; }
  .ws-grid {
    width: min(var(--pw), calc(var(--pw) * var(--cols) / var(--rows)));
    margin: 0 auto;
    font-size: calc(min(var(--pw) / var(--cols), var(--pw) / var(--rows)) * 0.46);
  }
  .words-head { margin: 12pt 0 6pt; }
  .words { columns: 4; }
  .words.words-many { columns: 5; }
  .words li { margin-bottom: 3pt; }
  .print-key { display: none; }
  body.with-answer-key .print-key { display: block; break-before: page; }
  .print-key h2 { margin-top: 0; }
  .print-key .ws-key { width: min(6.2in, calc(8.6in * var(--cols) / var(--rows))); margin: 0 auto; }
  .print-brand { margin: 0 0 8pt; font: 700 11pt/1 var(--font-display); letter-spacing: -0.02em; color: var(--accent); }
}
