/* Learn English — mobile-first styles (R8). */

*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --bg: #fff8e1;
  --surface: #ffffff;
  --text: #2b2118;
  --muted: #5c4a36;
  --play: #15803d;          /* white text 5.0:1 */
  --play-dark: #166534;
  --answer-0: #1d4ed8;      /* white text 6.7:1 */
  --answer-0-dark: #1e40af;
  --answer-1: #7e22ce;      /* white text 6.9:1 */
  --answer-1-dark: #6b21a8;
  --accent: #f59e0b;
  --star: #f59e0b;
  --star-empty: #e7dcc4;
  --try: #9a3412;           /* on --bg 6.9:1 */
  --focus: #0f172a;
  --radius: 24px;
  --tap: 64px;              /* minimum touch target (R8.2) */
  --font: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

.sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

#app {
  flex: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
}

.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: max(16px, env(safe-area-inset-top)) 16px 16px;
  text-align: center;
  position: relative;
}

.screen[hidden] {
  display: none;
}

h1,
h2 {
  margin: 0;
  font-size: clamp(2.25rem, 9vw, 3.5rem);
  line-height: 1.1;
  font-weight: 800;
}

/* ---------- Buttons ---------- */

.btn {
  min-height: var(--tap);
  min-width: var(--tap);
  border: 0;
  border-radius: var(--radius);
  font: inherit;
  font-weight: 800;
  color: #fff;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: 0 6px 0 rgb(0 0 0 / 0.18);
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}

.btn:active:not(:disabled) {
  transform: translateY(4px);
  box-shadow: 0 2px 0 rgb(0 0 0 / 0.18);
}

.btn:disabled {
  opacity: 0.6;
  cursor: default;
}

.btn:focus-visible,
.btn-speaker:focus-visible,
.credits a:focus-visible {
  outline: 4px solid var(--focus);
  outline-offset: 3px;
}

.btn-play {
  background: var(--play);
  font-size: 2rem;
  padding: 16px 56px;
  min-height: 80px;
}

.btn-play:hover:not(:disabled) {
  background: var(--play-dark);
}

.btn-speaker {
  flex: none;
  width: var(--tap);
  height: var(--tap);
  border: 3px solid var(--text);
  border-radius: 50%;
  background: var(--surface);
  color: var(--text);
  display: grid;
  place-items: center;
  cursor: pointer;
  touch-action: manipulation;
  padding: 0;
}

.btn-speaker svg {
  width: 32px;
  height: 32px;
}

/* Back to start (R5b); sits above the popup so it works mid-celebration. */
.btn-exit {
  position: fixed;
  top: max(8px, env(safe-area-inset-top));
  right: max(8px, env(safe-area-inset-right));
  z-index: 20;
  width: var(--tap);
  height: var(--tap);
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text);
  display: grid;
  place-items: center;
  cursor: pointer;
  touch-action: manipulation;
  padding: 0;
}

.btn-exit[hidden] {
  display: none;
}

.btn-exit svg {
  width: 36px;
  height: 36px;
}

.btn-exit:hover {
  background: rgb(43 33 24 / 0.08);
}

.btn-exit:focus-visible {
  outline: 4px solid var(--focus);
  outline-offset: 2px;
}

.no-speech .btn-speaker {
  display: none;   /* R6.4 */
}

/* ---------- Start ---------- */

.start-emojis {
  display: flex;
  gap: 8px;
}

.start-emojis img {
  width: clamp(72px, 22vw, 120px);
  height: auto;
}

.start-emojis img:nth-child(2) {
  transform: translateY(-12px);
}

.tagline {
  margin: 0;
  font-size: 1.375rem;
  color: var(--muted);
  font-weight: 700;
}

.start-error {
  margin: 0;
  color: var(--try);
  font-weight: 700;
  font-size: 1.125rem;
}

/* ---------- Question ---------- */

.progress {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  justify-content: center;
}

.progress-text {
  font-weight: 800;
  font-size: 1.25rem;
  min-width: 4.5ch;
}

.progress-dots {
  display: flex;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.progress-dots li {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--star-empty);
}

.progress-dots li.done {
  background: var(--accent);
}

.progress-dots li.current {
  background: var(--text);
}

/* Keep the progress row clear of the fixed X button on phones. */
@media (max-width: 479px) {
  .progress {
    justify-content: flex-start;
    padding-right: 72px;
    min-height: 48px;
  }

  .progress-dots {
    gap: 4px;
  }

  .progress-dots li {
    width: 10px;
    height: 10px;
  }
}

.question-emoji {
  width: min(60vw, 34dvh, 280px);
  height: auto;
  aspect-ratio: 1;
  margin-top: 4px;
}

.prompt-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.prompt-text {
  margin: 0;
  font-size: clamp(1.75rem, 7vw, 2.5rem);
  font-weight: 800;
}

.options {
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: 100%;
  max-width: 560px;
}

.option {
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn-answer {
  flex: 1;
  min-height: 80px;
  padding: 12px 16px;
  font-size: clamp(1.75rem, 7vw, 2.25rem);  /* ≥ 28px */
  overflow-wrap: anywhere;
}

.btn-answer-0 {
  background: var(--answer-0);
}

.btn-answer-1 {
  background: var(--answer-1);
}

@media (hover: hover) {
  .btn-answer-0:hover:not(:disabled) { background: var(--answer-0-dark); }
  .btn-answer-1:hover:not(:disabled) { background: var(--answer-1-dark); }
}

.btn-answer.correct {
  background: var(--play);
  outline: 6px solid var(--accent);
}

.btn-answer.shake {
  animation: shake 0.45s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-12px); }
  40% { transform: translateX(10px); }
  60% { transform: translateX(-8px); }
  80% { transform: translateX(6px); }
}

.feedback {
  margin: 0;
  min-height: 2.5rem;
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--try);
}

@media (min-width: 480px) {
  .options {
    flex-direction: row;
  }

  .option {
    flex: 1;
    flex-direction: column;
  }

  .btn-answer {
    width: 100%;
  }
}

/* Short phones (e.g. 320x568): keep both answers above the fold. */
@media (max-height: 700px) {
  .screen-question {
    justify-content: flex-start;
    gap: 10px;
    padding-top: max(10px, env(safe-area-inset-top));
  }

  .question-emoji {
    width: min(60vw, 26dvh, 280px);
    margin-top: 0;
  }

  .options {
    gap: 10px;
  }

  .btn-answer {
    min-height: 68px;
  }

  .feedback {
    min-height: 2rem;
    font-size: 1.5rem;
  }

  .credits {
    padding-top: 2px;
    padding-bottom: max(6px, env(safe-area-inset-bottom));
    font-size: 0.75rem;
    line-height: 1.25;
  }
}

/* ---------- Good job popup ---------- */

.popup {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgb(43 33 24 / 0.35);
  z-index: 10;
  padding: 16px;
}

.popup[hidden] {
  display: none;
}

.popup-card {
  background: var(--surface);
  border-radius: 32px;
  padding: 24px 40px 28px;
  box-shadow: 0 12px 40px rgb(0 0 0 / 0.25);
  animation: pop 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  max-width: 100%;
}

.popup-star {
  display: block;
  font-size: 5rem;
  line-height: 1;
  color: var(--star);
  animation: spin 0.8s ease;
}

.popup-text {
  margin: 8px 0 0;
  font-size: clamp(2.25rem, 10vw, 3rem);
  font-weight: 800;
  color: var(--play);
}

.popup-full {
  margin: 8px 0 0;
  font-size: 1.375rem;
  font-weight: 700;
  color: var(--muted);
}

/* ---------- Stop confirmation (R5b) ---------- */

.confirm {
  z-index: 30;   /* above the Good job popup and the X button */
}

.confirm .popup-card {
  padding: 24px 20px 28px;
}

.confirm-title {
  margin: 0 0 20px;
  font-size: clamp(1.75rem, 8vw, 2.25rem);
  font-weight: 800;
}

.confirm-actions {
  display: flex;
  gap: 16px;
  justify-content: center;
}

.confirm-actions .btn {
  min-width: 96px;
  font-size: 1.75rem;
  padding: 12px 24px;
}

.btn-stop {
  background: var(--try);
}

.btn-keep {
  background: var(--play);
}

@keyframes pop {
  from { transform: scale(0.4); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

@keyframes spin {
  from { transform: rotate(-180deg) scale(0.3); }
  to { transform: rotate(0) scale(1); }
}

/* ---------- Result ---------- */

.result-emoji {
  width: clamp(112px, 32vw, 160px);
  height: auto;
}

.result-stars {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.result-stars li {
  font-size: clamp(2.5rem, 12vw, 3.5rem);
  line-height: 1;
  color: var(--star-empty);
}

.result-stars li.filled {
  color: var(--star);
  animation: pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) both;
  animation-delay: calc(var(--i, 0) * 120ms);
}

.result-count {
  margin: 0;
  font-size: 1.375rem;
  font-weight: 700;
  color: var(--muted);
}

.confetti {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 5;
}

.confetti span {
  position: absolute;
  top: -20px;
  width: 12px;
  height: 18px;
  border-radius: 3px;
  animation: fall var(--d, 3s) linear var(--delay, 0s) forwards;
}

@keyframes fall {
  to { transform: translate(var(--x, 0), 110dvh) rotate(var(--r, 720deg)); }
}

/* ---------- Footer ---------- */

.credits {
  padding: 8px 16px max(12px, env(safe-area-inset-bottom));
  text-align: center;
  font-size: 0.875rem;
  color: var(--muted);
}

/* One line on every width: the text shrinks on narrow phones instead of wrapping. */
.credits {
  white-space: nowrap;
  padding-left: 8px;
  padding-right: 8px;
  font-size: clamp(0.625rem, 3.3vw, 0.875rem);
}

.credits .sep {
  margin: 0 4px;
}

.credits a {
  color: inherit;
}

/* ---------- Reduced motion (R8.4) ---------- */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }

  .confetti {
    display: none;
  }
}
