:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #0d0f12;
  color: #f7f4ee;
  --bg: #0d0f12;
  --panel: rgba(21, 24, 29, 0.78);
  --panel-solid: #171a20;
  --surface: #20242c;
  --surface-soft: #15181e;
  --line: rgba(255, 255, 255, 0.1);
  --line-strong: rgba(255, 255, 255, 0.18);
  --text: #f7f4ee;
  --muted: #aaa6a0;
  --quiet: #747a84;
  --accent: #72dac8;
  --accent-ink: #06201b;
  --gold: #e7ba58;
  --coral: #ef806f;
  --blue: #73a9ff;
}

* {
  box-sizing: border-box;
}

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

body {
  background:
    linear-gradient(145deg, rgba(114, 218, 200, 0.16) 0%, transparent 34%),
    linear-gradient(25deg, rgba(239, 128, 111, 0.14) 0%, transparent 30%),
    radial-gradient(circle at top center, rgba(255, 255, 255, 0.06), transparent 48%),
    var(--bg);
}

body::before {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.028) 1px, transparent 1px);
  background-size: 42px 42px;
  mask-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.68), transparent 72%);
  content: "";
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  touch-action: manipulation;
}

svg {
  display: block;
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.app-shell {
  position: relative;
  width: min(880px, 100%);
  min-height: 100svh;
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 18px calc(98px + env(safe-area-inset-bottom));
}

.topbar,
.panel-head,
.dialog-head,
.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar {
  padding: 4px 2px 14px;
}

.brand-lockup {
  min-width: 0;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  color: var(--text);
  font-size: clamp(1.7rem, 6vw, 2.7rem);
  line-height: 1;
}

h2 {
  margin-bottom: 0;
  color: var(--text);
  font-size: 1.06rem;
}

.screen-stack {
  display: block;
}

.screen[hidden] {
  display: none;
}

.talk-panel,
.transcript-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.055), transparent 46%),
    var(--panel);
  box-shadow: 0 28px 90px rgba(0, 0, 0, 0.32);
  backdrop-filter: blur(22px);
}

.talk-panel {
  display: grid;
  min-height: calc(100svh - 176px);
  place-items: center;
  align-content: center;
  gap: 20px;
  overflow: hidden;
  padding: clamp(28px, 7vw, 56px) 18px;
}

.orb {
  position: relative;
  display: grid;
  width: min(66vw, 310px);
  aspect-ratio: 1;
  place-items: center;
}

.orb::before {
  position: absolute;
  inset: 8%;
  border-radius: 50%;
  background: conic-gradient(from 140deg, var(--accent), var(--blue), var(--coral), var(--gold), var(--accent));
  opacity: 0.72;
  filter: blur(22px);
  content: "";
}

.orb-core,
.orb-ring {
  position: absolute;
  border-radius: 50%;
}

.orb-ring {
  inset: 0;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background:
    linear-gradient(var(--bg), var(--bg)) padding-box,
    conic-gradient(from 90deg, rgba(114, 218, 200, 0.12), rgba(231, 186, 88, 0.72), rgba(115, 169, 255, 0.32), rgba(114, 218, 200, 0.12)) border-box;
  border: 1px solid transparent;
  box-shadow: inset 0 0 30px rgba(255, 255, 255, 0.04);
  animation: rotate 18s linear infinite;
}

.orb-core {
  display: flex;
  width: 57%;
  aspect-ratio: 1;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background:
    radial-gradient(circle at 36% 28%, rgba(255, 255, 255, 0.42), transparent 24%),
    linear-gradient(145deg, #7ee6d3 0%, #2a736b 55%, #11181e 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.24),
    0 18px 60px rgba(8, 18, 20, 0.56);
  transition: transform 220ms ease, filter 220ms ease;
}

.orb-core span {
  display: block;
  width: 8px;
  height: 28px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.78);
  transform: scaleY(0.55);
  transform-origin: center;
}

.orb-core span:nth-child(2),
.orb-core span:nth-child(4) {
  height: 42px;
}

.orb-core span:nth-child(3) {
  height: 58px;
}

.orb.connected .orb-core {
  transform: scale(1.04);
  filter: saturate(1.16);
}

.orb.connected .orb-core span {
  animation: equalize 980ms ease-in-out infinite;
}

.orb.connected .orb-core span:nth-child(2) { animation-delay: 120ms; }
.orb.connected .orb-core span:nth-child(3) { animation-delay: 240ms; }
.orb.connected .orb-core span:nth-child(4) { animation-delay: 360ms; }
.orb.connected .orb-core span:nth-child(5) { animation-delay: 480ms; }

.orb.speaking .orb-core {
  animation: pulse 760ms ease-in-out infinite alternate;
}

.status-stack {
  width: min(500px, 100%);
  text-align: center;
}

.status-label {
  margin-bottom: 9px;
  color: var(--text);
  font-size: clamp(1.55rem, 5vw, 2.25rem);
  font-weight: 850;
  line-height: 1.04;
}

.status-detail {
  margin: 0 auto;
  max-width: 34rem;
  color: var(--muted);
  font-size: 0.98rem;
  line-height: 1.62;
}

.meter {
  display: flex;
  align-items: center;
  height: 34px;
  gap: 8px;
  opacity: 0.72;
}

.meter span {
  display: block;
  width: 7px;
  height: 8px;
  border-radius: 999px;
  background: linear-gradient(var(--accent), var(--blue));
}

.orb.connected ~ .meter span {
  animation: bars 900ms ease-in-out infinite;
}

.meter span:nth-child(2) { animation-delay: 90ms; }
.meter span:nth-child(3) { animation-delay: 180ms; }
.meter span:nth-child(4) { animation-delay: 270ms; }
.meter span:nth-child(5) { animation-delay: 360ms; }

.controls {
  display: grid;
  width: min(430px, 100%);
  grid-template-columns: 1fr 0.52fr;
  gap: 10px;
}

.primary-button,
.secondary-button,
.text-button,
.icon-button,
.nav-button {
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}

.primary-button {
  display: inline-flex;
  min-height: 56px;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 0 18px;
  background: linear-gradient(135deg, #8af2df, #f1c765);
  color: #09110f;
  font-weight: 850;
  box-shadow: 0 12px 34px rgba(114, 218, 200, 0.22);
}

.button-icon {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 0 5px rgba(9, 17, 15, 0.1);
}

.secondary-button {
  min-height: 56px;
  padding: 0 16px;
  border: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, 0.055);
  color: var(--text);
  font-weight: 760;
}

.text-button {
  min-height: 38px;
  padding: 0 10px;
  background: rgba(114, 218, 200, 0.1);
  color: var(--accent);
  font-weight: 760;
}

.icon-button {
  display: grid;
  width: 46px;
  height: 46px;
  flex: 0 0 46px;
  place-items: center;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
}

button {
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease, opacity 160ms ease;
}

button:active {
  transform: translateY(1px) scale(0.99);
}

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

.transcript-panel {
  display: flex;
  min-height: calc(100svh - 176px);
  flex-direction: column;
  padding: 18px;
}

.transcript {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  padding-top: 18px;
  scrollbar-color: rgba(255, 255, 255, 0.22) transparent;
}

.message {
  max-width: min(92%, 680px);
  padding: 13px 15px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(13, 15, 18, 0.66);
  color: var(--text);
  line-height: 1.55;
  overflow-wrap: anywhere;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.14);
}

.message.assistant {
  align-self: flex-start;
  border-color: rgba(114, 218, 200, 0.26);
}

.message.user {
  align-self: flex-end;
  border-color: rgba(231, 186, 88, 0.3);
  background: rgba(45, 39, 24, 0.7);
}

.message.system {
  max-width: 100%;
  align-self: stretch;
  color: var(--muted);
}

.bottom-nav {
  position: fixed;
  right: max(12px, env(safe-area-inset-right));
  bottom: max(12px, env(safe-area-inset-bottom));
  left: max(12px, env(safe-area-inset-left));
  z-index: 10;
  display: grid;
  width: min(430px, calc(100% - 24px));
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin: 0 auto;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: rgba(15, 17, 21, 0.84);
  padding: 7px;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(22px);
}

.nav-button {
  position: relative;
  display: flex;
  min-height: 50px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: transparent;
  color: var(--quiet);
  font-weight: 820;
}

.nav-button svg {
  width: 19px;
  height: 19px;
}

.nav-button.is-active {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
}

.nav-button.is-active svg {
  color: var(--accent);
}

.log-badge {
  display: grid;
  min-width: 22px;
  height: 22px;
  place-items: center;
  border-radius: 999px;
  background: var(--gold);
  color: #17140a;
  font-size: 0.73rem;
  line-height: 1;
}

.settings-dialog {
  width: min(560px, calc(100vw - 24px));
  max-height: min(760px, calc(100svh - 24px));
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.055), transparent 40%),
    #15181e;
  color: var(--text);
  padding: 0;
  box-shadow: 0 28px 90px rgba(0, 0, 0, 0.5);
}

.settings-dialog::backdrop {
  background: rgba(0, 0, 0, 0.68);
  backdrop-filter: blur(8px);
}

.settings-form {
  display: grid;
  gap: 16px;
  padding: 18px;
}

.field {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 760;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(8, 10, 13, 0.82);
  color: var(--text);
  padding: 13px 12px;
  outline: none;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: rgba(114, 218, 200, 0.6);
  box-shadow: 0 0 0 3px rgba(114, 218, 200, 0.12);
}

.field textarea {
  resize: vertical;
  line-height: 1.45;
}

.advanced-settings {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(8, 10, 13, 0.42);
  color: var(--text);
}

.advanced-settings summary {
  display: flex;
  min-height: 42px;
  align-items: center;
  padding: 0 12px;
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 820;
}

.advanced-grid {
  display: grid;
  gap: 12px;
  padding: 0 12px 12px;
}

.compact-field {
  font-size: 0.8rem;
}

.compact-field input,
.compact-field select {
  padding: 10px 10px;
}

.compact-field input:disabled,
.compact-field select:disabled {
  opacity: 0.45;
}

.switch {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-weight: 760;
}

.switch input {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
}

@keyframes rotate {
  to { transform: rotate(360deg); }
}

@keyframes pulse {
  from { transform: scale(1.04); }
  to { transform: scale(1.12); }
}

@keyframes equalize {
  0%, 100% { transform: scaleY(0.5); opacity: 0.62; }
  50% { transform: scaleY(1); opacity: 1; }
}

@keyframes bars {
  0%, 100% { height: 8px; opacity: 0.46; }
  50% { height: 34px; opacity: 1; }
}

@media (max-width: 820px) {
  .app-shell {
    padding: max(12px, env(safe-area-inset-top)) 12px calc(82px + env(safe-area-inset-bottom));
  }

  .talk-panel,
  .transcript-panel {
    min-height: calc(100svh - 132px);
  }
}

@media (max-width: 460px) {
  html,
  body {
    height: 100%;
    overflow: hidden;
  }

  .topbar {
    padding-bottom: 10px;
  }

  h1 {
    font-size: 1.65rem;
  }

  .icon-button {
    width: 40px;
    height: 40px;
    flex-basis: 40px;
  }

  .talk-panel {
    gap: 14px;
    min-height: calc(100svh - 140px);
    padding: 18px 14px;
  }

  .controls {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .orb {
    width: min(56vw, 210px, 34svh);
  }

  .status-label {
    margin-bottom: 6px;
    font-size: 1.45rem;
  }

  .status-detail {
    display: -webkit-box;
    max-width: 19rem;
    overflow: hidden;
    font-size: 0.88rem;
    line-height: 1.45;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }

  .primary-button,
  .secondary-button {
    min-height: 46px;
  }

  .bottom-nav {
    bottom: max(8px, env(safe-area-inset-bottom));
    width: min(360px, calc(100% - 24px));
    padding: 5px;
  }

  .nav-button {
    min-height: 42px;
  }

  .settings-dialog {
    width: calc(100vw - 20px);
    max-height: calc(100svh - 20px);
  }

  .settings-form {
    gap: 10px;
    padding: 12px;
  }

  .dialog-head,
  .dialog-actions {
    gap: 10px;
  }

  .field {
    gap: 5px;
    font-size: 0.8rem;
  }

  .field input,
  .field select,
  .field textarea {
    padding: 9px 10px;
  }

  .field textarea {
    max-height: 82px;
  }

  .advanced-settings summary {
    min-height: 36px;
    padding: 0 10px;
    font-size: 0.82rem;
  }

  .advanced-grid {
    gap: 8px;
    padding: 0 10px 10px;
  }

  .switch {
    gap: 8px;
    font-size: 0.86rem;
  }

  .switch input {
    width: 18px;
    height: 18px;
  }

  .dialog-actions .primary-button,
  .dialog-actions .secondary-button {
    min-height: 42px;
  }
}
