:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #10131a;
  color: #f5f7fb;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

body {
  background:
    radial-gradient(circle at 18% 16%, rgba(255, 255, 255, 0.34), transparent 0.18rem, transparent 0.2rem),
    radial-gradient(circle at 62% 12%, rgba(255, 255, 255, 0.24), transparent 0.13rem, transparent 0.16rem),
    radial-gradient(circle at 32% 24%, rgba(255, 255, 255, 0.62), transparent 0.08rem, transparent 0.1rem),
    radial-gradient(circle at 77% 22%, rgba(219, 235, 255, 0.54), transparent 0.07rem, transparent 0.09rem),
    radial-gradient(circle at 88% 10%, rgba(255, 255, 255, 0.5), transparent 0.06rem, transparent 0.08rem),
    radial-gradient(circle at 7% 28%, rgba(213, 232, 255, 0.44), transparent 0.06rem, transparent 0.08rem),
    radial-gradient(circle at 48% 8%, rgba(255, 255, 255, 0.46), transparent 0.05rem, transparent 0.07rem),
    radial-gradient(circle at top left, rgba(107, 166, 255, 0.28), transparent 34rem),
    linear-gradient(180deg, rgba(18, 44, 78, 0) 48%, rgba(7, 13, 21, 0.82) 100%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1600 900' preserveAspectRatio='none'%3E%3Cdefs%3E%3ClinearGradient id='back' x1='0' y1='0' x2='0' y2='1'%3E%3Cstop offset='0' stop-color='%233d668f'/%3E%3Cstop offset='1' stop-color='%23132639'/%3E%3C/linearGradient%3E%3ClinearGradient id='front' x1='0' y1='0' x2='0' y2='1'%3E%3Cstop offset='0' stop-color='%23567896'/%3E%3Cstop offset='1' stop-color='%230a1420'/%3E%3C/linearGradient%3E%3C/defs%3E%3Crect width='1600' height='900' fill='none'/%3E%3Cpolygon points='0,575 145,435 260,510 410,310 555,495 690,380 820,548 1000,330 1165,520 1290,420 1445,560 1600,455 1600,900 0,900' fill='url(%23back)' opacity='.86'/%3E%3Cpolygon points='410,310 475,392 430,372 397,432 356,378' fill='%23f0f6ff' opacity='.92'/%3E%3Cpolygon points='1000,330 1072,412 1018,394 980,455 932,401' fill='%23eef6ff' opacity='.9'/%3E%3Cpolygon points='0,675 170,535 285,638 440,455 610,665 765,502 930,690 1090,475 1270,675 1410,545 1600,665 1600,900 0,900' fill='url(%23front)'/%3E%3Cpolygon points='440,455 502,532 458,514 418,585 380,520' fill='%23f7fbff' opacity='.88'/%3E%3Cpolygon points='1090,475 1160,558 1108,540 1060,615 1010,545' fill='%23f7fbff' opacity='.86'/%3E%3Cpath d='M0 760 C220 710 315 750 475 708 C650 662 780 752 930 705 C1130 642 1305 730 1600 682 L1600 900 L0 900 Z' fill='%23050b12' opacity='.66'/%3E%3C/svg%3E"),
    linear-gradient(135deg, #081326 0%, #132d46 48%, #07111d 100%);
  background-attachment: fixed;
  background-position: center, center, center, center, center, center, center, left top, center, center bottom, center;
  background-repeat: no-repeat;
  background-size: auto, auto, auto, auto, auto, auto, auto, auto, auto, cover, cover;
}

button,
input {
  font: inherit;
}

.shell {
  position: relative;
  z-index: 1;
  height: 100dvh;
  min-height: 100vh;
  padding: 1.5rem;
}

.stage {
  overflow: hidden;
  background: transparent;
}

.stage {
  position: relative;
  height: 100%;
  min-height: 0;
}

#avatar {
  width: 100%;
  height: 100%;
  min-height: inherit;
}

.loading {
  position: absolute;
  left: 1rem;
  right: 1rem;
  bottom: 1rem;
  padding: 0.85rem 1rem;
  border-radius: 18px;
  background: rgba(5, 8, 14, 0.72);
  color: #dfe7ff;
}

.page-panel {
  position: absolute;
  top: 6.5rem;
  right: auto;
  bottom: 2rem;
  left: clamp(1.5rem, 4vw, 4rem);
  z-index: 3;
  width: min(24rem, calc(100% - 5rem));
  overflow: auto;
  border: 1px solid rgba(181, 210, 255, 0.38);
  border-radius: 24px;
  background: linear-gradient(145deg, rgba(23, 42, 70, 0.66), rgba(8, 16, 29, 0.5));
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.3), inset 0 1px rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(26px) saturate(135%);
}

.page-panel[hidden] {
  display: none;
}

.page-panel-header {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.15rem 0.85rem;
  border-bottom: 1px solid rgba(205, 225, 255, 0.12);
  background: linear-gradient(180deg, rgba(27, 51, 83, 0.5), rgba(15, 29, 49, 0.12));
  color: #dfe7ff;
  font-weight: 800;
}

.page-panel-header button {
  width: 2rem;
  min-height: 2rem;
  border-radius: 999px;
  background: rgba(143, 180, 255, 0.18);
  color: #dfe7ff;
}

.page-content {
  padding: 0 1.15rem 1.15rem;
  color: #eef4ff;
  line-height: 1.55;
}

.page-content h1,
.page-content h2,
.page-content h3,
.page-content h4 {
  margin: 1.25rem 0 0.5rem;
  line-height: 1.15;
}

.page-content p,
.page-content ul,
.page-content ol {
  margin: 0.75rem 0;
}

.page-content .page-list-item {
  padding-left: 1.1rem;
}

.page-content .page-list-item::before {
  display: inline-block;
  width: 1.1rem;
  margin-left: -1.1rem;
  content: "*";
}

.page-content .numberedListItem::before {
  content: "#";
}

.page-content .checkListItem::before {
  content: "[ ]";
}

.page-content .checkListItem.checked::before {
  content: "[x]";
}

.page-content .checked {
  text-decoration: line-through;
  opacity: 0.7;
}

.page-content img {
  display: block;
  width: 100%;
  height: auto;
  margin: 1rem 0;
  border-radius: 12px;
}

.conversation-panel {
  position: fixed;
  top: 1.5rem;
  right: 5.5rem;
  bottom: 1.5rem;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  width: min(26rem, calc(100vw - 7rem));
  min-height: 0;
  padding: 1.25rem;
  border: 1px solid rgba(143, 180, 255, 0.34);
  border-radius: 18px;
  background: rgba(7, 15, 27, 0.9);
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.34);
  backdrop-filter: blur(18px);
}

.conversation-panel[hidden] {
  display: none;
}

.eyebrow {
  margin: 0 0 0.5rem;
  color: #8fb4ff;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 6vw, 3.5rem);
  line-height: 0.95;
}

.muted {
  color: #aab3c5;
  line-height: 1.5;
}

.status {
  min-height: 2.6rem;
  padding: 0.8rem 1rem;
  border-radius: 16px;
  background: rgba(143, 180, 255, 0.12);
  color: #d8e3ff;
}

.conversation-control {
  display: grid;
  width: 3.5rem;
  min-height: 3.5rem;
  place-items: center;
  border-radius: 999px;
}

.conversation-control svg {
  width: 1.4rem;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.conversation-control .icon-stop,
.conversation-control.is-active .icon-microphone {
  display: none;
}

.conversation-control.is-active .icon-stop {
  display: block;
}

.action-dock .conversation-control {
  width: 3rem;
  min-height: 3rem;
  background: rgba(0, 0, 0, 0.18);
  color: #dfe7ff;
  box-shadow: 0 0 24px rgba(123, 167, 255, 0.16);
  backdrop-filter: blur(10px);
}

button {
  min-height: 3rem;
  border: 0;
  border-radius: 16px;
  background: #7ba7ff;
  color: #07101f;
  font-weight: 800;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.conversation {
  display: flex;
  flex: 1 1 0;
  flex-direction: column;
  gap: 0.35rem;
  overflow: auto;
  min-height: 0;
  padding: 0.9rem;
  background: transparent;
  color: #c8ffd9;
  font: 0.9rem/1.55 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  scrollbar-color: rgba(125, 255, 179, 0.45) transparent;
}

.text-prompt {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.75rem;
}

.text-prompt input {
  min-width: 0;
  min-height: 3rem;
  padding: 0 1rem;
  border: 1px solid rgba(143, 180, 255, 0.45);
  border-radius: 16px;
  outline: none;
  background: rgba(5, 8, 14, 0.58);
  color: #f5f7fb;
}

.text-prompt input:focus {
  border-color: #7ba7ff;
  box-shadow: 0 0 0 3px rgba(123, 167, 255, 0.2);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.message {
  max-width: 100%;
  padding: 0;
  border-radius: 0;
  line-height: inherit;
  white-space: pre-wrap;
}

.message::before {
  color: #7dffb3;
}

.message.user {
  align-self: stretch;
  background: transparent;
  color: #effff4;
}

.message.user::before {
  content: "> user: ";
}

.message.assistant {
  align-self: stretch;
  background: transparent;
  color: #b7ffd0;
}

.message.assistant::before {
  content: "> avatar: ";
}

.action-dock {
  position: fixed;
  top: 1.5rem;
  right: 1.5rem;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.avatar-scale-controls {
  position: fixed;
  bottom: 1.5rem;
  left: 1.5rem;
  z-index: 20;
  display: grid;
  overflow: hidden;
  border: 1px solid rgba(181, 210, 255, 0.28);
  border-radius: 16px;
  background: rgba(8, 18, 34, 0.4);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.2);
  backdrop-filter: blur(12px);
}

.avatar-scale-controls button {
  width: 2.7rem;
  min-height: 2.45rem;
  border-radius: 0;
  background: transparent;
  color: #eaf2ff;
  font-size: 1.35rem;
  font-weight: 500;
  line-height: 1;
}

.avatar-scale-controls button + button {
  border-top: 1px solid rgba(181, 210, 255, 0.2);
}

.avatar-scale-controls button:hover,
.avatar-scale-controls button:focus-visible {
  background: rgba(143, 180, 255, 0.2);
  outline: none;
}

.conversation-toggle,
.debug-toggle,
.settings-toggle {
  display: grid;
  place-items: center;
  min-height: 3rem;
  border: 0;
  border-radius: 16px;
  background: rgba(0, 0, 0, 0.18);
  color: #dfe7ff;
  box-shadow: 0 0 24px rgba(123, 167, 255, 0.16);
  backdrop-filter: blur(10px);
}

.conversation-toggle {
  width: 3rem;
}

.debug-toggle {
  width: 3rem;
  margin-left: auto;
  color: #ffd49a;
}

.settings-toggle {
  width: 3rem;
  color: #b7ffd0;
}

.conversation-toggle svg,
.debug-toggle svg,
.settings-toggle svg {
  width: 1.35rem;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.settings-panel {
  position: fixed;
  top: 5.15rem;
  right: 5.5rem;
  bottom: 1.5rem;
  z-index: 20;
  width: min(25rem, calc(100vw - 7rem));
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid rgba(125, 255, 179, 0.28);
  border-radius: 18px;
  background: rgba(7, 15, 27, 0.94);
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.34);
  backdrop-filter: blur(18px);
}

.settings-panel[hidden] {
  display: none;
}

.settings-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.1rem 0.75rem;
  border-bottom: 1px solid rgba(125, 255, 179, 0.15);
}

.settings-header strong,
.settings-header span {
  display: block;
}

.settings-header strong {
  color: #d8ffe5;
}

.settings-header span {
  margin-top: 0.25rem;
  color: #aab3c5;
  font-size: 0.78rem;
}

.settings-close {
  width: 1.8rem;
  min-height: 1.8rem;
  border-radius: 999px;
  background: transparent;
  color: #b7ffd0;
  font-size: 1.2rem;
  line-height: 1;
}

.settings-form {
  display: grid;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  gap: 0.85rem;
  padding: 1rem 1.1rem 1.1rem;
}

.settings-form fieldset {
  display: grid;
  gap: 0.6rem;
  margin: 0;
  padding: 0.8rem;
  border: 1px solid rgba(143, 180, 255, 0.2);
  border-radius: 12px;
}

.settings-form legend {
  padding: 0 0.35rem;
  color: #b7ffd0;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.settings-form label {
  display: grid;
  gap: 0.3rem;
  color: #c8d3e8;
  font-size: 0.85rem;
}

.settings-form select,
.settings-form input {
  min-height: 2.5rem;
  padding: 0 0.65rem;
  border: 1px solid rgba(143, 180, 255, 0.35);
  border-radius: 10px;
  background: rgba(5, 8, 14, 0.58);
  color: #f5f7fb;
}

.supertonic-settings {
  display: grid;
  gap: 0.6rem;
}

.settings-error {
  margin: 0;
  color: #ffb7ad;
  font-size: 0.85rem;
  line-height: 1.4;
}

.debug-panel {
  position: fixed;
  top: 5.15rem;
  right: 5.5rem;
  bottom: 1.5rem;
  left: auto;
  z-index: 20;
  width: min(42rem, calc(100vw - 7rem));
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid rgba(255, 178, 98, 0.28);
  border-radius: 18px;
  background: rgba(11, 12, 18, 0.9);
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.34);
  backdrop-filter: blur(18px);
}

.debug-panel[hidden] {
  display: none;
}

.debug-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 0.8rem;
  color: #ffb262;
  font: 0.78rem/1 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.debug-close {
  width: 1.8rem;
  min-height: 1.8rem;
  border-radius: 999px;
  background: transparent;
  color: #ffd49a;
  font-size: 1.2rem;
  line-height: 1;
}

#debugLog {
  flex: 1 1 0;
  overflow: auto;
  margin: 0;
  padding: 0 0.8rem 0.85rem;
  color: #d8dee9;
  font: 0.76rem/1.4 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  scrollbar-color: rgba(255, 178, 98, 0.58) transparent;
}

.debug-entry {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.28rem 0.45rem;
  padding: 0.34rem 0.1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.debug-entry:hover {
  background: rgba(255, 178, 98, 0.06);
}

.debug-absolute-time {
  color: #7f8a9c;
  font-variant-numeric: tabular-nums;
}

.debug-event {
  color: #f7c47f;
  font-weight: 700;
}

.debug-detail {
  display: inline-flex;
  gap: 0.22rem;
  max-width: 100%;
}

.debug-detail-key {
  color: #8490a4;
}

.debug-detail-value {
  color: #d8dee9;
  overflow-wrap: anywhere;
}

.debug-duration {
  padding: 0.08rem 0.3rem;
  border-radius: 4px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.debug-duration.is-fast {
  color: #8ae8ba;
  background: rgba(60, 183, 118, 0.16);
}

.debug-duration.is-warning {
  color: #ffd06b;
  background: rgba(255, 183, 77, 0.16);
}

.debug-duration.is-slow {
  color: #ff9f91;
  background: rgba(237, 99, 83, 0.18);
}

@media (max-width: 860px) {
  .shell {
    grid-template-columns: 1fr;
    padding: 0.75rem;
  }

  .stage {
    height: 100%;
    min-height: 0;
  }

  .page-panel {
    top: auto;
    width: auto;
    max-height: 65%;
    left: 0.75rem;
    right: 0.75rem;
    bottom: 0.75rem;
  }

  .action-dock {
    top: 0.75rem;
    right: 0.75rem;
  }

  .avatar-scale-controls {
    bottom: 0.75rem;
    left: 0.75rem;
  }

  .conversation-panel,
  .debug-panel,
  .settings-panel {
    top: 4.4rem;
    right: 0.75rem;
    bottom: 0.75rem;
    width: calc(100vw - 1.5rem);
  }

  .text-prompt {
    grid-template-columns: 1fr;
  }
}
