:root {
  color-scheme: dark;
  --bg: #0b0f17;
  --panel: #121826;
  --panel-2: #182131;
  --line: #253046;
  --text: #e8edf7;
  --muted: #93a1bb;
  --accent: #5b8cff;
  --accent-2: #33d69f;
  --danger: #ff6b6b;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-text-size-adjust: 100%;
}

body.listen {
  height: 100dvh;
  height: 100svh;
  overflow: hidden;
}

body.listen {
  --caption-font: 1.38rem; /* default ≈115% scale; listen.js overrides */
  --caption-line: 1.55;
}

a {
  color: var(--accent);
}

h1 {
  font-size: 1.15rem;
  margin: 0;
  letter-spacing: -0.01em;
}

h2 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 0 0 8px;
}

.pill {
  font-size: 0.75rem;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--muted);
  white-space: nowrap;
}

.pill.ok {
  border-color: rgba(51, 214, 159, 0.5);
  color: var(--accent-2);
}

.pill.warn {
  border-color: rgba(255, 193, 87, 0.5);
  color: #ffc157;
}

.pill.bad {
  border-color: rgba(255, 107, 107, 0.5);
  color: var(--danger);
}

/* —— Listener (mobile-first, full viewport) —— */
.listen-shell {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-height: 100dvh;
  max-height: 100svh;
  padding: max(8px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right))
    max(6px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  gap: 8px;
}

.listen-chrome {
  flex-shrink: 0;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  gap: 8px;
  align-items: center;
}

.listen-top {
  grid-column: 1;
  grid-row: 1;
  display: flex;
  align-items: center;
  min-height: 36px;
  min-width: 0;
}

.listen-top h1 {
  font-size: 1rem;
  font-weight: 600;
}

.listen-status {
  grid-column: 2;
  grid-row: 1;
  justify-self: end;
}

.listen-toolbar {
  grid-column: 1 / -1;
  grid-row: 2;
  display: flex;
  align-items: stretch;
  gap: 8px;
  min-width: 0;
}

@media (orientation: landscape) and (min-height: 280px) {
  .listen-shell {
    gap: 6px;
    padding-top: max(4px, env(safe-area-inset-top));
    padding-bottom: max(4px, env(safe-area-inset-bottom));
  }

  .listen-foot {
    display: none;
  }

  .listen-top {
    display: none;
  }

  .listen-chrome {
    display: flex;
    flex-direction: row;
    align-items: stretch;
    gap: 8px;
  }

  .listen-toolbar {
    order: 1;
    flex: 1;
    min-width: 0;
  }

  .listen-status {
    order: 2;
    flex-shrink: 0;
    align-self: center;
    max-width: 42vw;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .lang-select {
    padding-top: 8px;
    padding-bottom: 8px;
    font-size: 0.9rem;
  }

  .tool-btn {
    min-height: 40px;
    min-width: 40px;
  }

  body.listen-source-hidden-landscape .caption-panel--source {
    display: none;
  }
}

.lang-select {
  flex: 1;
  min-width: 0;
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 36px 10px 12px;
  font-size: 0.95rem;
  cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 16px) calc(50% - 3px), calc(100% - 10px) calc(50% - 3px);
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
}

.lang-select:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.tool-btn {
  flex-shrink: 0;
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  border-radius: 10px;
  min-width: 44px;
  min-height: 44px;
  padding: 0 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  font-weight: 600;
}

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

.tool-btn-sm {
  min-width: 40px;
  padding: 0 6px;
  font-size: 0.85rem;
}

.tool-btn[aria-pressed="true"] {
  border-color: rgba(51, 214, 159, 0.65);
  background: rgba(51, 214, 159, 0.12);
  color: var(--accent-2);
}

.font-tools {
  display: flex;
  gap: 4px;
}

.audio-icon {
  width: 22px;
  height: 22px;
  display: block;
  background: currentColor;
  mask-size: contain;
  mask-repeat: no-repeat;
  mask-position: center;
  -webkit-mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  -webkit-mask-position: center;
}

.audio-off {
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='currentColor'%3E%3Cpath d='M16.5 12c0-1.77-1.02-3.29-2.5-4.03v2.21l2.45 2.45c.03-.2.05-.41.05-.63zm2.5 0c0 .94-.2 1.82-.54 2.64l1.51 1.51C20.63 14.91 21 13.5 21 12c0-4.28-2.99-7.86-7-8.77v2.06c2.89.86 5 3.54 5 6.71zM4.27 3 3 4.27 7.73 9H3v6h4l5 5v-6.73l4.25 4.25c-.67.52-1.42.93-2.25 1.18v2.06a9.99 9.99 0 0 0 3.69-1.81L19.73 21 21 19.73l-9-9L4.27 3zM12 4 9.91 6.09 12 8.18V4z'/%3E%3C/svg%3E");
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='currentColor'%3E%3Cpath d='M16.5 12c0-1.77-1.02-3.29-2.5-4.03v2.21l2.45 2.45c.03-.2.05-.41.05-.63zm2.5 0c0 .94-.2 1.82-.54 2.64l1.51 1.51C20.63 14.91 21 13.5 21 12c0-4.28-2.99-7.86-7-8.77v2.06c2.89.86 5 3.54 5 6.71zM4.27 3 3 4.27 7.73 9H3v6h4l5 5v-6.73l4.25 4.25c-.67.52-1.42.93-2.25 1.18v2.06a9.99 9.99 0 0 0 3.69-1.81L19.73 21 21 19.73l-9-9L4.27 3zM12 4 9.91 6.09 12 8.18V4z'/%3E%3C/svg%3E");
}

.audio-on {
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='currentColor'%3E%3Cpath d='M3 9v6h4l5 5V4L7 9H3zm13.5 3c0-1.77-1.02-3.29-2.5-4.03v8.05c1.48-.73 2.5-2.25 2.5-4.02zM14 3.23v2.06c2.89.86 5 3.54 5 6.71s-2.11 5.85-5 6.71v2.06c4.01-.91 7-4.49 7-8.77s-2.99-7.86-7-8.77z'/%3E%3C/svg%3E");
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='currentColor'%3E%3Cpath d='M3 9v6h4l5 5V4L7 9H3zm13.5 3c0-1.77-1.02-3.29-2.5-4.03v8.05c1.48-.73 2.5-2.25 2.5-4.02zM14 3.23v2.06c2.89.86 5 3.54 5 6.71s-2.11 5.85-5 6.71v2.06c4.01-.91 7-4.49 7-8.77s-2.99-7.86-7-8.77z'/%3E%3C/svg%3E");
}

.listen-main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

@media (orientation: landscape) and (min-height: 280px) {
  .listen-main:not(.listen-main--stack) {
    flex-direction: row;
  }
  .listen-main:not(.listen-main--stack) .caption-panel {
    min-width: 0;
  }

  .listen-main:not(.listen-main--stack) .caption-panel--primary {
    flex: 1;
  }
}

.caption-panel {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}

.caption-panel.collapsed {
  flex: 0 0 auto;
}

.caption-panel--primary {
  flex: 1.4;
}

.caption-panel--source:not(.collapsed) {
  flex: 0.85;
  min-height: 0;
}

.caption-panel--source.collapsed {
  flex: 0 0 auto;
}

.caption-head {
  flex-shrink: 0;
  display: flex;
  align-items: stretch;
  background: var(--panel-2);
  border-bottom: 1px solid var(--line);
}

.caption-head .caption-toggle {
  border-bottom: none;
}

.caption-toggle {
  flex-shrink: 0;
  appearance: none;
  border: none;
  background: var(--panel-2);
  color: var(--muted);
  width: 100%;
  text-align: left;
  padding: 8px 12px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.caption-head .caption-toggle {
  flex: 1;
  min-width: 0;
}

.source-show-btn {
  flex-shrink: 0;
  appearance: none;
  border: none;
  border-left: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--accent);
  padding: 8px 14px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  letter-spacing: 0;
  text-transform: none;
}

.source-show-btn[hidden] {
  display: none;
}

.source-show-btn:not(:disabled):hover {
  background: rgba(91, 140, 255, 0.1);
}

.caption-toggle .chev {
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(45deg);
  transition: transform 0.15s;
}

.caption-panel:not(.collapsed) .caption-toggle .chev {
  transform: rotate(-135deg);
}

.caption-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.caption-panel.collapsed .caption-body {
  display: none;
}

.caption {
  margin: 0;
  padding: 10px 12px 12px;
  font-size: var(--caption-font);
  line-height: var(--caption-line);
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  word-break: break-word;
  white-space: pre-line;
  -webkit-overflow-scrolling: touch;
}

.caption-panel--primary .caption {
  font-weight: 500;
}

.listen-foot {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.68rem;
  color: var(--muted);
  min-height: 20px;
}

.listen-meta {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.page-build {
  flex-shrink: 0;
  font-size: 0.65rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  opacity: 0.85;
}

.page-foot--admin {
  max-width: 1080px;
  margin: 0 auto;
  padding: 8px 18px 28px;
  text-align: center;
}

/* Legacy stage layout (edge local UI if reused) */
.stage {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 18px;
  height: 100%;
  max-height: 100dvh;
  overflow: hidden;
}

.stage-head,
.stage-foot {
  flex-shrink: 0;
}

.stage-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.stage-foot {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--muted);
}

/* Edge console (venue ingest UI) — not used by listen-shell */
.lang-meta {
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
  word-break: break-word;
}

.player {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.listen-btn {
  appearance: none;
  border: none;
  border-radius: 14px;
  padding: 20px;
  font-size: 1.1rem;
  font-weight: 600;
  color: #08111f;
  background: var(--accent-2);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
}

.listen-btn:disabled {
  background: var(--panel-2);
  color: var(--muted);
  cursor: not-allowed;
}

.listen-btn.playing {
  background: var(--danger);
  color: #1a0505;
}

.volume-row {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.85rem;
  color: var(--muted);
}

.volume-row input[type="checkbox"] {
  flex: 0 0 auto;
  accent-color: var(--accent-2);
}

.volume-row input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
}

.captions {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
}

.captions h2 {
  margin: 0;
}

body.edge-console {
  overflow: auto;
  height: auto;
  min-height: 100dvh;
}

body.edge-console .stage {
  max-height: none;
  height: auto;
  min-height: 100dvh;
  overflow: visible;
}

body.edge-console #speaker-hero {
  flex-shrink: 0;
}

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

.admin {
  max-width: 1080px;
  margin: 0 auto;
  padding: 20px 18px 60px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.admin-head {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.admin-head input {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  padding: 8px 10px;
  min-width: 220px;
}

button.ghost {
  appearance: none;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 0.85rem;
}

button.ghost:hover {
  border-color: var(--accent);
}

button.ghost.danger:hover {
  border-color: var(--danger);
  color: var(--danger);
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 16px;
}

.card h3 {
  margin: 0 0 8px;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.card .value {
  font-size: 1.4rem;
  font-weight: 600;
}

.card .value.warn-text {
  color: var(--danger);
}

.card .sub {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 4px;
}

.meter {
  height: 10px;
  background: var(--panel-2);
  border-radius: 5px;
  overflow: hidden;
  margin-top: 10px;
}

.meter span {
  display: block;
  height: 100%;
  background: var(--accent-2);
  width: 0;
  transition: width 0.15s;
}

table.lanes {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  font-size: 0.85rem;
}

table.lanes th,
table.lanes td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

table.lanes th {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  background: var(--panel-2);
}

table.lanes tr:last-child td {
  border-bottom: none;
}

table.lanes .actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.last-text {
  color: var(--muted);
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: inline-block;
}

.add-row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.add-row select {
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 10px;
}

.add-row select option {
  background: #101725;
  color: var(--text);
}

table.lanes code {
  font-family: ui-monospace, "Cascadia Code", "Segoe UI Mono", monospace;
  font-size: 0.82rem;
}

.notice {
  font-size: 0.82rem;
  color: var(--danger);
  min-height: 1.2em;
}
