/* Keep It Alive: light, quiet, projector-first.
   Palette and fonts follow the Phrasal Verb Practice page, with stronger
   colors where projectors wash things out (the bar, tier labels). */

:root {
  color-scheme: light;
  --bg: #F7F7F5;
  --surface: #FFFFFF;
  --ink: #23272E;
  --muted: #565B63;
  --faint: #8A8F96;
  --line: #E3E3DD;
  --marker: #F5E9B8;
  --marker-strong: #EED98A;

  --green: #3E9A68;
  --amber: #D9962A;
  --red: #CF4F58;

  --weak: #8A8F96;  --weak-soft: #EEEEEA;
  --good: #3E7FB8;  --good-soft: #E3EDF7;
  --great: #3E9A68; --great-soft: #E2F2E8;
  --listen: #C0563F; --listen-soft: #F9E6E1;

  --c: #4E8A6C;      /* character color, set by JS */
  --c-soft: #E4EDE7;

  --font-display: "Instrument Sans", "Helvetica Neue", "Segoe UI", system-ui, sans-serif;
  --font-body: "Atkinson Hyperlegible", "Verdana", "Segoe UI", system-ui, sans-serif;

  /* 1rem ≈ 20px on a 1920×1080 projector; scales with the window. */
  font-size: clamp(13px, min(1.05vw, 1.9vh), 28px);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.45;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
button:focus-visible, input:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; }
mark { background: var(--marker); color: var(--ink); border-radius: 0.2em; padding: 0 0.15em; }

.screen { height: 100vh; height: 100dvh; padding: 2.2vh 3vw; }

.eyebrow {
  font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.14em;
  color: var(--muted); margin: 0;
}

/* Buttons */
.primary {
  background: var(--ink); color: #fff; border: 0; border-radius: 999px;
  padding: 0.7em 1.6em; font-weight: 700; font-size: 1.1rem; min-height: 3rem;
  transition: opacity .15s, transform .15s;
}
.primary:hover:not(:disabled) { opacity: .88; }
.primary:active:not(:disabled) { transform: scale(0.97); }
.primary:disabled { opacity: .35; cursor: default; }
.ghost {
  background: var(--surface); border: 1.5px solid var(--line); border-radius: 999px;
  padding: 0.5em 1.2em; font-weight: 700; font-size: 1rem; min-height: 2.8rem;
  transition: border-color .15s, background .15s;
}
.ghost:hover { border-color: var(--ink); }
.big { font-size: 1.25rem; min-height: 3.4rem; padding: 0.7em 1.8em; }
.link {
  background: none; border: 0; padding: 0.2em 0.4em; text-decoration: underline;
  color: var(--muted); font-weight: 400;
}

/* Avatar */
.avatar {
  width: 4.2rem; height: 4.2rem; border-radius: 50%; flex: none;
  display: grid; place-items: center;
  background: var(--c); color: #fff;
  font-family: var(--font-display); font-weight: 600; font-size: 1.5rem; letter-spacing: 0.02em;
}

/* ───────────── 1. SETUP ───────────── */
#setup { display: flex; flex-direction: column; gap: 3.2vh; justify-content: center; }
.setup-head { display: flex; flex-direction: column; gap: 0.6rem; }
.setup-head h1 {
  font-family: var(--font-display); font-weight: 500; font-size: 4.2rem;
  letter-spacing: -0.035em; line-height: 1; margin: 0;
}
.setup-head h1 .alive { color: var(--green); }
.lead { margin: 0; font-size: 1.3rem; color: var(--muted); max-width: 52ch; }
.lead mark { color: var(--ink); }

.cards { display: grid; grid-template-columns: repeat(5, 1fr); gap: 1.1rem; }
.card {
  --c: #999; --c-soft: #eee;
  text-align: left; background: var(--surface); border: 2px solid var(--line);
  border-radius: 1.1rem; padding: 1.3rem 1.2rem 1.2rem;
  display: flex; flex-direction: column; gap: 0.7rem; min-height: 15rem;
  transition: border-color .2s, transform .2s, background .2s, box-shadow .2s;
}
.card:hover { transform: translateY(-3px); border-color: var(--c); }
.card[aria-pressed="true"] {
  border-color: var(--c); background: var(--c-soft);
  box-shadow: 0 0 0 3px var(--c) inset;
}
.card .who { display: flex; align-items: center; gap: 0.8rem; }
.card .avatar { width: 3.4rem; height: 3.4rem; font-size: 1.2rem; }
.card strong { font-family: var(--font-display); font-weight: 600; font-size: 1.35rem; line-height: 1.1; display: block; }
.card .age { color: var(--muted); font-size: 0.95rem; }
.card .topic {
  align-self: flex-start; font-size: 0.8rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--c); background: var(--c-soft);
  border-radius: 999px; padding: 0.25em 0.8em;
}
.card[aria-pressed="true"] .topic { background: var(--surface); }
.card p { margin: 0; font-size: 1.05rem; color: var(--ink); line-height: 1.35; }

.setup-row { display: flex; align-items: flex-end; gap: 2.4rem; flex-wrap: wrap; }
.ctl { display: flex; flex-direction: column; gap: 0.45rem; }
.ctl-label { font-size: 0.9rem; color: var(--muted); }
.stepper {
  display: flex; align-items: center; background: var(--surface);
  border: 1.5px solid var(--line); border-radius: 999px; padding: 0.25rem;
}
.stepper button {
  width: 3rem; height: 3rem; border-radius: 50%; border: 0; background: var(--bg);
  font-size: 1.6rem; line-height: 1; font-weight: 700;
}
.stepper button:hover { background: var(--line); }
.stepper output {
  min-width: 5.5ch; text-align: center; font-family: var(--font-display);
  font-weight: 600; font-size: 1.4rem; font-variant-numeric: tabular-nums;
}
#pass {
  height: 3.6rem; width: 15rem; padding: 0 1.1rem; border-radius: 0.8rem;
  border: 1.5px solid var(--line); background: var(--surface); color: var(--ink); font-size: 1.2rem;
}
.saved { height: 3.6rem; display: flex; align-items: center; gap: 0.6rem; font-size: 1.15rem; color: var(--green); font-weight: 700; }
#startBtn { margin-left: auto; min-width: 12rem; }
.msg { margin: 0; min-height: 1.5em; color: var(--red); font-size: 1.1rem; }

/* ───────────── 2. GAME ───────────── */
#game {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto auto;
  gap: 1.6vh;
  background: linear-gradient(var(--c-soft), var(--bg) 40vh) no-repeat, var(--bg);
}

.topbar { display: flex; flex-direction: column; gap: 1vh; }
.bar {
  position: relative; height: 3.2rem; border-radius: 999px; overflow: hidden;
  background: var(--surface); border: 2px solid var(--line);
}
.fill {
  position: absolute; inset: 0 auto 0 0; width: 100%;
  background: var(--green); border-radius: 999px;
  transition: background-color .6s;
}
.fill.amber { background: var(--amber); }
.fill.red { background: var(--red); }
.fill.pulse { animation: pulse 0.9s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.55; } }
.bar.held .fill {
  background-image: repeating-linear-gradient(-45deg, rgba(255,255,255,.22) 0 12px, transparent 12px 24px);
}
.bar-label {
  position: absolute; right: 1.2rem; top: 50%; transform: translateY(-50%);
  font-family: var(--font-display); font-weight: 700; font-size: 1rem; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--ink);
  background: rgba(255,255,255,.85); border-radius: 999px; padding: 0.15em 0.8em;
}
.bar-label:empty { display: none; }

.status { display: flex; align-items: center; gap: 1.4rem; }
.turns { display: flex; align-items: baseline; gap: 0.4rem; color: var(--muted); }
.turns b { font-family: var(--font-display); font-size: 1.7rem; font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; }
.chips { display: flex; gap: 0.45rem; flex-wrap: wrap; }
.chip {
  font-size: 0.85rem; font-weight: 700; padding: 0.3em 0.85em; border-radius: 999px;
  border: 1.5px dashed var(--line); color: var(--faint); background: transparent;
  transition: all .35s;
}
.chip.on { border: 1.5px solid var(--c); background: var(--c); color: #fff; }
.chip.flash { animation: chipPop .6s ease-out; }
@keyframes chipPop { 40% { transform: scale(1.25); } }
.reveals { font-weight: 700; color: var(--muted); font-size: 1rem; white-space: nowrap; }
.reveals .star { color: var(--faint); font-size: 1.2rem; }
.reveals .star.on { color: var(--amber); }
.tools { margin-left: auto; display: flex; gap: 0.6rem; }
#pauseBtn.on { background: var(--ink); color: #fff; border-color: var(--ink); }
#endBtn.confirm { background: var(--red); color: #fff; border-color: var(--red); }
#stuckBtn.on { background: var(--marker); border-color: var(--marker-strong); }

.stage { display: flex; gap: 2rem; align-items: stretch; min-height: 0; }
.speaker {
  width: 9.5rem; flex: none; display: flex; flex-direction: column; align-items: center;
  gap: 0.35rem; padding-top: 2.4rem; text-align: center;
}
.speaker .avatar { width: 6.4rem; height: 6.4rem; font-size: 2.2rem; transition: box-shadow .3s; }
.speaker.busy .avatar { animation: ring 1.4s ease-in-out infinite; }
@keyframes ring { 50% { box-shadow: 0 0 0 0.6rem var(--c-soft); } }
.speaker b { font-family: var(--font-display); font-size: 1.25rem; font-weight: 600; }
.speaker > span { font-size: 0.85rem; color: var(--muted); }
.thinking { color: var(--c) !important; font-weight: 700; font-size: 1rem !important; }
.thinking i { font-style: normal; animation: dot 1.2s infinite; }
.thinking i:nth-child(2) { animation-delay: .2s; }
.thinking i:nth-child(3) { animation-delay: .4s; }
@keyframes dot { 0%, 60%, 100% { opacity: .2; } 30% { opacity: 1; } }

.talk { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 0.6rem; min-height: 0; }
.asked {
  margin: 0; font-size: 1.35rem; color: var(--muted); min-height: 1.5em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.asked b { color: var(--ink); font-weight: 700; }
.bubble {
  position: relative; flex: 1; min-height: 0; overflow: hidden;
  background: var(--surface); border: 2px solid var(--line); border-radius: 1.6rem;
  border-top-left-radius: 0.4rem;
  padding: 1.6rem 2.2rem; display: flex; align-items: center;
  box-shadow: 0 0.3rem 1.4rem rgba(35,39,46,.05);
}
.bubble p {
  margin: 0; font-size: 2.2rem; line-height: 1.38; letter-spacing: -0.005em;
  transition: opacity .25s;
}
.bubble.waiting p { opacity: 0.25; }
.bubble.fresh { animation: bubbleIn .35s ease-out; }
@keyframes bubbleIn { from { transform: translateY(0.6rem); opacity: 0; } }
.bubble .hk {
  background: var(--marker); border-radius: 0.2em; padding: 0 0.1em;
  text-decoration: underline 0.12em var(--c); text-underline-offset: 0.18em;
}

/* Feedback strip: height is reserved so nothing jumps */
.feedback {
  min-height: 4.6rem; display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  transition: opacity .6s;
}
.feedback.dim { opacity: 0.55; }
.feedback:hover, .feedback.dim:focus-within { opacity: 1; }
.tier {
  font-family: var(--font-display); font-weight: 700; font-size: 1.7rem; letter-spacing: 0.03em;
  padding: 0.25em 0.8em; border-radius: 0.8rem; color: #fff; white-space: nowrap;
}
.tier.weak { background: var(--weak); }
.tier.good { background: var(--good); }
.tier.great { background: var(--great); }
.tier.listen { background: var(--listen); }
.fb-bit {
  display: flex; align-items: center; gap: 0.5em; background: var(--surface);
  border: 1.5px solid var(--line); border-radius: 0.8rem; padding: 0.45em 0.9em; font-size: 1.1rem;
  max-width: 40rem;
}
.fb-bit small { color: var(--muted); font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.08em; }
.fb-bit.listen { border-color: var(--listen); background: var(--listen-soft); font-weight: 700; }
.fb-bit.reveal { border-color: var(--amber); background: #FBF1DC; font-weight: 700; }
.fb-bit.bonus { color: var(--muted); }
.fix s { color: var(--red); text-decoration-thickness: 2px; }
.fix b { color: var(--green); }
.override { margin-left: auto; display: flex; align-items: center; gap: 0.4rem; }
.override small { color: var(--faint); font-size: 0.85rem; margin-right: 0.3rem; }
.override button {
  border: 1.5px solid var(--line); background: var(--surface); border-radius: 0.7rem;
  padding: 0.45em 0.95em; font-weight: 700; font-size: 0.95rem; color: var(--muted); min-height: 2.8rem;
}
.override button:hover { border-color: var(--ink); color: var(--ink); }
.override button.cur { background: var(--ink); border-color: var(--ink); color: #fff; }

.floater {
  position: fixed; z-index: 20; pointer-events: none;
  font-family: var(--font-display); font-weight: 700; font-size: 2.4rem; color: var(--great);
  text-shadow: 0 2px 0 #fff, 0 0 12px #fff;
  transition: transform 1.1s cubic-bezier(.2,.7,.3,1), opacity 1.1s ease-in;
}
.floater.minus { color: var(--listen); }

/* Earlier lines */
.earlier {
  display: flex; flex-direction: column; gap: 0.35rem;
  background: rgba(255,255,255,.6); border: 1.5px solid var(--line); border-radius: 1rem;
  padding: 0.8rem 1.2rem; min-height: 3.2rem;
}
.earlier:empty { display: none; }
.earlier .row { display: flex; gap: 0.8rem; font-size: 1.15rem; line-height: 1.35; }
.earlier .row .who {
  flex: none; width: 5.5rem; font-weight: 700; color: var(--muted); font-size: 0.9rem;
  padding-top: 0.15em; text-transform: uppercase; letter-spacing: 0.06em;
}
.earlier .row.char .who { color: var(--c); }
.earlier .row .txt { overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 1; }
.earlier .row.prev .txt { -webkit-line-clamp: 2; }
.earlier .row.class .txt { color: var(--muted); }
.earlier .empty-tip { color: var(--muted); font-size: 1.1rem; margin: 0; }

/* Ask box */
.ask { display: flex; gap: 0.8rem; }
#q {
  flex: 1; min-width: 0; height: 4.4rem; padding: 0 1.5rem; border-radius: 1.1rem;
  border: 2px solid var(--line); background: var(--surface); color: var(--ink); font-size: 1.7rem;
}
#q:focus { border-color: var(--c); outline: none; box-shadow: 0 0 0 4px var(--c-soft); }
#q::placeholder { color: var(--faint); }
#askBtn { min-width: 9rem; font-size: 1.4rem; border-radius: 1.1rem; background: var(--c); }

.toast {
  position: fixed; left: 50%; bottom: 8.5rem; transform: translateX(-50%); z-index: 30;
  background: var(--ink); color: #fff; padding: 0.8em 1.6em; border-radius: 999px;
  font-size: 1.3rem; font-weight: 700; box-shadow: 0 0.4rem 1.6rem rgba(0,0,0,.18);
}

/* ───────────── 4. ROUND OVER ───────────── */
#over {
  display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 3vw;
  background: linear-gradient(var(--c-soft), var(--bg) 45vh) no-repeat, var(--bg);
}
.over-left { display: flex; flex-direction: column; gap: 2.2vh; min-height: 0; justify-content: center; }
#oHead {
  font-family: var(--font-display); font-weight: 500; font-size: 3.2rem; line-height: 1.05;
  letter-spacing: -0.03em; margin: 0;
}
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.7rem; }
.stat {
  background: var(--surface); border: 1.5px solid var(--line); border-radius: 1rem;
  padding: 0.8rem 1rem; display: flex; flex-direction: column; gap: 0.1rem;
}
.stat b { font-family: var(--font-display); font-weight: 600; font-size: 2.1rem; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: 0.9rem; }
.stat .split { display: flex; gap: 0.9rem; align-items: baseline; }
.stat .split i { font-style: normal; font-weight: 700; font-size: 0.95rem; }
.stat .split b { font-size: 2.1rem; }
.highlight {
  background: var(--surface); border: 1.5px solid var(--line); border-radius: 1rem;
  padding: 1rem 1.3rem; display: flex; flex-direction: column; gap: 0.45rem;
}
.highlight:empty { display: none; }
.highlight h4 { margin: 0; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.12em; color: var(--muted); }
.highlight .q { margin: 0; font-size: 1.45rem; font-weight: 700; }
.highlight .pair { display: grid; grid-template-columns: 1fr auto 1fr; gap: 1rem; align-items: center; }
.highlight .pair .q.theirs { color: var(--muted); font-weight: 400; }
.highlight .pair .q.better { color: var(--green); }
.highlight .arrow { font-size: 1.8rem; color: var(--faint); }
.over-btns { display: flex; gap: 0.8rem; flex-wrap: wrap; }

.over-right {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--surface); border: 1.5px solid var(--line); border-radius: 1.2rem; padding: 1.2rem 1.4rem;
}
.over-right h3 { margin: 0 0 0.6rem; font-family: var(--font-display); font-weight: 600; font-size: 1.3rem; }
.transcript {
  list-style: none; margin: 0; padding: 0 0.4rem 0 0; overflow-y: auto; flex: 1;
  display: flex; flex-direction: column; gap: 0.7rem; overscroll-behavior: contain;
}
.transcript li { font-size: 1.05rem; line-height: 1.4; }
.transcript .who { font-weight: 700; color: var(--c); margin-right: 0.4em; }
.transcript .class .who { color: var(--muted); }
.transcript .class { background: var(--bg); border-radius: 0.7rem; padding: 0.5rem 0.8rem; }
.tag {
  display: inline-block; margin-left: 0.4em; font-size: 0.72rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.06em; padding: 0.15em 0.6em; border-radius: 999px; color: #fff; vertical-align: 0.15em;
}
.tag.weak { background: var(--weak); }
.tag.good { background: var(--good); }
.tag.great { background: var(--great); }
.tag.listen { background: var(--listen); }
.tag.plain { background: var(--line); color: var(--muted); }
.tag.reveal { background: var(--amber); }

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

/* Narrow windows (laptop preview): stack cards */
@media (max-aspect-ratio: 4/3) {
  .cards { grid-template-columns: repeat(3, 1fr); }
  #over { grid-template-columns: 1fr; overflow-y: auto; }
  body { overflow: auto; }
}
