/* 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;
}

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

.app {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

/* ---------------------------------------------------------------- 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: 15px;
  letter-spacing: 0.24em;
  font-weight: 700;
}
.hud-brand p {
  margin: 2px 0 0;
  font-size: 11.5px;
  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; }

.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);
}
.level-picker span {
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}
.level-picker select {
  background: transparent;
  border: 0;
  outline: none;
  font-size: 13px;
  padding: 4px 2px;
}
.level-picker option { background: #0b1119; }

.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); }

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

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.02fr) minmax(0, 0.98fr);
  gap: 18px;
  padding: 18px 22px 22px;
  min-height: 0;
  height: calc(100vh - 68px);
}

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

.reactor-stage {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 18px 18px 14px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background:
    radial-gradient(circle at 50% 42%, rgba(56, 232, 255, 0.08), transparent 58%),
    linear-gradient(180deg, rgba(10, 16, 26, 0.75), rgba(6, 10, 17, 0.9));
  overflow: hidden;
  min-height: 0;
}

.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: min(100%, 430px);
  aspect-ratio: 1;
  margin: auto;
  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; }

/* 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))); }
}

.stage-readout {
  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;
}
.reactor[data-state="thinking"] + .stage-readout .state-dot { background: var(--gold); box-shadow: 0 0 10px var(--gold); }
.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); }

.voice-console {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 16px 10px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(4, 8, 14, 0.72);
  max-width: 100%;
}

.mic-btn {
  width: 52px; height: 52px;
  border-radius: 50%;
  display: grid; place-items: center;
  border: 1px solid var(--line-strong);
  background: radial-gradient(circle at 50% 35%, rgba(56, 232, 255, 0.24), rgba(56, 232, 255, 0.05));
  color: var(--energy);
  flex: none;
  transition: 0.2s ease;
}
.mic-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.mic-btn:hover { box-shadow: 0 0 0 4px rgba(56, 232, 255, 0.1); }
.mic-btn.is-live {
  background: radial-gradient(circle at 50% 35%, rgba(255, 107, 127, 0.4), rgba(255, 107, 127, 0.08));
  border-color: rgba(255, 107, 127, 0.7);
  color: #ffdbe0;
  animation: micpulse 1.4s ease-in-out infinite;
}
@keyframes micpulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 107, 127, 0.35); }
  50% { box-shadow: 0 0 0 10px rgba(255, 107, 127, 0); }
}

.voice-meta { display: flex; flex-direction: column; min-width: 0; }
.voice-name { font-size: 13px; letter-spacing: 0.06em; }
.voice-hint { font-size: 11.5px; color: var(--dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.stage-footer { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.chip-btn {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.02);
  color: var(--muted);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 12px;
  letter-spacing: 0.04em;
  transition: 0.18s ease;
}
.chip-btn:hover, .chip-btn.is-active { color: var(--energy); border-color: var(--line-strong); background: rgba(56, 232, 255, 0.07); }

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

.chat-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: linear-gradient(180deg, rgba(10, 16, 26, 0.86), rgba(6, 10, 17, 0.94));
  overflow: hidden;
}

.chat-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
}
.chat-tabs { display: flex; gap: 4px; padding: 3px; border-radius: 10px; background: rgba(255, 255, 255, 0.03); }
.chat-tab {
  border: 0; background: transparent; color: var(--muted);
  padding: 7px 14px; border-radius: 8px; font-size: 12.5px; letter-spacing: 0.04em;
  transition: 0.18s ease;
}
.chat-tab.is-active { background: rgba(56, 232, 255, 0.1); color: var(--energy); box-shadow: inset 0 0 0 1px rgba(56, 232, 255, 0.25); }
.text-btn { border: 0; background: transparent; color: var(--dim); font-size: 12px; }
.text-btn:hover { color: var(--text); }

.chat-context {
  padding: 8px 16px;
  font-size: 11.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--dim);
  border-bottom: 1px solid rgba(96, 190, 235, 0.08);
}

.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 18px 18px 8px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}
.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: 10px; letter-spacing: 0.18em; text-transform: uppercase; color: var(--dim);
  margin-bottom: 5px;
}
.msg.tutor .msg-meta strong { color: var(--gold); letter-spacing: 0.14em; }

.bubble {
  padding: 11px 14px;
  border-radius: 14px;
  font-size: 14.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 {
  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); } }

.composer {
  display: flex; align-items: flex-end; gap: 10px;
  padding: 12px 14px 14px;
  border-top: 1px solid var(--line);
  background: rgba(4, 8, 14, 0.5);
}
.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); }
.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 10px; font-size: 10.5px; letter-spacing: 0.22em;
  text-transform: uppercase; color: var(--muted);
}
.drawer-note { font-size: 11px; 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-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: 7px; }
.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: 12.5px; font-weight: 600; }
.voice-row-main span { font-size: 10.5px; 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;
}

/* --------------------------------------------------------------- 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; }

.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); }

/* 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) {
  .workspace { grid-template-columns: 1fr; height: auto; }
  .reactor-stage { min-height: 460px; }
  .chat-panel { min-height: 560px; }
  .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: 10px 14px; gap: 10px; }
  .hud-brand h1 { font-size: 12.5px; letter-spacing: 0.18em; }
  .hud-brand p { font-size: 10px; }
  .hud-actions { gap: 6px; }
  .level-picker span { display: none; }
  .level-picker { padding: 5px 8px; }
  .workspace { padding: 10px; gap: 10px; }
  .reactor-stage { padding: 12px; min-height: 400px; border-radius: 16px; }
  .reactor { width: min(100%, 320px); }
  .voice-console { width: 100%; }
  .voice-hint { white-space: normal; }
  .chat-panel { min-height: 520px; border-radius: 16px; }
  .messages { padding: 14px 12px 6px; }
  .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;
  }
}
