:root {
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #111827;
  background: #f8fafc;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

main {
  width: min(760px, 100%);
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 20px;
  box-shadow: 0 20px 60px rgba(15, 23, 42, 0.08);
  padding: 32px;
}

h1 { margin-top: 0; }

.language-controls {
  display: grid;
  grid-template-columns: minmax(180px, 320px);
  gap: 12px;
  margin: 24px 0 12px;
}

label {
  display: grid;
  gap: 6px;
  color: #475569;
  font-size: 0.9rem;
  font-weight: 700;
}

select,
#presenter-access-key {
  width: 100%;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  background: white;
  color: #111827;
  font: inherit;
  padding: 10px 12px;
}

select:disabled,
#presenter-access-key:disabled {
  background: #e2e8f0;
  color: #64748b;
}

.language-controls small {
  font-weight: 500;
}

.session-policy {
  margin: 0 0 12px;
  color: #64748b;
  font-size: 0.86rem;
  line-height: 1.5;
}

#broadcast-time-zone {
  color: #334155;
  font-weight: 700;
}

.controls {
  display: flex;
  gap: 12px;
  margin: 16px 0 24px;
}

button {
  border: 0;
  border-radius: 999px;
  padding: 12px 18px;
  font-weight: 700;
  cursor: pointer;
}

#start {
  background: #111827;
  color: white;
}

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

.broadcast-panel {
  margin: 8px 0 28px;
  border: 1px solid #bfdbfe;
  border-radius: 16px;
  background: #eff6ff;
  padding: 20px;
}

.broadcast-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.broadcast-heading h2,
.broadcast-heading p {
  margin: 0;
}

.eyebrow,
.listener-eyebrow {
  color: #2563eb;
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.live-badge,
.listener-status {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 800;
  padding: 5px 10px;
  white-space: nowrap;
}

.live-badge {
  background: #dcfce7;
  color: #166534;
}

.share-link {
  display: grid;
  gap: 7px;
  margin-top: 16px;
}

.share-link > label {
  color: #334155;
  font-size: 0.82rem;
  font-weight: 800;
}

.share-link > div {
  display: flex;
  gap: 8px;
}

.share-link input {
  min-width: 0;
  flex: 1;
  border: 1px solid #93c5fd;
  border-radius: 10px;
  background: white;
  color: #1e293b;
  font: inherit;
  padding: 10px 12px;
}

#copy-listener-link {
  border: 1px solid #2563eb;
  border-radius: 10px;
  background: #2563eb;
  color: white;
  padding: 10px 14px;
}

.storage-status {
  margin: 12px 0 0;
  color: #475569;
  font-size: 0.86rem;
  font-weight: 700;
}

.storage-status[data-state="saved"] {
  color: #166534;
}

.storage-status[data-state="saving"] {
  color: #1d4ed8;
}

.storage-status[data-state="error"] {
  color: #b91c1c;
}

.retry-storage {
  margin-top: 10px;
  border: 1px solid #b91c1c;
  border-radius: 10px;
  background: white;
  color: #b91c1c;
  padding: 9px 12px;
}

#original-subtitles,
#subtitles {
  min-height: 120px;
  padding: 16px;
  border-radius: 14px;
  background: #f1f5f9;
  font-size: 1.3rem;
  line-height: 1.5;
  white-space: pre-wrap;
}

.subtitle-message {
  display: grid;
  grid-template-columns: 76px 1fr;
  gap: 12px;
}

.subtitle-message + .subtitle-message {
  margin-top: 12px;
}

.subtitle-timestamp {
  color: #64748b;
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
  line-height: 1.9;
}

.subtitle-text {
  min-width: 0;
}

.technical-term,
button.technical-term:first-child {
  display: inline;
  border: 0;
  border-radius: 4px;
  background: #dbeafe;
  color: #1e3a8a;
  cursor: help;
  font: inherit;
  font-weight: 700;
  padding: 0 3px;
  text-align: inherit;
}

.technical-term:hover,
.technical-term:focus-visible {
  background: #bfdbfe;
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
}

.term-popover {
  position: fixed;
  z-index: 10;
  width: min(280px, calc(100vw - 24px));
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  background: white;
  box-shadow: 0 16px 40px rgba(15, 23, 42, 0.18);
  color: #111827;
  padding: 12px;
}

.term-popover strong,
.term-popover span {
  display: block;
}

.term-popover strong {
  margin-bottom: 4px;
}

.term-popover span {
  color: #475569;
  font-size: 0.95rem;
  line-height: 1.4;
}

#status {
  padding: 12px;
  border-radius: 12px;
  background: #0f172a;
  color: #e2e8f0;
  overflow-x: auto;
}

.listener-page {
  place-items: start center;
  background:
    radial-gradient(circle at top left, rgba(59, 130, 246, 0.12), transparent 32rem),
    #f8fafc;
}

.listener-shell {
  width: min(1120px, 100%);
  margin: 24px 0;
  padding: 36px;
}

.listener-header {
  max-width: 780px;
}

.listener-navigation {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  margin: 0 0 24px;
}

.listener-navigation a {
  color: #1d4ed8;
  font-size: 0.9rem;
  font-weight: 750;
  text-underline-offset: 3px;
}

.listener-navigation a:hover {
  color: #1e3a8a;
}

.listener-navigation a:focus-visible,
.recording-link:focus-visible,
.directory-action:focus-visible {
  border-radius: 6px;
  outline: 3px solid #3b82f6;
  outline-offset: 3px;
}

.listener-header h1 {
  margin-bottom: 8px;
  font-size: clamp(2rem, 6vw, 3.5rem);
  letter-spacing: -0.04em;
  line-height: 1;
}

.listener-eyebrow {
  margin: 0 0 10px;
}

.listener-introduction,
.listener-message {
  color: #475569;
  line-height: 1.6;
}

.listener-introduction {
  margin: 0;
  font-size: 1.05rem;
}

.listener-status-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 22px;
}

.listener-status[data-state="connected"],
.listener-status[data-state="live"] {
  background: #dcfce7;
  color: #166534;
}

.listener-status[data-state="connecting"],
.listener-status[data-state="loading"],
.listener-status[data-state="waiting"] {
  background: #dbeafe;
  color: #1d4ed8;
}

.listener-status[data-state="reconnecting"] {
  background: #fef3c7;
  color: #92400e;
}

.listener-status[data-state="offline"],
.listener-status[data-state="error"],
.listener-status[data-state="invalid"],
.listener-status[data-state="not-found"],
.listener-status[data-state="unavailable"] {
  background: #fee2e2;
  color: #b91c1c;
}

.listener-status[data-state="ended"] {
  background: #e2e8f0;
  color: #475569;
}

.listener-message {
  min-height: 1.6em;
  margin: 12px 0 0;
}

.listener-details {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin: 22px 0 0;
}

.listener-detail {
  min-width: 150px;
  border-left: 3px solid #bfdbfe;
  padding-left: 12px;
}

.listener-detail dt {
  color: #64748b;
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.listener-detail dd {
  margin: 3px 0 0;
  color: #0f172a;
  font-weight: 750;
}

.listener-caption-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
  margin-top: 32px;
}

.listener-caption-pane {
  min-width: 0;
  border: 1px solid #e2e8f0;
  border-radius: 18px;
  background: #f8fafc;
  padding: 18px;
}

.listener-caption-pane h2 {
  margin: 0 0 12px;
  font-size: 1rem;
}

#original-subtitles.listener-transcript,
#subtitles.listener-transcript {
  min-height: 320px;
  max-height: min(54vh, 600px);
  overflow-y: auto;
  background: white;
  scroll-behavior: smooth;
}

.listener-caption-line.is-interim {
  opacity: 0.76;
}

.listener-caption-line.is-interim .listener-caption-text::after {
  content: "\2026";
  color: #3b82f6;
  padding-left: 2px;
}

.listener-caption-time:empty {
  visibility: hidden;
}

.listener-caption-text {
  overflow-wrap: anywhere;
}

.listener-empty {
  margin: 0;
  color: #64748b;
  font-size: 1rem;
}

.recordings-shell {
  max-width: 980px;
}

.recordings-header {
  max-width: 720px;
}

.recordings-section {
  margin-top: 36px;
}

.recordings-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid #e2e8f0;
  padding-bottom: 14px;
}

.recordings-toolbar h2 {
  margin: 0;
  font-size: 1.25rem;
}

.directory-action {
  border: 1px solid #bfdbfe;
  border-radius: 10px;
  background: #eff6ff;
  color: #1d4ed8;
  padding: 9px 14px;
}

.recordings-status {
  min-height: 1.5em;
  margin: 14px 0 0;
  color: #475569;
  font-size: 0.92rem;
}

.recordings-directory {
  display: grid;
  gap: 24px;
  margin-top: 20px;
}

.recording-course {
  border: 1px solid #dbe3ee;
  border-radius: 18px;
  background: #f8fafc;
  overflow: hidden;
}

.recording-course > h3 {
  margin: 0;
  background: #eff6ff;
  color: #172554;
  font-size: 1.3rem;
  padding: 18px 20px;
}

.recording-day-list {
  display: grid;
}

.recording-day {
  padding: 20px;
}

.recording-day + .recording-day {
  border-top: 1px solid #e2e8f0;
}

.recording-day > h4 {
  margin: 0 0 14px;
  color: #334155;
  font-size: 1rem;
}

.recording-language-list,
.recording-entry-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.recording-language-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 14px;
}

.recording-language-group {
  min-width: 0;
}

.recording-language-group > h5 {
  margin: 0 0 7px;
  color: #64748b;
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.recording-entry-list {
  display: grid;
  gap: 8px;
}

.recording-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 72px;
  border: 1px solid #dbe3ee;
  border-radius: 12px;
  background: white;
  color: #0f172a;
  padding: 12px 14px;
  text-decoration: none;
  transition: border-color 120ms ease, box-shadow 120ms ease, transform 120ms ease;
}

.recording-link:hover {
  border-color: #93c5fd;
  box-shadow: 0 8px 20px rgba(37, 99, 235, 0.1);
  transform: translateY(-1px);
}

.recording-link-copy {
  display: grid;
  min-width: 0;
  gap: 4px;
}

.recording-link-copy strong {
  color: #1d4ed8;
}

.recording-link-time {
  color: #64748b;
  font-size: 0.8rem;
  line-height: 1.35;
}

.recording-status-badge {
  flex: none;
}

.recordings-empty {
  margin: 0;
  border: 1px dashed #cbd5e1;
  border-radius: 14px;
  background: #f8fafc;
  color: #475569;
  padding: 28px;
  text-align: center;
}

.recordings-error {
  border-color: #fecaca;
  background: #fef2f2;
  color: #991b1b;
}

.directory-retry {
  margin-top: 14px;
}

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

@media (prefers-reduced-motion: reduce) {
  #original-subtitles.listener-transcript,
  #subtitles.listener-transcript {
    scroll-behavior: auto;
  }

  .recording-link {
    transition: none;
  }
}

@media (max-width: 820px) {
  .listener-caption-grid {
    grid-template-columns: 1fr;
  }

  #original-subtitles.listener-transcript,
  #subtitles.listener-transcript {
    min-height: 220px;
    max-height: 420px;
  }
}

@media (max-width: 560px) {
  body {
    padding: 12px;
  }

  main {
    padding: 24px;
  }

  .listener-shell {
    margin: 0;
    padding: 24px 18px;
  }

  .language-controls {
    grid-template-columns: 1fr;
  }

  .subtitle-message {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .subtitle-timestamp {
    line-height: 1.2;
  }

  .share-link > div {
    align-items: stretch;
    flex-direction: column;
  }

  .recordings-toolbar,
  .recording-link {
    align-items: flex-start;
    flex-direction: column;
  }

  .recording-language-list {
    grid-template-columns: 1fr;
  }

  .recording-status-badge {
    align-self: flex-start;
  }
}
