/* =========================================================================
   The listening room.

   Entering a lesson dims the app. Everything here is arranged around one
   question: who is speaking right now? The answer is carried by colour
   temperature, so a student glancing at a phone on a bus knows whether to
   listen or to answer without reading anything.

   The resonance figure is the one bold element. It is a Chladni pattern - the
   shape sound actually makes on a vibrating plate - drawn per concept, and it
   resonates only while audio is playing. Everything around it stays quiet.
   ========================================================================= */

.player {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  flex-direction: column;
  background: var(--night);
  color: var(--night-text);
  animation: dim-lights var(--dur-slow) var(--ease-out);
}
@keyframes dim-lights {
  from { opacity: 0; transform: scale(1.015); }
  to { opacity: 1; transform: none; }
}

/* Who holds the floor. One variable drives the whole room. */
.player {
  --floor: var(--night-faint);
  --floor-glow: transparent;
}
.player[data-holder="teacher"] { --floor: var(--brass); --floor-glow: var(--brass-glow); }
.player[data-holder="student"] { --floor: var(--mint);  --floor-glow: var(--mint-glow); }
.player[data-holder="system"]  { --floor: var(--quiet); --floor-glow: rgba(123, 134, 196, 0.2); }

/* A wash of the floor colour from the top, so the room itself changes
   temperature rather than just an indicator somewhere on screen. */
.player::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 55vh;
  background: radial-gradient(
    120% 100% at 50% 0%,
    var(--floor-glow) 0%,
    transparent 68%
  );
  opacity: 0.75;
  pointer-events: none;
  transition: background var(--dur-slow) var(--ease-out), opacity var(--dur-slow) var(--ease-out);
}

/* --- Chrome -------------------------------------------------------------- */
.player-top {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  padding-top: max(var(--space-4), env(safe-area-inset-top, 0px));
}
.player-top .btn-icon { color: var(--night-soft); }
.player-top .btn-icon:hover { background: var(--night-raised); color: var(--night-text); }
.player-crumb {
  min-width: 0;
  font-size: var(--text-xs);
  color: var(--night-faint);
  letter-spacing: var(--tracking-wide);
}
.player-crumb strong { color: var(--night-soft); font-weight: 600; }

.player-stage {
  position: relative;
  z-index: 2;
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-5);
  padding: var(--space-4) var(--space-5);
  min-height: 0;
  /* The stage yields space to the answer panel rather than overflowing
     behind it, so nothing is ever half-hidden under a raised surface. */
  overflow: hidden;
  text-align: center;
}

/* --- The resonance figure ------------------------------------------------ */
.resonance {
  position: relative;
  width: min(19rem, 52vw, 34vh);
  aspect-ratio: 1;
  flex: none;
}
.resonance svg { width: 100%; height: 100%; overflow: visible; }
.resonance .plate {
  fill: none;
  stroke: color-mix(in srgb, var(--floor) 34%, transparent);
  stroke-width: 1;
}
.resonance .node {
  fill: none;
  stroke: var(--floor);
  stroke-width: 1.15;
  stroke-linecap: round;
  opacity: 0.8;
  transition: stroke var(--dur-slow) var(--ease-out);
}
.resonance .node-soft { opacity: 0.32; stroke-width: 0.7; }

/* The plate rings while sound is being produced, and stills when it is not.
   The motion reports state; it is not decoration. */
.resonance[data-active="true"] .ring {
  animation: resonate 3.4s var(--ease-in-out) infinite;
}
.resonance .ring { transform-origin: center; }
.resonance .ring:nth-child(2) { animation-delay: -0.5s; }
.resonance .ring:nth-child(3) { animation-delay: -1.1s; }
@keyframes resonate {
  0%, 100% { transform: scale(1); opacity: 0.85; }
  50%      { transform: scale(1.035); opacity: 1; }
}

/* Listening: the figure receives rather than emits. */
.resonance[data-mode="listening"] .halo {
  animation: listen 2.2s var(--ease-in-out) infinite;
}
@keyframes listen {
  0%, 100% { r: 47%; opacity: 0.12; }
  50%      { r: 49.5%; opacity: 0.3; }
}

.resonance[data-mode="busy"] .sweep {
  animation: sweep-round 2.6s linear infinite;
  transform-origin: center;
}
@keyframes sweep-round { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .resonance .ring, .resonance .halo, .resonance .sweep { animation: none !important; }
  .resonance[data-active="true"] .node { opacity: 1; }
}

/* --- Titles and turn state ----------------------------------------------- */
.player-titles { max-width: 34rem; }
.player-titles h1 {
  font-family: var(--font-serif);
  font-size: clamp(1.5rem, 4.2vw, 2.25rem);
  font-weight: 500;
  color: var(--night-text);
  letter-spacing: var(--tracking-tight);
  line-height: var(--leading-tight);
}
.player-titles p {
  margin-top: var(--space-2);
  font-size: var(--text-sm);
  color: var(--night-faint);
  line-height: var(--leading-snug);
}

.turn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 1.6rem;
  padding: 0.3rem 0.85rem 0.3rem 0.6rem;
  border-radius: var(--radius-full);
  background: color-mix(in srgb, var(--floor) 12%, transparent);
  color: var(--floor);
  font-size: var(--text-sm);
  font-weight: 600;
  letter-spacing: var(--tracking-snug);
  transition: background-color var(--dur-slow) var(--ease-out), color var(--dur-slow) var(--ease-out);
}
.turn-pip {
  width: 7px; height: 7px;
  border-radius: var(--radius-full);
  background: currentColor;
  flex: none;
}
.player[data-holder="teacher"] .turn-pip,
.player[data-holder="student"] .turn-pip { animation: breathe 2.4s var(--ease-in-out) infinite; }
@keyframes breathe {
  0%, 100% { opacity: 0.45; transform: scale(0.85); }
  50% { opacity: 1; transform: scale(1); }
}
@media (prefers-reduced-motion: reduce) {
  .turn-pip { animation: none !important; }
}
.turn-hint { color: var(--night-faint); font-weight: 400; font-size: var(--text-xs); }

/* --- Controls ------------------------------------------------------------ */
.player-controls {
  position: relative;
  z-index: 2;
  padding: var(--space-4) var(--space-5) max(var(--space-6), env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  width: min(40rem, 100%);
  margin-inline: auto;
}

.scrubber { display: flex; flex-direction: column; gap: 0.4rem; }
.scrub-track {
  position: relative;
  height: 22px;
  display: flex;
  align-items: center;
  cursor: pointer;
  touch-action: none;
}
.scrub-rail {
  position: absolute; left: 0; right: 0;
  height: 3px;
  background: var(--night-line);
  border-radius: var(--radius-full);
}
.scrub-fill {
  position: absolute; left: 0;
  height: 3px;
  background: var(--floor);
  border-radius: var(--radius-full);
  transition: width 180ms linear, background-color var(--dur-slow) var(--ease-out);
}
.scrub-thumb {
  position: absolute;
  width: 11px; height: 11px;
  border-radius: var(--radius-full);
  background: var(--night-text);
  transform: translateX(-50%);
  transition: left 180ms linear, transform var(--dur-fast) var(--ease-out);
  pointer-events: none;
}
.scrub-track:hover .scrub-thumb, .scrub-track:focus-visible .scrub-thumb { transform: translateX(-50%) scale(1.25); }
.scrub-track:focus-visible { box-shadow: var(--focus-ring); border-radius: var(--radius-full); }

/* Section boundaries, so the lesson's shape is visible on the bar. */
.scrub-mark {
  position: absolute;
  width: 1px; height: 8px;
  background: var(--night-line);
  transform: translateX(-50%);
}
.scrub-mark[data-check="true"] { background: color-mix(in srgb, var(--mint) 70%, transparent); height: 11px; }

.scrub-times {
  display: flex; justify-content: space-between;
  font-size: var(--text-2xs);
  color: var(--night-faint);
  font-variant-numeric: tabular-nums;
}

.transport {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
}
.transport button {
  display: grid; place-items: center;
  color: var(--night-soft);
  border-radius: var(--radius-full);
  transition: color var(--dur-fast) var(--ease-out), background-color var(--dur-fast) var(--ease-out),
              transform var(--dur-fast) var(--ease-out);
  /* Every transport control is at least 44px: this is used while walking. */
  min-width: 44px; min-height: 44px;
}
.transport button:hover:not(:disabled) { color: var(--night-text); background: var(--night-raised); }
.transport button:active:not(:disabled) { transform: scale(0.94); }
.transport button:disabled { opacity: 0.3; }
.transport svg { width: 1.35rem; height: 1.35rem; }

.transport .play {
  width: 66px; height: 66px;
  background: var(--night-text);
  color: var(--night);
}
.transport .play:hover:not(:disabled) { background: #fff; color: var(--night); }
.transport .play svg { width: 1.7rem; height: 1.7rem; }
.transport .skip-label {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  /* The digits sit in the clear middle of the arc, a touch low so they look
     centred against an arrowhead that hangs off the top. */
  padding-top: 2px;
  font-size: 8px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}
.transport .skip { position: relative; }

.player-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  flex-wrap: wrap;
}
.player-actions .segmented { background: var(--night-raised); }
.player-actions .segmented button { color: var(--night-faint); }
.player-actions .segmented button:hover { color: var(--night-text); }
.player-actions .segmented button[aria-pressed="true"] {
  background: var(--night-line); color: var(--night-text); box-shadow: none;
}
.player-actions .btn {
  background: transparent; color: var(--night-soft);
  border-color: transparent;
}
.player-actions .btn:hover:not(:disabled) { background: var(--night-raised); color: var(--night-text); }
.player-actions .btn-icon { color: var(--night-faint); }
.player-actions .btn-icon:hover { background: var(--night-raised); color: var(--night-text); }
.player-actions .btn-icon[aria-pressed="true"] { color: var(--brass); }

/* --- Your turn ----------------------------------------------------------- */
.answer-panel {
  position: relative;
  z-index: 2;
  width: min(40rem, 100%);
  margin-inline: auto;
  padding: var(--space-5);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  background: var(--night-raised);
  border-top: 1px solid color-mix(in srgb, var(--mint) 28%, transparent);
  animation: rise var(--dur) var(--ease-spring);
}
@keyframes rise {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: none; }
}
.answer-question {
  font-family: var(--font-serif);
  font-size: var(--text-md);
  line-height: var(--leading-snug);
  color: var(--night-text);
  margin-bottom: var(--space-4);
}
.answer-tools { display: flex; align-items: center; gap: var(--space-3); }

.mic {
  position: relative;
  width: 60px; height: 60px;
  border-radius: var(--radius-full);
  background: var(--mint);
  color: var(--night);
  display: grid; place-items: center;
  flex: none;
  transition: transform var(--dur-fast) var(--ease-out), background-color var(--dur) var(--ease-out);
}
.mic:hover { transform: scale(1.04); }
.mic svg { width: 1.5rem; height: 1.5rem; }
.mic[data-listening="true"]::after {
  content: "";
  position: absolute; inset: -6px;
  border-radius: var(--radius-full);
  border: 2px solid var(--mint);
  animation: mic-ring 1.5s var(--ease-out) infinite;
}
@keyframes mic-ring {
  0% { transform: scale(1); opacity: 0.7; }
  100% { transform: scale(1.35); opacity: 0; }
}
.mic[data-listening="true"] { background: var(--mint-deep); color: var(--night-text); }
@media (prefers-reduced-motion: reduce) { .mic[data-listening="true"]::after { animation: none; opacity: 0.5; } }

/* Live level meter: real feedback that the microphone is hearing something. */
.level { display: flex; align-items: center; gap: 3px; height: 28px; flex: 1 1 auto; }
.level i {
  flex: 1;
  min-width: 2px;
  max-width: 4px;
  height: var(--h, 15%);
  background: var(--mint);
  border-radius: 2px;
  opacity: 0.85;
  transition: height 90ms linear;
}

.answer-transcript {
  margin-top: var(--space-4);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  background: var(--night);
  color: var(--night-soft);
  font-size: var(--text-sm);
  line-height: var(--leading-snug);
  min-height: 2.6rem;
}
.answer-transcript em { color: var(--night-faint); font-style: normal; }

.answer-typed { margin-top: var(--space-3); display: flex; gap: var(--space-2); }
.answer-typed .input {
  background: var(--night);
  border-color: var(--night-line);
  color: var(--night-text);
}
.answer-typed .input::placeholder { color: var(--night-faint); }

/* --- Teacher's reply ----------------------------------------------------- */
.reply {
  position: relative;
  z-index: 2;
  width: min(40rem, 100%);
  margin-inline: auto;
  padding: var(--space-5);
  background: var(--night-raised);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  border-top: 1px solid color-mix(in srgb, var(--brass) 26%, transparent);
  animation: rise var(--dur) var(--ease-spring);
  max-height: 45vh;
  overflow-y: auto;
}
.reply-verdict {
  display: inline-flex; align-items: center; gap: var(--space-2);
  font-size: var(--text-xs); font-weight: 600;
  color: var(--brass);
  margin-bottom: var(--space-3);
}
.reply-text {
  font-family: var(--font-serif);
  font-size: var(--text-md);
  line-height: var(--leading-relaxed);
  color: var(--night-text);
}
.reply-source {
  margin-top: var(--space-3);
  font-size: var(--text-xs);
  color: var(--night-faint);
  font-style: italic;
}

/* --- Transcript ---------------------------------------------------------- */
.transcript {
  position: relative;
  z-index: 2;
  flex: 1 1 auto;
  overflow-y: auto;
  padding: var(--space-4) var(--space-5) var(--space-6);
  width: min(42rem, 100%);
  margin-inline: auto;
  -webkit-overflow-scrolling: touch;
}
.transcript-line {
  display: block;
  width: 100%;
  text-align: left;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  border-left: 2px solid transparent;
  color: var(--night-faint);
  font-family: var(--font-serif);
  line-height: var(--leading-relaxed);
  transition: color var(--dur) var(--ease-out), background-color var(--dur) var(--ease-out);
}
.transcript-line:hover { background: var(--night-raised); color: var(--night-soft); }
.transcript-line[aria-current="true"] {
  color: var(--night-text);
  background: var(--night-raised);
  border-left-color: var(--floor);
}
.transcript-kind {
  display: block;
  font-family: var(--font-sans);
  font-size: var(--text-2xs);
  font-weight: 700;
  letter-spacing: var(--tracking-wide);
  color: var(--night-faint);
  margin-bottom: 0.35rem;
}
.transcript-line[data-kind="check"] .transcript-kind,
.transcript-line[data-kind="assessment"] .transcript-kind { color: var(--mint); }

/* --- Mini player --------------------------------------------------------- */
.miniplayer {
  position: fixed;
  left: 0; right: 0;
  bottom: 0;
  z-index: 70;
  background: var(--night);
  color: var(--night-text);
  border-top: 1px solid var(--night-line);
  animation: rise var(--dur) var(--ease-out);
}
@media (max-width: 900px) {
  .miniplayer { bottom: calc(var(--tabbar-height) + env(safe-area-inset-bottom, 0px)); }
}
.miniplayer-track { height: 2px; background: var(--night-line); }
.miniplayer-track > i {
  display: block; height: 100%;
  background: var(--brass);
  transition: width 300ms linear;
}
.miniplayer-body {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-2) var(--space-4);
  height: calc(var(--miniplayer-height) - 2px);
}
.miniplayer-open {
  flex: 1 1 auto; min-width: 0; text-align: left;
  display: flex; align-items: center; gap: var(--space-3);
}
.miniplayer-title { font-size: var(--text-sm); font-weight: 600; }
.miniplayer-sub { font-size: var(--text-xs); color: var(--night-faint); }
.miniplayer .btn-icon { color: var(--night-soft); }
.miniplayer .btn-icon:hover { background: var(--night-raised); color: var(--night-text); }
.miniplayer .mini-play {
  background: var(--night-text); color: var(--night);
  width: 2.4rem; height: 2.4rem;
}
.miniplayer .mini-play:hover { background: #fff; color: var(--night); }

/* --- Finished ------------------------------------------------------------ */
.finished {
  position: relative; z-index: 2;
  flex: 1 1 auto;
  overflow-y: auto;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: var(--space-5);
  padding: var(--space-6) var(--space-5);
  text-align: center;
}
.finished-card {
  width: min(34rem, 100%);
  background: var(--night-raised);
  border: 1px solid var(--night-line);
  border-radius: var(--radius-xl);
  padding: var(--space-6);
  text-align: left;
}
.finished h2 {
  font-size: var(--text-2xl);
  color: var(--night-text);
  text-align: center;
}
.takeaway {
  display: flex; gap: var(--space-3);
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--night-line);
  font-family: var(--font-serif);
  line-height: var(--leading-relaxed);
  color: var(--night-soft);
}
.takeaway:last-child { border-bottom: none; }
.takeaway-mark { color: var(--brass); flex: none; }

@media (max-width: 640px) {
  .player-stage { gap: var(--space-4); }
  .player-controls { gap: var(--space-3); padding-inline: var(--space-4); }
  .transport { gap: var(--space-2); }
  .transport .play { width: 60px; height: 60px; }
  .player-actions { justify-content: center; }
}

/* Short viewports: the figure yields first, the controls never do. */
@media (max-height: 620px) {
  .resonance { width: min(12rem, 34vh); }
  .player-titles h1 { font-size: var(--text-lg); }
}

/* The voice control names the voice that is reading, so the label has to be
   allowed to shrink rather than push the transport row into a second line. */
.voice-button { min-width: 0; max-width: 11rem; }
.voice-label { min-width: 0; }
@media (max-width: 640px) {
  .voice-button { max-width: 7.5rem; }
}
