/* Arc Reactor Core — AI English Tutor
   Palette: deep space navy, arc cyan, stark gold.
   No external fonts or assets: the app must load from a cold deploy. */

:root {
  --bg: #04060b;
  --bg-2: #070b13;
  --panel: rgba(10, 16, 26, 0.82);
  --panel-solid: #0a101a;
  --line: rgba(96, 190, 235, 0.16);
  --line-strong: rgba(96, 210, 255, 0.34);
  --text: #e8f4fb;
  --muted: #8ea6b8;
  --dim: #5f7486;
  --energy: #38e8ff;
  --energy-soft: rgba(56, 232, 255, 0.16);
  --gold: #ffcf6b;
  --danger: #ff6b7f;
  --ok: #4ce5b1;
  --radius: 14px;
  --shadow: 0 22px 60px rgba(0, 0, 0, 0.55);
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono", Consolas, monospace;
  --sans: "Inter", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

/* The hidden attribute must win over component display rules. */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  background:
    radial-gradient(1200px 700px at 18% -10%, rgba(56, 232, 255, 0.09), transparent 60%),
    radial-gradient(900px 600px at 92% 110%, rgba(255, 207, 107, 0.05), transparent 60%),
    linear-gradient(180deg, var(--bg-2), var(--bg) 55%);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  /* The feed is the only scroller: a page-level scroll on a phone is what hid
     the foot of the core behind the browser chrome. */
  overflow: hidden;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--energy); }

.app {
  height: 100vh;
  height: 100dvh;
  /* --app-h is the visible viewport, kept in sync by app.js. On a phone the
     browser chrome is not always reflected in 100dvh (iOS Safari keeps the
     toolbar-collapsed value after a reload), so the shell grew past the
     screen; body never scrolls, so the extra pixels were clipped off the
     bottom and the view switch vanished with no way to reach it. */
  height: var(--app-h, 100dvh);
  max-height: var(--app-h, 100dvh);
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
}

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

.hud {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(8, 13, 22, 0.95), rgba(8, 13, 22, 0.6));
  backdrop-filter: blur(14px);
  position: sticky;
  top: 0;
  z-index: 30;
}

.hud-brand { display: flex; align-items: center; gap: 12px; min-width: 0; }

.hud-mark {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 2px solid var(--energy);
  box-shadow: 0 0 18px rgba(56, 232, 255, 0.55), inset 0 0 12px rgba(56, 232, 255, 0.5);
  position: relative;
  flex: none;
}
.hud-mark::after {
  content: "";
  position: absolute;
  inset: 9px;
  border-radius: 50%;
  background: var(--energy);
  box-shadow: 0 0 14px var(--energy);
}

.hud-brand h1 {
  margin: 0;
  font-size: 13.5px;
  letter-spacing: 0.24em;
  font-weight: 700;
}
.hud-brand p {
  margin: 2px 0 0;
  font-size: 10px;
  letter-spacing: 0.12em;
  color: var(--muted);
  text-transform: uppercase;
}
.hud-brand strong { color: var(--gold); font-weight: 600; }

.hud-center { display: flex; justify-content: center; }

.trial-chip {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 7px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: rgba(56, 232, 255, 0.06);
  box-shadow: inset 0 0 24px rgba(56, 232, 255, 0.08);
}
.trial-chip-label {
  font-size: 10px;
  letter-spacing: 0.22em;
  color: var(--muted);
}
.trial-chip-time {
  font-family: var(--mono);
  font-size: 15px;
  letter-spacing: 0.08em;
  color: var(--energy);
  font-variant-numeric: tabular-nums;
}
.trial-chip.is-warning { border-color: rgba(255, 107, 127, 0.5); }
.trial-chip.is-warning .trial-chip-time { color: var(--danger); }
.trial-chip.is-paid { border-color: rgba(255, 207, 107, 0.45); background: rgba(255, 207, 107, 0.07); }
.trial-chip.is-paid .trial-chip-label { color: var(--gold); }

.hud-actions { display: flex; justify-content: flex-end; align-items: center; gap: 8px; }

.topic-picker,
.level-picker {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px 5px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.02);
}
.topic-picker span,
.level-picker span {
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}
.topic-picker select,
.level-picker select {
  background: transparent;
  border: 0;
  outline: none;
  font-size: 13px;
  padding: 4px 2px;
}
.topic-picker option,
.level-picker option { background: #0b1119; }
.topic-picker select { max-width: 190px; text-overflow: ellipsis; }

.icon-btn {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.02);
  color: var(--muted);
  transition: color 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}
.icon-btn:hover { color: var(--energy); border-color: var(--line-strong); background: rgba(56, 232, 255, 0.06); }
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

.ghost-btn {
  border: 1px solid var(--line);
  background: transparent;
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 12.5px;
  color: var(--muted);
  transition: 0.18s ease;
}
.ghost-btn:hover { color: var(--text); border-color: var(--line-strong); }

/* Belongs to a link visit only: app.js shows it in a browser tab and hides it
   in the installed app. The media query is the CSS half of that rule, so a
   display-mode the script missed can never leave it inside the app. */
.install-btn { color: var(--energy); border-color: rgba(56, 232, 255, 0.35); }
@media (display-mode: standalone), (display-mode: fullscreen) {
  .install-btn { display: none !important; }
}

/* ------------------------------------------------------------ workspace */

/* The dashboard column: chat history (flexes and scrolls), composer (its own
   height), the plate above it. The workspace never scrolls as a whole, so the
   composer is always the bottom row of the screen. */
.workspace {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px 22px 22px;
  min-height: 0;
  height: auto;
  overflow: hidden;
}

.stage-bar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

/* Two views of one stage. This switch is the only thing that changes which
   layer owns the pointer: the core in core mode, the feed in chat mode. */
.mode-switch {
  display: inline-flex;
  gap: 3px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(6, 11, 18, 0.72);
}
.mode-tab {
  border: 0;
  padding: 6px 13px;
  border-radius: 999px;
  background: transparent;
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--dim);
  white-space: nowrap;
  transition: color 0.18s ease, background 0.18s ease, box-shadow 0.18s ease;
}
.mode-tab:hover { color: var(--muted); }
.mode-tab.is-active {
  color: var(--energy);
  background: rgba(120, 220, 226, 0.12);
  box-shadow: inset 0 0 0 1px rgba(120, 220, 226, 0.3);
}
.mode-tab:focus-visible { outline: 1px solid var(--line-strong); outline-offset: 2px; }

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

.stage-grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(96, 190, 235, 0.055) 1px, transparent 1px),
    linear-gradient(90deg, rgba(96, 190, 235, 0.055) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: radial-gradient(circle at 50% 45%, #000 15%, transparent 78%);
  pointer-events: none;
}

.reactor {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  margin: 0;
  display: grid;
  place-items: center;
  flex: none;
}

.reactor-glow {
  position: absolute;
  inset: 6%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(56, 232, 255, 0.28), transparent 62%);
  filter: blur(18px);
  opacity: 0.55;
  pointer-events: none;
  transition: opacity 0.4s ease;
}

.reactor-svg-wrap { position: relative; width: 100%; height: 100%; }
.reactor-svg { width: 100%; height: 100%; overflow: visible; display: block; }

/* AEGIS Arc Reactor: the canvas paints the whole core, so it takes the wrap's
   box and nothing else has to be positioned. It is out of flow on purpose: a
   canvas with width/height attributes has an intrinsic size, and as an in-flow
   grid item it kept the taller raster from the chat view after the core view
   came back, overflowing the square plate. */
.aegis-canvas { display: block; position: absolute; inset: 0; width: 100%; height: 100%; touch-action: manipulation; }

/* SVG groups rotate around the 210,210 view-box centre. */
.r-outer, .r-mid, .r-inner, .r-ticks {
  transform-box: view-box;
  transform-origin: 210px 210px;
}
.r-outer { animation: rspin 26s linear infinite; }
.r-mid { animation: rspinrev 18s linear infinite; }
.r-inner { animation: rspin 12s linear infinite; }
.r-ticks { animation: rspinrev 40s linear infinite; }

.r-core { animation: breathe 4.6s ease-in-out infinite; transform-box: view-box; transform-origin: 210px 210px; }
.r-ripple { opacity: 0; transform-box: view-box; transform-origin: 210px 210px; }
.r-blade { opacity: 0.75; }

.reactor[data-state="idle"] .r-outer { animation-duration: 30s; }
.reactor[data-state="listening"] .r-ripple { animation: ripple 2.1s ease-out infinite; }
.reactor[data-state="listening"] .r-ripple:nth-of-type(2) { animation-delay: 0.7s; }
.reactor[data-state="listening"] .r-ripple:nth-of-type(3) { animation-delay: 1.4s; }
.reactor[data-state="listening"] .reactor-glow { opacity: 0.85; }

.reactor[data-state="thinking"] .r-outer { animation-duration: 2.4s; }
.reactor[data-state="thinking"] .r-mid { animation-duration: 1.5s; }
.reactor[data-state="thinking"] .r-inner { animation-duration: 0.95s; }
.reactor[data-state="thinking"] .r-ticks { animation-duration: 6s; }
.reactor[data-state="thinking"] .r-core { animation: breathe 1.1s ease-in-out infinite; }
.reactor[data-state="thinking"] .reactor-glow { opacity: 0.42; }

.reactor[data-state="speaking"] .r-core {
  animation: speakpulse 0.5s ease-in-out infinite;
  filter: drop-shadow(0 0 calc(6px + 14px * var(--speak, 0.6)) var(--energy));
}
.reactor[data-state="speaking"] .reactor-glow { opacity: calc(0.5 + 0.5 * var(--speak, 0.6)); }
.reactor[data-state="speaking"] .r-outer { animation-duration: 14s; }

@keyframes rspin { to { transform: rotate(360deg); } }
@keyframes rspinrev { to { transform: rotate(-360deg); } }
@keyframes breathe {
  0%, 100% { transform: scale(1); opacity: 0.85; }
  50% { transform: scale(1.035); opacity: 1; }
}
@keyframes ripple {
  0% { transform: scale(0.72); opacity: 0.75; }
  100% { transform: scale(1.18); opacity: 0; }
}
@keyframes speakpulse {
  0%, 100% { transform: scale(calc(1 + 0.02 * var(--speak, 0.6))); }
  50% { transform: scale(calc(1.02 + 0.035 * var(--speak, 0.6))); }
}

/* Pinned to the foot of the stage: the core stays centred, and the floating
   transcript gets the whole band above the status line to grow into. */
.stage-readout {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  z-index: 3;
  pointer-events: none;
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.2em;
  color: var(--muted);
  text-transform: uppercase;
}
.state-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--energy);
  box-shadow: 0 0 10px var(--energy);
  animation: ledpulse 2.4s ease-in-out infinite;
}
.core-wrap:has(.reactor[data-state="thinking"]) ~ .stage-readout .state-dot { background: var(--gold); box-shadow: 0 0 10px var(--gold); }
.core-wrap:has(.reactor[data-state="listening"]) ~ .stage-readout .state-dot { background: var(--danger); box-shadow: 0 0 10px var(--danger); }
@keyframes ledpulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }
.state-label { color: var(--text); }
.state-sep { color: var(--dim); }
.state-detail { letter-spacing: 0.08em; text-transform: none; font-family: var(--sans); color: var(--dim); }

/* Replay is the only control the core block needs, so it sits in the core's
   bottom-right corner. */
.corner-btn {
  position: absolute;
  right: 2px;
  bottom: 2px;
  z-index: 2;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(4, 8, 14, 0.72);
  color: var(--muted);
  transition: color 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}
.corner-btn:hover { color: var(--energy); border-color: var(--line-strong); background: rgba(56, 232, 255, 0.08); }
.corner-btn svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.drawer-field { display: flex; flex-direction: column; gap: 6px; }
.drawer-field span {
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}
.drawer-select {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.02);
  color: var(--text);
  font-size: 13px;
}
.drawer-select option { background: #0b1119; }

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

.text-btn { border: 0; background: transparent; color: var(--dim); font-size: 12px; }
.text-btn:hover { color: var(--text); }

/* Status line and Clear on one row: the core's live state on the left, the one
   control the feed needs on the right. Cheaper than the bar it replaced. */
.chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex: none;
  padding: 5px 14px;
  border-bottom: 1px solid var(--line);
}
.chat-status {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  font-size: 9px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-status strong { color: var(--energy); font-weight: 600; }
.chat-status .status-dot { flex: none; background: var(--ok); box-shadow: 0 0 8px rgba(76, 229, 177, 0.65); }
.chat-status-sep { opacity: 0.5; }
.chat-head .text-btn { flex: none; font-size: 10px; padding: 2px 2px; }

.messages {
  /* The scroll feed itself: oldest at the top, newest appended at the bottom.
     `auto` (not smooth) so the programmatic pin to scrollHeight lands at once. */
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 14px 18px 8px;
  display: flex;
  flex-direction: column;
  gap: 11px;
  scroll-behavior: auto;
}
.messages::-webkit-scrollbar { width: 8px; }
.messages::-webkit-scrollbar-thumb { background: rgba(96, 190, 235, 0.18); border-radius: 8px; }

.msg { display: flex; flex-direction: column; max-width: 88%; }
.msg.tutor { align-self: flex-start; }
.msg.user { align-self: flex-end; align-items: flex-end; }

.msg-meta {
  display: flex; align-items: center; gap: 8px;
  font-size: 8.5px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--dim);
  margin-bottom: 4px;
}
.msg.tutor .msg-meta strong { color: var(--gold); letter-spacing: 0.14em; }

.bubble {
  padding: 9px 12px;
  border-radius: 13px;
  font-size: 13.5px;
  white-space: pre-wrap;
  word-break: break-word;
}
.msg.tutor .bubble {
  background: linear-gradient(180deg, rgba(56, 232, 255, 0.075), rgba(56, 232, 255, 0.03));
  border: 1px solid rgba(56, 232, 255, 0.16);
  border-left: 2px solid rgba(56, 232, 255, 0.55);
  border-top-left-radius: 4px;
}
.msg.user .bubble {
  background: linear-gradient(180deg, rgba(255, 207, 107, 0.12), rgba(255, 207, 107, 0.05));
  border: 1px solid rgba(255, 207, 107, 0.2);
  border-top-right-radius: 4px;
}

.bubble .correction {
  display: block;
  margin: 7px 0;
  padding: 7px 10px;
  border-radius: 8px;
  border-left: 2px solid var(--gold);
  background: rgba(255, 207, 107, 0.08);
  color: #ffe6b0;
  font-family: var(--mono);
  font-size: 12.8px;
  white-space: pre-wrap;
}
.bubble .mn-explain {
  display: block;
  margin: 7px 0 0;
  padding: 7px 10px;
  border-radius: 8px;
  background: rgba(76, 229, 177, 0.07);
  border-left: 2px solid var(--ok);
  color: #c7fff0;
}
.bubble strong { color: #fff; }

.msg-tools { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.msg-tool {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.02);
  color: var(--muted);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 10.5px;
  letter-spacing: 0.04em;
  transition: 0.18s ease;
}
.msg-tool:hover { color: var(--energy); border-color: var(--line-strong); }
.msg-tool[disabled] { opacity: 0.5; cursor: progress; }

.typing {
  flex: none;
  display: flex; align-items: center; gap: 5px;
  padding: 0 20px 10px; color: var(--dim); font-size: 11.5px;
}
.typing span {
  width: 6px; height: 6px; border-radius: 50%; background: var(--energy);
  opacity: 0.4; animation: typing 1.2s ease-in-out infinite;
}
.typing span:nth-child(2) { animation-delay: 0.15s; }
.typing span:nth-child(3) { animation-delay: 0.3s; }
.typing em { font-style: normal; letter-spacing: 0.12em; text-transform: uppercase; margin-left: 6px; }
@keyframes typing { 0%, 100% { opacity: 0.25; transform: translateY(0); } 50% { opacity: 1; transform: translateY(-3px); } }

/* Zone 2: its own bordered row, so it reads as a distinct bar between the feed
   and the core instead of an edge on the panel. */
.composer {
  /* The foot row. It is last in the column (not position: fixed) so the phone
     keyboard pushes it up instead of covering it. */
  position: relative;
  z-index: 5;
  flex: none;
  width: 100%;
  max-width: 880px;
  margin: 0 auto;
  display: flex; align-items: flex-end; gap: 10px;
  padding: 12px 14px 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(4, 8, 14, 0.72);
}
.composer textarea {
  flex: 1;
  resize: none;
  max-height: 132px;
  padding: 11px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.025);
  outline: none;
  font-size: 14px;
  line-height: 1.45;
}
.composer textarea:focus { border-color: var(--line-strong); }
/* Only a very long draft scrolls, and then the bar is part of the dark field
   instead of a light native gutter next to the send button. */
.composer textarea { scrollbar-width: thin; scrollbar-color: rgba(120, 220, 226, 0.32) transparent; }
.composer textarea::-webkit-scrollbar { width: 6px; }
.composer textarea::-webkit-scrollbar-thumb { background: rgba(120, 220, 226, 0.3); border-radius: 6px; }
.composer textarea::-webkit-scrollbar-track { background: transparent; }
.send-btn {
  width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--line-strong);
  background: linear-gradient(180deg, rgba(56, 232, 255, 0.22), rgba(56, 232, 255, 0.08));
  color: var(--energy);
  display: grid; place-items: center;
  flex: none;
  transition: 0.18s ease;
}
.send-btn svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linejoin: round; }
.send-btn:hover { box-shadow: 0 0 18px rgba(56, 232, 255, 0.28); }
.send-btn[disabled] { opacity: 0.45; box-shadow: none; cursor: not-allowed; }

/* --------------------------------------------------------------- drawer */

.drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(400px, 92vw);
  background: linear-gradient(180deg, #0a111b, #060a11);
  border-left: 1px solid var(--line-strong);
  box-shadow: var(--shadow);
  transform: translateX(102%);
  transition: transform 0.32s cubic-bezier(0.3, 0.8, 0.3, 1);
  z-index: 60;
  display: flex;
  flex-direction: column;
}
.drawer.is-open { transform: translateX(0); }
.drawer-head {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 10px;
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--line);
}
.drawer-head h2 { margin: 0; font-size: 13px; letter-spacing: 0.24em; }
.drawer-head p { margin: 5px 0 0; font-size: 11.5px; color: var(--dim); max-width: 300px; }
.drawer-head .icon-btn { font-size: 20px; line-height: 1; }
.drawer-body { overflow-y: auto; padding: 16px 18px 26px; display: flex; flex-direction: column; gap: 22px; }
.drawer-section h3 {
  margin: 0 0 8px; font-size: 9.5px; letter-spacing: 0.2em;
  text-transform: uppercase; color: var(--muted);
}
.drawer-note { font-size: 10.5px; color: var(--dim); margin: 8px 0 0; }
.drawer-note code { color: var(--muted); }

.style-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.style-card {
  position: relative;
  display: flex; flex-direction: column; gap: 8px;
  padding: 10px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.018);
  text-align: left;
  transition: 0.18s ease;
}
.style-card:hover { border-color: var(--line-strong); }
.style-card.is-active { border-color: var(--energy); box-shadow: inset 0 0 0 1px rgba(56, 232, 255, 0.3), 0 0 18px rgba(56, 232, 255, 0.12); }
.style-card.is-locked { opacity: 0.78; }
.style-thumb { width: 100%; aspect-ratio: 1.35; display: grid; place-items: center; }
.style-thumb svg { width: 100%; height: 100%; }
.style-thumb-rive {
  width: 58%; aspect-ratio: 1; border-radius: 50%;
  background: radial-gradient(circle at 38% 32%, rgba(255, 255, 255, 0.9), rgba(56, 232, 255, 0.55) 26%, rgba(138, 92, 255, 0.4) 58%, rgba(5, 7, 13, 0.9) 100%);
  box-shadow: 0 0 22px rgba(56, 232, 255, 0.45), inset 0 0 18px rgba(56, 232, 255, 0.35);
}
.style-name { font-size: 11.5px; line-height: 1.3; }
.style-badge {
  display: block;
  margin-top: 2px;
  font-size: 8px; line-height: 1.3; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--gold); background: rgba(255, 207, 107, 0.1);
  border: 1px solid rgba(255, 207, 107, 0.28);
  padding: 3px 5px; border-radius: 6px; text-align: center;
}

.swatch-row { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.swatch {
  position: relative;
  aspect-ratio: 1;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  transition: 0.18s ease;
}
.swatch::after {
  content: ""; position: absolute; inset: 4px; border-radius: 7px;
  border: 1px solid rgba(0, 0, 0, 0.35);
}
.swatch:hover { transform: translateY(-1px); }
.swatch.is-active { box-shadow: 0 0 0 2px #fff, 0 0 16px currentColor; }
.swatch.is-locked { opacity: 0.5; }
.swatch span {
  position: absolute; bottom: -15px; left: 0; right: 0;
  font-size: 8px; text-align: center; color: var(--dim);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.swatch-row { row-gap: 20px; }

.voice-list { display: flex; flex-direction: column; gap: 16px; }

/* Two menus in one column: a heading per gender, the rows beneath it. */
.voice-group { display: flex; flex-direction: column; gap: 7px; }
.voice-group-title {
  margin: 0 0 1px;
  font-family: var(--mono);
  font-size: 9.5px;
  font-weight: 400;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--dim);
}
.voice-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.018);
  text-align: left;
  transition: 0.18s ease;
}
.voice-row:hover { border-color: var(--line-strong); }
.voice-row.is-active { border-color: var(--energy); background: rgba(56, 232, 255, 0.07); }
.voice-row.is-locked { opacity: 0.72; }
.voice-row-main { display: flex; flex-direction: column; gap: 2px; }
.voice-row-main strong { font-size: 12px; font-weight: 600; }
.voice-row-main span { font-size: 10px; color: var(--dim); }
.voice-lock {
  font-size: 8.5px; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--gold); border: 1px solid rgba(255, 207, 107, 0.3);
  border-radius: 999px; padding: 2px 7px; white-space: nowrap;
}

.scrim {
  position: fixed; inset: 0; background: rgba(2, 4, 8, 0.62);
  backdrop-filter: blur(3px); z-index: 50;
}

/* ---------------------------------------------------------- install guide */
/* iOS has no install prompt, so these numbered steps stand in for it. */
.install-card { width: min(440px, 100%); }
.install-head { display: flex; gap: 14px; align-items: flex-start; margin-bottom: 18px; }
.install-share {
  flex: none;
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border-radius: 12px;
  border: 1px solid rgba(56, 232, 255, 0.35);
  background: rgba(56, 232, 255, 0.08);
  color: var(--energy);
}
.install-share[hidden] { display: none; }
.install-share svg {
  width: 20px; height: 20px;
  fill: none; stroke: currentColor; stroke-width: 1.7;
  stroke-linecap: round; stroke-linejoin: round;
}
.install-head h2 { margin: 0 0 4px; font-size: 13px; letter-spacing: 0.18em; }
.install-head .modal-sub { margin: 0; font-size: 12.5px; line-height: 1.5; }
.install-steps {
  margin: 0 0 14px; padding: 0; list-style: none;
  counter-reset: install-step;
  display: grid; gap: 10px;
}
.install-steps li {
  counter-increment: install-step;
  display: flex; gap: 11px;
  font-size: 13.5px; line-height: 1.45;
}
.install-steps li::before {
  content: counter(install-step);
  flex: none;
  width: 21px; height: 21px;
  display: grid; place-items: center;
  border-radius: 50%;
  border: 1px solid rgba(56, 232, 255, 0.3);
  background: rgba(56, 232, 255, 0.12);
  color: var(--energy);
  font-size: 11px; font-weight: 600;
}
.install-note { margin: 0; font-size: 11.5px; line-height: 1.5; color: var(--muted); }
.install-card .modal-actions { margin-top: 16px; }

/* --------------------------------------------------------------- modals */

.modal {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  padding: 20px;
  background: rgba(2, 4, 8, 0.78);
  backdrop-filter: blur(6px);
  z-index: 80;
  overflow-y: auto;
}
.modal[hidden] { display: none; }

.modal-card {
  width: min(520px, 100%);
  background: linear-gradient(180deg, #0b131e, #070b12);
  border: 1px solid var(--line-strong);
  border-radius: 18px;
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.04);
  padding: 26px;
  position: relative;
  animation: cardin 0.28s ease;
}
@keyframes cardin { from { opacity: 0; transform: translateY(10px) scale(0.99); } }
.modal-card.small { width: min(430px, 100%); }
.modal-card h2 { margin: 0 0 6px; font-size: 15px; letter-spacing: 0.22em; }
.modal-sub { margin: 0 0 18px; color: var(--muted); font-size: 13px; }
/* The gate copy is bilingual: Mongolian first, English underneath. */
.modal-sub-mn { margin-bottom: 8px; color: var(--text); }
.modal-sub-en { font-size: 12px; }
.gate-foot-en { margin-top: 4px; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > span { font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); }
.field input, .field select {
  padding: 11px 13px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  outline: none;
  font-size: 14.5px;
}
.field input:focus, .field select:focus { border-color: var(--line-strong); }

.primary-btn {
  border: 1px solid rgba(56, 232, 255, 0.45);
  background: linear-gradient(180deg, rgba(56, 232, 255, 0.24), rgba(56, 232, 255, 0.08));
  color: #dffbff;
  border-radius: 11px;
  padding: 12px 20px;
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  transition: 0.18s ease;
}
.primary-btn:hover { box-shadow: 0 0 22px rgba(56, 232, 255, 0.25); }
.primary-btn:disabled { opacity: 0.55; cursor: progress; }
.primary-btn.wide { width: 100%; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }

.switch-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  margin-bottom: 14px;
  cursor: pointer;
}
.switch-row > span { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.switch-row strong { font-size: 13px; font-weight: 600; }
.switch-row em { font-size: 11px; color: var(--dim); font-style: normal; }
.switch-row input { position: absolute; opacity: 0; pointer-events: none; }
.switch-row i {
  width: 42px; height: 24px; border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--line);
  position: relative; flex: none; transition: 0.2s ease;
}
.switch-row i::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--dim); transition: 0.2s ease;
}
.switch-row input:checked + i { background: rgba(56, 232, 255, 0.22); border-color: var(--line-strong); }
.switch-row input:checked + i::after { left: 20px; background: var(--energy); box-shadow: 0 0 10px var(--energy); }

/* gate */
.gate-badge {
  display: inline-block; margin-bottom: 12px;
  font-size: 9.5px; letter-spacing: 0.24em;
  color: var(--gold); border: 1px solid rgba(255, 207, 107, 0.35);
  background: rgba(255, 207, 107, 0.07);
  padding: 4px 10px; border-radius: 999px;
}
.switch-link {
  display: block; width: 100%;
  margin: -4px 0 14px;
  border: 0; background: transparent;
  color: var(--muted); font-size: 11.5px; text-align: left;
  text-decoration: underline; text-underline-offset: 3px;
}
.switch-link:hover { color: var(--energy); }
.gate-error { margin: 0 0 12px; color: var(--danger); font-size: 12px; }
.gate-foot { margin: 16px 0 0; font-size: 11.5px; color: var(--dim); }

/* paywall */
.modal-card.paywall-card { width: min(720px, 100%); }
.depleted-mark {
  width: 44px; height: 44px; border-radius: 50%;
  border: 2px solid var(--danger);
  box-shadow: 0 0 24px rgba(255, 107, 127, 0.4), inset 0 0 14px rgba(255, 107, 127, 0.3);
  margin-bottom: 12px;
  position: relative;
}
.depleted-mark::after {
  content: ""; position: absolute; inset: 13px; border-radius: 50%;
  background: var(--danger);
}
.paywall-card h2 { color: #ffdfe4; font-size: 15px; }

.plan-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 18px 0; }
.plan-card {
  padding: 14px;
  border-radius: 13px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.018);
  display: flex; flex-direction: column; gap: 6px;
  position: relative;
}
.plan-card.is-featured { border-color: rgba(255, 207, 107, 0.4); background: rgba(255, 207, 107, 0.05); }
.plan-tag {
  font-size: 8.5px; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--gold); font-weight: 600;
}
.plan-card h4 { margin: 0; font-size: 12.5px; line-height: 1.3; }
.plan-price { font-family: var(--mono); font-size: 18px; color: var(--gold); letter-spacing: 0.02em; }
.plan-blurb { margin: 0; font-size: 10.5px; color: var(--dim); line-height: 1.4; }

.iban-box {
  border: 1px dashed rgba(96, 190, 235, 0.28);
  border-radius: 12px;
  padding: 14px 16px;
  background: rgba(56, 232, 255, 0.03);
  margin-bottom: 18px;
}
.iban-box h3 { margin: 0 0 10px; font-size: 10px; letter-spacing: 0.22em; color: var(--muted); }
.iban-box dl { margin: 0; display: flex; flex-direction: column; gap: 6px; }
.iban-box dl > div { display: flex; gap: 10px; font-size: 13px; }
.iban-box dt { width: 118px; flex: none; color: var(--dim); font-size: 11px; text-transform: uppercase; letter-spacing: 0.1em; padding-top: 2px; }
.iban-box dd { margin: 0; font-family: var(--mono); font-size: 12.5px; word-break: break-word; }
.iban-note { margin: 12px 0 0; font-size: 11.5px; color: var(--muted); }
.claim-form { margin-top: 4px; }
.pending-box {
  display: flex; gap: 12px; align-items: flex-start;
  margin-top: 14px; padding: 14px;
  border: 1px solid rgba(255, 207, 107, 0.32);
  background: rgba(255, 207, 107, 0.06);
  border-radius: 12px;
}
.pending-box strong { font-size: 13px; color: var(--gold); }
.pending-box p { margin: 3px 0 0; font-size: 12px; color: var(--muted); }
.pending-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--gold); margin-top: 5px; flex: none; animation: ledpulse 1.6s ease-in-out infinite; }
.paywall-close { margin-top: 16px; }

/* toast */
.toast {
  position: fixed;
  left: 50%; bottom: 26px;
  transform: translateX(-50%);
  padding: 11px 18px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: rgba(8, 14, 22, 0.95);
  color: var(--text);
  font-size: 12.5px;
  box-shadow: var(--shadow);
  z-index: 120;
  max-width: calc(100vw - 32px);
}
.toast.is-error { border-color: rgba(255, 107, 127, 0.45); color: #ffd9df; }

/* ---------------------------------------------------------------- admin */

.admin-body {
  min-height: 100vh;
  padding: 26px 22px 60px;
}
.admin-wrap { max-width: 1180px; margin: 0 auto; }
.admin-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.admin-head h1 { margin: 0; font-size: 16px; letter-spacing: 0.22em; }
.admin-head p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.admin-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.admin-key { display: flex; gap: 8px; }
.admin-key input {
  padding: 9px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03); width: 220px; outline: none;
}
.admin-key input:focus { border-color: var(--line-strong); }

.stat-row { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; margin-bottom: 18px; }
.stat {
  padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px;
  background: rgba(255, 255, 255, 0.02);
}
.stat span { display: block; font-size: 10px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--dim); }
.stat strong { font-family: var(--mono); font-size: 22px; font-weight: 500; }
.stat.is-gold strong { color: var(--gold); }
.stat.is-ok strong { color: var(--ok); }
.stat.is-danger strong { color: var(--danger); }

.table-wrap { border: 1px solid var(--line); border-radius: 14px; overflow: hidden; background: rgba(8, 13, 20, 0.6); }
table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
thead th {
  text-align: left; padding: 11px 14px;
  font-size: 9.5px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--dim);
  border-bottom: 1px solid var(--line); background: rgba(255, 255, 255, 0.02);
}
tbody td { padding: 12px 14px; border-bottom: 1px solid rgba(96, 190, 235, 0.07); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: rgba(56, 232, 255, 0.03); }
.student-id { font-family: var(--mono); font-size: 12.5px; }
.student-sub { color: var(--dim); font-size: 10.5px; margin-top: 2px; }
.badge {
  display: inline-block; padding: 3px 9px; border-radius: 999px;
  font-size: 9.5px; letter-spacing: 0.1em; text-transform: uppercase;
  border: 1px solid transparent;
}
.badge.trial { color: var(--energy); background: rgba(56, 232, 255, 0.08); border-color: rgba(56, 232, 255, 0.28); }
.badge.pending { color: var(--gold); background: rgba(255, 207, 107, 0.08); border-color: rgba(255, 207, 107, 0.32); }
.badge.active { color: var(--ok); background: rgba(76, 229, 177, 0.08); border-color: rgba(76, 229, 177, 0.3); }
.badge.expired { color: var(--muted); background: rgba(255, 255, 255, 0.04); border-color: var(--line); }
.approve-group { display: flex; gap: 6px; flex-wrap: wrap; }
.approve-btn {
  border: 1px solid var(--line); background: rgba(255, 255, 255, 0.02);
  border-radius: 8px; padding: 6px 9px; font-size: 10.5px; color: var(--muted);
  transition: 0.18s ease; white-space: nowrap;
}
.approve-btn:hover { color: var(--ok); border-color: rgba(76, 229, 177, 0.45); background: rgba(76, 229, 177, 0.07); }
.approve-btn[disabled] { opacity: 0.5; cursor: progress; }
.empty-row td { text-align: center; color: var(--dim); padding: 34px 14px; }
.admin-note { margin-top: 14px; font-size: 11.5px; color: var(--dim); }

/* Last resort: if the shell still measures taller than the visible viewport
   (a browser with no usable visualViewport height), the page scrolls so the
   view switch stays reachable instead of sitting behind a clipped overflow. */
body.is-page-scroll { overflow-y: auto; }

/* locked core */
.app[data-locked="true"] .reactor {
  cursor: pointer;
  filter: saturate(0.35) brightness(0.62);
  transition: filter 0.4s ease;
}
.app[data-locked="true"] .reactor-glow { opacity: 0.22; }

/* ------------------------------------------------------------ responsive */

@media (max-width: 1080px) {
  .hud { grid-template-columns: 1fr auto; }
  .hud-center { grid-column: 1 / -1; order: 3; justify-content: flex-start; }
}

@media (max-width: 760px) {
  body { font-size: 14px; }
  .hud { padding: 7px 12px; gap: 8px; }
  .hud-brand h1 { font-size: 11.5px; letter-spacing: 0.16em; }
  .hud-brand p { font-size: 9px; }
  .hud-actions { gap: 6px; }
  .topic-picker span,
  .level-picker span { display: none; }
  .topic-picker,
  .level-picker { padding: 5px 8px; }
  .workspace { padding: 8px; gap: 8px; }
  /* Short phones: keep a small foot reserve for the state readout. */
  .stage-readout { bottom: 6px; }
  .messages { padding: 10px 12px 4px; }
  .msg { max-width: 94%; }
  .plan-grid { grid-template-columns: 1fr; }
  .modal-card { padding: 20px; }
  .stat-row { grid-template-columns: repeat(2, 1fr); }
  .table-wrap { overflow-x: auto; }
  table { min-width: 760px; }
}

@media (prefers-reduced-motion: reduce) {
  .r-outer, .r-mid, .r-inner, .r-ticks, .r-core, .r-ripple, .state-dot, .pending-dot, .typing span {
    animation: none !important;
  }
}
