/* ── Fonts ─────────────────────────────────────────────────────────────────── */
@font-face {
  font-family: 'IM Fell English';
  src: url('/fonts/im-fell-english-regular-latin.woff2') format('woff2');
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'IM Fell English';
  src: url('/fonts/im-fell-english-italic-latin.woff2') format('woff2');
  font-weight: 400; font-style: italic; font-display: swap;
}
@font-face {
  font-family: 'Caveat';
  src: url('/fonts/caveat-latin.woff2') format('woff2');
  font-weight: 400 700; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Special Elite';
  src: url('/fonts/special-elite-latin.woff2') format('woff2');
  font-weight: 400; font-style: normal; font-display: swap;
}

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

html {
  background: #f4ecd8;
  color: #1c1c1c;
  font-family: 'IM Fell English', Georgia, serif;
  font-size: 18px;
  line-height: 1.6;
}

body {
  background: #f4ecd8;
  padding: 0 0 3rem;          /* scrollable pages (about, leaderboard) */
}

/* ── Wizard body (index.html only) ─────────────────────────────────────────── */
/*
 * Every section fills exactly the viewport — no page scroll, ever.
 * Think of it as a multi-step onboarding wizard.
 */
body.wizard {
  padding: 0;
  overflow: hidden;
  height: 100vh;
  height: 100dvh;
}
body.wizard section:not([hidden]) {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
/* Defensive — guarantees the [hidden] attribute always wins, even if
 * another rule sets a stronger display value on the section. */
body.wizard section[hidden] { display: none; }

/* ── Site header ───────────────────────────────────────────────────────────── */
.site-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.4rem 1rem;
  padding: 0.55rem 1.5rem;
  border-bottom: 1px solid #1c1c1c;
  background: #f4ecd8;
}

.site-title {
  font-family: 'Caveat', cursive;
  font-size: 1.5rem;
  font-weight: 400;
  letter-spacing: 0.02em;
  line-height: 1.2;
  white-space: nowrap;
}
.site-title a { text-decoration: none; color: inherit; }

.site-nav {
  display: flex;
  gap: 1.25rem;
  font-size: 0.88rem;
  font-style: italic;
}
.site-nav a[aria-current="page"] { text-decoration: underline; }

/* ── Hamburger toggle ──────────────────────────────────────────────────────── */
/* Hidden on desktop; revealed at the mobile breakpoint below. */
.nav-toggle {
  display: none;
  width: 34px;
  height: 28px;
  padding: 0;
  background: transparent;
  border: 1px solid #1c1c1c;
  cursor: pointer;
  position: relative;
}
.nav-toggle::before,
.nav-toggle::after,
.nav-toggle .bar {
  content: '';
  position: absolute;
  left: 5px;
  right: 5px;
  height: 2px;
  background: #1c1c1c;
}
.nav-toggle::before { top: 6px; }
.nav-toggle::after  { bottom: 6px; }
.nav-toggle .bar    { top: 50%; transform: translateY(-50%); }

/* ── Page body (content area for non-playing wizard steps) ─────────────────── */
.page-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 1.25rem 1.5rem;
  max-width: 820px;
  width: 100%;
  margin: 0 auto;
}

.page-body--center {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* ── Start page ────────────────────────────────────────────────────────────── */
.start-content {
  max-width: 640px;
  width: 100%;
}

.intro {
  font-size: 1rem;
  line-height: 1.7;
  margin-bottom: 1rem;
}

.curve-figure {
  margin: 0.75rem 0;
  text-align: center;
}
.curve-figure img {
  max-width: 100%;
  max-height: 38vh;
  max-height: 38dvh;
  width: auto;
  height: auto;
  border: 1px solid #c9b99a;
  display: block;
  margin: 0 auto;
  object-fit: contain;
}
.curve-figure figcaption {
  font-family: 'Special Elite', monospace;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  margin-top: 0.3rem;
  opacity: 0.6;
}

/* ── Buttons ───────────────────────────────────────────────────────────────── */
.btn-primary,
.btn-secondary,
.btn-share {
  display: inline-block;
  border: 2px solid #1c1c1c;
  background: transparent;
  color: #1c1c1c;
  padding: 0.45em 1.25em;
  font-family: 'IM Fell English', serif;
  font-size: 1rem;
  cursor: pointer;
  text-decoration: none;
  line-height: 1.4;
  transition: background 0.12s, color 0.12s;
}
.btn-primary:hover,
.btn-secondary:hover,
.btn-share:hover {
  background: #1c1c1c;
  color: #f4ecd8;
}
.btn-primary:disabled,
.btn-secondary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.btn-primary { margin-top: 1.25rem; }

/* ── Playing layout ────────────────────────────────────────────────────────── */
/* Game bar sits below the shared site-header during play. */
.game-bar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0.35rem 1.5rem;
  border-bottom: 1px solid #c9b99a;
  background: #f8f3e8;
}

.timer {
  font-family: 'Special Elite', monospace;
  font-size: 1.5rem;
  min-width: 3.8rem;
  letter-spacing: 0.05em;
}
.timer-red { color: #c0392b; }

.word-label { font-size: 0.9rem; }

.playing-main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: 820px;
  width: 100%;
  margin: 0 auto;
  padding: 0.6rem 1.5rem;
  overflow: hidden;
}

.passage-faded {
  flex: 2;
  min-height: 0;
  overflow-y: auto;
  font-size: 1rem;
  line-height: 1.75;
  padding: 0.75rem 1.25rem;
  border: 1px solid #c9b99a;
  background: #f8f3e8;
  user-select: none;
  scroll-behavior: smooth;
}
.passage-faded span { transition: opacity 0.15s; }
.passage-faded span.word-done { opacity: 0.3; }

.typing-area {
  flex: 3;
  min-height: 0;
  resize: none;
  font-family: 'Special Elite', monospace;
  font-size: 1rem;
  line-height: 1.65;
  padding: 0.75rem 1rem;
  border: 2px solid #1c1c1c;
  background: #fffdf7;
  width: 100%;
  outline: none;
  color: #1c1c1c;
}
.typing-area:focus { background: #fffef9; }

/* ── Time's Up ─────────────────────────────────────────────────────────────── */
.timesup-content {
  max-width: 520px;
  width: 100%;
  text-align: center;
}
.timesup-heading {
  font-family: 'Caveat', cursive;
  font-size: 3rem;
  font-weight: 400;
  line-height: 1.1;
  margin-bottom: 1.25rem;
  letter-spacing: 0.02em;
}
.timesup-stat {
  font-size: 1.05rem;
  line-height: 1.65;
  margin-bottom: 0.5rem;
}
.timesup-equiv {
  font-size: 1rem;
  font-style: italic;
  opacity: 0.85;
  margin-bottom: 0.25rem;
}
.timesup-note {
  font-size: 0.85rem;
  opacity: 0.6;
  margin-bottom: 0;
}

/* ── Sign form ─────────────────────────────────────────────────────────────── */
.sign-content {
  max-width: 420px;
  width: 100%;
}

.section-heading {
  font-family: 'Caveat', cursive;
  font-size: 1.4rem;
  font-weight: 400;
  margin-bottom: 0.6rem;
  padding-bottom: 0.25rem;
  border-bottom: 1px solid #c9b99a;
}

.instruction {
  font-size: 0.95rem;
  margin-bottom: 0.75rem;
  opacity: 0.85;
}

.sign-form {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}
.sign-form label {
  font-style: italic;
  font-size: 0.9rem;
  margin-top: 0.3rem;
}
.field-hint {
  font-size: 0.78rem;
  font-style: normal;
  opacity: 0.6;
}

.text-input,
.select-input {
  font-family: 'IM Fell English', serif;
  font-size: 1rem;
  padding: 0.4em 0.6em;
  border: 1px solid #1c1c1c;
  background: #fffdf7;
  color: #1c1c1c;
  width: 100%;
}

/* ── Country combobox ──────────────────────────────────────────────────────── */
.combo-wrap { position: relative; }
.combo-input { width: 100%; }
.combo-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #fffdf7;
  border: 1px solid #1c1c1c;
  border-top: none;
  list-style: none;
  max-height: 200px;
  overflow-y: auto;
  z-index: 100;
}
.combo-dropdown li {
  padding: 0.38em 0.7em;
  cursor: pointer;
  font-family: 'IM Fell English', serif;
  font-size: 0.92rem;
}
.combo-dropdown li:hover,
.combo-dropdown li.active { background: #f0e8d0; }

.error-text {
  color: #c0392b;
  font-size: 0.88rem;
  min-height: 1.3em;
}

/* ── Posted / results ──────────────────────────────────────────────────────── */
.result-summary {
  font-size: 1rem;
  line-height: 1.7;
  margin-bottom: 1rem;
  padding: 0.85rem 1.1rem;
  border: 1px solid #1c1c1c;
  background: #fffdf7;
}

.chart-container {
  position: relative;
  margin-bottom: 1rem;
}

@keyframes dot-pulse {
  0%   { r: 7; opacity: 1; }
  50%  { r: 11; opacity: 0.5; }
  100% { r: 7; opacity: 1; }
}
.player-dot { animation: dot-pulse 0.6s ease-in-out 2; }

.share-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-bottom: 0.75rem;
}
.play-again-row { margin-top: 0.25rem; }

/* ── Scrollable pages (about, leaderboard) ─────────────────────────────────── */
.card {
  max-width: 820px;
  margin: 1.5rem auto;
  padding: 1.5rem 2rem;
  border: 1px solid #1c1c1c;
  background: #fffdf7;
}

.leaderboard-card { max-width: 820px; }

.filter-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
  font-size: 0.95rem;
  font-style: italic;
}
.select-inline { font-size: 0.9rem; }

.lb-status {
  font-size: 0.9rem;
  opacity: 0.7;
  margin-bottom: 0.5rem;
}

.table-wrapper { overflow-x: auto; }

.lb-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}
.lb-table th, .lb-table td {
  padding: 0.4em 0.75em;
  text-align: left;
  border-bottom: 1px solid #c9b99a;
}
.lb-table th {
  font-style: italic;
  font-weight: 400;
  border-bottom: 2px solid #1c1c1c;
}
.lb-table tr:hover td { background: #f8f3e8; }

.pagination-row { display: flex; gap: 1rem; margin-top: 1rem; }

.about-card p { margin-bottom: 1rem; }
.about-card h2 {
  font-family: 'Caveat', cursive;
  font-size: 1.35rem;
  font-weight: 400;
  margin-top: 1.5rem;
  margin-bottom: 0.5rem;
  border-bottom: 1px solid #c9b99a;
  padding-bottom: 0.2rem;
}
.equation {
  font-family: 'Caveat', cursive;
  font-size: 1.3rem;
  text-align: center;
  padding: 0.5rem 0;
  letter-spacing: 0.05em;
}
.back-link { margin-top: 2rem; font-style: italic; }

/* ── Mobile ────────────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  html { font-size: 16px; }

  /* Header collapses to one row: title + hamburger.
   * Nav drops down from the bottom edge of the header when opened. */
  .site-header {
    padding: 0.45rem 1rem;
    flex-wrap: nowrap;             /* keep title and toggle on one row */
    position: relative;            /* anchor for the dropdown nav */
  }
  .site-title {
    font-size: 1.15rem;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .nav-toggle { display: block; flex-shrink: 0; }

  .site-nav {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    flex-direction: column;
    gap: 0.5rem;
    min-width: 160px;
    padding: 0.6rem 1rem;
    background: #f4ecd8;
    border: 1px solid #1c1c1c;
    border-top: none;
    font-size: 0.95rem;
    z-index: 50;
  }
  .site-header.nav-open .site-nav { display: flex; }

  .page-body { padding: 1rem; }

  /* Playing screen on mobile: passage shrinks to a peek-strip so the
   * textarea keeps usable height even when the keyboard pops up.
   * Auto-scroll (game.js) keeps the current word centered in the strip. */
  .game-bar { gap: 1rem; padding: 0.3rem 1rem; }
  .timer { font-size: 1.25rem; }
  .playing-main { padding: 0.4rem 0.75rem; gap: 0.35rem; }
  .passage-faded {
    flex: 1;
    min-height: 60px;
    padding: 0.45rem 0.75rem;
    font-size: 14px;
    line-height: 1.5;
  }
  .typing-area {
    flex: 4;
    font-size: 16px;               /* suppress iOS auto-zoom */
    padding: 0.6rem 0.85rem;
  }

  .timesup-heading { font-size: 2.2rem; }

  .text-input, .select-input, .combo-input { font-size: 16px; } /* suppress iOS auto-zoom */

  .card { padding: 1rem; margin: 1rem 0.5rem; }
}
