:root {
  color-scheme: dark;
  --bg: #0e141c;
  --panel: rgba(16, 28, 44, 0.94);
  --panel-solid: #132033;
  --line: rgba(168, 204, 240, 0.18);
  --text: #e8f2fb;
  --muted: #a6bdd4;
  --accent: #5aa6f0;
  --accent-ink: #071422;
  --accent-deep: #16324d;
  --warn: #8ec8ff;
  --danger: #ffb4a8;
  font-family: "Avenir Next", "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; }
body {
  color: var(--text);
  background:
    radial-gradient(820px 420px at 12% -8%, rgba(90, 166, 240, 0.2), transparent 58%),
    radial-gradient(680px 460px at 100% 110%, rgba(24, 64, 120, 0.42), transparent 52%),
    var(--bg);
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, p { margin: 0; }
h1 {
  font-family: "Iowan Old Style", Palatino, "Songti SC", serif;
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.1;
}
h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

.shell {
  width: min(1120px, calc(100% - 32px));
  height: 100dvh;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 12px;
  padding: 16px 0 12px;
  overflow: hidden;
}
.masthead { display: flex; flex-direction: column; gap: 10px; }
.top, .top-meta, .brand, .controls, .key-row { display: flex; align-items: center; }
.top { justify-content: space-between; gap: 16px; min-height: 52px; }
.brand { gap: 12px; min-width: 0; }
.mark {
  width: 36px;
  height: 36px;
  flex: none;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #d7ecff, #5aa6f0 48%, #1a4d86 80%);
  box-shadow: 0 0 0 6px rgba(90, 166, 240, 0.16);
}
.eyebrow { color: var(--accent); font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; }
.top-meta { gap: 14px; flex: none; }
.top-meta a { color: var(--muted); font-size: 13px; text-underline-offset: 3px; white-space: nowrap; }
.settings-button, .scrim { display: none; }
.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  background: rgba(12, 20, 32, 0.72);
  border-radius: 999px;
  padding: 6px 12px 6px 10px;
  color: var(--text);
  font-size: 13px;
  white-space: nowrap;
}
.pill::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #6d8499;
}
.pill[data-phase="listening"]::before { background: var(--accent); }
.pill[data-phase="speaking"]::before,
.pill[data-phase="busy"]::before { background: var(--warn); }
.banner {
  margin: 0;
  padding: 10px 12px;
  border-radius: 14px;
  background: #1a3554;
  color: #d6e9ff;
  font-size: 14px;
  line-height: 1.5;
}
.banner[hidden] { display: none; }

.stage {
  min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 12px;
}
.conversation, .side, .dock {
  border: 1px solid var(--line);
  background: var(--panel);
}
.conversation {
  border-radius: 24px;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding: 8px;
}
.transcript {
  min-height: 0;
  flex: 1;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
}
.transcript:has(.empty) { justify-content: center; }
.empty { max-width: 460px; }
.empty-title {
  font-family: "Iowan Old Style", Palatino, "Songti SC", serif;
  font-size: 34px;
  letter-spacing: -0.03em;
  margin-bottom: 8px;
}
.empty p { color: var(--muted); line-height: 1.65; }
.empty ul {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  list-style: none;
  margin: 16px 0 0;
  padding: 0;
}
.empty li {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 11px;
  color: var(--text);
  font-size: 13px;
  background: rgba(232, 242, 251, 0.04);
}
.line {
  width: fit-content;
  max-width: min(640px, 88%);
  padding: 10px 12px;
  border-radius: 16px;
  background: rgba(232, 242, 251, 0.05);
}
.line.user { margin-left: auto; background: rgba(90, 166, 240, 0.18); }
.line.tool {
  max-width: 100%;
  background: transparent;
  border: 1px dashed var(--line);
  color: var(--muted);
}
.who { display: block; font-size: 12px; color: var(--accent); margin-bottom: 3px; }
.line p { line-height: 1.55; white-space: pre-wrap; }
.line.partial p::after { content: " ▍"; color: var(--accent); }
.previews { display: flex; gap: 8px; padding: 0 12px 12px; }
.previews figure { margin: 0; width: min(168px, 46%); }
.previews video {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 14px;
  background: #000;
}
.previews figcaption { color: var(--muted); font-size: 12px; margin-top: 4px; }

.side {
  border-radius: 24px;
  overflow: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.side section, .side details { display: flex; flex-direction: column; gap: 8px; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
input, textarea, select {
  width: 100%;
  border: 1px solid var(--line);
  background: rgba(8, 14, 22, 0.55);
  border-radius: 12px;
  padding: 10px 12px;
  outline: none;
}
textarea { resize: vertical; min-height: 72px; }
input:focus, textarea:focus, select:focus, button:focus-visible { border-color: rgba(90, 166, 240, 0.85); }
.key-row { gap: 8px; }
.key-row input { flex: 1; min-width: 0; }
.key-row button { min-width: 64px; padding-inline: 12px; }
.voices { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.voice {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(232, 242, 251, 0.04);
  color: var(--text);
  cursor: pointer;
}
.voice input {
  width: 15px;
  height: 15px;
  margin: 0;
  padding: 0;
  accent-color: var(--accent);
}
.voice span { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.voice strong { font-size: 14px; font-weight: 600; }
.voice small { color: var(--muted); font-size: 12px; }
.voice:has(input:checked) {
  border-color: rgba(90, 166, 240, 0.75);
  background: rgba(90, 166, 240, 0.16);
}
.hint, .muted, #sessionLine { color: var(--muted); }
.hint, #sessionLine { font-size: 12px; line-height: 1.5; }
#sessionLine { word-break: break-all; }
.note {
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(90, 166, 240, 0.12);
  color: var(--text);
  font-size: 13px;
  line-height: 1.5;
}
#notes, #eventLog { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
#notes li, #eventLog li {
  border-top: 1px solid var(--line);
  padding-top: 8px;
  font-size: 13px;
  line-height: 1.45;
}
#notes time, #eventLog b { display: block; color: var(--muted); font-size: 12px; font-weight: 500; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 0; }
.stats div { padding: 8px; border-radius: 12px; background: rgba(232, 242, 251, 0.04); }
.stats dt { color: var(--muted); font-size: 12px; }
.stats dd { margin: 4px 0 0; font-variant-numeric: tabular-nums; }
summary {
  cursor: pointer;
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 36px;
}
summary::-webkit-details-marker { display: none; }
summary::after { content: "＋"; color: var(--muted); font-weight: 500; }
details[open] > summary::after { content: "–"; }
details[open] > summary { margin-bottom: 4px; }

.dock {
  border-radius: 22px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 12px 14px;
  align-items: center;
}
.orb {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 50% 38%, #d7ecff, #5aa6f0 46%, #1a4d86 78%);
  box-shadow: 0 0 0 calc(6px + var(--level) * 8px) rgba(90, 166, 240, calc(0.12 + var(--level) * 0.2));
  transform: scale(calc(1 + var(--level) * 0.06));
  transition: transform 80ms linear;
}
.orb strong { font-size: 12px; color: var(--accent-ink); letter-spacing: 0.04em; }
.orb.is-speaking { box-shadow: 0 0 0 10px rgba(142, 200, 255, 0.28); }
.orb.is-user { box-shadow: 0 0 0 10px rgba(90, 166, 240, 0.34); }
#caption {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.controls { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
button {
  border: 1px solid var(--line);
  background: rgba(232, 242, 251, 0.04);
  border-radius: 999px;
  padding: 10px 14px;
  min-width: 76px;
}
button:disabled { opacity: 0.42; cursor: not-allowed; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 650; }
button.end { color: var(--danger); border-color: rgba(255, 180, 168, 0.45); background: rgba(74, 32, 28, 0.45); }
button[aria-pressed="true"] { background: var(--accent-deep); color: var(--accent); border-color: rgba(90, 166, 240, 0.45); }

@media (prefers-reduced-motion: reduce) {
  .orb, .side { transition: none; }
}
@media (max-width: 860px) {
  .shell {
    width: 100%;
    padding: 10px 12px calc(8px + env(safe-area-inset-bottom));
    gap: 8px;
  }
  .masthead, .dock { position: relative; z-index: 25; }
  .top { gap: 8px; min-height: 44px; }
  h1 { font-size: 22px; }
  .mark { width: 30px; height: 30px; }
  .top-meta { gap: 8px; }
  .top-meta a { font-size: 12px; }
  .settings-button {
    display: inline-flex;
    align-items: center;
    min-height: 36px;
    padding: 6px 12px;
    min-width: 0;
  }
  .stage { display: block; }
  .conversation { height: 100%; border-radius: 20px; }
  .empty-title { font-size: 28px; }
  .scrim {
    position: fixed;
    inset: 0;
    z-index: 15;
    border: 0;
    border-radius: 0;
    background: rgba(6, 12, 20, 0.62);
  }
  body.settings-open .scrim { display: block; }
  .side {
    position: fixed;
    z-index: 20;
    top: 64px;
    right: 12px;
    bottom: calc(148px + env(safe-area-inset-bottom));
    left: 12px;
    width: auto;
    border-radius: 20px;
    background: var(--panel-solid);
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
    opacity: 0;
    transform: translateY(8px);
    pointer-events: none;
  }
  body.settings-open .side {
    opacity: 1;
    transform: none;
    pointer-events: auto;
  }
  .dock {
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-areas: "orb caption" "controls controls";
    gap: 8px 10px;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  }
  .orb { grid-area: orb; width: 52px; height: 52px; }
  #caption { grid-area: caption; font-size: 13px; }
  .controls { grid-area: controls; gap: 6px; }
  .controls button {
    flex: 1 1 0;
    min-width: 0;
    min-height: 44px;
    padding-inline: 6px;
    white-space: nowrap;
    font-size: 13px;
  }
}

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
