:root {
  color-scheme: dark;
  --bg: #08111e;
  --panel: rgba(9, 21, 38, 0.82);
  --panel-strong: rgba(7, 18, 32, 0.94);
  --line: rgba(131, 162, 188, 0.16);
  --line-strong: rgba(131, 162, 188, 0.28);
  --text: #edf5ff;
  --muted: #8fa9c3;
  --accent: #79d2ff;
  --accent-strong: #1f92c8;
  --accent-warm: #d8b46b;
  --success: #39c49d;
  --danger: #e06f6f;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.38);
  --radius: 24px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(121, 210, 255, 0.18), transparent 32%),
    radial-gradient(circle at bottom right, rgba(216, 180, 107, 0.14), transparent 28%),
    linear-gradient(180deg, #050d17 0%, #08111e 42%, #050b12 100%);
  color: var(--text);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(121, 210, 255, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(121, 210, 255, 0.04) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(circle at center, black 35%, transparent 85%);
}

button,
textarea,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  min-height: 100vh;
  min-height: 100dvh;
}

.sidebar {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1.25rem;
  background: rgba(7, 16, 28, 0.74);
  border-right: 1px solid var(--line);
  backdrop-filter: blur(20px);
}

.brand-card,
.panel-section,
.composer,
.topbar,
.settings-card {
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.brand-card {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr);
  gap: 1rem;
  padding: 1.1rem;
  border-radius: var(--radius);
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border-radius: 18px;
  background:
    linear-gradient(135deg, rgba(121, 210, 255, 0.25), rgba(31, 146, 200, 0.35)),
    linear-gradient(180deg, rgba(216, 180, 107, 0.18), transparent);
  border: 1px solid rgba(121, 210, 255, 0.28);
  color: var(--accent);
  font-size: 1.4rem;
  font-weight: 700;
}

.eyebrow {
  margin: 0 0 0.3rem;
  font-size: 0.75rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent-warm);
}

.brand-card h1,
.topbar h2,
.hero h3,
.settings-header h3 {
  margin: 0;
  font-weight: 650;
}

.muted {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

.primary-button,
.ghost-button {
  border-radius: 999px;
  border: 1px solid transparent;
  padding: 0.82rem 1.1rem;
  transition: transform 140ms ease, border-color 140ms ease, background 140ms ease;
}

.primary-button {
  background: linear-gradient(135deg, var(--accent-strong), #0b5f88);
  color: white;
  font-weight: 600;
}

.ghost-button {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  border-color: var(--line);
}

.primary-button:hover,
.ghost-button:hover {
  transform: translateY(-1px);
}

.primary-button:disabled,
.ghost-button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.panel-section {
  border-radius: 20px;
  padding: 1rem;
}

.panel-label {
  margin-bottom: 0.75rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.thread-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 38vh;
  overflow: auto;
}

.thread-button {
  width: 100%;
  padding: 0.9rem 1rem;
  border-radius: 18px;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  text-align: left;
}

.thread-button.active {
  border-color: rgba(121, 210, 255, 0.36);
  background: rgba(31, 146, 200, 0.16);
}

.thread-title {
  display: block;
  font-weight: 600;
  margin-bottom: 0.3rem;
}

.thread-meta {
  display: block;
  font-size: 0.88rem;
  color: var(--muted);
}

.stance-list {
  margin: 0;
  padding-left: 1rem;
  color: var(--muted);
  line-height: 1.7;
}

.main-panel {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  gap: 1rem;
  padding: 1.2rem;
  min-width: 0;
}

.topbar {
  grid-row: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.2rem;
  border-radius: var(--radius);
}

.status-cluster {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  padding: 0.55rem 0.8rem;
  font-size: 0.9rem;
  color: var(--muted);
}

.status-pill.connected {
  color: var(--success);
  border-color: rgba(57, 196, 157, 0.34);
}

.status-pill.disconnected {
  color: var(--danger);
  border-color: rgba(224, 111, 111, 0.34);
}

.menu-button {
  display: none;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  padding: 0.7rem 1rem;
}

.hero {
  grid-row: 2;
  padding: 1.2rem 1.3rem 0;
}

.transcript {
  grid-row: 3;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-height: 0;
  overflow: auto;
  padding: 0 0.2rem 0.4rem;
}

.message {
  max-width: min(760px, 100%);
  padding: 1rem 1.1rem;
  border-radius: 22px;
  border: 1px solid var(--line);
  background: rgba(8, 18, 31, 0.78);
}

.message.user {
  align-self: flex-end;
  background: linear-gradient(135deg, rgba(31, 146, 200, 0.24), rgba(10, 38, 58, 0.9));
  border-color: rgba(121, 210, 255, 0.28);
}

.message.assistant {
  align-self: flex-start;
}

.message-role {
  display: block;
  margin-bottom: 0.55rem;
  font-size: 0.78rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent-warm);
}

.message-body {
  margin: 0;
  white-space: pre-wrap;
  line-height: 1.62;
}

.composer {
  grid-row: 4;
  display: grid;
  gap: 0.75rem;
  padding: 1rem;
  border-radius: var(--radius);
  align-self: end;
}

.composer-label,
.field span {
  font-size: 0.88rem;
  color: var(--muted);
}

.voice-status {
  min-height: 1.35rem;
  font-size: 0.88rem;
  color: var(--muted);
}

.voice-status.ready {
  color: var(--success);
}

.voice-status.partial {
  color: var(--accent-warm);
}

.voice-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.ghost-button.recording {
  border-color: rgba(224, 111, 111, 0.42);
  color: var(--danger);
}

.composer textarea,
.field input {
  width: 100%;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: rgba(3, 12, 20, 0.84);
  color: var(--text);
  padding: 1rem;
  resize: none;
}

.composer textarea {
  min-height: 68px;
  max-height: 240px;
}

.composer-actions,
.settings-actions,
.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
}

@media (max-width: 640px) {
  .composer-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .voice-actions {
    width: 100%;
  }

  .voice-actions .ghost-button,
  .composer-actions .primary-button {
    width: 100%;
  }
}

.settings-dialog {
  border: none;
  padding: 0;
  background: transparent;
}

.settings-dialog::backdrop {
  background: rgba(0, 0, 0, 0.56);
}

.settings-card {
  width: min(520px, calc(100vw - 2rem));
  border-radius: 28px;
  padding: 1.2rem;
}

.field {
  display: grid;
  gap: 0.55rem;
  margin: 1rem 0 1.2rem;
}

@media (max-width: 960px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(88vw, 320px);
    transform: translateX(-105%);
    transition: transform 160ms ease;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .menu-button {
    display: inline-flex;
  }

  .main-panel {
    padding-top: max(1rem, env(safe-area-inset-top));
    padding-bottom: max(1rem, env(safe-area-inset-bottom));
  }

  .topbar {
    flex-wrap: wrap;
  }

  .status-cluster {
    width: 100%;
    justify-content: space-between;
  }
}
