/* base.css — global tokens, layout primitives, start-menu styles, and the
   chrome that's shared across all screens (overlay, toasts, tooltip).
   Game-screen-specific rules live in game.css. */

:root {
  --bg-0: #0a0820;
  --bg-1: #1a0f30;
  --bg-2: #261540;
  --ink: #f5edff;
  --ink-dim: #b9a8d8;
  --ink-faint: #7a6a99;
  --accent: #f4a8d8;
  --accent-2: #b59cff;
  --amber: #FAC775;
  --amber-ink: #633806;
  --seagreen: #5DCAA5;
  --danger: #ff7a8a;
  --panel: rgba(36, 22, 64, 0.72);
  --panel-border: rgba(181, 156, 255, 0.18);
  --tier-grad: linear-gradient(90deg,
    #5b6cff 0%, #8a5cff 12%, #c45cff 24%, #ff5cd0 36%,
    #ff6c8a 48%, #ff9a5c 60%, #ffd45c 72%, #b8ff7a 86%, #5cffd0 100%);
  --src-wordnet: #b59cff;
  --src-gcide: #f4a8d8;
  --src-wiktionary: #5DCAA5;
  --src-scrabble: #FAC775;
  --shadow-lg: 0 20px 60px -20px rgba(0,0,0,0.6);
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: linear-gradient(180deg, var(--bg-0) 0%, var(--bg-1) 60%, var(--bg-2) 100%);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
/* Horizontal-scroll prevention lives on <html> only. Putting it on <body> too
   would auto-promote body to its own scrollport (the browser converts
   overflow-y from visible→auto whenever overflow-x is non-visible), creating
   nested scrollports that break position:sticky on body's descendants. */
html { overflow-x: hidden; }

body { min-height: 100vh; position: relative; }

/* weerrd reads all-lowercase: menus, buttons, labels, letters. Form controls
   don't inherit text-transform by default, so pull them in. Definition text
   keeps its real capitals (names like "the Druids", abbreviations). */
html { text-transform: lowercase; }
button, input, select, textarea, output { text-transform: inherit; }
.tt-def, .def-float__def, .tt-syns, .tt-hyps, .def-float__meta { text-transform: none; }

.ambient {
  position: fixed; inset: 0; pointer-events: none; z-index: 0;
  overflow: hidden;
}
.blob {
  position: absolute; border-radius: 50%; filter: blur(50px); opacity: 0.42;
  /* translateZ promotes the blob to its own GPU layer up front, so the
     animation never has to switch from CPU to GPU mid-cycle (a common cause
     of blur+motion stutter). Lighter 50px blur drops compositor cost ~40%. */
  transform: translateZ(0);
  will-change: transform;
  /* Constant orbit duration per blob — no activity-driven speed swap.
     Mid-cycle animation-duration changes cause visible playhead jumps,
     which read as "jitter for no reason". Milestone advances are the
     only thing that disturbs the blobs (see .blob.respawn). */
  animation-duration: var(--orbit-base, 18s);
}

.blob-a { width: 420px; height: 420px; left: 8%;  top: 6%;
  background: #6b3bff; --orbit-base: 18s; animation-name: blobOrbit1; animation-iteration-count: infinite; animation-timing-function: linear; }
.blob-b { width: 360px; height: 360px; right: 6%; top: 38%;
  background: #ff5cd0; --orbit-base: 22s; animation-name: blobOrbit2; animation-iteration-count: infinite; animation-timing-function: linear; }
.blob-c { width: 300px; height: 300px; left: 30%; bottom: 8%;
  background: #5DCAA5; opacity: 0.32; --orbit-base: 26s;
  animation-name: blobOrbit3; animation-iteration-count: infinite; animation-timing-function: linear; }
.blob-d { width: 180px; height: 180px; left: 60%; top: 12%;
  background: #b59cff; opacity: 0.35; --orbit-base: 14s;
  animation-name: blobOrbit2; animation-direction: reverse; animation-delay: -6s; animation-iteration-count: infinite; animation-timing-function: linear; }
.blob-e { width: 140px; height: 140px; left: 5%; bottom: 22%;
  background: #ff9a5c; opacity: 0.28; --orbit-base: 12s;
  animation-name: blobOrbit1; animation-direction: reverse; animation-delay: -3s; animation-iteration-count: infinite; animation-timing-function: linear; }
.blob-f { width: 220px; height: 220px; right: 18%; bottom: 6%;
  background: #8a5cff; opacity: 0.30; --orbit-base: 16s;
  animation-name: blobOrbit3; animation-direction: reverse; animation-delay: -8s; animation-iteration-count: infinite; animation-timing-function: linear; }
.blob-g { width: 110px; height: 110px; left: 45%; top: 48%;
  background: #5cffd0; opacity: 0.22; --orbit-base: 10s;
  animation-name: blobOrbit2; animation-delay: -2s; animation-iteration-count: infinite; animation-timing-function: linear; }
/* Five more fuzzy balls — varied sizes, complementary palette. */
.blob-h { width: 260px; height: 260px; left: 78%; top: 70%;
  background: #ffd45c; opacity: 0.24; --orbit-base: 20s;
  animation-name: blobOrbit1; animation-delay: -5s; animation-iteration-count: infinite; animation-timing-function: linear; }
.blob-i { width: 90px; height: 90px; left: 18%; top: 65%;
  background: #5cb8ff; opacity: 0.30; --orbit-base: 9s;
  animation-name: blobOrbit3; animation-delay: -1s; animation-iteration-count: infinite; animation-timing-function: linear; }
.blob-j { width: 320px; height: 320px; right: 28%; top: 4%;
  background: #c45cff; opacity: 0.22; --orbit-base: 24s;
  animation-name: blobOrbit2; animation-direction: reverse; animation-delay: -11s; animation-iteration-count: infinite; animation-timing-function: linear; }
.blob-k { width: 70px; height: 70px; right: 38%; bottom: 32%;
  background: #ff6c8a; opacity: 0.28; --orbit-base: 8s;
  animation-name: blobOrbit1; animation-delay: -4s; animation-iteration-count: infinite; animation-timing-function: linear; }
.blob-l { width: 200px; height: 200px; left: 2%; top: 50%;
  background: #b8ff7a; opacity: 0.20; --orbit-base: 19s;
  animation-name: blobOrbit3; animation-direction: reverse; animation-delay: -7s; animation-iteration-count: infinite; animation-timing-function: linear; }

.hidden { display: none !important; }

.screen {
  position: relative; z-index: 1;
  max-width: 520px;
  margin: 0 auto;
  padding: 24px 18px 64px;
  display: flex; flex-direction: column;
  gap: 18px;
}

.overlay {
  position: fixed; inset: 0; z-index: 10;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at center, rgba(20,10,45,0.85), rgba(8,6,20,0.98));
  backdrop-filter: blur(6px);
}
.loading-card { text-align: center; }
.loading-card .status { color: var(--ink-dim); margin-top: 4px; font-size: 14px; }

.wordmark {
  font-size: 48px; font-weight: 800; letter-spacing: 0.06em; margin: 0;
  text-transform: lowercase;
  background: linear-gradient(90deg,
    #5b6cff 0%,  #8a5cff 8%,  #c45cff 16%, #ff5cd0 24%,
    #ff6c8a 32%, #ff9a5c 40%, #ffd45c 48%, #b8ff7a 56%,
    #5cffd0 64%, #5cb8ff 72%, #b59cff 80%, #ff5cd0 88%, #5b6cff 100%);
  background-size: 400% 100%;
  -webkit-background-clip: text; background-clip: text; color: transparent;
  text-align: center;
  animation: wordmarkScroll 12s linear infinite, wordmarkGlow 4s ease-in-out infinite;
  filter: drop-shadow(0 0 12px rgba(181,156,255,0.45));
}
.wordmark-small { font-size: 22px; letter-spacing: 0.10em;
  animation: wordmarkScroll 9s linear infinite, wordmarkGlow 3.2s ease-in-out infinite; }
.tagline { text-align: center; color: var(--ink-dim); margin: -6px 0 12px; font-style: italic; }

/* Lifetime facts panel — two-column dl, label / value. */
.menu-stats {
  display: grid; grid-template-columns: 1fr auto; gap: 6px 12px;
  margin: 0; padding: 10px 12px;
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(181,156,255,0.18);
  border-radius: 10px;
  font-size: 14px;
}
.menu-stats dt { color: var(--ink-dim); }
.menu-stats dd { margin: 0; font-weight: 700; text-align: right; color: var(--ink); font-variant-numeric: tabular-nums; }

.menu-group { display: flex; flex-direction: column; gap: 8px; }
.menu-group h2 { font-size: 13px; font-weight: 600; text-transform: lowercase;
  letter-spacing: 0.14em; color: var(--ink-faint); margin: 0; }

/* Resume picker — recent saved puzzles, click to jump back in. */
.resume-list { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
@media (max-width: 480px) { .resume-list { grid-template-columns: 1fr; } }
.resume-item {
  position: relative;
  background: var(--panel); border: 1px solid var(--panel-border); color: var(--ink);
  border-radius: var(--radius); padding: 10px 12px; cursor: pointer;
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  text-align: left; min-height: 52px;
  transition: transform 0.12s, border-color 0.12s, background 0.12s;
}
.resume-item:hover { transform: translateY(-1px); border-color: var(--accent-2); }
.resume-item:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; }
/* Top On-weerrdward rows: faint rainbow border + soft glow so they read as
   trophies, distinct from the plain resume rows. */
.completed-item {
  border-color: rgba(244,168,216,0.55);
  box-shadow: 0 0 18px rgba(181,156,255,0.25);
  background: linear-gradient(135deg, rgba(95,108,255,0.10) 0%, rgba(244,168,216,0.10) 100%), var(--panel);
}
.completed-item:hover { border-color: rgba(244,168,216,0.95); }
.completed-item .resume-line::before {
  content: '★ ';
  background: linear-gradient(90deg, #ff9a5c, #ffd45c, #b8ff7a, #5cffd0, #b59cff);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.resume-line { font-weight: 700; font-size: 14px; }
.resume-meta { font-size: 11px; color: var(--ink-faint); }
/* Delete × — only revealed on hover/focus of the row, so the picker stays
   clean by default. Clicking it removes both the snapshot and the best-score
   record (handled in ui.js via deleteSavedPuzzle). */
.resume-delete {
  position: absolute; top: 4px; right: 4px;
  width: 20px; height: 20px; padding: 0; line-height: 1;
  font-size: 14px; font-weight: 700;
  color: var(--ink-faint);
  background: transparent; border: 1px solid transparent; border-radius: 4px;
  cursor: pointer; opacity: 0;
  transition: opacity 0.12s, color 0.12s, background 0.12s, border-color 0.12s;
}
.resume-item:hover .resume-delete,
.resume-item:focus-within .resume-delete { opacity: 1; }
.resume-delete:hover {
  color: #fff;
  background: rgba(255, 90, 110, 0.85);
  border-color: rgba(255, 90, 110, 1);
}

.choice-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
/* minmax(0, 1fr) lets the four buttons shrink evenly on narrow screens
   instead of the longest label ("frequent") pushing past the edge. */
.choice-row-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.choice-row-4 .choice { padding-left: 4px; padding-right: 4px; }
.choice {
  background: var(--panel); border: 1px solid var(--panel-border); color: var(--ink);
  border-radius: var(--radius); padding: 12px 10px; cursor: pointer;
  font-size: 15px; font-weight: 600; line-height: 1.2;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  min-height: 56px; transition: transform 0.12s, border-color 0.12s, background 0.12s;
}
.choice span { font-size: 11px; font-weight: 500; color: var(--ink-faint); }
.choice[aria-pressed="true"] {
  border-color: var(--accent-2);
  background: linear-gradient(180deg, rgba(181,156,255,0.18), rgba(244,168,216,0.10));
  box-shadow: 0 0 0 2px rgba(181,156,255,0.25), 0 8px 24px -10px rgba(181,156,255,0.4);
}
.choice:hover { transform: translateY(-1px); }

/* Compact choice row — buttons hug their content (used by Letter count for
   single-digit values 6/7/8). Sits left-aligned at natural width. */
.choice-row-compact {
  display: flex; gap: 8px; justify-content: flex-start;
  grid-template-columns: none;
}
.choice-tight {
  min-height: 0; padding: 8px 16px; font-size: 18px;
  flex: 0 0 auto; min-width: 48px;
}
.hint { font-size: 12px; color: var(--ink-faint); margin: 4px 2px 0; }

.primary {
  background: linear-gradient(135deg, #b59cff, #f4a8d8);
  color: #1a0a30; border: none; border-radius: var(--radius);
  padding: 16px; font-size: 17px; font-weight: 800; cursor: pointer;
  letter-spacing: 0.06em; box-shadow: var(--shadow-lg);
  transition: transform 0.12s, filter 0.12s;
}
.primary:hover { transform: translateY(-1px); filter: brightness(1.05); }
.primary:active { transform: translateY(0); }

.ghost {
  background: transparent; color: var(--ink-dim); border: 1px solid var(--panel-border);
  border-radius: 50%; width: 36px; height: 36px; cursor: pointer; font-size: 20px;
  display: grid; place-items: center;
}
.ghost:hover { color: var(--ink); border-color: var(--accent-2); }

.ghost-icon { padding: 0; }
.ghost-icon svg {
  width: 22px; height: 26px;
  fill: currentColor; stroke: none;
}

.toast-stack {
  /* Top-center so AllWeerrd / wild / score-tier toasts surface near the
     score bar instead of competing with the action-row at the bottom. */
  position: fixed; left: 0; right: 0; top: 18px; z-index: 20;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--panel); border: 1px solid var(--panel-border);
  border-radius: 999px; padding: 10px 18px; font-weight: 700;
  color: var(--ink); backdrop-filter: blur(8px);
  animation: toastIn 0.3s ease, toastOut 0.4s ease 2.4s forwards;
}
.toast.wild {
  border-color: rgba(244,168,216,0.85);
  color: var(--accent);
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.08em;
  padding: 12px 22px;
  background: linear-gradient(90deg, rgba(244,168,216,0.22), rgba(181,156,255,0.22));
  box-shadow: 0 0 32px rgba(244,168,216,0.55), 0 0 64px rgba(181,156,255,0.35);
  text-shadow: 0 0 14px rgba(244,168,216,0.85);
}
.toast.weerrd  { border-color: rgba(93,202,165,0.6); color: var(--seagreen); }
.toast.error  { border-color: rgba(255,122,138,0.5); color: var(--danger); }

.tooltip {
  position: fixed; z-index: 30; max-width: 280px;
  background: rgba(10,8,32,0.96); border: 1px solid var(--panel-border);
  border-radius: 10px; padding: 10px 12px; color: var(--ink);
  font-size: 13px; line-height: 1.4; pointer-events: none;
  box-shadow: var(--shadow-lg);
}
.tooltip .tt-word { font-weight: 700; text-transform: lowercase; margin-bottom: 2px; }
.tooltip .tt-pos { font-style: italic; color: var(--ink-faint); font-size: 11px; margin-bottom: 4px; }
.tooltip .tt-def { margin-bottom: 6px; }
.tooltip .tt-syns,
.tooltip .tt-hyps { font-size: 11px; color: var(--ink-dim); margin-top: 2px; }
.tooltip .tt-pos:empty,
.tooltip .tt-syns:empty,
.tooltip .tt-hyps:empty { display: none; }

@media (max-width: 380px) {
  .wordmark { font-size: 38px; }
  .input-display { font-size: 24px; }
}

/* ---------------- Playways button + tooltip + modal ---------------- */

.playways-wrap {
  position: relative;
  display: flex;
  justify-content: center;
  margin: 4px 0 6px;
}
.playways-btn {
  background: linear-gradient(135deg, rgba(181, 156, 255, 0.18), rgba(244, 168, 216, 0.12));
  color: var(--ink);
  border: 1px solid rgba(181, 156, 255, 0.45);
  border-radius: 999px;
  padding: 6px 18px;
  font-size: 13px; font-weight: 700;
  letter-spacing: 0.10em; text-transform: lowercase;
  cursor: pointer;
  transition: transform 0.12s, filter 0.12s, border-color 0.12s;
}
.playways-btn:hover  { transform: translateY(-1px); filter: brightness(1.12); border-color: var(--accent-2); }
.playways-btn:active { transform: translateY(0); }

/* Hover tip — short summary, anchored below the button. Pure CSS, no JS. */
.playways-tooltip {
  position: absolute;
  top: 100%; left: 50%;
  margin-top: 8px;
  transform: translateX(-50%) translateY(4px);
  width: max-content; max-width: min(86vw, 340px);
  background: rgba(20, 12, 48, 0.96);
  border: 1px solid rgba(181, 156, 255, 0.4);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 12px; line-height: 1.42; font-weight: 400;
  color: rgba(220, 210, 255, 0.90);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.55);
  opacity: 0; visibility: hidden;
  transition: opacity 0.18s ease, transform 0.18s ease;
  pointer-events: none;
  z-index: 30;
}
.playways-tooltip p { margin: 0 0 6px; }
.playways-tooltip p:last-child { margin: 0; }
.playways-wrap:hover .playways-tooltip,
.playways-wrap:focus-within .playways-tooltip {
  opacity: 1; visibility: visible;
  transform: translateX(-50%) translateY(0);
}

/* Modal — dim backdrop, springy card, scrolls vertically if too tall. */
.playways-modal {
  position: fixed; inset: 0; z-index: 60;
  display: flex; align-items: center; justify-content: center;
  background: rgba(8, 4, 28, 0.78);
  backdrop-filter: blur(6px);
  padding: 24px;
  animation: playwaysFadeIn 0.28s ease;
}
.playways-modal.hidden { display: none; }
.playways-card {
  position: relative;
  background: linear-gradient(180deg, rgba(40, 25, 80, 0.96), rgba(20, 10, 50, 0.96));
  border: 1px solid rgba(181, 156, 255, 0.4);
  border-radius: 16px;
  padding: 28px 28px 24px;
  max-width: 600px; max-height: 88vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
  animation: playwaysSpring 0.42s cubic-bezier(0.2, 1.2, 0.3, 1);
  color: var(--ink);
}
.playways-card h2 {
  margin: 0 0 16px;
  font-size: 22px; font-weight: 800;
  letter-spacing: 0.14em; text-transform: lowercase;
  background: linear-gradient(90deg, #b59cff, #f4a8d8, #5DCAA5);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.playways-list {
  margin: 0; padding-left: 20px;
  font-size: 14px; line-height: 1.55;
  color: rgba(220, 210, 255, 0.92);
}
.playways-list li { margin-bottom: 10px; }
.playways-list li:last-child { margin-bottom: 0; }
.playways-list strong { color: var(--accent); font-weight: 700; }
.playways-close {
  position: absolute; right: 12px; top: 10px;
  background: transparent; color: var(--ink-dim);
  border: 1px solid var(--panel-border);
  border-radius: 999px; width: 28px; height: 28px;
  font-size: 18px; line-height: 1; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: color 0.12s, border-color 0.12s, background 0.12s;
}
.playways-close:hover {
  color: var(--ink); border-color: var(--accent-2);
  background: rgba(181, 156, 255, 0.12);
}
@keyframes playwaysFadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes playwaysSpring {
  0%   { transform: scale(0.6); opacity: 0; }
  60%  { transform: scale(1.02); opacity: 1; }
  100% { transform: scale(1); }
}
@media (prefers-reduced-motion: reduce) {
  .playways-modal, .playways-card,
  .playways-tooltip {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
