*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:     #030308;
  --ind:    #6366f1;
  --ind-d:  #4f46e5;
  --blue:   #3b82f6;
  --red:    #ef4444;
  --green:  #22c55e;
  --yellow: #eab308;
  --txt:    #e2e8f0;
  --txt2:   #94a3b8;
  --txt3:   #475569;
  --border: rgba(255,255,255,.06);
  --g2:     rgba(255,255,255,.05);
}

html, body { height: 100%; overflow: hidden; }

body {
  background:
    radial-gradient(ellipse 130% 50% at 50% -5%, rgba(79,70,229,.11) 0%, transparent 60%),
    radial-gradient(ellipse 70% 45% at 85% 105%, rgba(59,130,246,.07) 0%, transparent 55%),
    radial-gradient(circle, rgba(255,255,255,.016) 1px, transparent 1px) 0 0 / 20px 20px,
    var(--bg);
  color: var(--txt);
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 14px;
  display: flex; flex-direction: column; height: 100vh;
}

/* ── Steps ─────────────────────────────────────────── */
.step { display: none; flex: 1; flex-direction: column; overflow: hidden; }
.step.active { display: flex; }

/* ── Shared card (connect + enroll) ─────────────────── */
.card-screen { flex: 1; display: flex; align-items: center; justify-content: center; }
.card {
  background: rgba(255,255,255,.03);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 44px 40px;
  width: 400px;
  display: flex; flex-direction: column; align-items: center; gap: 22px;
  box-shadow: 0 24px 80px rgba(0,0,0,.6);
}
.card .logo {
  width: 68px; height: 68px; border-radius: 50%;
  border: 2px solid rgba(99,102,241,.45);
  object-fit: cover; object-position: center 8%;
  box-shadow: 0 0 30px rgba(99,102,241,.2);
}
.card h1 { font-size: 24px; font-weight: 700; color: #fff; letter-spacing: -.3px; }
.card h2 { font-size: 20px; font-weight: 700; color: #fff; letter-spacing: -.2px; }
.card .sub { font-size: 13px; color: var(--txt3); text-align: center; line-height: 1.6; }

.field { width: 100%; display: flex; flex-direction: column; gap: 7px; }
.field label { font-size: 11px; color: var(--txt2); font-weight: 600; letter-spacing: .5px; text-transform: uppercase; }
.field input {
  width: 100%; background: rgba(255,255,255,.04);
  border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 15px; color: var(--txt); font-size: 14px;
  font-family: monospace; outline: none; transition: border-color .15s;
}
.field input:focus { border-color: rgba(99,102,241,.55); }

.btn-primary {
  width: 100%; background: linear-gradient(135deg, var(--ind-d), var(--blue));
  border: none; border-radius: 12px; padding: 13px;
  color: #fff; font-size: 14px; font-weight: 600;
  cursor: pointer; transition: opacity .15s, transform .1s;
  box-shadow: 0 4px 24px rgba(79,70,229,.4);
}
.btn-primary:hover  { opacity: .88; }
.btn-primary:active { transform: scale(.98); }
.btn-primary:disabled { opacity: .35; cursor: not-allowed; }
.btn-primary.success {
  background: linear-gradient(135deg, #16a34a, #15803d);
  box-shadow: 0 4px 24px rgba(22,163,74,.35);
}

.err-msg { font-size: 12px; color: var(--red); min-height: 16px; text-align: center; }

/* ── Enroll ────────────────────────────────────────── */
.enroll-screen {
  align-items: flex-start;
  overflow-y: auto;
  padding: 32px 16px;
}
.enroll-screen::-webkit-scrollbar { width: 2px; }
.enroll-screen::-webkit-scrollbar-thumb { background: var(--ind); border-radius: 1px; }

.enroll-card {
  width: 540px;
  max-width: 100%;
  margin: auto;
  gap: 20px;
}

/* passage reading box */
.passage-box {
  width: 100%;
  background: rgba(99,102,241,.06);
  border: 1px solid rgba(99,102,241,.18);
  border-left: 3px solid var(--ind);
  border-radius: 14px;
  padding: 18px 20px 20px;
  display: flex; flex-direction: column; gap: 10px;
}

.passage-label {
  display: flex; align-items: center; gap: 7px;
  font-size: 10px; font-weight: 700; letter-spacing: .8px;
  text-transform: uppercase; color: var(--ind);
}

.passage-label::before {
  content: '';
  display: inline-block; width: 6px; height: 6px;
  border-radius: 50%; background: var(--ind);
  box-shadow: 0 0 6px rgba(99,102,241,.7);
  flex-shrink: 0;
}

.passage-text {
  font-size: 15.5px; line-height: 1.75; color: var(--txt);
  font-weight: 400; letter-spacing: .01em;
}

.passage-hint {
  font-size: 11.5px; color: var(--txt3); line-height: 1.5;
  display: flex; align-items: center; gap: 6px;
}

/* enroll controls row (timer + viz) */
.enroll-controls {
  display: flex; align-items: center; gap: 18px; width: 100%;
}

.timer-wrap {
  position: relative; width: 100px; height: 100px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.timer-wrap svg { position: absolute; inset: 0; transform: rotate(-90deg); }
#timerCircle { transition: stroke-dashoffset .25s linear; }
#timerCount { font-size: 28px; font-weight: 700; color: #fff; z-index: 1; }

.enroll-right {
  flex: 1; display: flex; flex-direction: column; gap: 10px; min-width: 0;
}

.enroll-viz { width: 100%; height: 40px; opacity: 0; transition: opacity .3s; }
.enroll-viz.on { opacity: 1; }

.enroll-status { font-size: 13px; color: var(--txt2); min-height: 18px; }
.enroll-status.ok   { color: var(--green); }
.enroll-status.fail { color: var(--red); }

.enroll-btns { display: flex; flex-direction: column; gap: 10px; width: 100%; }

.btn-ghost {
  background: rgba(255,255,255,.05); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 16px; color: var(--txt2);
  font-size: 13px; cursor: pointer; transition: background .15s, color .15s;
  width: 100%; text-align: center;
}
.btn-ghost:hover { background: rgba(255,255,255,.09); color: var(--txt); }

/* ── Session topbar ────────────────────────────────── */
.s-topbar {
  flex-shrink: 0; position: relative;
  display: flex; align-items: center; justify-content: space-between;
  height: 48px; padding: 0 20px;
  border-bottom: 1px solid var(--border);
  background: rgba(3,3,8,.85); backdrop-filter: blur(8px);
  z-index: 10;
}

.s-brand {
  position: absolute; left: 50%; transform: translateX(-50%);
  font-size: 13px; font-weight: 600; color: var(--txt3);
  pointer-events: none; user-select: none; letter-spacing: .1px;
}

.s-left { display: flex; align-items: center; gap: 10px; }

.state-dot {
  width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
  transition: background .35s, box-shadow .35s;
}
.state-dot.idle       { background: rgba(255,255,255,.2); }
.state-dot.listening  { background: var(--green); animation: ping .6s ease-out infinite; }
.state-dot.recording  { background: var(--green); animation: ping .9s ease-out infinite; }
.state-dot.processing { background: var(--yellow); box-shadow: 0 0 6px rgba(234,179,8,.55); }
.state-dot.generating { background: var(--ind);   box-shadow: 0 0 7px rgba(99,102,241,.7); }

@keyframes ping {
  0%  { box-shadow: 0 0 0 0   rgba(34,197,94,.75); }
  70% { box-shadow: 0 0 0 8px rgba(34,197,94,0); }
  100%{ box-shadow: 0 0 0 0   rgba(34,197,94,0); }
}

.state-text { display: flex; flex-direction: column; gap: 1px; }
.state-label { font-size: 13px; font-weight: 600; color: var(--txt); transition: color .3s; line-height: 1; }
.state-sub   { font-size: 10px; color: var(--txt3); line-height: 1; min-height: 10px; }

.s-right { display: flex; align-items: center; gap: 10px; }

.turn-counter {
  font-size: 11px; color: var(--txt3);
  background: var(--g2); border: 1px solid var(--border);
  padding: 3px 9px; border-radius: 20px;
  font-variant-numeric: tabular-nums;
}

.gear-btn {
  width: 30px; height: 30px; border-radius: 8px;
  background: rgba(255,255,255,.05); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  color: var(--txt3); cursor: pointer; transition: background .15s, color .15s;
  font-size: 15px; line-height: 1;
}
.gear-btn:hover { background: rgba(255,255,255,.09); color: var(--txt); }

/* ── Answer feed ────────────────────────────────────── */
#chat {
  flex: 1; overflow-y: auto; min-height: 0;
  padding: 24px 0 28px;
  display: flex; flex-direction: column; gap: 16px;
}
#chat::-webkit-scrollbar { width: 2px; }
#chat::-webkit-scrollbar-thumb { background: linear-gradient(var(--ind), var(--blue)); border-radius: 1px; }

.empty-state {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 12px; color: var(--txt3); font-size: 15px;
  user-select: none; pointer-events: none;
}
.empty-state img {
  width: 52px; height: 52px; border-radius: 50%;
  border: 1.5px solid rgba(99,102,241,.3);
  object-fit: cover; object-position: center 8%;
  opacity: .38;
}
.empty-state .big { font-size: 15px; font-weight: 500; color: var(--txt2); }

/* ── Q+A card ───────────────────────────────────────── */
.qa-card {
  margin: 0 24px;
  max-width: 860px;
  width: calc(100% - 48px);
  align-self: center;
  background: rgba(255,255,255,.032);
  border: 1px solid rgba(255,255,255,.065);
  border-radius: 16px;
  padding: 20px 24px 18px;
  transition: opacity .5s ease, border-color .35s, box-shadow .35s;
  animation: cardIn .22s ease-out;
}
.qa-card.faded { opacity: .68; }
.qa-card.generating {
  border-color: rgba(99,102,241,.4);
  box-shadow: 0 0 24px rgba(99,102,241,.1), 0 6px 28px rgba(0,0,0,.35);
}

@keyframes cardIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.q-label {
  font-size: 10px; font-weight: 700; letter-spacing: .8px;
  text-transform: uppercase; color: var(--txt3);
  margin-bottom: 6px;
}
.q-text { font-size: 16px; color: var(--txt2); line-height: 1.5; font-weight: 400; }

.card-divider {
  border: none; border-top: 1px solid rgba(255,255,255,.07);
  margin: 14px 0 16px;
}

.card-a { font-size: 18px; line-height: 1.68; color: #fff; word-break: break-word; }

.cursor {
  display: inline-block; width: 2px; height: 20px;
  background: rgba(255,255,255,.5); margin-left: 3px;
  vertical-align: middle; border-radius: 1px;
  animation: blink .8s steps(1) infinite;
}
@keyframes blink { 0%,100%{ opacity:1 } 50%{ opacity:0 } }

.thinking { display: flex; gap: 5px; align-items: center; padding: 6px 0; }
.thinking span {
  width: 6px; height: 6px; border-radius: 50%; background: var(--txt3);
  animation: tdot .9s ease-in-out infinite;
}
.thinking span:nth-child(2) { animation-delay: .15s; }
.thinking span:nth-child(3) { animation-delay: .30s; }
@keyframes tdot { 0%,100%{ transform:translateY(0);opacity:.3 } 50%{ transform:translateY(-5px);opacity:1 } }

.card-turn { font-size: 10px; color: var(--txt3); text-align: right; margin-top: 12px; }

.img-grid { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.img-grid img {
  width: 160px; height: 112px; object-fit: cover;
  border-radius: 10px; border: 1px solid var(--border);
  cursor: pointer; transition: border-color .15s, transform .12s;
}
.img-grid img:hover { border-color: rgba(99,102,241,.55); transform: scale(1.04); }

/* ── Markdown in card-a ─────────────────────────────── */
.card-a strong { font-weight: 650; color: #fff; }
.card-a em     { font-style: italic; color: var(--txt2); }
.card-a code {
  background: rgba(0,0,0,.5); border: 1px solid rgba(255,255,255,.09);
  padding: 2px 7px; border-radius: 5px;
  font-family: 'SF Mono','Fira Code',monospace; font-size: 15px; color: #a5b4fc;
}
.card-a pre {
  background: rgba(0,0,0,.55); border: 1px solid rgba(255,255,255,.07);
  border-radius: 10px; padding: 14px 16px; overflow-x: auto; margin: 8px 0;
}
.card-a pre code { background: none; border: none; padding: 0; color: #cbd5e1; font-size: 14px; }
.card-a ul, .card-a ol { padding-left: 0; margin: 6px 0; display: flex; flex-direction: column; gap: 6px; list-style: none; }
.card-a li { padding-left: 22px; position: relative; }
.card-a ul li::before { content: "•"; position: absolute; left: 0; color: var(--ind); font-weight: 700; }
.card-a ol { counter-reset: ol; }
.card-a ol li { counter-increment: ol; }
.card-a ol li::before { content: counter(ol) "."; position: absolute; left: 0; color: var(--txt3); font-size: 15px; }
.card-a h1 { font-size: 22px; font-weight: 700; color: #fff; margin: 10px 0 6px; }
.card-a h2 { font-size: 19px; font-weight: 650; color: #e2e8f0; margin: 8px 0 4px; }
.card-a h3 { font-size: 17px; font-weight: 650; color: var(--txt2); margin: 6px 0 3px; }
.card-a .gap { height: 8px; }
.card-a .br  { display: block; height: 3px; }

/* ── Footer ─────────────────────────────────────────── */
.s-footer {
  flex-shrink: 0; height: 44px;
  display: flex; align-items: center; gap: 14px;
  padding: 0 24px;
  border-top: 1px solid var(--border);
}
.viz-wrap { width: 80px; height: 20px; flex-shrink: 0; }
#viz { width: 100%; height: 100%; opacity: 0; transition: opacity .3s; }
#viz.on { opacity: 1; }
.footer-status { font-size: 12px; color: var(--txt3); }

/* ── Settings overlay ───────────────────────────────── */
.settings-overlay {
  position: fixed; inset: 0; z-index: 50;
  display: none; align-items: flex-end; justify-content: center;
}
.settings-overlay.open { display: flex; }
.settings-overlay::before {
  content: ''; position: fixed; inset: 0;
  background: rgba(0,0,0,.45); backdrop-filter: blur(5px);
}
.settings-panel {
  position: relative; z-index: 1;
  background: #09090f;
  border: 1px solid var(--border); border-bottom: none;
  border-radius: 20px 20px 0 0;
  padding: 24px 24px 36px;
  width: 100%; max-width: 480px;
  display: flex; flex-direction: column; gap: 18px;
  box-shadow: 0 -20px 60px rgba(0,0,0,.5);
}
.sp-header { display: flex; align-items: center; justify-content: space-between; }
.sp-title { font-size: 15px; font-weight: 700; color: #fff; }
.sp-close {
  background: rgba(255,255,255,.07); border: 1px solid var(--border);
  border-radius: 8px; padding: 4px 12px; color: var(--txt2);
  font-size: 12px; cursor: pointer; transition: background .15s;
}
.sp-close:hover { background: rgba(255,255,255,.11); color: var(--txt); }

.sp-row { display: flex; flex-direction: column; gap: 9px; }
.sp-label { font-size: 10px; font-weight: 700; letter-spacing: .6px; text-transform: uppercase; color: var(--txt3); }
.sp-slider-row { display: flex; align-items: center; gap: 10px; }
.sp-slider-row input[type=range] { flex: 1; accent-color: var(--ind); cursor: pointer; height: 4px; }
.sp-val { font-size: 13px; color: var(--txt2); font-variant-numeric: tabular-nums; min-width: 30px; text-align: right; }

.sp-divider { border: none; border-top: 1px solid var(--border); }

.sp-actions { display: flex; gap: 8px; }
.sp-btn {
  flex: 1; background: rgba(255,255,255,.05); border: 1px solid var(--border);
  border-radius: 10px; padding: 11px 14px; color: var(--txt2);
  font-size: 13px; cursor: pointer; transition: background .15s, color .15s; text-align: center;
}
.sp-btn:hover { background: rgba(255,255,255,.09); color: var(--txt); }
.sp-btn.danger { color: rgba(239,68,68,.8); }
.sp-btn.danger:hover { background: rgba(239,68,68,.09); color: var(--red); }

.sp-conn { display: flex; align-items: center; gap: 8px; }
.conn-dot {
  width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0;
  background: var(--txt3); transition: background .3s, box-shadow .3s;
}
.conn-dot.on  { background: var(--green); box-shadow: 0 0 5px var(--green); }
.conn-dot.err { background: var(--red); }
.conn-label { font-size: 12px; color: var(--txt3); }

.hidden { display: none !important; }

/* ── Rate limit banner ──────────────────────────────── */
.rl-banner {
  position: fixed; bottom: 56px; left: 50%; transform: translateX(-50%);
  background: rgba(234,179,8,.12); border: 1px solid rgba(234,179,8,.35);
  color: #fde047; border-radius: 10px;
  padding: 12px 18px; font-size: 13px;
  display: flex; align-items: center; gap: 10px;
  z-index: 900; white-space: nowrap;
  box-shadow: 0 8px 24px rgba(0,0,0,.5);
}
.rl-banner span { color: #fff; font-weight: 600; }
.rl-banner button {
  background: none; border: none; color: #fde047;
  cursor: pointer; font-size: 14px; padding: 0 2px;
  opacity: .7; transition: opacity .15s;
}
.rl-banner button:hover { opacity: 1; }

/* ── Lightbox ───────────────────────────────────────── */
.lightbox {
  display: none;
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0,0,0,.88);
  align-items: center; justify-content: center;
  padding: 60px 48px;
  cursor: zoom-out;
}
.lightbox.open { display: flex; }
.lb-wrap {
  position: relative;
  display: inline-flex;
  cursor: default;
}
.lb-img {
  display: block;
  width: auto; height: auto;
  max-width: 100%; max-height: 100%;
  border-radius: 10px;
  box-shadow: 0 24px 80px rgba(0,0,0,.8);
}
.lb-close {
  position: absolute; top: -18px; right: -18px;
  background: rgba(30,30,40,.85); border: 1px solid rgba(255,255,255,.15);
  color: #fff; font-size: 16px; line-height: 1;
  width: 42px; height: 42px; border-radius: 50%;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: background .2s;
  box-shadow: 0 4px 12px rgba(0,0,0,.5);
}
.lb-close:hover { background: rgba(239,68,68,.8); }
