:root {
  --bg: #fdf6ec;
  --card: #ffffff;
  --ink: #3b3024;
  --muted: #8a7d6b;
  --teal: #0f766e;
  --teal-dark: #0b5751;
  --teal-tint: #e6f2f1;
  --marigold: #f6a821;
  --marigold-tint: #fdeeD2;
  --orange: #e2711d;
  --red: #d64545;
  --ok: #2f7d4f;
  --ok-tint: #e8f4ec;
  --bad-tint: #fbeaea;
  --locked: #d8cfc2;
  --radius: 16px;
  --shadow: 0 2px 12px rgba(59, 48, 36, 0.09);
  font-family: "Avenir Next", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  /* dvh, not vh: on mobile browsers 100vh includes the retracted URL bar, so
     content sits underneath it until the user scrolls. */
  min-height: 100dvh;
  /* iOS paints a grey box over any tapped element; we have our own :active. */
  -webkit-tap-highlight-color: transparent;
}

/* The layout is a phone-width column at every size — on a laptop it simply
   centres. One shape everywhere is what keeps the two clients consistent. */
.app {
  max-width: 640px;
  margin: 0 auto;
  padding:
    calc(24px + env(safe-area-inset-top))
    calc(16px + env(safe-area-inset-right))
    calc(80px + env(safe-area-inset-bottom))
    calc(16px + env(safe-area-inset-left));
}

h1, h2, h3 { margin: 0.2em 0; }

.subtitle { color: var(--muted); margin-bottom: 24px; }

button {
  font: inherit;
  cursor: pointer;
  border: none;
  border-radius: var(--radius);
  /* Opts out of double-tap-to-zoom, which otherwise delays every tap ~300ms. */
  touch-action: manipulation;
  /* Stops a long press on a word chip from starting a text selection. */
  -webkit-user-select: none;
  user-select: none;
}

/* Anything tappable clears the 44px minimum touch target. */
.btn, .choice, .chip, .lesson-node, .profile-card, .emoji-option,
.speak-btn, .quit, .sound-toggle, .linkish, .google-btn { min-height: 44px; }

/* ---------- Buttons ---------- */
.btn {
  padding: 14px 28px;
  font-weight: 700;
  font-size: 1rem;
  background: var(--teal);
  color: white;
  box-shadow: var(--shadow);
  transition: background 0.15s, transform 0.05s;
  /* Set here as well as on `button`, since the Google sign-in .btn is an
     <a> and was rendering square while every other button was rounded. */
  border-radius: var(--radius);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { background: var(--locked); color: #7d7466; cursor: not-allowed; }
.btn.secondary { background: white; color: var(--ink); border: 2px solid #e8dfd2; }
.btn.danger { background: var(--red); }

/* ---------- Login & account ---------- */
.login-view { text-align: left; }
.login-view .google-btn {
  display: inline-block;
  text-decoration: none;
  margin-top: 6px;
}
.account-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 4px;
}
.account-pic { width: 26px; height: 26px; border-radius: 50%; }
/* Only rendered when the local dev bypass is enabled; muted so it never
   reads as the normal way in. */
.dev-login { color: var(--muted); font-size: 0.85rem; margin-top: 18px; }
.dev-login a { color: var(--orange); font-weight: 700; }
.linkish {
  background: none;
  color: var(--orange);
  font-weight: 700;
  padding: 0 8px;
  font-size: 0.9rem;
}

/* ---------- Profile picker ---------- */
.profiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 14px;
  margin: 20px 0;
}
.profile-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 10px;
  text-align: center;
  border: 2px solid transparent;
  transition: transform 0.1s;
}
.profile-card:active { transform: scale(0.97); }
.profile-card .avatar { font-size: 2.6rem; }
.profile-card .name { font-weight: 700; margin-top: 6px; }
.profile-card .tally { color: var(--muted); font-size: 0.85rem; }

.new-profile {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-top: 10px;
}
.new-profile input[type="text"] {
  font: inherit;
  padding: 12px 14px;
  border: 2px solid #e8dfd2;
  border-radius: 12px;
  width: 100%;
  margin-bottom: 12px;
}
.emoji-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.emoji-option {
  font-size: 1.6rem;
  background: var(--bg);
  border-radius: 12px;
  padding: 6px 10px;
  min-width: 44px;
  border: 2px solid transparent;
}
.emoji-option.selected { border-color: var(--teal); background: var(--teal-tint); }

/* ---------- Dashboard ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
  gap: 10px;
}
.topbar .who { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.topbar .who .avatar { font-size: 1.8rem; }
.stats { display: flex; gap: 10px; }
.pill {
  background: var(--card);
  border-radius: 999px;
  box-shadow: var(--shadow);
  padding: 8px 14px;
  font-weight: 700;
  font-size: 0.95rem;
  white-space: nowrap;
}
.pill.josh.dead { filter: grayscale(1); opacity: 0.6; }

.mascot {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin: 18px 0 26px;
}
.mascot .rick { font-size: 3rem; transform: scaleX(-1); }
.speech {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 16px;
  position: relative;
  flex: 1;
}
.speech::before {
  content: "";
  position: absolute;
  left: -8px;
  top: 20px;
  border: 8px solid transparent;
  border-right-color: var(--card);
  border-left: 0;
}

.unit { margin-bottom: 28px; }
.unit-header {
  background: linear-gradient(120deg, var(--marigold), var(--orange));
  color: #3a2606;
  border-radius: var(--radius);
  padding: 14px 18px;
  box-shadow: var(--shadow);
}
.unit-header.locked { background: var(--locked); color: #7d7466; }
.unit-header p { margin: 4px 0 0; font-size: 0.9rem; opacity: 0.85; }

.lesson-path { display: flex; flex-direction: column; gap: 10px; padding: 16px 0 0 22px; }
.lesson-node {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 16px;
  width: 100%;
  text-align: left;
  border: 2px solid transparent;
}
.lesson-node:not(:disabled):active { transform: scale(0.99); border-color: var(--marigold); }
.lesson-node:disabled { opacity: 0.55; cursor: not-allowed; }
.lesson-node .bubble {
  width: 44px; height: 44px;
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: 1.3rem;
  background: var(--marigold-tint);
  border: 2px solid var(--marigold);
  flex-shrink: 0;
}
.lesson-node.completed .bubble { background: var(--teal-tint); border-color: var(--teal); }
.lesson-node.locked .bubble { background: var(--bg); border-color: var(--locked); }
.lesson-node .meta { flex: 1; }
.lesson-node .meta .title { font-weight: 700; }
.lesson-node .meta .sub { color: var(--muted); font-size: 0.85rem; }

/* ---------- Lesson player ---------- */
.lesson-top { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.quit { background: none; font-size: 1.4rem; color: var(--muted); padding: 4px 12px; min-width: 44px; }
.progress-track {
  flex: 1;
  height: 14px;
  background: #eadfce;
  border-radius: 999px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--marigold), var(--orange));
  border-radius: 999px;
  transition: width 0.3s ease;
}

.exercise-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}
.exercise-card .kicker {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--orange);
}
.exercise-card h2 { font-size: 1.3rem; margin: 8px 0 20px; }
.exercise-card.shake { animation: shake 0.4s; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-8px); }
  75% { transform: translateX(8px); }
}

.choices { display: flex; flex-direction: column; gap: 10px; }
.choice {
  padding: 14px 16px;
  background: var(--bg);
  border: 2px solid #e8dfd2;
  border-radius: 14px;
  font-weight: 600;
  text-align: left;
  font-size: 1rem;
}
.choice.selected { border-color: var(--teal); background: var(--teal-tint); }

.fill-input {
  font: inherit;
  font-size: 1.1rem;
  padding: 14px;
  width: 100%;
  border: 2px solid #e8dfd2;
  border-radius: 14px;
}

.word-bank, .word-answer { display: flex; flex-wrap: wrap; gap: 8px; min-height: 52px; }
.word-answer {
  border-bottom: 2px dashed #d8cfc2;
  padding-bottom: 10px;
  margin-bottom: 16px;
}
.chip {
  padding: 10px 16px;
  background: var(--bg);
  border: 2px solid #e8dfd2;
  border-radius: 12px;
  font-weight: 600;
  font-size: 1rem;
}
.chip.in-answer { background: var(--marigold-tint); border-color: var(--marigold); }
.chip.ghost { opacity: 0.25; pointer-events: none; }

.hint { color: var(--muted); font-size: 0.9rem; margin-top: 16px; }
.hint button {
  background: none;
  color: var(--orange);
  font-weight: 700;
  padding: 10px 0;
  min-height: 44px;
}

.actions { margin-top: 22px; display: flex; justify-content: flex-end; }

.feedback {
  margin-top: 18px;
  border-radius: 14px;
  padding: 14px 16px;
  font-weight: 600;
  animation: pop 0.2s ease;
}
.feedback.good { background: var(--ok-tint); color: var(--ok); }
.feedback.bad { background: var(--bad-tint); color: #a52f2f; }
.feedback .ans { font-weight: 800; }
@keyframes pop { from { transform: scale(0.95); opacity: 0; } }

/* ---------- Results ---------- */
.results {
  text-align: center;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 40px 24px;
}
.results .big { font-size: 4rem; }
.results .quip { font-size: 1.1rem; margin: 10px 0 22px; }
.result-pills { display: flex; justify-content: center; gap: 12px; flex-wrap: wrap; margin-bottom: 26px; }
.result-pill {
  background: var(--bg);
  border-radius: 14px;
  padding: 12px 18px;
  font-weight: 800;
}
.result-pill .label { display: block; font-size: 0.7rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }

/* ---------- Confetti ---------- */
#confetti-layer { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 50; }
.confetto {
  position: absolute;
  top: -20px;
  width: 10px; height: 14px;
  animation: fall linear forwards;
}
@keyframes fall {
  to { transform: translateY(110dvh) rotate(720deg); }
}

.fade-in { animation: fadeIn 0.25s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } }

.speak-btn {
  background: var(--teal-tint);
  border: 2px solid var(--teal);
  color: var(--teal-dark);
  border-radius: 999px;
  padding: 4px 14px;
  font-size: 0.9rem;
  font-weight: 700;
  vertical-align: middle;
  /* inline-flex so the text stays centred inside the 44px touch target */
  display: inline-flex;
  align-items: center;
}
.speak-btn:active { background: var(--teal); color: white; }

.sound-toggle {
  position: fixed;
  /* Clears the home indicator on a full-screen iPhone. */
  right: calc(18px + env(safe-area-inset-right));
  bottom: calc(18px + env(safe-area-inset-bottom));
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--card);
  box-shadow: var(--shadow);
  font-size: 1.3rem;
  z-index: 40;
}
.sound-toggle:active { transform: scale(0.92); }

/* ---------- Pointer-only enhancements ----------
   Hover styling is gated behind a real pointer. On a touchscreen a tap
   satisfies :hover and the style then sticks until the user taps elsewhere,
   which left lesson nodes and profile cards looking selected after you'd
   moved on. Touch feedback comes from the :active rules above instead. */
@media (hover: hover) and (pointer: fine) {
  .btn:hover { background: var(--teal-dark); }
  .btn.secondary:hover { background: var(--bg); }
  .btn.danger:hover { background: #b73535; }
  .profile-card:hover { transform: translateY(-3px); border-color: var(--marigold); }
  .lesson-node:not(:disabled):hover { border-color: var(--marigold); }
  .speak-btn:hover { background: var(--teal); color: white; }
  .sound-toggle:hover { transform: scale(1.08); }
}

.error-banner {
  background: var(--bad-tint);
  color: #a52f2f;
  padding: 12px 16px;
  border-radius: 12px;
  margin-bottom: 16px;
  font-weight: 600;
}
