/* =========================================================
   DESIGN TOKENS — change the look of the whole site here.
   Direction A: "Midnight and marigold"
   ========================================================= */
:root {
  --bg:        #0F1420;  /* page background (deep midnight) */
  --text:      #EEF0F5;  /* main text */
  --muted:     #9AA3B5;  /* secondary text */
  --line:      #2A3245;  /* thin borders */
  --surface:   #252D40;  /* subtle raised areas (selected pills, menus) */
  --accent:    #F2B33D;  /* marigold: the one accent color */
  --on-accent: #1A1405;  /* text on top of marigold */

  --font-display: "Instrument Serif", "Iowan Old Style", Georgia, serif;
  --font-ui: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;

  --radius-pill: 999px;
  --space-1: 0.5rem;
  --space-2: 1rem;
  --space-3: 1.5rem;
  --space-4: 2.5rem;
  --tap: 44px;           /* minimum touch target size */
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background-color: var(--bg);
  /* Soft ambient light: warm marigold top-left, cool blue bottom-right,
     and a faint warm glow behind the topic. Subtle on purpose. */
  background-image:
    radial-gradient(40rem 32rem at 8% -6%, rgba(242, 179, 61, 0.11), transparent 70%),
    radial-gradient(44rem 34rem at 100% 104%, rgba(78, 110, 210, 0.13), transparent 70%),
    radial-gradient(60rem 30rem at 50% 45%, rgba(242, 179, 61, 0.05), transparent 70%);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
p { margin: 0; }
a { color: inherit; }
button, select, input { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.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;
}

/* ---------- Page layout: header / centered practice area / footer ---------- */
.page {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: var(--space-3) 1.25rem max(var(--space-2), env(safe-area-inset-bottom));
  max-width: 64rem;
  margin: 0 auto;
  transition: transform 0.3s ease-out;   /* slides up when the framework guide opens */
}

/* ---------- Header ---------- */
.brand { text-align: center; }
.brand__name {
  margin: 0;
  font-weight: 400;
  font-family: var(--font-display);
  font-size: 1.75rem;
  line-height: 1.1;
  letter-spacing: -0.01em;
}
.brand__by {
  margin-top: 0.35rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  font-size: 0.8125rem;
  color: var(--muted);
}
/* "alexlayspeaks" in a small, quiet pill with the Instagram icon */
.ig-pill {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0.65rem 0.2rem 0.55rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  color: var(--text);
  font-weight: 500;
  text-decoration: none;
  transition: color 0.15s, border-color 0.15s;
}
.ig-pill:hover { color: var(--accent); border-color: rgba(242, 179, 61, 0.5); }

/* ---------- Practice area ---------- */
.practice {
  flex: 1;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
  padding: var(--space-4) 0;
}

/* ---------- Settings ---------- */
.settings {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
}
.settings__row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.75rem;
  width: 100%;
}

/* Pill-shaped segmented control (used for Topic/Word and difficulty) */
.segmented {
  display: inline-flex;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
}
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.segmented span {
  display: flex;
  align-items: center;
  min-height: calc(var(--tap) - 8px);
  padding: 0 1.25rem;
  border-radius: var(--radius-pill);
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--muted);
  transition: background-color 0.2s, color 0.2s;
  cursor: pointer;
}
.segmented label:hover span { color: var(--text); }
.segmented input:checked + span { background: var(--accent); color: var(--on-accent); }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.segmented--small span { padding: 0 0.9rem; font-size: 0.875rem; }
.segmented--small input:checked + span { background: var(--surface); color: var(--text); }

/* Category dropdown styled as a pill */
.select { position: relative; display: inline-flex; width: min(100%, 17rem); }
.select[hidden] { display: none; }
.select select {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  white-space: nowrap;
  overflow: hidden;
  min-height: var(--tap);
  padding: 0 2.5rem 0 1.25rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  background: transparent;
  font-size: 0.875rem;
  font-weight: 500;
  text-overflow: ellipsis;
  cursor: pointer;
}
.select select:hover { border-color: var(--muted); }
.select select option { background: var(--bg); color: var(--text); }
.select::after {
  content: "";
  position: absolute;
  right: 1.1rem;
  top: 50%;
  width: 7px; height: 7px;
  border-right: 1.5px solid var(--muted);
  border-bottom: 1.5px solid var(--muted);
  transform: translateY(-70%) rotate(45deg);
  pointer-events: none;
}

/* ---------- The topic (hero) ---------- */
.stage {
  text-align: center;
  width: 100%;
  max-width: 46rem;
  min-height: 9rem;  /* keeps the layout from jumping between short and long topics */
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.75rem;
}
.stage__label {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent);
}
.stage__result {
  font-family: var(--font-display);
  font-size: clamp(2.25rem, 7vw, 4.5rem);
  line-height: 1.05;
  letter-spacing: -0.015em;
  text-wrap: balance;
}
/* ---------- Spin animation layer ----------
   The real result text stays in place (invisible) to hold the layout;
   the reel plays on top of it. The layer reaches a little past the text
   so tall letters (g, y, p) are never clipped. */
.stage__result { position: relative; }
.stage__result.is-spinning { color: transparent; }
.reel {
  position: absolute;
  inset: -0.25em -0.5rem;
  overflow: hidden;
  color: var(--text);
  pointer-events: none;
}
/* Words: a soft fade at the top and bottom edges, like a real slot window */
.reel--word {
  inset: -0.12em -0.5rem;
  -webkit-mask-image: linear-gradient(transparent, #000 14%, #000 86%, transparent);
          mask-image: linear-gradient(transparent, #000 14%, #000 86%, transparent);
}
.reel__column { position: absolute; top: 0.12em; left: 0.5rem; right: 0.5rem; will-change: transform; }
.reel__item {
  display: flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
}
/* Topics: each flip sits exactly where the final text will be */
.reel__flip {
  position: absolute;
  top: 0.25em;
  left: 0.5rem;
  right: 0.5rem;
  text-wrap: balance;
  will-change: transform, opacity;
}
.btn.is-busy { pointer-events: none; }

/* Word mode: a single word gets even more room to shine */
.stage--word .stage__result {
  white-space: nowrap;   /* single words never wrap, so the reel lines up exactly */
  font-size: clamp(3rem, 14vw, 7.5rem);
  line-height: 1;
  letter-spacing: -0.02em;
}

/* ---------- Buttons ---------- */
.actions { display: flex; gap: 0.75rem; align-items: center; }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 48px;
  padding: 0 1.75rem;
  border-radius: var(--radius-pill);
  border: 1px solid transparent;
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.12s, background-color 0.2s, border-color 0.2s;
}
.btn:active { transform: scale(0.97); }
.btn--primary {
  background: var(--accent);
  color: var(--on-accent);
  box-shadow: 0 8px 26px -8px rgba(242, 179, 61, 0.55);   /* soft marigold glow */
  transition: transform 0.12s, background-color 0.2s, box-shadow 0.25s;
}
.btn--primary:hover {
  background: #F5C05C;
  box-shadow: 0 10px 32px -8px rgba(242, 179, 61, 0.75);
}
.btn--ghost { background: transparent; border-color: var(--line); color: var(--text); }
.btn--ghost:hover { border-color: var(--muted); }

/* ---------- Timer button on the main page ---------- */
.timer { min-width: 8.5rem; }
.timer__time { font-family: var(--font-display); font-size: 1.375rem; font-weight: 400; line-height: 1; }
.timer__hint { font-size: 0.8125rem; color: var(--muted); font-weight: 500; }

/* ---------- Speaking view: full-screen timer ----------
   Built to be readable from a few meters away on a laptop screen. */
body.is-speaking { overflow: hidden; }
.speak {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: clamp(1.25rem, 4vh, 3rem) 1.25rem max(clamp(1.25rem, 4vh, 2.5rem), env(safe-area-inset-bottom));
  background-color: var(--bg);
  background-image:
    radial-gradient(40rem 32rem at 8% -6%, rgba(242, 179, 61, 0.09), transparent 70%),
    radial-gradient(44rem 34rem at 100% 104%, rgba(78, 110, 210, 0.11), transparent 70%),
    radial-gradient(60rem 30rem at 50% 55%, rgba(242, 179, 61, 0.05), transparent 70%);
  text-align: center;
  animation: speak-in 0.25s ease-out;
}
.speak[hidden] { display: none; }
@keyframes speak-in { from { opacity: 0; } to { opacity: 1; } }

.speak__top { display: flex; flex-direction: column; gap: 0.5rem; max-width: 60rem; }
.speak__topic {
  font-family: var(--font-display);
  font-size: clamp(1.75rem, 4.2vw, 3.5rem);
  line-height: 1.1;
  text-wrap: balance;
}
.speak--word .speak__topic { font-size: clamp(2.25rem, 6vw, 4.5rem); }

.speak__clock {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(0.75rem, 2.5vh, 1.5rem);
  width: 100%;
  min-height: 0;
  container-type: size;   /* lets the ring size itself to the space that's left */
}
/* The ring is as big as the screen allows, and the numbers scale with it */
.ring {
  --ring: min(84vw, 58vh, 40rem);
  --ring: min(84cqw, 96cqh, 40rem);   /* never bigger than the space between topic and buttons */
  position: relative;
  width: var(--ring);
  height: var(--ring);
}
.ring__svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);      /* start the ring at 12 o'clock */
  overflow: visible;
}
.ring__track {
  fill: none;
  stroke: var(--line);
  stroke-width: 1.2;
}
.ring__arc {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-dasharray: 100 100;
  stroke-dashoffset: 0;           /* JS increases this as time runs out */
  transition: stroke-dashoffset 0.12s linear, stroke-width 0.4s;
}
.ring__head circle {
  fill: var(--accent);
  filter: drop-shadow(0 0 1.6px rgba(242, 179, 61, 0.9));
}
.ring__head { transform-origin: 50px 50px; transition: transform 0.12s linear, opacity 0.3s; }

.ring__center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: calc(var(--ring) * 0.03);
}
.speak__time {
  font-family: var(--font-display);
  font-size: calc(var(--ring) * 0.36);
  line-height: 0.85;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  transition: color 0.6s, opacity 0.3s;
}
.speak__note {
  font-size: clamp(0.75rem, calc(var(--ring) * 0.032), 1rem);
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
  transition: color 0.6s;
}
.speak__controls { display: flex; gap: 0.75rem; align-items: center; }
.speak__toggle { min-width: 9rem; }

.speak.is-paused .speak__time { opacity: 0.45; }
.speak.is-paused .ring__head { opacity: 0.4; }

/* Final 10 seconds: the numbers warm up to marigold */
.speak.is-final .speak__time { color: #F7CD7A; }

/* Time's up: full marigold ring + numbers, one gentle pulse */
.speak.is-done .speak__time,
.speak.is-done .speak__note { color: var(--accent); }
.speak.is-done .ring__track { stroke: var(--accent); stroke-width: 2.2; }
.speak.is-done .ring__head { opacity: 0; }
.speak.pulse .ring { animation: time-up 1.2s ease-out 1; }
@keyframes time-up {
  0%   { transform: scale(1);    filter: drop-shadow(0 0 0 rgba(242, 179, 61, 0)); }
  25%  { transform: scale(1.03); filter: drop-shadow(0 0 24px rgba(242, 179, 61, 0.45)); }
  100% { transform: scale(1);    filter: drop-shadow(0 0 0 rgba(242, 179, 61, 0)); }
}

/* Narrow phones: keep the four controls on one line */
@media (max-width: 420px) {
  .speak__controls { gap: 0.5rem; }
  .speak__toggle { min-width: 0; padding: 0 1.25rem; }
  #speak-close { padding: 0 1.1rem; }
}

/* Ticking on/off button: show the matching icon */
#speak-ticks .icon-sound-off { display: none; }
#speak-ticks[aria-pressed="false"] .icon-sound-on { display: none; }
#speak-ticks[aria-pressed="false"] .icon-sound-off { display: block; }

/* Small round icon button (restart) */
.btn--icon {
  width: 48px;
  min-height: 48px;
  padding: 0;
  background: transparent;
  border-color: var(--line);
  color: var(--muted);
}
.btn--icon:hover { color: var(--text); border-color: var(--muted); }
.btn[hidden] { display: none; }

@media (prefers-reduced-motion: reduce) {
  .speak, .speak.pulse .ring { animation: none; }
  .ring__arc, .ring__head { transition: none; }
  .fw-panel { animation: none; }
  .page { transition: none; }
}

/* ---------- Frameworks footer ---------- */
.frameworks { text-align: center; }
.frameworks__toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  min-height: var(--tap);
  padding: 0 1rem;
  border: 0;
  background: none;
  font-size: 0.875rem;
  color: var(--muted);
  cursor: pointer;
}
.frameworks__toggle strong { color: var(--text); font-weight: 500; text-wrap: balance; }
.frameworks__toggle { max-width: 100%; text-align: center; }
.frameworks__toggle:hover strong { color: var(--accent); }
.chev {
  width: 7px; height: 7px; margin-left: 0.35rem;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: translateY(-2px) rotate(45deg);
}

.frameworks__toggle[aria-expanded="true"] .chev { transform: translateY(2px) rotate(225deg); }

/* ---------- Framework guide panel (slides up from the bottom) ---------- */
.fw-panel {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 5;
  width: min(100%, 34rem);
  max-height: 85vh;
  max-height: 85dvh;
  overflow-y: auto;
  transform: translateX(-50%);
  padding: 1rem 1.25rem max(1.5rem, env(safe-area-inset-bottom));
  background: #141A28;
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.35);
  animation: fw-up 0.25s ease-out;
}
.fw-panel[hidden] { display: none; }
@keyframes fw-up {
  from { transform: translate(-50%, 24px); opacity: 0; }
  to   { transform: translate(-50%, 0);    opacity: 1; }
}

.fw-panel__head { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; }
.fw-tabs {
  display: inline-flex;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
}
.fw-tab {
  position: relative;
  min-height: 36px;
  padding: 0 1rem;
  border: 0;
  border-radius: var(--radius-pill);
  background: none;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  transition: background-color 0.2s, color 0.2s;
}
.fw-tab:hover { color: var(--text); }
.fw-tab[aria-selected="true"] { background: var(--surface); color: var(--text); }
/* a small marigold dot marks the recommended framework */
.fw-tab.is-recommended::after {
  content: "";
  position: absolute;
  top: 6px;
  right: 7px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
}
.fw-close {
  display: grid;
  place-items: center;
  width: var(--tap);
  height: var(--tap);
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--muted);
  cursor: pointer;
}
.fw-close:hover { color: var(--text); }

.fw-body { padding-top: 1.1rem; }
.fw-title { margin: 0; font-family: var(--font-display); font-weight: 400; font-size: 1.6rem; line-height: 1.15; }
.fw-purpose { margin-top: 0.25rem; color: var(--muted); font-size: 0.9375rem; }
.fw-steps {
  list-style: none;
  margin: 1rem 0 0;
  padding: 0;
  display: grid;
  gap: 0.55rem;
}
.fw-steps li {
  display: grid;
  grid-template-columns: 5.25rem 1fr;
  gap: 0.75rem;
  font-size: 0.9375rem;
  line-height: 1.4;
}
.fw-steps strong { color: var(--accent); font-weight: 600; }
.fw-example {
  margin-top: 1rem;
  padding-left: 0.85rem;
  border-left: 2px solid var(--line);
  font-family: var(--font-display);
  font-size: 1.05rem;
  line-height: 1.4;
  color: var(--muted);
}
.fw-arrow { margin: 0 0.4rem; color: var(--accent); }
.fw-good { margin-top: 1rem; font-size: 0.8125rem; color: var(--muted); }
.fw-good span:first-child {
  margin-right: 0.35rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-size: 0.6875rem;
  color: var(--text);
}

/* ---------- Gentle fade-in when the page opens ----------
   Each part rises softly into place, one after another. */
@keyframes rise-in {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}
.brand, .settings, .stage, .actions, .frameworks {
  animation: rise-in 0.6s cubic-bezier(0.2, 0.7, 0.2, 1) both;
}
.settings   { animation-delay: 0.08s; }
.stage      { animation-delay: 0.16s; }
.actions    { animation-delay: 0.24s; }
.frameworks { animation-delay: 0.32s; }
@media (prefers-reduced-motion: reduce) {
  .brand, .settings, .stage, .actions, .frameworks { animation: none; }
}

/* ---------- Touch screens: every tap target at least 44px tall ---------- */
@media (pointer: coarse) {
  .segmented span { min-height: var(--tap); }
  .fw-tab { min-height: var(--tap); }
  /* invisible larger tap area around the Instagram pill, same look */
  .ig-pill::after { content: ""; position: absolute; inset: -10px -6px; }
}

/* ---------- Short screens (small phones): tighter spacing ---------- */
@media (max-height: 700px) {
  .page { padding-top: 1rem; }
  .practice { gap: 1.25rem; padding: 1.25rem 0; }
  .settings { gap: 0.5rem; }
  .stage { min-height: 0; }
}

/* ---------- Larger screens ---------- */
@media (min-width: 640px) {
  .page { padding-top: var(--space-4); }
  .brand__name { font-size: 2rem; }
}

/* ---------- Phones turned sideways (wide but short) ----------
   Use the width instead of the height: header on one line, all
   settings in one row, and the topic/word sized to the screen height,
   so everything fits without scrolling. */
@media (orientation: landscape) and (max-height: 500px) {
  .page { padding: 0.5rem 1.25rem max(0.25rem, env(safe-area-inset-bottom)); }

  .brand { display: flex; align-items: center; justify-content: center; gap: 0.75rem; }
  .brand__name { font-size: 1.35rem; }
  .brand__by { margin-top: 0; }

  .practice { gap: clamp(0.5rem, 3vh, 1rem); padding: 0.5rem 0; }
  .settings { flex-direction: row; flex-wrap: wrap; justify-content: center; gap: 0.5rem; }
  .settings__row { width: auto; gap: 0.5rem; }
  .select { width: 15rem; }

  .stage { min-height: 0; gap: 0.35rem; }
  .stage__label { font-size: 0.6875rem; }
  .stage__result { font-size: clamp(1.4rem, 8.5vh, 2.6rem); }
  .stage--word .stage__result { font-size: clamp(2.5rem, 19vh, 5rem); }

  .btn { min-height: 44px; }
  .frameworks__toggle { min-height: 36px; }
}
