:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-2: #f7f7f7;
  --border: #e5e5e5;
  --text: #111111;
  --muted: #555555;
  --primary: #111111;
  --primary-hover: #333333;
  --primary-text: #ffffff;
  --danger: #c62828;
  --danger-hover: #b71c1c;
  --warning: #8a6d00;
  --radius: 10px;
  --font: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
}

code {
  background: var(--surface-2);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  font-size: 0.85em;
  color: var(--text);
}

.auth-page {
  display: grid;
  place-items: center;
  min-height: 100vh;
  background: var(--bg);
}

.auth-card {
  width: min(420px, 92vw);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  box-shadow: var(--shadow);
}

.brand {
  text-align: center;
  margin-bottom: 1.5rem;
}

.brand-icon {
  font-size: 2.5rem;
}

.brand h1 {
  margin: 0.5rem 0 0.25rem;
  font-size: 1.35rem;
  color: var(--text);
}

.brand p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.auth-form label {
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 500;
}

.auth-form input,
.text-input,
.select-input {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
}

.auth-form input:focus,
.text-input:focus {
  outline: none;
  border-color: var(--text);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.topbar h1 {
  margin: 0;
  font-size: 1.25rem;
  color: var(--text);
}

.subtitle {
  margin: 0.25rem 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.portal-layout {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 2rem 1rem;
  min-height: calc(100vh - 72px);
  background: var(--surface-2);
}

.portal-card {
  width: min(720px, 100%);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

@media (max-width: 600px) {
  .form-row {
    grid-template-columns: 1fr;
  }
}

.tune-section {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
}

.tune-section summary {
  padding: 0.75rem 1rem;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  list-style: none;
}

.tune-section summary::-webkit-details-marker {
  display: none;
}

.tune-body {
  padding: 0 1rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.text-area {
  width: 100%;
  min-height: 200px;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.78rem;
  line-height: 1.45;
  resize: vertical;
  background: var(--surface);
  color: var(--text);
}

.slider-field input[type="range"] {
  width: 100%;
  margin: 0.35rem 0;
}

.field-hint,
.label-hint {
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 400;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.88rem;
  cursor: pointer;
}

.form-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.save-toast {
  margin-top: 0.5rem;
  font-size: 0.85rem;
  color: var(--primary);
  text-align: center;
}

.save-toast.hidden {
  display: none;
}

/* Help modal */
.help-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.help-modal.hidden {
  display: none;
}

.help-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
}

.help-modal-panel {
  position: relative;
  width: min(640px, 100%);
  max-height: min(90vh, 820px);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15);
}

.help-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.help-modal-header h2 {
  margin: 0;
  font-size: 1.15rem;
}

.help-modal-close {
  border: none;
  background: transparent;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
  padding: 0.25rem 0.5rem;
  border-radius: 6px;
}

.help-modal-close:hover {
  background: var(--surface-2);
  color: var(--text);
}

.help-modal-body {
  padding: 1rem 1.25rem;
  overflow-y: auto;
  flex: 1;
}

.help-modal-body section {
  margin-bottom: 1.25rem;
}

.help-modal-body h3 {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
}

.help-callout {
  padding: 0.85rem 1rem;
  border-radius: 8px;
  margin-bottom: 1.25rem;
  font-size: 0.9rem;
  line-height: 1.5;
}

.help-callout p {
  margin: 0.35rem 0 0;
}

.help-callout-warning {
  background: #fff8e6;
  border: 1px solid #e6d48a;
  color: #3d3200;
}

.help-callout-warning strong {
  display: block;
  font-size: 0.95rem;
}

.help-steps {
  margin: 0;
  padding-left: 1.25rem;
  font-size: 0.9rem;
  line-height: 1.55;
}

.help-steps li + li {
  margin-top: 0.45rem;
}

.help-list {
  margin: 0;
  padding-left: 1.15rem;
  font-size: 0.9rem;
  line-height: 1.55;
}

.help-params {
  margin: 0;
  font-size: 0.88rem;
  line-height: 1.5;
}

.help-params dt {
  font-weight: 600;
  margin-top: 0.75rem;
  color: var(--text);
}

.help-params dt:first-child {
  margin-top: 0;
}

.help-params dd {
  margin: 0.2rem 0 0;
  color: var(--muted);
}

.help-modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1.25rem;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.help-checkbox {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--muted);
  cursor: pointer;
}

body.help-modal-open {
  overflow: hidden;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}

.config-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.form-field label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
}

.btn-block {
  width: 100%;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.65rem 1.25rem;
  border-radius: 8px;
  border: none;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s;
}

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

.btn-primary {
  background: var(--primary);
  color: var(--primary-text);
  width: 100%;
}

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

.btn-danger {
  background: var(--danger);
  color: #fff;
  width: 100%;
  margin-top: 0.5rem;
}

.btn-danger:hover {
  background: var(--danger-hover);
}

.btn-ghost {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-ghost:hover {
  background: var(--surface-2);
  border-color: var(--text);
}

.models-grid,
.voices-grid {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.card-option {
  display: block;
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.card-option:hover {
  border-color: var(--text);
  background: var(--surface-2);
}

.card-option.selected {
  border-color: var(--text);
  background: var(--surface-2);
  box-shadow: inset 0 0 0 1px var(--text);
}

.card-option input {
  display: none;
}

.card-option .title {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text);
}

.card-option .desc {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 0.25rem;
}

.badge {
  display: inline-block;
  font-size: 0.7rem;
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  margin-left: 0.5rem;
}

.text-input,
.select-input {
  width: 100%;
}

.greeting-preview {
  margin: 0.5rem 0 0;
  padding: 0.65rem 0.75rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.85rem;
  color: var(--text);
  line-height: 1.4;
}

.session-panel {
  display: flex;
  flex-direction: column;
  min-height: 500px;
}

.session-header {
  margin-bottom: 1rem;
}

.session-header h2 {
  margin: 0;
  color: var(--text);
}

.session-meta {
  color: var(--muted);
  font-size: 0.9rem;
  margin-top: 0.35rem;
}

.visualizer {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  height: 180px;
  border-radius: var(--radius);
  background: var(--surface-2);
  border: 1px solid var(--border);
  margin-bottom: 1rem;
  position: relative;
}

.visualizer.active {
  background: var(--surface);
}

.visualizer.active .pulse-ring {
  animation: pulse 1.5s ease-out infinite;
}

.pulse-ring {
  position: absolute;
  width: 80px;
  height: 80px;
  border-radius: 50%;
  border: 2px solid var(--text);
  opacity: 0;
}

@keyframes pulse {
  0% {
    transform: scale(0.8);
    opacity: 0.6;
  }
  100% {
    transform: scale(1.8);
    opacity: 0;
  }
}

#session-state {
  font-size: 1.1rem;
  font-weight: 600;
  z-index: 1;
  color: var(--text);
}

.mic-meter-wrap {
  position: absolute;
  bottom: 12px;
  left: 12px;
  right: 12px;
  z-index: 1;
}

.mic-meter-label {
  font-size: 0.7rem;
  color: var(--muted);
  display: block;
  margin-bottom: 4px;
}

.mic-meter-track {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}

.mic-meter-fill {
  height: 100%;
  width: 0%;
  background: var(--text);
  border-radius: 3px;
  transition: width 0.05s linear;
}

.mic-warning {
  margin: 0.5rem 0 0;
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
  font-size: 0.82rem;
  line-height: 1.4;
  background: #fff8e6;
  border: 1px solid #e6d9a8;
  color: #6b5700;
}

.mic-warning.hidden {
  display: none;
}

.transcript-box h3 {
  margin: 0 0 0.5rem;
  font-size: 0.9rem;
  color: var(--muted);
  font-weight: 600;
}

.event-log {
  flex: 1;
  margin: 0;
  padding: 1rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: auto;
  font-size: 0.78rem;
  line-height: 1.5;
  max-height: 360px;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}

.session-status {
  margin-top: 1rem;
  min-height: 1.25rem;
  font-size: 0.9rem;
  color: var(--muted);
  text-align: center;
}

.session-status:empty {
  display: none;
}

.status-badge {
  margin-top: 0.75rem;
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  font-size: 0.8rem;
  text-align: center;
  border: 1px solid var(--border);
}

.status-badge.ok {
  background: var(--surface);
  color: var(--text);
}

.status-badge.warn {
  background: #fffbeb;
  color: var(--warning);
  border-color: #f0e6b8;
}

.status-badge.error {
  background: #fff5f5;
  color: var(--danger);
  border-color: #f5c6c6;
}

.alert {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.alert-error {
  background: #fff5f5;
  color: var(--danger);
  border: 1px solid #f5c6c6;
}

.hidden {
  display: none !important;
}

.loading,
.hint {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0;
}

.session-controls {
  margin-top: 0.5rem;
}
