:root {
  --bg: #ffffff;        /* page — white */
  --card: #fdf6ea;      /* card + features — very light warm cream */
  --cream-2: #f3eddc;   /* slightly deeper cream for bars/fills */
  --ink: #23282b;
  --muted: #707567;
  --faint: #a8ac9d;
  --line: #ece6d6;
  --line-2: #ddd6c4;
  --accent: #e0902a;        /* Modern Family orange */
  --accent-deep: #c2761a;   /* deeper — for buttons with white text */
  --accent-soft: #fbeed8;
  --accent-line: #ecca9b;
  --good: #5f8a4d;          /* green — kept for "correct" only */
  --good-soft: #e8efe0;
  --good-line: #b9cfa9;
  --red: #c1503b;
  --red-soft: #f6e2dc;
  --red-line: #e2b3a8;
  --radius: 14px;
  --radius-sm: 9px;
  --sans: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", system-ui, sans-serif;
  --serif: ui-serif, "Iowan Old Style", Georgia, serif;
  --shadow: 0 1px 2px rgb(40 40 30 / 6%), 0 8px 30px rgb(40 40 30 / 8%);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  /* Column layout so the "made for avery" credit is a real footer at the bottom
     of the page (in flow) rather than floating fixed over the content. */
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

button, input { font: inherit; color: inherit; }
button:focus-visible, input:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
[hidden] { display: none !important; }

.app {
  flex: 1 0 auto;            /* fill the viewport so the card centers, footer sits below */
  display: grid;
  /* Center the UI vertically when it fits; fall back to top-aligned (scrollable)
     when content is taller than the screen, so nothing gets clipped on mobile. */
  align-content: safe center;
  justify-items: center;
  gap: 18px;
  padding: clamp(20px, 5vw, 48px) 16px;
}
/* While searching (touch), pin the card to the top so it doesn't re-center —
   and the search bar doesn't jump — as the results list resizes while typing. */
body.searching .app { align-content: start; }
.avery-homage {
  flex: 0 0 auto;
  margin: 0;
  padding: 4px 0 10px;
  text-align: center;
  font-size: 10px;
  line-height: 1;
  color: rgb(35 40 43 / 24%);
}

/* centered logo / wordmark */
.brand { display: block; text-align: center; text-decoration: none; line-height: 1; }
#brand-logo { max-height: 54px; width: auto; }
.brand-text { font-size: 40px; font-weight: 800; letter-spacing: 0; color: var(--ink); }
/* "family" matches the Modern Family logo's golden orange (brighter than the
   theme --accent burnt orange used on buttons). */
.brand-text span { color: #f0a83c; }
.puzzle-date {
  margin: -8px 0 2px;
  color: var(--muted);
  font-size: 17px;
  font-weight: 700;
  letter-spacing: .02em;
}

/* loading / setup */
.panel {
  width: min(440px, 100%);
  text-align: center;
  padding: 48px 24px;
}
.panel h1 { font-size: 22px; margin: 0 0 8px; }
.panel p { color: var(--muted); margin: 0 auto; max-width: 40ch; }
.setup-today { display: inline-block; margin: 18px auto 0; }
.setup-quote { margin: 0 auto 14px; max-width: 38ch; }
.setup-quote blockquote {
  margin: 0;
  color: var(--ink);
  font-size: 22px;
  font-weight: 800;
  line-height: 1.18;
}
.setup-quote figcaption {
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}
.spinner {
  width: 34px; height: 34px; margin: 0 auto;
  border: 3px solid var(--line-2); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.setup-details { margin: 20px auto 0; max-width: 360px; display: grid; gap: 6px; font-size: 13px; text-align: left; }
.setup-details div { display: grid; grid-template-columns: 84px 1fr; gap: 10px; }
.setup-details dt { color: var(--faint); }
.setup-details dd { margin: 0; overflow-wrap: anywhere; }

/* the game card — single column */
.card {
  width: min(460px, 100%);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: clamp(18px, 4vw, 26px);
  display: grid;
  gap: 16px;
}

.ghost-link {
  background: none; border: 0; padding: 0; cursor: pointer;
  color: var(--accent-deep); font-size: 13px; text-decoration: none;
}
.ghost-link:hover { text-decoration: underline; }

/* clip-length bars */
.game-intro {
  position: relative;
  margin: -4px 0 4px;   /* a little breathing room above the length track */
  color: #8b8f7f;   /* a step darker than --faint for legibility */
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 6px;
}
.info-button {
  width: 18px;
  height: 18px;
  border: 1px solid var(--line-2);
  border-radius: 50%;
  background: #fff;
  color: var(--muted);
  font: italic 700 11px/1 var(--serif);
  cursor: pointer;
}
.info-button:hover, .info-button.open {
  border-color: var(--accent);
  color: var(--accent-deep);
}
.rules-popover {
  position: absolute;
  z-index: 5;
  top: 24px;
  left: 0;
  width: min(320px, calc(100vw - 48px));
  padding: 10px 12px;
  border: 1px solid var(--line-2);
  border-radius: var(--radius-sm);
  background: #fff;
  box-shadow: var(--shadow);
  color: var(--muted);
  line-height: 1.35;
  text-align: left;
}
.length-track {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
}
.length-step {
  position: relative;
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--line-2);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--muted);
  font-size: 12px; font-weight: 700;
  display: grid; place-items: center;
  appearance: none; -webkit-appearance: none; cursor: default;
}
.length-step.open { cursor: pointer; }
.length-step.open:hover { border-color: var(--accent); color: var(--ink); }
.length-step.active {
  background: var(--accent);
  border-color: var(--accent-deep);
  color: #fff;
  box-shadow: 0 1px 4px rgb(192 118 26 / 35%);
}
.length-step.spent { background: var(--card); color: var(--faint); opacity: 0.55; }
/* Lock states for the shorter clips. about-to-lock: you've stepped up to a
   longer clip but haven't played it — stays a normal white button, just wearing
   the lock badge ("this will lock"), still tappable to step back. locked-in: you
   played past it — committed, the button goes gray with a darker lock. */
.length-step.locked-in { background: var(--card); color: var(--faint); }
.length-step .lock {
  position: absolute;
  top: 2px; right: 3px;
  display: grid; place-items: center;
  pointer-events: none;
}
.length-step .lock svg { display: block; width: 14px; height: 14px; }
.length-step.about-to-lock .lock { color: rgb(35 40 43 / 42%); }   /* lighter — about to happen */
.length-step.about-to-lock .lock svg { stroke-dasharray: 1.5 2; }  /* dotted outline */
.length-step.locked-in .lock { color: rgb(35 40 43 / 72%); }       /* darker, solid — locked in */

.skip-hint, .guess-label { margin: -6px 0 -10px; font-size: 12px; color: #8b8f7f; }

/* play */
.play {
  position: relative;
  overflow: hidden;          /* clip the progress fill to the rounded button */
  height: 60px;
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--accent-deep);
  color: #fff;
  font-size: 16px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center; gap: 12px;
  cursor: pointer;
  transition: background 120ms ease, transform 80ms ease;
}
/* Playback progress fills the button itself (a lighter sweep) — no separate bar. */
.play-fill {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 0;
  background: rgb(255 255 255 / 22%);
  pointer-events: none;
}
.play-icon, #play-label { position: relative; z-index: 1; }
.play:hover:not(:disabled) { background: #a8650f; }
.play:active:not(:disabled) { transform: translateY(1px); }
.play:disabled { opacity: 0.5; cursor: default; }
.play-icon {
  width: 0; height: 0;
  border-top: 8px solid transparent; border-bottom: 8px solid transparent;
  border-left: 13px solid currentColor;
}
.play.playing .play-icon {
  width: 13px; height: 16px; border: 0;
  box-shadow: inset 4px 0 0 currentColor, inset -4px 0 0 currentColor;
}

/* guess form */
form { display: grid; gap: 12px; }
.combo-wrap {
  position: relative;
  display: grid; grid-template-columns: 1fr 40px;
  border: 1px solid var(--line-2);
  border-radius: var(--radius-sm);
  background: #fff;
}
#guess-input { min-width: 0; height: 48px; padding: 0 14px; border: 0; background: transparent; outline: 0; }
.combo-wrap { scroll-margin-top: 14px; }   /* leave a little gap when we scroll search to the top */
#guess-input::placeholder { color: var(--faint); }
.icon-button { border: 0; border-left: 1px solid var(--line); background: none; color: var(--faint); cursor: pointer; font-size: 18px; }
.icon-button:hover { color: var(--ink); }

.results-list {
  margin: 0; padding: 5px; list-style: none;
  max-height: 320px; overflow: auto;
  border: 1px solid var(--line-2); border-radius: var(--radius-sm);
  background: #fff; box-shadow: var(--shadow);
  position: relative;   /* offset parent for season-jump (head.offsetTop) */
}
.results-list li.opt { border-radius: 8px; cursor: pointer; padding: 8px 10px; }
.results-list li.opt:hover, .results-list li.opt.active { background: var(--accent-soft); }
.results-list li.opt.guessed { cursor: default; opacity: 0.45; }
.results-list li.opt.guessed:hover { background: none; }
.results-list li.guessed .opt-title::after { content: " · already guessed"; color: var(--faint); font-weight: 400; font-size: 12px; }
.results-list li.results-more {
  list-style: none;
  margin: 4px 2px 2px;
  padding: 9px 10px 7px;
  border-top: 1px solid var(--line);
  text-align: center;
  font-size: 11.5px;
  color: var(--faint);
}
.opt-row { display: flex; align-items: center; gap: 10px; }
/* Fixed-width S/E column so titles align across single/double-digit codes. */
.opt-row .opt-meta { flex: none; width: 50px; font-size: 12px; font-weight: 600; color: var(--faint); font-variant-numeric: tabular-nums; }
.opt-row .opt-title { font-weight: 600; color: var(--ink); }
/* Right-justified ⓘ — reveals the plot on tap without selecting the episode. */
.opt-info {
  margin-left: auto; flex: none; width: 22px; height: 22px;
  border: 1px solid var(--line-2); border-radius: 50%; background: #fff;
  color: var(--muted); font: italic 700 12px/1 var(--serif); cursor: pointer;
}
.opt-info:hover, .opt-info.open { border-color: var(--accent); color: var(--accent-deep); }
.opt-desc { margin: 6px 2px 2px; }
.opt-desc .opt-sub { display: block; font-size: 12.5px; line-height: 1.4; color: var(--muted); }
.opt-desc .search-hit {
  border-radius: 3px;
  padding: 0 2px;
  background: #fff0b7;
  color: var(--ink);
}
.opt-desc .opt-src { font-size: 10px; letter-spacing: .05em; color: var(--faint); text-transform: uppercase; }
.results-list .season-head {
  list-style: none; padding: 11px 10px 5px; margin: 0;
  font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  color: var(--faint); position: sticky; top: -5px; background: #fff;
  display: flex; align-items: center; gap: 10px;
}
/* Trailing rule turns each season label into a scannable divider. */
.results-list .season-head::after {
  content: ""; flex: 1; height: 1px; background: var(--line-2);
}

.season-jump { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 2px; }
.season-chip {
  border: 1px solid var(--line-2); background: #fff; color: var(--muted);
  border-radius: 999px; padding: 3px 10px; font-size: 12px; font-weight: 700; cursor: pointer;
}
.season-chip:hover { border-color: var(--accent); color: var(--accent); }

.actions { display: grid; grid-template-columns: 1fr auto; gap: 10px; }
.primary, .ghost {
  min-height: 46px; padding: 0 18px;
  border-radius: var(--radius-sm); font-weight: 700; cursor: pointer;
}
.primary { border: 0; background: var(--accent-deep); color: #fff; }
.primary:hover:not(:disabled) { background: #a8650f; }
.primary:disabled { opacity: 0.45; cursor: default; }
.ghost { border: 1px solid var(--line-2); background: #fff; color: var(--ink); }
.ghost:hover { border-color: var(--accent); color: var(--accent); }
.guess-selected-pill {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  margin-left: 6px;
  padding: 0 8px;
  border-radius: 999px;
  background: rgb(255 255 255 / 20%);
  border: 1px solid rgb(255 255 255 / 38%);
  color: #fff;
  font-size: .86em;
  font-weight: 800;
}

.round-message { min-height: 20px; margin: 0; font-size: 14px; color: var(--muted); }
/* classifier output — only shown when the describe-mode flag is on */
.describe-feedback { margin: 2px 0 0; padding: 9px 12px; border-radius: 10px; font-size: 13.5px;
  background: var(--accent-soft); color: var(--accent-deep); border: 1px solid var(--accent-line); }
.round-message.error { color: var(--red); }

/* Guess scoreboard — deliberately NOT button-like (the length bars above are the
   tappable controls). Filled, borderless, shorter cells so it reads as status. */
.guess-list { margin: 0; padding: 0; list-style: none; display: flex; gap: 5px; }
.guess-row {
  flex: 1 1 0; min-width: 0; min-height: 30px;
  display: flex; align-items: center; justify-content: center; padding: 3px 2px;
  border: 0; border-radius: 7px; background: #e8e1d2;
}
.guess-row.empty { color: var(--faint); }
/* Saturated-pastel fills (not a pale tint) so a guessed tile reads as a solid
   green/red chip; the code sits on top in a deep same-hue tone. */
.guess-row.correct { background: #a7d695; }
.guess-row.wrong { background: #f1a08c; }
.guess-index { color: var(--faint); font-size: 11px; font-weight: 700; }
.guess-code {
  display: flex; flex-direction: row; align-items: baseline; justify-content: center;
  gap: 3px; line-height: 1; white-space: nowrap;
  font-weight: 700; font-size: 11px; color: var(--ink);
}
.guess-row.correct .guess-code { color: #2f5121; }
.guess-row.wrong .guess-code { color: #7a2b1c; }
/* A guess that just landed pops in (scale + fade with a little overshoot) so the
   red/green result is obvious. Only the freshly-added tile gets .landed. */
@keyframes guess-pop {
  0% { transform: scale(0.45); opacity: 0; }
  60% { transform: scale(1.14); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}
.guess-row.landed { animation: guess-pop 0.34s cubic-bezier(0.34, 1.56, 0.64, 1); }
@media (prefers-reduced-motion: reduce) { .guess-row.landed { animation: none; } }
.result-episode .ep-meta { color: var(--muted); font-weight: 400; }

.view-result { justify-self: center; }

/* modal overlay (result + reveal-confirm) */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center; padding: 18px;
  background: rgb(20 18 14 / 46%);
  backdrop-filter: blur(2px);
}
.modal {
  position: relative;
  width: min(440px, 100%);
  max-height: calc(100dvh - 32px);   /* never taller than the screen */
  overflow-y: auto;                  /* scroll within if it still doesn't fit */
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgb(30 30 20 / 28%);
  padding: clamp(18px, 4.5vw, 28px);
  text-align: center;
}
.modal.small { width: min(340px, 100%); }
.modal-close {
  position: absolute; top: 12px; right: 12px;
  width: 32px; height: 32px; border: 0; border-radius: 8px;
  background: none; color: var(--faint); font-size: 20px; cursor: pointer;
}
.modal-close:hover { background: var(--bg); color: var(--ink); }
.result-burst {
  position: absolute;
  inset: 0;
  overflow: visible;
  pointer-events: none;
}
.result-burst .burst-trophy {
  position: absolute;
  top: var(--y);
  left: 50%;
  font-size: 22px;
  line-height: 1;
  opacity: 0;
  transform: translate(-50%, 0) scale(.6) rotate(0deg);
  animation: trophy-pop 1100ms cubic-bezier(.18,.82,.22,1) forwards;
  animation-delay: var(--delay);
}
@keyframes trophy-pop {
  0% { opacity: 0; transform: translate(-50%, 0) scale(.55) rotate(0deg); }
  12% { opacity: 1; }
  80% { opacity: 1; }
  100% {
    opacity: 0;
    transform: translate(calc(-50% + var(--x)), var(--rise)) scale(1.05) rotate(var(--rot));
  }
}
/* Result card order: wordmark → season/ep → title → clip → [squares + Share frame] → RooFlix/status */
/* Wordmark + date are hidden in the share modal to keep it compact (they're
   already on the main screen). */
.result-brand, .result-date { display: none; }
.result-brand .brand-text { font-size: 24px; }
.result-date {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .02em;
}
.result-status { margin: 10px 0 0; font-size: 13px; color: var(--muted); }
.result-episode { margin: 0 0 2px; font-weight: 600; font-size: 13px; letter-spacing: .04em; color: var(--muted); }
.modal h2 { margin: 0; font-size: clamp(22px, 5.5vw, 30px); }
.result-title { color: var(--ink); }
.reveal-video { display: block; width: 100%; max-height: 40dvh; margin: 12px 0 0; border-radius: var(--radius-sm); background: #000; object-fit: contain; }
/* Wordle result + Share live in one frame — your result, ready to share. */
.result-share {
  margin: 12px 0 0; padding: 12px 14px;
  border: 1px solid var(--accent-line); border-radius: var(--radius-sm);
  background: var(--accent-soft);
  display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.result-share .primary { min-width: 160px; }
.result-share .primary.copied { background: var(--good); }
/* 6×6 result grid: rows = clip lengths, cols = guesses. Gray by default. */
.result-squares { margin: 0; display: grid; gap: 3px; justify-content: center; }
.result-grid-row {
  display: grid;
  grid-template-columns: repeat(6, 13px) minmax(24px, auto);
  gap: 3px;
  align-items: center;
}
.result-squares .sq { display: block; width: 13px; height: 13px; border-radius: 2px; background: #d8d0bf; }
.result-squares .sq-miss { background: var(--red); }
.result-squares .sq-hit { background: var(--good); }
.result-row-label {
  min-width: 24px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
  text-align: left;
}
.rooflix-btn.result-watch, a#rooflix-link { margin-top: 12px; }
.dialog-actions { margin: 20px 0 0; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.rooflix-btn {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 46px; padding: 0 16px;
  border: 1px solid var(--line-2); border-radius: var(--radius-sm);
  background: #fff; color: var(--ink); font-weight: 700; text-decoration: none;
}
.rooflix-btn:hover { border-color: var(--accent); color: var(--accent-deep); }
.rooflix-btn .rooflix-logo { height: 18px; width: auto; }
.rooflix-btn .rooflix-fallback { color: var(--accent); }

/* subtle yesterday / back-to-today links, below the card */
.game-footer { display: flex; gap: 18px; justify-content: center; min-height: 16px; }
.footer-link {
  background: none; border: 0; padding: 0; cursor: pointer;
  color: var(--faint); font-size: 13px; text-decoration: none;
}
.footer-link:hover { color: var(--accent-deep); text-decoration: underline; }

/* ?avery=love launch-day backdoor — hidden 1-N clip selector */
.avery-strip { display: inline-flex; align-items: center; gap: 5px; }
.avery-strip .avery-heart { color: var(--accent); font-size: 12px; margin-right: 1px; }
.avery-pick {
  min-width: 22px; height: 22px; padding: 0 4px; border-radius: 6px;
  border: 1px solid var(--accent-line); background: var(--accent-soft);
  color: var(--accent-deep); font: inherit; font-size: 12px; font-weight: 700; cursor: pointer;
}
.avery-pick:hover { border-color: var(--accent); }
.avery-pick.active { background: var(--accent-deep); border-color: var(--accent-deep); color: #fff; }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
