:root {
  --bg: #08090b;
  --glass-bg: rgba(255, 255, 255, 0.032);
  --glass-bg-hover: rgba(255, 255, 255, 0.062);
  --glass-bg-active: rgba(255, 255, 255, 0.095);
  --glass-elevated: rgba(20, 22, 27, 0.78);
  --border: rgba(255, 255, 255, 0.085);
  --border-strong: rgba(255, 255, 255, 0.16);
  --border-active: rgba(255, 255, 255, 0.34);
  --specular: inset 0 1px 0 rgba(255, 255, 255, 0.11);
  --shadow: 0 24px 64px rgba(0, 0, 0, 0.5);

  --text: #f5f5f7;
  --text-secondary: #c7cad1;
  --text-muted: #848996;
  --text-dim: #575c68;

  --ok: #34d399;
  --warn: #f59e0b;
  --danger: #f43f5e;

  --radius: 18px;
  --radius-md: 12px;
  --radius-sm: 9px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Subtle studio top-light & architectural micro-grid (no neon/purple gradients) */
.bg-grid {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image:
    radial-gradient(ellipse 70% 40% at 50% -10%, rgba(255, 255, 255, 0.055), transparent 70%),
    radial-gradient(rgba(255, 255, 255, 0.045) 1px, transparent 1px);
  background-size: 100% 100%, 24px 24px;
}

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

.hidden {
  display: none !important;
}

/* Frosted Glass Surfaces */
.glass {
  background: var(--glass-bg);
  backdrop-filter: blur(24px) saturate(140%);
  -webkit-backdrop-filter: blur(24px) saturate(140%);
  border: 1px solid var(--border);
  box-shadow: var(--specular), var(--shadow);
}

.glass-elevated {
  background: var(--glass-elevated);
  backdrop-filter: blur(32px) saturate(160%);
  -webkit-backdrop-filter: blur(32px) saturate(160%);
  border: 1px solid var(--border-strong);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.16), 0 32px 80px rgba(0, 0, 0, 0.65);
}

/* App Shell */
.app {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 1380px;
  margin: 0 auto;
  padding: 16px 22px 20px;
  gap: 16px;
}

/* Header */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px 10px 18px;
  border-radius: var(--radius);
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
}

.brand-mark {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #f5f5f7;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.12);
}

.brand-name {
  font-weight: 600;
  font-size: 14.5px;
  letter-spacing: -0.02em;
}

.brand-sep {
  color: var(--text-dim);
  font-size: 13px;
}

.brand-sub {
  font-size: 12.5px;
  color: var(--text-muted);
  letter-spacing: -0.01em;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.model-picker {
  display: flex;
  align-items: center;
  gap: 6px;
}

.glass-select {
  appearance: none;
  background-color: rgba(255, 255, 255, 0.045);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%239ca3af' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 28px 6px 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 11.5px;
  cursor: pointer;
  outline: none;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.glass-select:hover {
  background-color: rgba(255, 255, 255, 0.075);
  border-color: var(--border-strong);
}

.glass-select:focus {
  border-color: var(--border-active);
}

.glass-select option {
  background: #121418;
  color: var(--text);
}

.custom-model-input {
  width: 170px;
  padding: 5.5px 9px !important;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 11.5px !important;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  font-weight: 500;
  padding: 5.5px 11px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  color: var(--text-secondary);
}

.status-dot {
  width: 6.5px;
  height: 6.5px;
  border-radius: 50%;
  background: var(--text-dim);
  transition: background-color 0.2s ease, box-shadow 0.2s ease;
}

.status-connecting .status-dot {
  background: var(--warn);
  box-shadow: 0 0 8px rgba(245, 158, 11, 0.65);
}

.status-listening .status-dot {
  background: var(--ok);
  box-shadow: 0 0 8px rgba(52, 211, 153, 0.65);
}

.status-speaking .status-dot {
  background: #ffffff;
  box-shadow: 0 0 10px rgba(255, 255, 255, 0.85);
}

.status-error .status-dot {
  background: var(--danger);
}

.key-dot {
  width: 6.5px;
  height: 6.5px;
  border-radius: 50%;
  background: var(--warn);
}

.key-dot.ready {
  background: var(--ok);
}

/* Main Grid */
.workspace {
  display: grid;
  grid-template-columns: 316px 1fr;
  gap: 16px;
  min-height: 0;
  flex: 1;
}

/* Sidebar */
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
  border-radius: var(--radius);
  padding: 16px;
}

.sidebar-divider {
  height: 1px;
  background: var(--border);
}

.sidebar-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.personalities-section {
  min-height: 0;
  flex: 1;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.section-header h2,
.transcript-header h2 {
  margin: 0;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.section-meta {
  font-size: 11px;
  color: var(--text-dim);
}

.count-badge {
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.045);
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid var(--border);
}

.voice-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  padding: 3px;
  border-radius: 11px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid var(--border);
}

.voice-chip {
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  border-radius: 8px;
  padding: 6px 2px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.voice-chip:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
}

.voice-chip.active {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.18);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18);
  color: #ffffff;
}

.personality-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
  overflow-y: auto;
  padding-right: 4px;
}

.personality-list::-webkit-scrollbar,
.transcript-list::-webkit-scrollbar,
.prompt-drawer::-webkit-scrollbar {
  width: 5px;
}

.personality-list::-webkit-scrollbar-thumb,
.transcript-list::-webkit-scrollbar-thumb,
.prompt-drawer::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.12);
  border-radius: 999px;
}

.personality-item {
  position: relative;
  width: 100%;
  text-align: left;
  appearance: none;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  padding: 10px 12px;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
  color: var(--text);
}

.personality-item:hover {
  background: var(--glass-bg-hover);
  border-color: var(--border);
}

.personality-item.active {
  background: var(--glass-bg-active);
  border-color: var(--border-strong);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.14);
}

.personality-item.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 10px;
  bottom: 10px;
  width: 2.5px;
  border-radius: 0 3px 3px 0;
  background: #ffffff;
}

.personality-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.personality-name {
  font-size: 13.5px;
  font-weight: 560;
  letter-spacing: -0.01em;
}

.personality-dir {
  margin-top: 3px;
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.badge {
  font-size: 10px;
  font-weight: 600;
  padding: 1.5px 6px;
  border-radius: 999px;
  letter-spacing: 0.02em;
}

.badge-nsfw {
  background: rgba(244, 63, 94, 0.12);
  color: #fda4af;
  border: 1px solid rgba(244, 63, 94, 0.28);
}

/* Main Stage */
.stage {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 0;
}

.error-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  background: rgba(244, 63, 94, 0.12);
  border-color: rgba(244, 63, 94, 0.3);
  color: #fecdd3;
  font-size: 13px;
}

.voice-card {
  border-radius: var(--radius);
  padding: 20px 22px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.active-persona-bar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.active-persona-title {
  display: flex;
  align-items: center;
  gap: 9px;
}

.active-persona-title h1 {
  margin: 0;
  font-size: 21px;
  font-weight: 600;
  letter-spacing: -0.025em;
}

.active-direction {
  margin: 4px 0 0;
  font-size: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  color: var(--text-muted);
}

.prompt-drawer {
  background: rgba(0, 0, 0, 0.34);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  max-height: 150px;
  overflow-y: auto;
}

.prompt-drawer pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
  line-height: 1.55;
  color: var(--text-secondary);
}

/* Smoked Glass Acoustic Meter */
.meter-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8px 0 4px;
  gap: 14px;
}

.meter-shell {
  width: 100%;
  max-width: 540px;
  height: 120px;
  border-radius: 22px;
  background: rgba(0, 0, 0, 0.32);
  border: 1px solid var(--border);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), inset 0 -1px 0 rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px 18px;
  transition: border-color 0.25s ease, box-shadow 0.25s ease;
}

.meter-shell.state-listening {
  border-color: rgba(52, 211, 153, 0.28);
  box-shadow: inset 0 1px 0 rgba(52, 211, 153, 0.14), 0 0 36px rgba(52, 211, 153, 0.06);
}

.meter-shell.state-speaking {
  border-color: rgba(255, 255, 255, 0.24);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18), 0 0 36px rgba(255, 255, 255, 0.06);
}

#waveCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

.orb-hint {
  margin: 0;
  font-size: 13px;
  color: var(--text-muted);
  letter-spacing: -0.005em;
}

.controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

/* Transcript */
.transcript-card {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  border-radius: var(--radius);
  padding: 15px 18px;
  gap: 12px;
}

.transcript-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.transcript-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 9px;
  padding-right: 4px;
}

.transcript-empty {
  color: var(--text-dim);
  font-size: 13px;
  text-align: center;
  margin: auto 0;
}

.msg {
  display: flex;
  flex-direction: column;
  gap: 3px;
  max-width: 82%;
  padding: 10px 13px;
  border-radius: 13px;
  font-size: 13.5px;
  line-height: 1.5;
}

.msg-user {
  align-self: flex-end;
  background: rgba(255, 255, 255, 0.09);
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

.msg-assistant {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid var(--border);
}

.msg-system {
  align-self: center;
  background: transparent;
  color: var(--text-dim);
  font-size: 11.5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  padding: 2px 8px;
}

.msg-role {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
}

.text-form {
  display: flex;
  gap: 8px;
}

.glass-input {
  flex: 1;
  background: rgba(0, 0, 0, 0.32);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 9px 12px;
  font-size: 13.5px;
  outline: none;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.glass-input:focus {
  border-color: var(--border-active);
  background: rgba(0, 0, 0, 0.45);
}

.glass-input:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Buttons */
.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-weight: 550;
  letter-spacing: -0.01em;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  transition: transform 0.12s ease, background-color 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}

.btn:active:not(:disabled) {
  transform: scale(0.985);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: #f5f5f7;
  color: #090a0c;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35), inset 0 1px 0 #ffffff;
}

.btn-primary:hover:not(:disabled) {
  background: #ffffff;
}

.btn-danger {
  background: rgba(244, 63, 94, 0.14);
  border-color: rgba(244, 63, 94, 0.36);
  color: #fecdd3;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.btn-danger:hover:not(:disabled) {
  background: rgba(244, 63, 94, 0.22);
}

.btn-glass {
  background: rgba(255, 255, 255, 0.055);
  border-color: var(--border);
  color: var(--text);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.btn-glass:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--border-strong);
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
}

.btn-ghost:hover:not(:disabled) {
  color: var(--text);
  background: rgba(255, 255, 255, 0.055);
}

.btn-lg {
  padding: 11px 24px;
  font-size: 13.5px;
  border-radius: 999px;
}

.btn-sm {
  padding: 6.5px 12px;
  font-size: 12px;
}

.btn-xs {
  padding: 4.5px 10px;
  font-size: 11.5px;
}

.icon-btn {
  appearance: none;
  background: transparent;
  border: none;
  color: inherit;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  padding: 2px 6px;
  opacity: 0.75;
}

.icon-btn:hover {
  opacity: 1;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.62);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}

.modal {
  width: 100%;
  max-width: 430px;
  border-radius: var(--radius);
  padding: 20px 22px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  margin: 0;
  font-size: 15.5px;
  font-weight: 600;
  letter-spacing: -0.015em;
}

.modal-desc {
  margin: 0;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-muted);
}

.modal-desc code {
  background: rgba(255, 255, 255, 0.07);
  padding: 1px 5px;
  border-radius: 5px;
  font-size: 12px;
  color: var(--text);
}

.modal-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* Responsive */
@media (max-width: 900px) {
  .app {
    height: auto;
    min-height: 100vh;
    padding: 10px 12px 16px;
  }

  .topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .topbar-actions {
    justify-content: space-between;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .sidebar {
    max-height: 320px;
  }

  .transcript-card {
    min-height: 280px;
  }
}
