:root {
  --bg: #0f1522;
  --surface: #182234;
  --surface-2: #223049;
  --text: #eef2f8;
  --muted: #93a1ba;
  --line: #ffffff14;
  --accent: #6da83c;
  --accent-hi: #7fbd4c;
  --danger: #d1524d;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(120% 60% at 50% -10%, #1c2a45 0%, transparent 55%), var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, system-ui, "Segoe UI", sans-serif;
  display: flex; flex-direction: column;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) 16px calc(env(safe-area-inset-bottom) + 12px);
}
header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 2px 8px;
}
.brand { font-weight: 800; letter-spacing: .3px; }
.icon-btn {
  background: none; border: 0; color: var(--muted); font-size: 22px; padding: 6px;
}
main { flex: 1; display: flex; flex-direction: column; }
.hint { color: var(--muted); font-size: 14px; margin: 6px 2px 0; }

.mic-wrap { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; margin: 12px 0; }
.mic-stage { --level: 0; position: relative; width: 132px; height: 132px; display: grid; place-items: center; }
.halo {
  position: absolute; inset: 0; border-radius: 50%; pointer-events: none;
  opacity: 0; transform: scale(1); will-change: transform, opacity;
  transition: opacity .06s linear, transform .06s linear;
}
.halo-wide { background: radial-gradient(circle, #7fbd4c3d 0%, #7fbd4c24 45%, #7fbd4c00 72%); }
.halo-tight { box-shadow: 0 0 0 5px #7fbd4c59, 0 0 24px 4px #7fbd4c40; }
.mic-stage.live .halo-wide {
  opacity: calc(.22 + var(--level) * .78);
  transform: scale(calc(1.08 + var(--level) * 1.05));
}
.mic-stage.live .halo-tight {
  opacity: calc(.3 + var(--level) * .7);
  transform: scale(calc(1.01 + var(--level) * .3));
}
.mic-stage.live .mic { transform: scale(calc(1 + var(--level) * .06)); transition: transform .06s linear, background .15s ease, box-shadow .15s ease; }
.mic {
  width: 132px; height: 132px; border-radius: 50%;
  border: 0; color: #fff; background: var(--surface-2);
  box-shadow: 0 10px 30px #0009, inset 0 0 0 1px #6da83c33;
  display: grid; place-items: center; touch-action: none;
  transition: transform .08s ease, background .15s ease, box-shadow .15s ease;
}
.mic:active { transform: scale(.96); }
.mic.recording {
  background: var(--accent);
  box-shadow: 0 0 0 0 #6da83c66, 0 10px 30px #0009;
}
/* constant pulse only when Web Audio metering is unavailable */
.mic.recording.fallback { animation: pulse 1.2s infinite; }
.mic.busy { background: #d99a2e; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 #6da83c66, 0 10px 30px #0009; }
  70% { box-shadow: 0 0 0 22px #6da83c00, 0 10px 30px #0009; }
  100% { box-shadow: 0 0 0 0 #6da83c00, 0 10px 30px #0009; }
}
.status { color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .6px; }
.upload-link {
  background: none; border: 0; color: var(--muted); font-size: 13px;
  text-decoration: underline; padding: 2px 8px;
}
.upload-link:active { color: var(--text); }
.status.err { color: var(--danger); text-transform: none; letter-spacing: 0; }

.result-card { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 14px; display: flex; flex-direction: column; }
.result-card[hidden] { display: none; }

/* conversation view */
.turns { display: flex; flex-direction: column; gap: 12px; max-height: 46vh; overflow-y: auto; }
.turns[hidden], textarea[hidden], .raw-toggle[hidden], .raw-text[hidden] { display: none; }
.turn { display: flex; flex-direction: column; gap: 4px; }
.chip {
  align-self: flex-start; border: 0; border-radius: 999px; padding: 3px 11px;
  font-size: 12px; font-weight: 700; letter-spacing: .3px; color: #fff;
}
.chip-0 { background: #4f8fdd; } .chip-1 { background: #6da83c; }
.chip-2 { background: #d99a2e; } .chip-3 { background: #b56bd8; }
.chip-4 { background: #d1524d; } .chip-5 { background: #3cb8a8; }
.turn-text { margin: 0 0 0 4px; font-size: 16px; line-height: 1.5; }
.raw-toggle {
  background: none; border: 0; color: var(--muted); font-size: 13px;
  text-decoration: underline; padding: 8px 0 0; align-self: flex-start;
}
.raw-text {
  background: var(--bg); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 12px; color: var(--muted); font-size: 14px; line-height: 1.5;
  font-family: inherit; white-space: pre-wrap; margin: 8px 0 0;
  max-height: 30vh; overflow-y: auto;
}
textarea {
  width: 100%; min-height: 120px; resize: vertical; border: 0; outline: 0;
  background: transparent; color: var(--text); font-size: 17px; line-height: 1.5;
  font-family: inherit;
}
.actions { display: flex; gap: 10px; margin-top: 10px; }
.btn {
  flex: 1; padding: 13px; border-radius: 12px; border: 0; font-weight: 700; font-size: 15px;
  background: var(--surface-2); color: var(--text);
}
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:active { background: var(--accent-hi); }
.btn.ghost { background: transparent; color: var(--muted); box-shadow: inset 0 0 0 1px var(--line); }
.copied { text-align: center; color: var(--accent-hi); font-weight: 700; font-size: 14px; margin-top: 10px; }

.sheet { position: fixed; inset: 0; background: #000a; display: grid; align-items: end; z-index: 40; }
/* the `hidden` attribute must win over display:grid, or the sheet (and its
   full-screen dim) is stuck open; this was the bug the audit caught. */
.sheet[hidden] { display: none; }
.sheet-inner {
  background: var(--surface); border-radius: 20px 20px 0 0; padding: 20px 18px calc(env(safe-area-inset-bottom) + 20px);
  border-top: 1px solid var(--line);
}
.note { color: var(--muted); font-size: 12px; margin: 4px 0 12px; }

.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.sheet-head h2 { margin: 4px 0; }
.btn.small { flex: 0 0 auto; padding: 8px 12px; font-size: 13px; }
.history { list-style: none; margin: 0; padding: 0; max-height: 62vh; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.hist-item { display: flex; align-items: stretch; gap: 8px; }
.hist-text {
  flex: 1; text-align: left; background: var(--bg); border: 1px solid var(--line);
  border-radius: 12px; padding: 10px 12px; color: var(--text); font-size: 15px; line-height: 1.4;
}
.hist-time { display: block; color: var(--muted); font-size: 11px; margin-bottom: 3px; }
