:root {
  --ink: #13231d;
  --ink-soft: #46564f;
  --paper: #f3eee4;
  --paper-strong: #fbf8f1;
  --line: rgba(19, 35, 29, 0.14);
  --green: #1b5a49;
  --amber: #d57f2b;
  --shadow: 0 30px 70px rgba(17, 23, 20, 0.12);
  --radius-lg: 28px;
  --radius-md: 18px;
  --radius-sm: 12px;
  --max-public: 980px;
  --max-admin: 1200px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Avenir Next", "Segoe UI", "Trebuchet MS", sans-serif;
}

h1,
h2,
h3,
p {
  margin: 0;
}

button,
input,
textarea,
summary {
  font: inherit;
}

.public-page {
  color: #fff;
  background: linear-gradient(145deg, #0a1628 0%, #0f2038 30%, #0a1a30 60%, #060e1e 100%);
}

.admin-page {
  color: #f7f0e5;
  background:
    radial-gradient(circle at top right, rgba(213, 127, 43, 0.22), transparent 22rem),
    radial-gradient(circle at top left, rgba(93, 154, 129, 0.16), transparent 18rem),
    linear-gradient(180deg, #10221f 0%, #0b1816 60%, #081210 100%);
}

.public-shell,
.admin-shell {
  width: min(calc(100% - 1.5rem), var(--max-public));
  margin: 0 auto;
  padding: 1rem 0 2rem;
}

.admin-shell {
  width: min(calc(100% - 1.5rem), var(--max-admin));
}

.public-header,
.admin-header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
  margin-bottom: 1rem;
}

.header-actions {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.35rem;
}

.admin-live-indicator {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}

.brand-block h1 {
  margin-top: 0.25rem;
  letter-spacing: -0.05em;
  line-height: 0.95;
  font-family: "Optima", "Avenir Next", "Trebuchet MS", sans-serif;
}

.public-header h1 {
  font-size: clamp(2.2rem, 8vw, 4.4rem);
}

.admin-header h1 {
  font-size: clamp(1.5rem, 4.5vw, 2.55rem);
}

.eyebrow {
  font-size: 0.78rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--amber);
}

.panel {
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.public-page .panel {
  background: rgba(251, 248, 241, 0.88);
  border: 1px solid rgba(19, 35, 29, 0.08);
}

.admin-page .panel {
  background: rgba(16, 31, 28, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.language-switch {
  display: inline-flex;
  gap: 0.5rem;
  align-items: center;
}

.flag-chip,
.button {
  border: 0;
  cursor: pointer;
  border-radius: 999px;
  transition: transform 160ms ease, background 160ms ease, opacity 160ms ease;
}

.flag-chip:hover,
.button:hover {
  transform: translateY(-1px);
}

.flag-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.55rem 0.8rem;
  background: rgba(255, 255, 255, 0.68);
  color: var(--ink-soft);
  border: 1px solid rgba(19, 35, 29, 0.12);
}

.flag-chip.is-active {
  background: var(--ink);
  color: var(--paper-strong);
}

.flag-chip-flag {
  font-size: 1rem;
}

.flag-chip-text {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.12em;
}

.caption-stage,
.history-panel,
.admin-panel {
  padding: 1.1rem;
}

.caption-stage {
  min-height: 54vh;
  display: grid;
  align-items: stretch;
}

.caption-stage.is-live {
  box-shadow: 0 30px 80px rgba(27, 90, 73, 0.2);
}

.stage-status-row,
.status-cluster {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  align-items: center;
}

.caption-frame {
  display: grid;
  align-content: center;
  gap: 1rem;
  padding: 1.4rem 0 0.4rem;
}

.caption-intro {
  font-size: 0.9rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.caption-text {
  font-size: clamp(2rem, 6.7vw, 4.8rem);
  line-height: 1.04;
  letter-spacing: -0.05em;
  max-width: 14ch;
  font-family: "Optima", "Avenir Next", "Trebuchet MS", sans-serif;
}

.caption-meta,
.support-note,
.history-line-meta,
.message-label,
.preview-label,
.subtle-pill,
.status-pill {
  font-size: 0.85rem;
}

.caption-meta,
.support-note,
.history-line-meta {
  line-height: 1.5;
}

.caption-meta,
.support-note,
.history-line-meta,
.preview-label,
.message-label {
  color: var(--ink-soft);
}

.section-heading {
  display: grid;
  gap: 0.2rem;
  margin-bottom: 1rem;
}

.preview-stack .section-heading {
  margin-top: 20px;
}

.section-heading-with-provider {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.9rem;
  flex-wrap: wrap;
}

.section-heading-main {
  display: grid;
  gap: 0.2rem;
}

.control-meta {
  display: grid;
  gap: 0.22rem;
  justify-items: end;
}

.room-select-inline {
  display: grid;
  gap: 0;
}

.room-select-inline select {
  min-width: 9.8rem;
  padding-top: 0.52rem;
  padding-bottom: 0.52rem;
}

.control-provider-line {
  margin: 0;
  font-size: 0.74rem;
  letter-spacing: 0.06em;
  color: #f0bb82;
  font-weight: 600;
  text-align: right;
}

.section-heading h2,
.section-heading h3 {
  font-size: 1.3rem;
  letter-spacing: -0.03em;
}

.history-list,
.admin-messages-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.75rem;
}

.history-line,
.admin-message-card {
  padding: 0.95rem 1rem;
  border-radius: var(--radius-md);
}

.public-page .history-line {
  background: rgba(255, 255, 255, 0.58);
  border: 1px solid rgba(19, 35, 29, 0.08);
}

.admin-page .admin-message-card {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.history-line.is-draft,
.admin-message-card.is-draft {
  border-style: dashed;
}

.history-line-text,
.preview-text,
.message-text {
  margin: 0;
  line-height: 1.6;
}

.history-line-text {
  font-size: 1rem;
}

.empty-state {
  padding: 1.1rem;
  border-radius: var(--radius-md);
  border: 1px dashed var(--line);
  color: var(--ink-soft);
  text-align: center;
}

.admin-page .empty-state {
  border-color: rgba(255, 255, 255, 0.16);
  color: rgba(247, 240, 229, 0.72);
}

.status-pill,
.subtle-pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 0.45rem 0.8rem;
  width: fit-content;
}

.status-pill.neutral {
  background: rgba(19, 35, 29, 0.08);
  color: var(--ink-soft);
}

.status-pill.success {
  background: rgba(27, 90, 73, 0.14);
  color: var(--green);
}

.status-pill.warning {
  background: rgba(213, 127, 43, 0.14);
  color: #9b5a16;
}

.admin-page .status-pill.neutral {
  background: rgba(255, 255, 255, 0.08);
  color: rgba(247, 240, 229, 0.8);
}

.admin-page .status-pill.success {
  background: rgba(93, 154, 129, 0.18);
  color: #a9e0ca;
}

.admin-page .status-pill.warning {
  background: rgba(213, 127, 43, 0.18);
  color: #f0c896;
}

.subtle-pill {
  background: rgba(255, 255, 255, 0.5);
  color: var(--ink-soft);
  border: 1px solid rgba(19, 35, 29, 0.08);
}

.admin-page .subtle-pill {
  background: rgba(255, 255, 255, 0.06);
  color: rgba(247, 240, 229, 0.82);
  border-color: rgba(255, 255, 255, 0.08);
}

.admin-grid {
  display: grid;
  gap: 1rem;
}

.control-stack,
.preview-stack {
  display: grid;
  gap: 1rem;
}

.admin-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.control-stack .section-heading-with-provider + .admin-actions {
  margin-top: 4px;
}

.control-stack .admin-actions + .toggle-row {
  margin-top: calc(40px - 1rem);
}

.control-stack .toggle-row + .audio-meter-wrap {
  margin-top: calc(45px - 1rem);
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.toggle-label {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.6;
  white-space: nowrap;
}

.toggle-row-mic .toggle-label {
  margin-right: 15px;
}
.toggle-group {
  display: flex;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.15);
}

.toggle-group .mode-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.mode-btn {
  padding: 0.45rem 0.9rem;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  background: rgba(255,255,255,0.06);
  color: rgba(255,255,255,0.5);
  transition: background 0.2s, color 0.2s;
}
.mode-btn.mode-btn-active {
  background: rgba(240,187,130,0.18);
  color: #f0bb82;
}

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

.button {
  padding: 0.95rem 1.1rem;
  font-weight: 700;
}

.button.primary {
  background: linear-gradient(135deg, #f0bb82, #d57f2b);
  color: #24170a;
}

.button.primary.is-active {
  border: 1px solid rgba(218, 255, 246, 0.95);
  box-shadow:
    0 0 0 1px rgba(218, 255, 246, 0.28),
    0 0 16px rgba(132, 255, 225, 0.48);
  animation: start-live-glow 1.6s ease-in-out infinite;
}

.button.primary.is-active:disabled {
  opacity: 1;
}

.button.secondary {
  background: rgba(255, 255, 255, 0.06);
  color: inherit;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.button.wide {
  width: 100%;
}

.button:disabled,
.flag-chip:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

@keyframes start-live-glow {
  0%, 100% {
    box-shadow:
      0 0 0 1px rgba(218, 255, 246, 0.22),
      0 0 12px rgba(132, 255, 225, 0.32);
  }
  50% {
    box-shadow:
      0 0 0 1px rgba(218, 255, 246, 0.42),
      0 0 24px rgba(132, 255, 225, 0.68);
  }
}

.backup-box {
  padding: 1rem;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.stt-debug-box {
  padding: 0.9rem;
  border-radius: var(--radius-md);
  background: rgba(3, 8, 14, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.stt-debug-log {
  margin-top: 0.5rem;
  max-height: 190px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.78rem;
  line-height: 1.42;
  color: #bfe6ff;
  font-family: Menlo, Monaco, Consolas, "Courier New", monospace;
}

.backup-box summary {
  cursor: pointer;
  font-weight: 700;
}

.backup-box[open] summary {
  margin-bottom: 0.8rem;
}

.field {
  display: grid;
  gap: 0.45rem;
  margin-bottom: 0.9rem;
}

.field span {
  font-size: 0.82rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: inherit;
}

textarea {
  width: 100%;
  min-height: 7rem;
  resize: vertical;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.05);
  color: inherit;
  padding: 0.9rem 1rem;
  outline: none;
}

input {
  width: 100%;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.05);
  color: inherit;
  padding: 0.9rem 1rem;
  outline: none;
}

select {
  width: 100%;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.05);
  color: inherit;
  padding: 0.9rem 1rem;
  outline: none;
}

input:focus,
textarea:focus,
select:focus {
  border-color: rgba(213, 127, 43, 0.5);
}

.preview-grid,
.admin-message-grid {
  display: grid;
  gap: 0.75rem;
}

.preview-card,
.message-block {
  padding: 1rem;
  border-radius: var(--radius-md);
}

.admin-page .preview-card,
.admin-page .message-block {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.admin-page .preview-card.accent {
  background: rgba(213, 127, 43, 0.12);
}

.admin-page .admin-source {
  background: rgba(93, 154, 129, 0.12);
}

.preview-label,
.message-label {
  display: inline-flex;
  margin-bottom: 0.45rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.preview-text,
.message-text {
  font-size: 1rem;
}

.admin-message-meta {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 0.8rem;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  align-items: center;
}

.login-panel {
  width: min(100%, 28rem);
  margin: 0 auto;
  padding: 1.4rem;
}

.login-form {
  margin-top: 1rem;
}

.login-error {
  margin-top: 1rem;
  color: #f0c896;
}

.logout-link {
  color: inherit;
  text-decoration: none;
  font-size: 0.92rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.25);
}

/* ── Audio meter ── */
.audio-meter-wrap {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  opacity: 0.62;
  transition: opacity 180ms ease;
}

.audio-meter-wrap.is-active {
  opacity: 1;
}

.audio-meter-track {
  display: flex;
  gap: 3px;
  align-items: flex-end;
  height: 40px;
}

.audio-meter-seg {
  flex: 1;
  border-radius: 3px 3px 2px 2px;
  background: rgba(255, 255, 255, 0.1);
  height: 3px;
  will-change: height;
  transition: height 60ms ease-out, background 120ms ease;
}

.audio-meter-seg.lit {
  background: linear-gradient(to top, #d57f2b, #f5c97a);
}

.audio-meter-seg.lit.peak {
  background: linear-gradient(to top, #d57f2b, #fff0c0);
  box-shadow: 0 0 6px rgba(213, 127, 43, 0.5);
}

/* ── Viewer (student page) ── */
.viewer-bar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 0.6rem 1.2rem;
  background: rgba(255, 255, 255, 0.06);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.viewer-bar-left {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  justify-content: flex-start;
}

.viewer-bar-right {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  justify-content: flex-end;
}

.viewer-flag {
  font-size: 1.82rem;
  opacity: 0.62;
  user-select: none;
  line-height: 1;
  background: transparent;
  border: 0;
  padding: 0;
  cursor: pointer;
  transition: transform 180ms ease, opacity 180ms ease, filter 180ms ease;
}

.viewer-flag:hover {
  transform: scale(1.12);
  opacity: 0.92;
}

.viewer-flag.is-active {
  opacity: 1;
  filter: drop-shadow(0 0 6px rgba(255, 255, 255, 0.42));
}

.viewer-title {
  font-size: 0.72rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.35);
  font-weight: 600;
  text-align: center;
}

.alive-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.25);
  flex-shrink: 0;
  transition: background 300ms ease, box-shadow 300ms ease;
}

.alive-dot.is-live {
  background: #34d399;
  box-shadow: 0 0 8px rgba(52, 211, 153, 0.6);
  animation: alive-pulse 2s ease-in-out infinite;
}

@keyframes alive-pulse {
  0%, 100% { box-shadow: 0 0 6px rgba(52, 211, 153, 0.4); }
  50%      { box-shadow: 0 0 14px rgba(52, 211, 153, 0.8); }
}

.alive-label {
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.35);
  transition: color 300ms ease;
}

.alive-label.is-live {
  color: #34d399;
}

.viewer-stage {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  height: calc(100vh - 48px);
  padding: 0 1.5rem;
  text-align: center;
  position: relative;
  overflow: hidden;
}

.viewer-lines {
  position: relative;
  width: 100%;
  max-width: 54rem;
  height: 100%;
  padding: 0 clamp(0.4rem, 2vw, 1.2rem);
  overflow: hidden;
  -webkit-mask-image: linear-gradient(to bottom, transparent 0%, black 18%, black 82%, transparent 100%);
  mask-image: linear-gradient(to bottom, transparent 0%, black 18%, black 82%, transparent 100%);
}

.viewer-text {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(50% - 120px);
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  transition: opacity 320ms ease;
}

.viewer-lines.is-idle .viewer-text {
  opacity: 0;
}

.viewer-line {
  font-family: "Optima", "Avenir Next", "Trebuchet MS", sans-serif;
  font-size: clamp(1.3rem, 4.2vw, 2.6rem);
  line-height: 1.5;
  letter-spacing: -0.02em;
  color: rgba(255, 255, 255, 0.62);
  font-weight: 400;
  margin: 0;
  padding: 0.08em 0;
  transition: color 180ms ease, opacity 180ms ease, transform 180ms ease;
}

.viewer-line.is-current {
  color: #fff;
  opacity: 1;
  transform: translateY(0);
}

.viewer-line:not(.is-current) {
  opacity: 0.72;
}

.viewer-line.is-draft {
  color: rgba(255, 255, 255, 0.82);
}

.viewer-watermark-wrap {
  position: absolute;
  top: calc(50% - 35px);
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.2rem;
  opacity: 0;
  transition: opacity 1.5s ease;
  pointer-events: none;
}

.viewer-watermark-wrap.is-visible {
  opacity: 1;
}

.viewer-watermark {
  width: min(60vw, 420px);
  height: auto;
  opacity: 0.15;
  filter: brightness(1.2);
}

.viewer-idle {
  font-size: 0.82rem;
  color: rgba(255, 255, 255, 0.25);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

@media (min-width: 760px) {
  .public-shell,
  .admin-shell {
    padding-top: 1.3rem;
    padding-bottom: 2.5rem;
  }

  .history-panel,
  .caption-stage,
  .admin-panel {
    padding: 1.4rem;
  }

  .admin-grid {
    grid-template-columns: minmax(18rem, 0.8fr) minmax(28rem, 1.2fr);
  }

  .preview-stack .section-heading {
    margin-top: 0;
  }

  .admin-preview-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .admin-message-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}
