:root {
  color-scheme: light;
  font-family: Inter, "Noto Sans SC", "PingFang SC", system-ui, sans-serif;
  font-synthesis: none;
  --page-top: #f8fbf7;
  --page-bottom: #eef4f0;
  --text: #18312b;
  --heading: #122b25;
  --heading-soft: #1b342d;
  --muted: #667b74;
  --subtle: #75877f;
  --link: #176d58;
  --accent: #2b9873;
  --accent-text: #27785e;
  --border: rgba(198, 214, 207, .86);
  --border-solid: #cbdad4;
  --divider: #e3ebe7;
  --surface: rgba(255, 255, 255, .88);
  --surface-solid: #fbfcfb;
  --surface-soft: #f8faf9;
  --surface-hover: #f1f8f5;
  --surface-badge: rgba(255, 255, 255, .72);
  --shadow: rgba(37, 67, 57, .07);
  --focus: rgba(36, 137, 107, .2);
  --glow-green: rgba(132, 216, 175, .18);
  --glow-gold: rgba(255, 204, 126, .12);
  --user-border: #d9e3f0;
  --user-bg: #f7faff;
  --bot-border: #d0e7dc;
  --bot-bg: #f2faf6;
  --ready-text: #167457;
  --ready-border: #9dd0bf;
  --ready-bg: #eefaf5;
  --warning-text: #9b6815;
  --warning-border: #ead09d;
  --warning-bg: #fff9ed;
  --error-text: #ad3946;
  --error-border: #e6b4ba;
  --error-bg: #fff4f5;
  --media-start: rgba(244, 251, 247, .96);
  --media-end: rgba(255, 251, 242, .94);
  --media-orb: rgba(242, 194, 117, .1);
  --media-accent-start: #dcece5;
  --media-accent-end: #f2e7cf;
  --media-news-start: #dceee6;
  --media-news-end: #cae7dc;
  --media-lesson-start: #fff0d7;
  --media-lesson-end: #f5d7aa;
  --media-lesson-text: #a56823;
  --playlist-bg: rgba(255, 255, 255, .5);
  --playlist-active-bg: rgba(233, 248, 241, .92);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page-top: #0b1412;
  --page-bottom: #111d19;
  --text: #dce9e4;
  --heading: #f3faf7;
  --heading-soft: #e3f0eb;
  --muted: #9aada5;
  --subtle: #84978f;
  --link: #7bd5b3;
  --accent: #5bc49b;
  --accent-text: #7bd9b5;
  --border: rgba(127, 158, 146, .26);
  --border-solid: #3a5148;
  --divider: #2b3e37;
  --surface: rgba(20, 34, 29, .9);
  --surface-solid: #101c18;
  --surface-soft: #192923;
  --surface-hover: #20372f;
  --surface-badge: rgba(31, 50, 43, .9);
  --shadow: rgba(0, 0, 0, .3);
  --focus: rgba(91, 196, 155, .34);
  --glow-green: rgba(46, 139, 105, .14);
  --glow-gold: rgba(180, 118, 50, .1);
  --user-border: #31485f;
  --user-bg: #17232f;
  --bot-border: #2d4d40;
  --bot-bg: #142720;
  --ready-text: #70d5ad;
  --ready-border: #376f5c;
  --ready-bg: #153328;
  --warning-text: #e7bd72;
  --warning-border: #6f5832;
  --warning-bg: #302719;
  --error-text: #ef97a1;
  --error-border: #73424a;
  --error-bg: #351f24;
  --media-start: rgba(20, 40, 33, .96);
  --media-end: rgba(42, 34, 24, .94);
  --media-orb: rgba(196, 131, 53, .11);
  --media-accent-start: #253d34;
  --media-accent-end: #3c3527;
  --media-news-start: #203e33;
  --media-news-end: #285044;
  --media-lesson-start: #493821;
  --media-lesson-end: #5b4023;
  --media-lesson-text: #f0bb71;
  --playlist-bg: rgba(22, 38, 32, .72);
  --playlist-active-bg: rgba(31, 74, 58, .84);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(180deg, var(--page-top) 0%, var(--page-bottom) 100%);
  color: var(--text);
}

button, input { font: inherit; }
button, a { transition: transform .16s ease, border-color .16s ease, background .16s ease; }
button:disabled { opacity: .42; cursor: not-allowed; }
button:focus-visible, input:focus-visible, a:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}
a { color: var(--link); text-decoration: none; }

.page-glow {
  position: fixed;
  z-index: -1;
  border-radius: 50%;
  filter: blur(12px);
  pointer-events: none;
}
.glow-one {
  top: -220px;
  right: -150px;
  width: 520px;
  height: 520px;
  background: var(--glow-green);
}
.glow-two {
  top: 390px;
  left: -190px;
  width: 440px;
  height: 440px;
  background: var(--glow-gold);
}

.shell {
  width: min(1240px, calc(100% - 40px));
  margin: 0 auto;
  padding: 38px 0 64px;
}
.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
}
.topbar h1 {
  margin: 5px 0 8px;
  color: var(--heading);
  font-size: clamp(28px, 4vw, 46px);
  font-weight: 760;
  letter-spacing: -.035em;
}
.eyebrow, .card-title small, .media-copy small {
  margin: 0;
  color: var(--accent-text);
  font-size: 11px;
  font-weight: 760;
  letter-spacing: .16em;
}
.subtitle { margin: 0; color: var(--muted); }
.header-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding-top: 9px;
}
.entry-links { display: inline-flex; flex-wrap: wrap; gap: 10px; }
.flow-link, .theme-toggle {
  min-height: 36px;
  border: 1px solid var(--border-solid);
  border-radius: 999px;
  background: var(--surface-badge);
  padding: 8px 13px;
  font-size: 13px;
  font-weight: 650;
}
.theme-toggle { display: inline-flex; align-items: center; gap: 7px; }
.theme-toggle span:first-child { width: 15px; font-size: 15px; line-height: 1; }
.flow-link:hover, .theme-toggle:hover:not(:disabled) {
  border-color: #78aa9a;
  background: var(--surface-solid);
  transform: translateY(-1px);
}

.state, .protocol {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  border: 1px solid var(--border-solid);
  border-radius: 999px;
  background: var(--surface-soft);
  padding: 7px 11px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}
.state::before {
  width: 7px;
  height: 7px;
  margin-right: 7px;
  border-radius: 50%;
  background: var(--subtle);
  content: "";
}
.state.ready { color: var(--ready-text); border-color: var(--ready-border); background: var(--ready-bg); }
.state.ready::before { background: #20a679; box-shadow: 0 0 0 4px rgba(32, 166, 121, .1); }
.state.connecting { color: var(--warning-text); border-color: var(--warning-border); background: var(--warning-bg); }
.state.connecting::before { background: #d99a31; }
.state.error { color: var(--error-text); border-color: var(--error-border); background: var(--error-bg); }
.state.error::before { background: #d95867; }

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(310px, .78fr);
  gap: 20px;
  margin-top: 32px;
}
.dashboard-media,
.dashboard-session,
.dashboard-protocol,
.dashboard-events { grid-column: 1 / -1; }

.card {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 22px;
  background: var(--surface);
  box-shadow: 0 16px 48px var(--shadow);
  backdrop-filter: blur(14px);
}
.conversation-card, .settings-card, .session-card, .protocol-card, .events-card, .debug-audio-card { padding: 23px; }
.card-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 19px;
}
.card-title.compact { margin-bottom: 5px; }
.card-title h2 {
  margin: 4px 0 0;
  color: var(--heading-soft);
  font-size: 19px;
  letter-spacing: -.015em;
}

.conversation-card { display: flex; flex-direction: column; }
.conversation-grid {
  display: grid;
  flex: 1;
  grid-template-rows: 1fr 1fr;
  gap: 13px;
}
.bubble {
  min-height: 112px;
  border: 1px solid;
  border-radius: 17px;
  padding: 17px 18px;
}
.bubble-label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 720;
  letter-spacing: .08em;
}
.bubble-dot { width: 7px; height: 7px; border-radius: 50%; }
.bubble p { margin: 13px 0 0; color: var(--text); line-height: 1.75; white-space: pre-wrap; }
.bubble.user { border-color: var(--user-border); background: var(--user-bg); }
.bubble.user .bubble-dot { background: #6f8fbd; }
.bubble.bot { border-color: var(--bot-border); background: var(--bot-bg); }
.bubble.bot .bubble-dot { background: #2eaa7f; }
.text-input-debug {
  margin-top: 16px;
  border-top: 1px solid var(--divider);
  padding-top: 16px;
}
.text-input-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.text-input-heading div { display: grid; gap: 5px; }
.text-input-heading small {
  color: var(--accent-text);
  font-size: 10px;
  font-weight: 760;
  letter-spacing: .13em;
}
.text-input-heading strong { color: var(--heading-soft); font-size: 14px; }
.text-input-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 9px; margin-top: 11px; }
.text-input-row button { min-width: 96px; }

label {
  display: grid;
  gap: 7px;
  margin-top: 13px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}
input[type="text"], input[type="password"], label > input:not([type]) {
  width: 100%;
  border: 1px solid var(--border-solid);
  border-radius: 12px;
  background: var(--surface-solid);
  color: var(--text);
  padding: 11px 12px;
  outline: none;
}
label > input:focus { border-color: #61a58f; box-shadow: 0 0 0 3px var(--focus); }
.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
  margin-top: 18px;
}
#remoteAudio, #mediaAudio { display: none; }
button {
  border: 1px solid var(--border-solid);
  border-radius: 11px;
  background: var(--surface-soft);
  color: var(--text);
  padding: 10px 12px;
  cursor: pointer;
  font-weight: 650;
}
button:hover:not(:disabled) { border-color: #78aa9a; background: var(--surface-hover); transform: translateY(-1px); }
button.primary, button.media-primary {
  border-color: transparent;
  background: linear-gradient(135deg, #258565, #3aa781);
  color: white;
  box-shadow: 0 9px 22px rgba(37, 133, 101, .18);
}
.notice {
  margin: 17px 0 0;
  border-left: 3px solid #7cbaa5;
  padding-left: 11px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.65;
}

.session-overview {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr);
  gap: 12px;
}
.facts, .session-grid {
  display: grid;
  gap: 9px;
  margin: 14px 0 0;
}
.session-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.facts { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.facts div, .session-grid div {
  min-width: 0;
  border: 1px solid var(--divider);
  border-radius: 13px;
  background: var(--surface-soft);
  padding: 11px 12px;
}
dt { color: var(--subtle); font-size: 11px; }
dd { margin: 6px 0 0; color: var(--text); font-size: 11px; overflow-wrap: anywhere; }

.media-card {
  position: relative;
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr);
  gap: 22px;
  overflow: hidden;
  padding: 23px;
  background: linear-gradient(135deg, var(--media-start), var(--media-end));
}
.media-card::after {
  position: absolute;
  right: -80px;
  bottom: -120px;
  width: 260px;
  height: 260px;
  border-radius: 50%;
  background: var(--media-orb);
  content: "";
  pointer-events: none;
}
.media-accent {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 112px;
  height: 112px;
  border-radius: 24px;
  background: linear-gradient(145deg, var(--media-accent-start), var(--media-accent-end));
  color: var(--accent-text);
  font-size: 40px;
  box-shadow: inset 0 0 0 1px var(--border);
}
.media-card[data-state="news"] .media-accent {
  background: linear-gradient(145deg, var(--media-news-start), var(--media-news-end));
}
.media-card[data-state="lesson"] .media-accent {
  background: linear-gradient(145deg, var(--media-lesson-start), var(--media-lesson-end));
  color: var(--media-lesson-text);
}
.media-main { position: relative; z-index: 1; min-width: 0; }
.media-heading { display: flex; justify-content: space-between; gap: 18px; }
.media-copy { min-width: 0; }
.media-copy h2 {
  overflow: hidden;
  margin: 6px 0 5px;
  color: var(--heading-soft);
  font-size: 20px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.media-copy p {
  overflow: hidden;
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.media-badges { display: flex; flex: 0 0 auto; align-items: flex-start; gap: 7px; }
.media-badges span, .media-badges b {
  border-radius: 999px;
  background: var(--surface-badge);
  padding: 6px 9px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 650;
}
.media-badges b { color: var(--accent-text); }
.media-progress-row {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) 38px;
  gap: 9px;
  align-items: center;
  margin-top: 18px;
}
.media-progress-row time { color: var(--subtle); font: 10px ui-monospace, monospace; text-align: center; }
#mediaProgress { width: 100%; accent-color: var(--accent); cursor: pointer; }
.media-controls { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.media-controls button { min-width: 74px; padding: 8px 11px; font-size: 11px; }
.media-playlist {
  display: grid;
  gap: 6px;
  max-height: 178px;
  margin: 15px 0 0;
  padding: 0;
  overflow: auto;
  list-style: none;
}
.media-playlist:empty { display: none; }
.media-playlist button {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) 38px;
  gap: 8px;
  width: 100%;
  border-color: transparent;
  background: var(--playlist-bg);
  padding: 8px 9px;
  text-align: left;
}
.media-playlist button.active { border-color: var(--ready-border); background: var(--playlist-active-bg); }
.media-playlist span, .media-playlist small { color: var(--subtle); font-size: 10px; }
.media-playlist strong {
  overflow: hidden;
  color: var(--text);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.protocol-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 9px;
  margin: 0;
}
.protocol-summary div {
  min-width: 0;
  border: 1px solid var(--divider);
  border-radius: 13px;
  background: var(--surface-soft);
  padding: 11px;
}
.protocol-summary dd { text-align: left; }
.protocol-packets { display: grid; gap: 8px; margin: 15px 0 0; padding: 0; list-style: none; }
.protocol-packets li {
  display: grid;
  grid-template-columns: minmax(160px, .8fr) minmax(160px, .8fr) minmax(220px, 1.4fr);
  gap: 10px;
  align-items: center;
  border-top: 1px solid var(--divider);
  padding-top: 10px;
  color: var(--muted);
  font-size: 11px;
}
.protocol-packets strong { color: var(--text); font-weight: 650; }
.protocol-packets code { color: var(--accent-text); overflow-wrap: anywhere; }
.debug-audio-controls { display: flex; gap: 8px; margin-top: 12px; }
.debug-audio-controls input { flex: 1; min-width: 0; }
.debug-audio-list { display: grid; gap: 8px; margin: 12px 0 0; padding: 0; list-style: none; max-height: 240px; overflow-y: auto; }
.debug-audio-list li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 8px;
  align-items: center;
  border-top: 1px solid var(--divider);
  padding-top: 8px;
  font-size: 12px;
}
.debug-audio-name { color: var(--muted); overflow-wrap: anywhere; }
#debugAudioPlayer { width: 100%; margin-top: 12px; display: block; }

#eventLog {
  max-height: 360px;
  margin: 0;
  padding: 0;
  overflow: auto;
  list-style: none;
  font: 11px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace;
}
#eventLog li {
  display: grid;
  grid-template-columns: 76px minmax(150px, 220px) minmax(0, 1fr);
  gap: 12px;
  align-items: start;
  border-top: 1px solid var(--divider);
  padding: 9px 0;
}
#eventLog time { color: var(--subtle); }
#eventLog strong { overflow: hidden; color: var(--accent-text); font-weight: 650; text-overflow: ellipsis; }
#eventLog code { color: var(--muted); white-space: pre-wrap; overflow-wrap: anywhere; }

@media (max-width: 980px) {
  .dashboard-grid { grid-template-columns: 1fr; }
  .dashboard-media,
  .dashboard-session,
  .dashboard-protocol,
  .dashboard-events { grid-column: auto; }
  .conversation-grid { grid-template-rows: auto; }
  .session-overview { grid-template-columns: 1fr; gap: 0; }
}

@media (max-width: 720px) {
  .shell { width: min(100% - 24px, 1240px); padding-top: 24px; }
  .topbar { display: block; }
  .header-actions { justify-content: flex-start; margin-top: 17px; }
  .dashboard-grid { margin-top: 24px; gap: 14px; }
  .conversation-card, .settings-card, .session-card, .protocol-card, .events-card { padding: 18px; }
  .text-input-row { grid-template-columns: 1fr; }
  .session-grid { grid-template-columns: 1fr 1fr; }
  .facts { grid-template-columns: 1fr; }
  .media-card { grid-template-columns: 72px minmax(0, 1fr); gap: 14px; padding: 18px; }
  .media-accent { width: 72px; height: 72px; border-radius: 18px; font-size: 28px; }
  .media-heading { display: block; }
  .media-badges { margin-top: 10px; }
  .protocol-summary { grid-template-columns: 1fr 1fr; }
  .protocol-packets li { grid-template-columns: 1fr; }
  #eventLog li { grid-template-columns: 64px minmax(0, 1fr); gap: 4px 10px; }
  #eventLog code { grid-column: 1 / -1; }
}

@media (max-width: 480px) {
  .header-actions { align-items: stretch; flex-direction: column; }
  .header-actions > * { justify-content: center; width: 100%; }
  .card-title { align-items: flex-start; }
  .session-grid, .protocol-summary { grid-template-columns: 1fr; }
  .media-card { grid-template-columns: 1fr; }
  .media-accent { width: 58px; height: 58px; }
  .media-copy h2 { white-space: normal; }
  .media-controls { display: grid; grid-template-columns: 1fr 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
