/* AEGIS design layer for the public tutor
   ------------------------------------------------------------------
   The tutor now shares the visual language of the operator's AEGIS HUD —
   steel-blue ground, a single cyan accent, mono micro-labels, glass panels,
   a fixed frame with corner brackets, a vignette and a scanline pass — while
   the content stays student-facing: no operator names, ports, hosts or status
   readouts, and no secrets.

   Loaded after styles.css, so this file only overrides; nothing here is needed
   for the app to function if it is removed. */

:root {
  --bg: #141b22;
  --bg-2: #10161c;
  --panel: rgba(12, 18, 40, 0.52);
  --panel-solid: #121a22;
  --line: rgba(145, 200, 225, 0.14);
  --line-strong: rgba(120, 220, 226, 0.42);
  --text: #e6f2f8;
  --muted: #8fa9b6;
  --dim: #6d8694;
  --energy: #78dce2;
  --energy-soft: rgba(120, 220, 226, 0.14);
  --gold: #f0c975;
  --danger: #fb7185;
  --ok: #4ce5b1;
  --radius: 10px;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.6);
}

body {
  background:
    radial-gradient(circle at 50% 30%, #202b36 0%, #161e26 42%, #10161c 100%),
    var(--bg-2);
  background-attachment: fixed;
  letter-spacing: 0.005em;
}

/* Vignette + scanlines: fixed, inert, and behind every control. */
body::before,
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}
body::before {
  background: radial-gradient(120% 90% at 50% 45%, transparent 42%, rgba(4, 8, 12, 0.62) 100%);
}
body::after {
  background: repeating-linear-gradient(
    180deg,
    rgba(140, 224, 232, 0.035) 0px,
    rgba(140, 224, 232, 0.035) 1px,
    transparent 1px,
    transparent 3px
  );
  opacity: 0.55;
  animation: scan-drift 9s linear infinite;
}
@keyframes scan-drift {
  to { transform: translateY(3px); }
}

.app { position: relative; z-index: 1; }

/* Fixed HUD frame with corner brackets, drawn without extra markup. */
.app::after {
  content: "";
  position: fixed;
  inset: 10px;
  pointer-events: none;
  z-index: 2;
  border: 1px solid rgba(145, 200, 225, 0.07);
  background:
    linear-gradient(var(--energy), var(--energy)) left top / 20px 1px no-repeat,
    linear-gradient(var(--energy), var(--energy)) left top / 1px 20px no-repeat,
    linear-gradient(var(--energy), var(--energy)) right top / 20px 1px no-repeat,
    linear-gradient(var(--energy), var(--energy)) right top / 1px 20px no-repeat,
    linear-gradient(var(--energy), var(--energy)) left bottom / 20px 1px no-repeat,
    linear-gradient(var(--energy), var(--energy)) left bottom / 1px 20px no-repeat,
    linear-gradient(var(--energy), var(--energy)) right bottom / 20px 1px no-repeat,
    linear-gradient(var(--energy), var(--energy)) right bottom / 1px 20px no-repeat;
  opacity: 0.4;
}

/* ------------------------------------------------------------- HUD header */

.hud {
  background: linear-gradient(180deg, rgba(16, 22, 28, 0.94), rgba(16, 22, 28, 0.55));
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(16px);
  padding: 12px 22px;
}

.hud-brand h1 {
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 400;
  letter-spacing: 0.26em;
  color: #eaf7fb;
  text-shadow: 0 0 18px rgba(140, 224, 232, 0.35);
}
.hud-brand p {
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.28em;
  color: var(--dim);
}
.hud-brand strong { color: var(--gold); letter-spacing: 0.14em; }

.hud-mark {
  width: 30px;
  height: 30px;
  border-width: 1.5px;
  border-color: var(--energy);
  box-shadow: 0 0 20px rgba(120, 220, 226, 0.5), inset 0 0 12px rgba(120, 220, 226, 0.45);
}
.hud-mark::after { inset: 8px; }

.trial-chip {
  border-radius: 4px;
  background: rgba(120, 220, 226, 0.05);
  box-shadow: inset 0 0 22px rgba(120, 220, 226, 0.07);
}
.trial-chip-label {
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.26em;
}
.trial-chip-time { font-size: 14px; }

.topic-picker,
.level-picker,
.icon-btn,
.ghost-btn,
.msg-tool {
  border-radius: 4px;
  background: rgba(12, 18, 34, 0.55);
  border-color: var(--line);
}
.topic-picker span,
.level-picker span,
.ghost-btn {
  font-family: var(--mono);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-size: 10.5px;
}
.icon-btn:hover,
.corner-btn:hover,
.ghost-btn:hover { border-color: var(--line-strong); color: var(--energy); background: rgba(120, 220, 226, 0.07); }

/* ---------------------------------------------------------- reactor stage */

@keyframes ambient-breathe {
  0%, 100% { opacity: 0.42; transform: translate(-50%, -50%) scale(0.98); }
  50% { opacity: 0.68; transform: translate(-50%, -50%) scale(1.03); }
}

.stage-grid {
  background-size: 38px 38px;
  mask-image: radial-gradient(circle at 50% 46%, #000 12%, transparent 72%);
  opacity: 0.9;
}

.reactor { z-index: 1; }
.reactor-glow {
  inset: 2%;
  filter: blur(26px);
  background: radial-gradient(circle, color-mix(in srgb, var(--energy) 34%, transparent), transparent 62%);
}

/* Ambient SVG layer: halo rings turn slowly, motes shimmer out of phase. */
.r-ambient {
  transform-box: view-box;
  transform-origin: 210px 210px;
  animation: rspin 90s linear infinite;
}
.r-halo { opacity: 0.16; }
.r-halo-2 { opacity: 0.08; }
.r-mote {
  animation: mote 6.5s ease-in-out infinite;
  animation-delay: var(--d, 0s);
}
@keyframes mote {
  0%, 100% { opacity: 0.12; }
  50% { opacity: 0.75; }
}

.reactor[data-state="thinking"] .r-ambient { animation-duration: 22s; }
.reactor[data-state="listening"] .r-ambient { animation-duration: 40s; }

.state-dot { box-shadow: 0 0 12px var(--energy); }
.stage-readout { font-size: 9px; letter-spacing: 0.22em; }
.state-detail { font-family: var(--mono); letter-spacing: 0.1em; color: var(--dim); }


/* The core itself is the talk control: press and hold it, speak, release to
   send. There is no separate mic button, so the reactor carries the affordance
   and reacts while it is held. */
.reactor {
  cursor: pointer;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.16s ease, filter 0.3s ease;
}
.reactor:focus-visible { outline: none; }
.reactor:focus-visible .reactor-svg-wrap {
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(120, 220, 226, 0.55), 0 0 34px rgba(120, 220, 226, 0.28);
}

/* A faint static ring marks the hold target before the first press. */
.reactor::before {
  content: "";
  position: absolute;
  inset: 7%;
  border-radius: 50%;
  border: 1px solid rgba(120, 220, 226, 0.16);
  pointer-events: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.reactor.is-armed { transform: scale(0.972); }
.reactor.is-armed::before {
  border-color: rgba(120, 220, 226, 0.55);
  box-shadow: inset 0 0 40px rgba(120, 220, 226, 0.16);
}

/* Held / listening: the bloom swells and a ring pushes out from the core. */
.reactor[data-state="listening"] .reactor-glow { opacity: 1; filter: blur(30px); }
.reactor[data-state="listening"] .r-inner { animation-duration: 5s; }
.reactor[data-state="listening"] .r-ticks { animation-duration: 10s; }
.reactor[data-state="listening"] .r-core { animation-duration: 1.6s; }
.reactor[data-state="listening"]::before {
  border-color: rgba(120, 220, 226, 0.6);
  animation: core-listen 2.2s ease-out infinite;
}
@keyframes core-listen {
  0% { transform: scale(0.9); opacity: 0.9; }
  70% { transform: scale(1.14); opacity: 0; }
  100% { transform: scale(1.14); opacity: 0; }
}

/* ------------------------------------------------------------- chat panel */

.text-btn { font-family: var(--mono); font-size: 10px; letter-spacing: 0.16em; text-transform: uppercase; }

.messages::-webkit-scrollbar-thumb { background: rgba(120, 220, 226, 0.18); }

.msg-meta { font-family: var(--mono); font-size: 9.5px; letter-spacing: 0.2em; }
.msg.tutor .msg-meta strong { color: var(--gold); text-shadow: 0 0 14px rgba(240, 201, 117, 0.3); }

.bubble {
  border-radius: 6px;
  font-size: 14.5px;
  line-height: 1.55;
}
.msg.tutor .bubble {
  background: linear-gradient(180deg, rgba(120, 220, 226, 0.07), rgba(120, 220, 226, 0.025));
  border: 1px solid rgba(120, 220, 226, 0.14);
  border-left: 2px solid rgba(120, 220, 226, 0.5);
}
.msg.user .bubble {
  background: linear-gradient(180deg, rgba(240, 201, 117, 0.1), rgba(240, 201, 117, 0.04));
  border: 1px solid rgba(240, 201, 117, 0.18);
}
.bubble .correction { border-radius: 4px; background: rgba(240, 201, 117, 0.08); color: #ffe9bd; }
.bubble .mn-explain { border-radius: 4px; background: rgba(76, 229, 177, 0.06); color: #cbfff1; }

.typing em { font-family: var(--mono); font-size: 9.5px; letter-spacing: 0.2em; }

.composer { border-top-color: var(--line); background: rgba(9, 14, 20, 0.7); }
.composer textarea,
.field input,
.field select {
  border-radius: 4px;
  border-color: var(--line);
  background: rgba(8, 13, 20, 0.75);
}
.composer textarea:focus,
.field input:focus,
.field select:focus {
  border-color: var(--line-strong);
  box-shadow: 0 0 0 3px rgba(120, 220, 226, 0.09);
}
.composer button,
.primary-btn {
  border-radius: 4px;
  background: rgba(120, 220, 226, 0.1);
  border: 1px solid rgba(120, 220, 226, 0.4);
  color: #d9fbff;
  font-family: var(--mono);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-size: 11px;
}
.send-btn { background: rgba(120, 220, 226, 0.12); border: 1px solid rgba(120, 220, 226, 0.4); color: var(--energy); }

/* ------------------------------------------------------ modals and drawer */

.modal-card,
.drawer {
  border-radius: 10px;
  border: 1px solid var(--line);
  background: linear-gradient(160deg, rgba(22, 30, 38, 0.98), rgba(12, 18, 26, 0.98));
  box-shadow: var(--shadow), inset 0 0 60px rgba(4, 10, 16, 0.6);
}
.modal { background: rgba(4, 6, 10, 0.86); backdrop-filter: blur(8px); }
.modal-card h2,
.drawer h2 {
  font-family: var(--mono);
  font-weight: 400;
  letter-spacing: 0.16em;
}
.gate-badge {
  font-family: var(--mono);
  border-radius: 3px;
  letter-spacing: 0.22em;
  background: rgba(120, 220, 226, 0.08);
  border: 1px solid rgba(120, 220, 226, 0.28);
  color: var(--energy);
}
.plan-card { border-radius: 8px; }
.plan-card.is-featured { border-color: rgba(240, 201, 117, 0.45); box-shadow: inset 0 0 30px rgba(240, 201, 117, 0.07); }
.plan-tag { font-family: var(--mono); letter-spacing: 0.2em; }
.plan-price { font-family: var(--mono); letter-spacing: 0.02em; }

.toast {
  border-radius: 4px;
  border: 1px solid rgba(120, 220, 226, 0.3);
  background: rgba(11, 18, 26, 0.96);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.08em;
}

/* ----------------------------------------------------------------- mobile */
/* Students mostly arrive on a phone, so the small-screen layout is its own
   composition: one column, the core sized to the viewport, and the chat taking
   the rest with a composer that the keyboard cannot cover. */

@media (max-width: 860px) {
  /* minmax(0, 1fr) lets the middle row shrink instead of overflowing, and no
     min-height floor: an app taller than the visible viewport hid the view
     switch under the browser chrome (the body is overflow: hidden). */
  /* The same visible-viewport height as the desktop rule, via app.js: 100dvh
     alone put the view switch under the clipped edge on a phone after a
     reload. */
  .app { grid-template-rows: auto minmax(0, 1fr); height: var(--app-h, 100dvh); max-height: var(--app-h, 100dvh); min-height: 0; }

  /* Two clean rows: the brand and the timer share the first, the controls take
     the second. The title never has to wrap against the buttons again. */
  .hud {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "brand  status"
      "actions actions";
    align-items: center;
    gap: 8px 10px;
    padding: 10px 14px calc(10px + env(safe-area-inset-top, 0px));
  }
  .hud-brand { grid-area: brand; gap: 9px; min-width: 0; }
  .hud-brand > div { min-width: 0; }
  .hud-brand h1 { font-size: 11px; letter-spacing: 0.14em; white-space: nowrap; }
  .hud-brand p {
    font-size: 8.5px;
    letter-spacing: 0.16em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .hud-mark { width: 24px; height: 24px; flex: none; }
  .hud-center { grid-area: status; justify-content: flex-end; min-width: 0; }
  .hud-actions { grid-area: actions; gap: 6px; justify-content: flex-start; }
  .hud-actions .icon-btn#customizerBtn { margin-left: auto; }
  .topic-picker { padding: 4px 6px 4px 8px; min-width: 0; }
  .topic-picker span { display: none; }
  .topic-picker select { font-size: 12px; max-width: 172px; }
  .corner-btn { right: 0; bottom: 0; width: 32px; height: 32px; }
  .icon-btn { width: 34px; height: 34px; }
  .trial-chip { padding: 5px 10px; gap: 6px; flex: none; }
  .trial-chip-label { font-size: 8px; letter-spacing: 0.16em; }
  .trial-chip-time { font-size: 13px; }

  /* The stage or the chat takes every remaining pixel; the feed shrinks first,
     the core band only when the feed is already at its floor. */
  .workspace {
    gap: 8px;
    /* The switch is the last row of the column now, so the foot needs real
       clearance: an installed PWA draws under the gesture bar and reports no
       safe-area inset for it, which is what clipped the switch on the phone. */
    padding: 8px 12px calc(24px + env(safe-area-inset-bottom, 0px));
    height: auto;
    min-height: 0;
  }

  /* One plate on a phone too. The core fills the middle of the screen and the
     history runs behind it in the two edge columns (mode 1 in styles.css), so
     there is no second box stacked under the core any more. */
  .stage-shell { gap: 8px; }
  .mode-tab { padding: 5px 10px; font-size: 9px; letter-spacing: 0.12em; }
  /* The readout shares the plate's foot with the flanks, so it stays centred in
     the clear middle band. */
  .stage-readout { font-size: 9px; letter-spacing: 0.12em; bottom: 6px; }

  .messages { padding: 10px 12px 4px; gap: 10px; }
  .msg { max-width: 94%; }
  .bubble { font-size: 12.8px; }
  .msg-meta { font-size: 8.5px; letter-spacing: 0.16em; }
  /* The composer is a row of the stage now, not the last row of the screen:
     the workspace padding owns the safe area, so the bar stays symmetric. */
  .composer {
    padding: 8px 10px;
    gap: 8px;
  }
  /* 16px stops iOS from zooming the page. The field stays one line tall, and
     the hint scales with the phone width so it never wraps and gets clipped. */
  .composer textarea { font-size: 16px; min-height: 0; padding: 9px 10px; }
  .composer textarea::placeholder {
    font-size: clamp(8.5px, 2.7vw, 11.5px);
    letter-spacing: 0.01em;
  }
  .app::after { inset: 6px; }
}

/* Narrow phones: the timer drops its label rather than squeezing the title,
   and the composer gives its side padding back to the input hint. */
@media (max-width: 380px) {
  .hud-brand h1 { font-size: 11px; letter-spacing: 0.14em; }
  .composer { padding-left: 7px; padding-right: 7px; gap: 6px; }
  .trial-chip-label { display: none; }
  .trial-chip:not(.is-paid)::before {
    content: "TRIAL";
    font-family: var(--mono);
    font-size: 7.5px;
    letter-spacing: 0.16em;
    color: var(--dim);
  }
}

@media (prefers-reduced-motion: reduce) {
  body::after,
  .core-layer::before,
  .r-ambient,
  .r-mote { animation: none; }
  body::after { opacity: 0.35; }
}
/* ============================================================== stage v33 ==
   The middle of the screen is rebuilt here, and this block is the only place
   that defines it. No container queries, no grid reflow, no mode rules left in
   the older sheets:

     .stage-body    the container: relative, w-full, flex-1, overflow hidden,
                    padding 0, centred
     .core-layer    layer 1: the reactor, absolute inset 0, centred, z 10
     .flank-layer   layer 2: two 35% columns at the edges, z 20, no pointer
     .chat-layer    layer 3: the reading view over everything, z 30

   The composer and the view switch are the last two rows of the shell, so
   both stay pinned at the foot in either view. */

.workspace {
  padding: 0 0 12px;
  gap: 10px;
  overflow: hidden;
}

.stage-shell {
  position: relative;
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  gap: 10px;
  width: 100%;
  max-width: none;
  min-height: 0;
  margin: 0;
}

/* The container. Everything below is an absolute layer of this box.
   It is a square around the core (width, capped by the room left above the
   composer), so the plate edges meet the core with no dead band top or
   bottom. Whatever height the column does not use stays below the plate, in
   the gap the .composer's auto top margin opens up. */
.stage-body {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 1 auto;
  width: 100%;
  aspect-ratio: 1 / 1;
  min-height: 0;
  padding: 0;
  border-radius: 0;
  overflow: hidden;
}

/* ------------------------------------------------ layer 1: the reactor --- */

.core-layer {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 44%, rgba(120, 220, 226, 0.1), transparent 58%),
    linear-gradient(180deg, rgba(16, 24, 32, 0.5), rgba(11, 16, 22, 0.74));
}

/* The ambient bloom that used to hang off the old stage frame. */
.core-layer::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 44%;
  width: min(88%, 600px);
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: radial-gradient(
    circle,
    color-mix(in srgb, var(--energy) 24%, transparent) 0%,
    color-mix(in srgb, var(--energy) 7%, transparent) 42%,
    transparent 68%
  );
  filter: blur(26px);
  opacity: 0.55;
  pointer-events: none;
  animation: ambient-breathe 7.5s ease-in-out infinite;
}

/* The size contract: the largest square the plate's height allows, so the core
   touches the top and bottom edges instead of floating in padding. Nothing here
   is allowed to cap it a second time. */
.core-wrap {
  position: relative;
  flex: none;
  margin: 0;
  height: 100%;
  width: auto;
  aspect-ratio: 1 / 1;
  max-width: 100%;
  max-height: 100%;
}
.core-wrap .reactor {
  width: 100%;
  height: 100%;
}

/* --------------------------------- layer 2: the flanking transcript ----- */

.flank-layer {
  position: absolute;
  inset: 0;
  z-index: 20;
  pointer-events: none;
}

/* Two edge columns, above the core but transparent to every tap, so the
   reactor can be held anywhere the text overlaps it. */
.flank-col {
  position: absolute;
  top: 12px;
  bottom: 56px;
  width: 35%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 9px;
  overflow: hidden;
  pointer-events: none;
  text-shadow: 0 1px 3px rgba(2, 6, 23, 0.92);
  transition: opacity 0.22s ease, visibility 0.22s ease;
}
.flank-left { left: 8px; text-align: left; }
.flank-right { right: 8px; text-align: right; }
.flank-msg {
  margin: 0;
  overflow-wrap: anywhere;
  hyphens: auto;
}

/* ------------------------------------- layer 3: the reading view -------- */

.chat-layer {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 16px;
  border-radius: 0;
  background: rgba(2, 6, 23, 0.9);
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.22s ease, visibility 0.22s ease;
}

.stage-shell[data-mode="chat"] .chat-layer {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

/* Only the core view is square: the reading view takes the whole height back,
   so the transcript keeps its room instead of the reserved band. */
.stage-shell[data-mode="chat"] .stage-body {
  flex: 1 1 auto;
  aspect-ratio: auto;
}

/* The flanks belong to the core view only. */
.stage-shell[data-mode="chat"] .flank-layer {
  opacity: 0;
  visibility: hidden;
}

/* The feed is the scroller; the layer's 16px padding is its only inset. */
.chat-layer .messages {
  flex: 1 1 auto;
  min-height: 0;
  padding: 0;
  overflow-y: auto;
}
.chat-layer .chat-head {
  flex: none;
  padding: 0 0 8px;
}

/* ------------------------------------------ layer 4: the bottom controls - */

.composer {
  position: relative;
  z-index: 5;
  flex: none;
  width: 100%;
  max-width: none;
  /* Pinned to the foot: the height the square plate leaves over collects
     here, between the chat area and the input. */
  margin: auto 0 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(9, 14, 20, 0.72);
}

.stage-bar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

@media (max-width: 860px) {
  .workspace {
    padding: 0 0 calc(22px + env(safe-area-inset-bottom, 0px));
    gap: 8px;
  }
  .stage-shell { gap: 8px; }
  .flank-col { top: 8px; bottom: 48px; }
  .flank-left { left: 6px; }
  .flank-right { right: 6px; }
  .chat-layer { padding: 12px; }
  .composer { padding: 8px 10px; border-radius: 10px; }
}
