:root {
  color-scheme: light;
  --bg: #f4f7f5;
  --topbar: rgba(255, 255, 255, 0.86);
  --surface: #ffffff;
  --surface-2: #fbfcfb;
  --line: #d9e4df;
  --control-line: #adc1ba;
  --text: #17201b;
  --muted: #55615b;
  --accent: #146c5f;
  --accent-hover: #0d4e45;
  --secondary: #eef5f2;
  --danger: #a23b3b;
  --danger-bg: #fff4f4;
  --warn: #b68a2c;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
select,
input {
  font: inherit;
}

button {
  min-height: 42px;
  border: 1px solid var(--control-line);
  border-radius: 6px;
  background: var(--secondary);
  color: var(--text);
  padding: 0 16px;
  cursor: pointer;
}

button:hover {
  border-color: var(--accent);
  background: #e3eee9;
}

button.primary {
  border-color: transparent;
  background: var(--accent);
  color: #ffffff;
  font-weight: 700;
}

button.primary:hover {
  background: var(--accent-hover);
}

button.danger {
  border-color: var(--danger);
  background: var(--danger-bg);
  color: var(--danger);
}

button.danger:hover {
  background: #ffe8e8;
  border-color: var(--danger);
}

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

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 30px;
  line-height: 1.1;
}

h2 {
  font-size: 16px;
}

.muted {
  color: var(--muted);
}

.topbar,
.listener-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 28px 32px 16px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--topbar);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(173, 193, 186, 0.45);
}

.status-cluster,
.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  border-radius: 999px;
  border: 1px solid var(--line);
  padding: 0 12px;
  font-size: 13px;
  font-weight: 700;
}

.pill.ok {
  background: rgba(20, 108, 95, 0.12);
  border-color: rgba(20, 108, 95, 0.25);
  color: var(--accent);
}

.pill.warn {
  background: rgba(182, 138, 44, 0.13);
  border-color: rgba(182, 138, 44, 0.32);
  color: #7f5f19;
}

.pill.neutral {
  color: var(--muted);
}

.control-grid {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) minmax(320px, 1fr);
  gap: 18px;
  padding: 16px 32px 32px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 18px;
  box-shadow: 0 10px 28px rgba(48, 70, 60, 0.06);
}

.panel.wide {
  grid-column: 1 / -1;
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.field,
.volume-field {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
  color: var(--muted);
}

.auth-shell {
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-panel {
  width: min(420px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 24px;
  box-shadow: 0 10px 28px rgba(48, 70, 60, 0.06);
}

.auth-panel h1 {
  margin-bottom: 20px;
}

.auth-panel button {
  width: 100%;
}

.auth-error {
  margin-bottom: 16px;
  border: 1px solid #f0c4c4;
  border-radius: 6px;
  background: var(--danger-bg);
  color: var(--danger);
  padding: 10px 12px;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-2);
  padding: 0 14px;
  margin-bottom: 16px;
}

.toggle-row span {
  display: grid;
  gap: 2px;
}

.toggle-row small {
  color: var(--muted);
}

.toggle-row input {
  width: 48px;
  height: 26px;
  appearance: none;
  border-radius: 999px;
  background: var(--secondary);
  border: 1px solid var(--control-line);
  position: relative;
  cursor: pointer;
}

.toggle-row input::after {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  top: 3px;
  border-radius: 50%;
  background: #ffffff;
  transition: transform 140ms ease;
}

.toggle-row input:checked {
  background: var(--accent);
  border-color: var(--accent);
}

.toggle-row input:checked::after {
  transform: translateX(22px);
  background: #ffffff;
}

.inline-toggle {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
}

.inline-toggle input {
  width: 44px;
  height: 24px;
  appearance: none;
  border-radius: 999px;
  background: var(--secondary);
  border: 1px solid var(--control-line);
  position: relative;
  cursor: pointer;
}

.inline-toggle input::after {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  left: 3px;
  top: 3px;
  border-radius: 50%;
  background: #ffffff;
  transition: transform 140ms ease;
}

.inline-toggle input:checked {
  background: var(--accent);
  border-color: var(--accent);
}

.inline-toggle input:checked::after {
  transform: translateX(20px);
}

.field strong {
  color: var(--text);
}

select,
input[type="text"],
input[type="range"] {
  width: 100%;
}

input[type="range"] {
  accent-color: var(--accent);
}

select {
  min-height: 42px;
  border: 1px solid var(--control-line);
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text);
  padding: 0 12px;
}

input[type="text"] {
  min-height: 42px;
  border: 1px solid var(--control-line);
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text);
  padding: 0 12px;
}

.meter-wrap {
  height: 16px;
  overflow: hidden;
  border-radius: 999px;
  background: #e6eee9;
  border: 1px solid var(--line);
  margin: 18px 0;
}

.meter {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--warn));
  transition: width 80ms linear;
}

.session-list {
  display: grid;
  gap: 12px;
  margin-bottom: 14px;
}

.channel-controls {
  display: grid;
  gap: 10px;
}

.channel-controls .toggle-row {
  margin-bottom: 0;
}

.session-list div,
.lan-links a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-2);
  padding: 0 14px;
}

.session-list strong {
  color: var(--accent);
}

.runtime-overview {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.audience-controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(240px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.audience-controls .toggle-row {
  margin-bottom: 0;
}

.runtime-overview div,
.runtime-language-row {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-2);
}

.runtime-overview div {
  display: grid;
  gap: 5px;
  min-height: 72px;
  align-content: center;
  padding: 12px 14px;
}

.runtime-overview span,
.runtime-language-row span {
  color: var(--muted);
  font-size: 13px;
}

.runtime-overview strong,
.runtime-language-row b {
  color: var(--accent);
}

.runtime-language-list {
  display: grid;
  gap: 10px;
}

.runtime-language-row {
  display: grid;
  grid-template-columns: minmax(110px, 0.9fr) repeat(3, minmax(110px, 1fr));
  gap: 12px;
  align-items: center;
  min-height: 48px;
  padding: 0 14px;
}

.runtime-language-row span {
  display: inline-flex;
  justify-content: space-between;
  gap: 8px;
}

.lan-links {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.lan-links a {
  display: grid;
  align-content: center;
  justify-content: stretch;
  gap: 4px;
  min-height: 72px;
  color: var(--text);
  text-decoration: none;
  padding: 10px 14px;
}

.lan-links a small {
  color: var(--muted);
}

.glossary-form {
  display: grid;
  grid-template-columns: minmax(180px, 1.1fr) minmax(260px, 1.6fr) minmax(130px, 0.6fr) auto;
  gap: 12px;
  align-items: end;
  margin-bottom: 10px;
}

.glossary-form .field {
  margin-bottom: 0;
}

.glossary-list {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.glossary-hint {
  color: var(--muted);
  font-size: 13px;
}

.glossary-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-2);
  padding: 12px 14px;
}

.glossary-item div {
  display: grid;
  gap: 3px;
}

.glossary-item span,
.glossary-item small,
.empty-list {
  color: var(--muted);
}

.diagnostics {
  display: grid;
  gap: 8px;
  max-height: 190px;
  overflow: auto;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
}

.diagnostics div {
  border-top: 1px solid var(--line);
  padding-top: 8px;
}

.records-main {
  display: grid;
  gap: 18px;
  padding: 16px 32px 32px;
}

.record-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.record-summary div {
  display: grid;
  gap: 5px;
  min-height: 72px;
  align-content: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-2);
  padding: 12px 14px;
}

.record-summary span {
  color: var(--muted);
  font-size: 13px;
}

.record-summary strong {
  color: var(--accent);
}

.records-list {
  display: grid;
  gap: 10px;
}

.record-language-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.record-language-panel {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-2);
}

.record-language-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 48px;
  border-bottom: 1px solid var(--line);
  background: #ffffff;
  padding: 0 14px;
}

.record-language-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
}

.record-language-header span {
  color: var(--muted);
  font-size: 13px;
}

.record-rows {
  display: grid;
  max-height: calc(100vh - 290px);
  overflow: auto;
}

.record-rows .empty-list {
  padding: 14px;
}

.record-row {
  display: grid;
  grid-template-columns: 84px minmax(0, 1fr);
  gap: 12px;
  border-top: 1px solid rgba(217, 228, 223, 0.75);
  padding: 10px 14px;
}

.record-row:first-child {
  border-top: 0;
}

.record-row time {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
  white-space: nowrap;
}

.record-row p {
  color: var(--text);
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.projector-shell {
  height: 100vh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
  background: #f8f2df;
}

.projector-shell::before {
  content: "";
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, rgba(20, 108, 95, 0.12), rgba(182, 138, 44, 0.14));
  pointer-events: none;
}

.projector-grid {
  position: relative;
  z-index: 1;
  width: 100vw;
  height: auto;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(var(--visible-columns, 3), minmax(0, 1fr));
}

.projector-empty {
  display: grid;
  place-items: center;
  min-height: 0;
  color: #55615b;
  font-size: clamp(28px, 4vw, 58px);
  font-weight: 800;
  text-align: center;
}

.projector-empty[hidden] {
  display: none;
}

.caption-column {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: 72px 1fr;
  border-left: 1px solid rgba(20, 108, 95, 0.28);
  background: transparent;
}

.caption-column[hidden],
.caption-column.projector-hidden {
  display: none;
}

.caption-column:first-child {
  border-left: 0;
}

.caption-column.first-visible {
  border-left: 0;
}

.caption-column header {
  display: flex;
  align-items: center;
  justify-content: center;
  border-bottom: 1px solid rgba(20, 108, 95, 0.22);
  color: #55615b;
  font-size: 24px;
  font-weight: 800;
}

.caption-stack {
  --caption-size: 46px;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  gap: 22px;
  min-height: 0;
  padding: 28px 32px 42px;
  overflow: hidden;
}

.caption-line {
  color: #17201b;
  font-size: var(--caption-size);
  line-height: 1.18;
  overflow-wrap: anywhere;
}

.caption-line.old {
  color: #55615b;
  font-size: calc(var(--caption-size) * 0.72);
}

.caption-line.live {
  color: #146c5f;
}

.projector-status {
  position: fixed;
  right: 18px;
  bottom: 14px;
  color: #55615b;
  font-size: 14px;
}

.projector-top {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 18px;
  padding: 12px 22px 12px 24px;
}

.projector-logo {
  width: auto;
  height: clamp(34px, 4.2vw, 56px);
  max-width: 140px;
  object-fit: contain;
}

.projector-disclaimer {
  width: min(1120px, 100%);
  min-height: 68px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 22px;
  border: 1px solid rgba(20, 108, 95, 0.28);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.42);
  color: #55615b;
  font-size: 14px;
  line-height: 1.3;
  text-align: center;
  padding: 10px 18px;
}

.projector-disclaimer span {
  min-width: 0;
  flex: 1;
}

.listener-shell {
  background: var(--bg);
}

.listener-header {
  position: relative;
  border-bottom: 1px solid var(--line);
  background: var(--topbar);
  backdrop-filter: blur(12px);
}

.listener-logo {
  display: none;
}

.listener-main {
  display: grid;
  gap: 24px;
  padding: 28px;
}

.listener-captions {
  display: flex;
  min-height: 52vh;
  flex-direction: column;
  justify-content: flex-start;
  gap: 18px;
}

.listener-captions .caption-line {
  font-size: clamp(28px, 6vw, 56px);
}

.listener-captions .caption-line.old {
  font-size: clamp(22px, 4vw, 36px);
}

.volume-field {
  max-width: 360px;
}

.listener-disclaimer {
  max-width: 760px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

@media (max-width: 900px) {
  .control-grid,
  .lan-links,
  .glossary-form,
  .audience-controls,
  .runtime-overview,
  .runtime-language-row,
  .record-summary,
  .record-language-grid {
    grid-template-columns: 1fr;
  }

  .record-rows {
    max-height: none;
  }

  .runtime-language-row {
    padding: 12px 14px;
  }

  .topbar,
  .listener-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .listener-logo {
    display: block;
    position: absolute;
    top: 24px;
    right: 28px;
    width: auto;
    height: 88px;
    max-width: 256px;
    object-fit: contain;
    pointer-events: none;
  }

  .projector-grid {
    grid-template-columns: 1fr;
    grid-template-rows: repeat(var(--visible-columns, 3), minmax(0, 1fr));
  }

  .caption-column {
    grid-template-rows: 48px 1fr;
    border-left: 0;
    border-top: 1px solid rgba(20, 108, 95, 0.28);
  }

  .caption-column.first-visible {
    border-top: 0;
  }

  .caption-column header {
    font-size: 18px;
  }

  .caption-stack {
    padding: 18px;
    gap: 10px;
  }

  .projector-disclaimer {
    width: 100%;
    min-height: 102px;
    display: grid;
    gap: 3px;
    font-size: 11px;
    padding: 8px 12px;
  }

  .projector-top {
    gap: 10px;
    padding: 8px 12px;
  }

  .projector-logo {
    height: 30px;
    max-width: 84px;
  }
}
