/* Literally: one stylesheet, no build step. Mobile first. */

:root {
  --bg: #f6f1e9;
  --surface: #fffdf9;
  --surface-2: #efe8dc;
  --text: #221e19;
  --muted: #6b6358;
  --faint: #9b9183;
  --line: #e2d9ca;
  --accent: #b0412a;
  --accent-strong: #8c301c;
  --accent-soft: #f5e1d8;
  --on-accent: #ffffff;
  --good: #2c7546;
  --good-soft: #ddefe3;
  --bad: #ad3628;
  --bad-soft: #f7e0dc;
  --focus: #1f5fd6;
  --shadow: 0 1px 2px rgb(60 40 20 / 6%), 0 6px 20px rgb(60 40 20 / 6%);
  --radius: 16px;
  --radius-sm: 10px;
  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji";
  --font-display: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, "Times New Roman", serif;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #15130f;
  --surface: #1f1c17;
  --surface-2: #2a261f;
  --text: #f2ece2;
  --muted: #b5ac9e;
  --faint: #81796c;
  --line: #3a352c;
  --accent: #ee8d6f;
  --accent-strong: #f6a78d;
  --accent-soft: #3b241c;
  --on-accent: #1a0e09;
  --good: #82d39f;
  --good-soft: #1d3325;
  --bad: #ff9283;
  --bad-soft: #3c201b;
  --focus: #8fb5ff;
  --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 8px 24px rgb(0 0 0 / 25%);
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15130f;
    --surface: #1f1c17;
    --surface-2: #2a261f;
    --text: #f2ece2;
    --muted: #b5ac9e;
    --faint: #81796c;
    --line: #3a352c;
    --accent: #ee8d6f;
    --accent-strong: #f6a78d;
    --accent-soft: #3b241c;
    --on-accent: #1a0e09;
    --good: #82d39f;
    --good-soft: #1d3325;
    --bad: #ff9283;
    --bad-soft: #3c201b;
    --focus: #8fb5ff;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 8px 24px rgb(0 0 0 / 25%);
    color-scheme: dark;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 17px;
  line-height: 1.5;
}

a {
  color: var(--accent-strong);
  text-underline-offset: 0.15em;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 6px;
}

.sr-only {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: 12px;
  top: -60px;
  z-index: 50;
  padding: 8px 14px;
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
}

.skip-link:focus {
  top: 10px;
}

/* ---------- Header ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(8px);
  -webkit-backdrop-filter: saturate(1.4) blur(8px);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}

.topbar-inner {
  max-width: 600px;
  margin: 0 auto;
  padding: 6px 10px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
}

.topbar-side {
  display: flex;
  gap: 2px;
}

.topbar-side--end {
  justify-content: flex-end;
}

.wordmark {
  margin: 0;
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 600;
  font-size: 1.7rem;
  letter-spacing: 0.01em;
  line-height: 1;
}

.wordmark a {
  color: var(--text);
  text-decoration: none;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}

.icon-btn:hover {
  background: var(--surface-2);
}

.icon-btn svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-btn svg .dot {
  fill: currentColor;
  stroke: none;
}

#btn-theme .icon-sun {
  display: none;
}

.is-dark #btn-theme .icon-sun {
  display: block;
}

.is-dark #btn-theme .icon-moon {
  display: none;
}

/* ---------- Page ---------- */

.page {
  flex: 1;
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
  padding: 14px 16px 28px;
}

.tagline {
  margin: 4px 0 14px;
  color: var(--muted);
  font-size: 0.95rem;
  text-align: center;
}

.tagline em {
  font-family: var(--font-display);
  font-size: 1.08em;
}

.meta {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 10px;
  margin: 0 2px 12px;
  font-size: 0.9rem;
  color: var(--muted);
}

.meta-number {
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.meta-progress {
  margin-left: auto;
  display: inline-flex;
  gap: 5px;
  align-items: center;
}

.pip {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  border: 1.5px solid var(--faint);
}

.pip.is-on {
  background: var(--accent);
  border-color: var(--accent);
}

.pip.is-right {
  background: var(--good);
  border-color: var(--good);
}

.notice {
  margin: 0 0 14px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  font-size: 0.93rem;
}

.notice a {
  font-weight: 600;
}

/* ---------- Clues ---------- */

.clues {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
}

.clue {
  position: relative;
  padding: 14px 16px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.clue.is-current {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), var(--shadow);
}

.clue.is-new {
  animation: clue-in 380ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

@keyframes clue-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.clue-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--muted);
}

.clue-lang {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-weight: 600;
  color: var(--text);
}

.flag {
  font-size: 1.25rem;
  line-height: 1;
}

.clue-index {
  font-variant-numeric: tabular-nums;
}

.clue-word {
  margin: 8px 0 0;
  /* Right-to-left words still read correctly; this keeps every card aligned the same way. */
  text-align: left;
  font-size: 1.9rem;
  line-height: 1.2;
  font-weight: 650;
  overflow-wrap: anywhere;
}

.clue-translit {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 1rem;
}

.clue-literal {
  margin: 8px 0 0;
  font-family: var(--font-display);
  font-size: 1.3rem;
  line-height: 1.3;
}

.clue-literal .label {
  font-family: var(--font-ui);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--faint);
  margin-right: 6px;
}

.clue-literal q {
  quotes: "“" "”";
}

.clue-move {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 10px 0 0;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.88rem;
  font-weight: 600;
}

.clue-move.is-wrong {
  background: var(--bad-soft);
  color: var(--bad);
}

.clue-move.is-skip {
  background: var(--surface-2);
  color: var(--muted);
}

.clue-move.is-right {
  background: var(--good-soft);
  color: var(--good);
}

.clue-note {
  margin: 12px 0 0;
  padding-top: 10px;
  border-top: 1px dashed var(--line);
  font-size: 0.92rem;
  color: var(--muted);
}

.clue-note a {
  white-space: nowrap;
}

.badge {
  display: inline-block;
  margin-right: 6px;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  vertical-align: 1px;
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.clue.is-locked {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 16px;
  background: transparent;
  border: 1.5px dashed var(--line);
  box-shadow: none;
  color: var(--faint);
  font-size: 0.88rem;
}

.clue.is-unseen {
  opacity: 0.92;
}

.clue.is-unseen::before {
  content: "Not needed";
  position: absolute;
  top: -9px;
  right: 14px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* ---------- Guess form ---------- */

.guess {
  position: sticky;
  bottom: 0;
  z-index: 10;
  margin: 14px -16px 0;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(to bottom, color-mix(in srgb, var(--bg) 0%, transparent), var(--bg) 18px);
}

.combo {
  position: relative;
}

#guess-input {
  width: 100%;
  height: 52px;
  padding: 0 16px;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 1.1rem;
  box-shadow: var(--shadow);
  -webkit-appearance: none;
  appearance: none;
}

#guess-input::placeholder {
  color: var(--faint);
}

#guess-input:focus {
  outline: none;
  border-color: var(--accent);
}

#guess-input:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.combo.is-shaking {
  animation: shake 360ms ease;
}

@keyframes shake {
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(3px); }
}

.suggestions {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(100% + 6px);
  z-index: 30;
  margin: 0;
  padding: 6px;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 10px 30px rgb(0 0 0 / 16%);
  /* About five rows on a phone, so most of the clue above stays visible. */
  max-height: min(34vh, 236px);
  overflow-y: auto;
}

.suggestions li {
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 1.02rem;
}

.suggestions li mark {
  background: none;
  color: inherit;
  font-weight: 700;
}

.suggestions li:hover,
.suggestions li[aria-selected="true"] {
  background: var(--accent-soft);
}

.guess-actions {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  margin-top: 10px;
}

.guess-hint {
  margin: 8px 2px 0;
  font-size: 0.82rem;
  color: var(--muted);
  text-align: center;
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 20px;
  border: 1.5px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 650;
  cursor: pointer;
  text-decoration: none;
  touch-action: manipulation;
}

.btn:hover {
  background: var(--surface-2);
}

.btn-primary {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--on-accent);
}

.btn-primary:hover {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
}

.btn-quiet {
  background: transparent;
}

.btn-danger {
  border-color: var(--bad);
  color: var(--bad);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* ---------- Result ---------- */

.result {
  margin: 0 0 16px;
  padding: 18px 18px 16px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  text-align: center;
}

.result:focus {
  outline: none;
}

.result.is-won {
  border-color: var(--good);
  box-shadow: 0 0 0 1px var(--good), var(--shadow);
}

.result-kicker {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}

.result.is-won .result-kicker {
  color: var(--good);
}

.result-answer {
  margin: 4px 0 2px;
  font-family: var(--font-display);
  font-size: 2.5rem;
  line-height: 1.1;
  font-weight: 600;
}

.result-detail {
  margin: 0;
  color: var(--muted);
}

.result-grid {
  margin: 10px 0 0;
  font-size: 1.3rem;
  letter-spacing: 0.08em;
}

.result-actions {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.result-next {
  margin: 14px 0 0;
  font-size: 0.92rem;
  color: var(--muted);
}

.result-next time {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--text);
}

.result-streak {
  margin: 4px 0 0;
  font-size: 0.92rem;
  color: var(--muted);
}

/* Ko-fi "Buy me a coffee": a plain link styled as a small pill (no Ko-fi script, nothing tracked) */
.kofi-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 700;
  line-height: 1.4;
  text-decoration: none;
  white-space: nowrap;
  vertical-align: middle;
}

.kofi-link:hover {
  border-color: var(--accent);
}

.kofi-link svg {
  flex: none;
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.support-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 12px 0 0;
  font-size: 0.92rem;
  color: var(--muted);
}

.footer-support {
  padding-top: 6px;
}

.result-more {
  margin: 18px 0 8px;
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--faint);
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  top: calc(70px + env(safe-area-inset-top));
  z-index: 60;
  transform: translate(-50%, -8px);
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 12px;
  background: var(--text);
  color: var(--bg);
  font-weight: 650;
  font-size: 0.95rem;
  box-shadow: 0 8px 24px rgb(0 0 0 / 22%);
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------- Dialogs ---------- */

.dialog {
  width: min(520px, calc(100vw - 24px));
  max-height: calc(100dvh - 32px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 24px 60px rgb(0 0 0 / 30%);
  /* The body scrolls on its own; the frame never does. */
  overflow: hidden;
}

.dialog::backdrop {
  background: rgb(20 14 8 / 45%);
  backdrop-filter: blur(2px);
}

.dialog[open] {
  display: flex;
  flex-direction: column;
  animation: dialog-in 200ms ease;
}

@keyframes dialog-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 8px 4px 20px;
}

.dialog-head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 600;
}

.dialog-body {
  flex: 1 1 auto;
  min-height: 0;
  padding: 4px 20px 16px;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.dialog-foot {
  padding: 4px 20px 20px;
  display: flex;
  justify-content: flex-end;
}

.prose p,
.prose ul {
  margin: 0.6em 0;
}

.prose ul {
  padding-left: 1.2em;
}

.prose li + li {
  margin-top: 0.35em;
}

.help-example {
  margin: 12px 0 6px;
  padding: 12px 14px;
  list-style: none;
  border-radius: 14px;
  background: var(--surface-2);
}

.help-example li + li {
  margin-top: 4px;
}

.help-example q {
  font-family: var(--font-display);
  font-size: 1.08em;
}

.help-answer {
  font-size: 0.95rem;
  color: var(--muted);
}

/* Stats */

.stat-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 6px 0 18px;
  text-align: center;
}

.stat-num {
  display: block;
  font-size: 1.8rem;
  font-weight: 700;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.stat-label {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  line-height: 1.25;
}

.dist-title {
  margin: 0 0 8px;
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--faint);
}

.dist {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.dist li {
  display: grid;
  grid-template-columns: 1.4em 1fr;
  align-items: center;
  gap: 8px;
  font-variant-numeric: tabular-nums;
  font-size: 0.9rem;
}

.dist-bar {
  min-width: 2em;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--surface-2);
  text-align: right;
  font-weight: 700;
}

.dist li.is-latest .dist-bar {
  background: var(--accent);
  color: var(--on-accent);
}

.stats-note {
  margin: 16px 0 0;
  font-size: 0.85rem;
  color: var(--muted);
}

/* Archive */

.archive-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
}

.archive-list a {
  display: grid;
  grid-template-columns: 3.4em 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  color: var(--text);
  text-decoration: none;
}

.archive-list a:hover {
  background: var(--surface-2);
}

.archive-list .a-num {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.archive-list .a-date {
  color: var(--muted);
  font-size: 0.9rem;
}

.archive-list .a-status {
  font-size: 0.85rem;
  font-weight: 650;
  color: var(--muted);
}

.archive-list .a-status.is-won {
  color: var(--good);
}

.archive-list .a-status.is-lost {
  color: var(--bad);
}

.archive-note {
  margin: 0 0 12px;
  font-size: 0.88rem;
  color: var(--muted);
}

/* ---------- Footer ---------- */

.footer {
  padding: 18px 16px calc(24px + env(safe-area-inset-bottom));
  text-align: center;
  font-size: 0.82rem;
  color: var(--muted);
}

.footer p {
  margin: 4px 0;
}

.noscript {
  max-width: 600px;
  margin: 20px auto;
  padding: 16px;
  text-align: center;
}

/* ---------- Errors / loading ---------- */

.loading {
  padding: 40px 0;
  text-align: center;
  color: var(--muted);
}

.error-box {
  padding: 18px;
  border-radius: var(--radius);
  background: var(--bad-soft);
  color: var(--text);
  text-align: center;
}

/* ---------- Larger screens ---------- */

@media (min-width: 640px) {
  body {
    font-size: 18px;
  }

  .page {
    padding-top: 22px;
  }

  .clue {
    padding: 18px 22px;
  }

  .clue-word {
    font-size: 2.2rem;
  }

  .guess {
    position: static;
    margin: 16px 0 0;
    padding: 0;
    background: none;
  }

  /* No on-screen keyboard here, so open below the box and keep the clue in view. */
  .suggestions {
    top: calc(100% + 6px);
    bottom: auto;
    max-height: 340px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---------- About and other text pages ---------- */

a.icon-btn {
  color: var(--text);
}

.about h1 {
  margin: 10px 0 12px;
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 600;
  line-height: 1.15;
}

.about h2 {
  margin: 28px 0 6px;
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 600;
}

.about q {
  font-family: var(--font-display);
  font-size: 1.06em;
}

.about code {
  padding: 1px 5px;
  border-radius: 6px;
  background: var(--surface-2);
  font-size: 0.88em;
}

.about-back {
  margin-top: 30px;
  text-align: center;
}

.about .wordmark {
  margin: 16px 0 8px;
  font-size: 2rem;
}

.share-fallback {
  display: block;
  width: 100%;
  margin-top: 12px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 0.95rem;
  resize: none;
}

.clue {
  scroll-margin: 72px 0 200px;
}

.result {
  scroll-margin-top: 72px;
}
