:root {
  color-scheme: light;
  --bg: #f5f7f4;
  --ink: #15171c;
  --muted: #667085;
  --line: rgba(21, 23, 28, 0.12);
  --panel: rgba(255, 255, 255, 0.92);
  --panel-strong: #ffffff;
  --accent: #0f766e;
  --accent-dark: #115e59;
  --warm: #b7791f;
  --danger: #b91c1c;
  --success: #15803d;
  --shadow: 0 18px 48px rgba(20, 28, 35, 0.10);
  --subtitle-size: 40px;
}

body.dark {
  color-scheme: dark;
  --bg: #101418;
  --ink: #f4f7fb;
  --muted: #a7b0bd;
  --line: rgba(255, 255, 255, 0.14);
  --panel: rgba(21, 27, 34, 0.94);
  --panel-strong: #151b22;
  --accent: #2dd4bf;
  --accent-dark: #5eead4;
  --warm: #fbbf24;
  --danger: #f87171;
  --success: #4ade80;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.24);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(255,255,255,0.70), rgba(245,247,244,0.96)),
    var(--bg);
}

body.dark {
  background:
    linear-gradient(180deg, rgba(16,20,24,0.90), rgba(16,20,24,1)),
    var(--bg);
}

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

.live-shell {
  width: min(1180px, calc(100% - 28px));
  margin: 0 auto;
  padding: 24px 0 48px;
}

.pin-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
}

.pin-panel {
  width: min(520px, 100%);
}

.pin-form {
  display: grid;
  gap: 14px;
  padding: 18px;
}

.pin-form label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-weight: 850;
}

.pin-message {
  min-height: 22px;
  margin: 0;
  color: var(--danger);
  font-weight: 800;
}

.live-hero {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 18px;
  align-items: end;
  padding: 20px 0 16px;
}

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

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 8px; font-size: clamp(34px, 6vw, 60px); line-height: 1; letter-spacing: 0; }
h2 { margin-bottom: 0; font-size: 16px; }
h3 { margin: 0 0 8px; font-size: 14px; }

.lead {
  max-width: 720px;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 18px;
  line-height: 1.5;
}

.status-card,
.notice,
.control-panel,
.install-panel,
.stage-panel,
.history-panel,
.transcript-panel,
.action-panel,
.export-panel,
.summary-panel,
.audio-panel,
.diagnostics-panel,
.sessions-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.status-card {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 170px;
  padding: 12px 14px;
  font-weight: 800;
}

.status-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--muted);
}
.status-dot.listening { background: var(--accent); box-shadow: 0 0 0 6px rgba(15, 118, 110, 0.16); }
.status-dot.translating { background: var(--warm); box-shadow: 0 0 0 6px rgba(183, 121, 31, 0.16); }
.status-dot.error { background: var(--danger); box-shadow: 0 0 0 6px rgba(185, 28, 28, 0.14); }

.notice {
  padding: 14px 16px;
  color: #5f4618;
  background: rgba(255, 250, 235, 0.96);
  box-shadow: none;
}
body.dark .notice { color: #fde68a; background: rgba(120, 85, 20, 0.22); }

.control-panel,
.install-panel,
.stage-panel,
.history-panel,
.transcript-panel,
.action-panel,
.export-panel,
.summary-panel,
.audio-panel,
.diagnostics-panel,
.sessions-panel {
  margin-top: 16px;
  overflow: hidden;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  padding: 16px;
}
.controls-main { padding-bottom: 10px; }

button {
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0 16px;
  cursor: pointer;
  font-weight: 800;
}
button:disabled { cursor: not-allowed; opacity: 0.48; }
.primary { color: white; background: #0f766e; }
.primary:hover:not(:disabled) { background: #115e59; }
.secondary { color: var(--ink); background: var(--panel-strong); border-color: var(--line); }
.ghost { color: var(--danger); background: transparent; border-color: rgba(185, 28, 28, 0.24); }
.compact { min-height: 34px; padding: 0 10px; font-size: 13px; }

.demo-toggle,
.checkbox-row label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  color: var(--muted);
  font-weight: 750;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  padding: 0 16px 16px;
}
.settings-grid label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}
select, input[type="text"], input[type="date"], textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  color: var(--ink);
  background: var(--panel-strong);
}
textarea { resize: vertical; }

.panel-heading {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  padding: 14px 16px;
  color: var(--muted);
}
.panel-heading span { font-size: 13px; font-weight: 800; }

.finality-badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 900;
}
.finality-badge.processing { color: #7a4f08; background: rgba(251, 191, 36, 0.18); }
.finality-badge.done { color: var(--success); background: rgba(21, 128, 61, 0.12); }

.current-translation {
  min-height: 260px;
  display: grid;
  place-items: center;
  padding: 30px;
  text-align: center;
  white-space: pre-wrap;
  font-size: var(--subtitle-size);
  line-height: 1.18;
  font-weight: 900;
  background: var(--panel-strong);
}
.current-translation.processing { opacity: 0.88; }

.font-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  border-top: 1px solid var(--line);
  padding: 12px 16px;
}

.translation-history {
  max-height: 360px;
  overflow: auto;
  padding: 12px 16px 16px;
  scroll-behavior: smooth;
}
.translation-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 10px;
  background: var(--panel-strong);
}
.translation-item.latest {
  border-color: rgba(15, 118, 110, 0.45);
  box-shadow: inset 4px 0 0 #0f766e;
}
.translation-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}
.translation-text { white-space: pre-wrap; line-height: 1.5; font-weight: 750; }

details summary {
  cursor: pointer;
  border-bottom: 1px solid var(--line);
  padding: 14px 16px;
  color: var(--muted);
  font-weight: 900;
}
.transcript-box {
  min-height: 120px;
  padding: 16px;
  color: var(--muted);
  white-space: pre-wrap;
  font-size: 15px;
  line-height: 1.55;
}

.checkbox-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 18px;
  padding: 0 16px 14px;
}

.room-link-box {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 12px;
  margin: 0 16px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--panel-strong);
  overflow-wrap: anywhere;
}
.room-link-box b {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.qr-panel {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 14px;
  align-items: center;
  margin: 0 16px 16px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 14px;
  background: var(--panel-strong);
}
.qr-placeholder {
  display: grid;
  place-items: center;
  width: 132px;
  aspect-ratio: 1;
  border: 2px solid var(--ink);
  border-radius: 8px;
  font-weight: 950;
}

.room-entry {
  display: grid;
  gap: 10px;
  padding: 16px;
}

body.viewer-large { --subtitle-size: 48px; }
body.viewer-small { --subtitle-size: 32px; }

.install-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  padding: 16px;
}
.install-grid ol {
  margin: 0;
  padding-left: 20px;
  color: var(--muted);
  line-height: 1.55;
}

.https-status {
  margin: 16px 16px 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  font-weight: 800;
}
.https-status.ok {
  color: var(--success);
  background: rgba(21, 128, 61, 0.10);
}
.https-status.warn {
  color: #7a4f08;
  background: rgba(251, 191, 36, 0.16);
}

.summary-grid {
  display: grid;
  gap: 12px;
  padding: 16px;
}
.summary-block {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--panel-strong);
}
.summary-block ul { margin: 0; padding-left: 18px; }

.diagnostics-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  padding: 16px;
}
.diagnostic {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: var(--panel-strong);
}
.diagnostic b { display: block; margin-bottom: 4px; font-size: 12px; color: var(--muted); }
.diagnostics-panel > button { margin: 0 16px 16px; }

.saved-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 16px;
  list-style: none;
}
.saved-list li {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--panel-strong);
}
.session-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  z-index: 20;
  transform: translateX(-50%) translateY(16px);
  opacity: 0;
  pointer-events: none;
  border-radius: 8px;
  padding: 12px 14px;
  color: white;
  background: rgba(21, 23, 28, 0.94);
  font-weight: 800;
  transition: opacity 0.18s ease, transform 0.18s ease;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media print {
  body { background: white; color: black; }
  .live-hero, .notice, .control-panel, .stage-panel, .history-panel, .transcript-panel, .action-panel, .summary-panel, .audio-panel, .diagnostics-panel, .sessions-panel, .toast { display: none !important; }
  .export-print { display: block !important; }
}

@media (max-width: 900px) {
  .settings-grid, .diagnostics-grid, .install-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 720px) {
  .live-shell {
    width: min(100% - 18px, 680px);
    padding-top: 14px;
  }
  .live-hero { grid-template-columns: 1fr; gap: 14px; }
  .lead { font-size: 16px; }
  .controls, .font-controls { display: grid; grid-template-columns: 1fr 1fr; }
  .controls button, .font-controls button, .demo-toggle { width: 100%; justify-content: center; }
  .settings-grid, .diagnostics-grid, .install-grid { grid-template-columns: 1fr; }
  .room-link-box, .qr-panel { grid-template-columns: 1fr; }
  .panel-heading { align-items: flex-start; flex-direction: column; }
  .current-translation {
    min-height: 310px;
    padding: 20px;
    font-size: calc(var(--subtitle-size) * 0.82);
  }
  .translation-history { max-height: 300px; }
}

@media (max-width: 430px) {
  .controls, .font-controls { grid-template-columns: 1fr; }
}
