/* ============================================================
   textbroadcast — shared design tokens
   Visual language borrows from the broadcast control room:
   tally lights (on-air red), the pending/approved states read
   like a vision-mixer's status lamps, and timestamps/codes sit
   in a monospace data face. Audience-facing surfaces stay warm
   paper; backstage (admin) and the big screen (broadcast) stay
   in the dark "control room" register.
   ============================================================ */

:root {
  --ink: #14172a;
  --ink-soft: #1c2038;
  --ink-line: rgba(255, 255, 255, 0.09);

  --paper: #f6f3ec;
  --paper-ink: #1b1b18;
  --paper-line: rgba(20, 20, 16, 0.12);

  --signal: #ff5d3a;
  --signal-dim: rgba(255, 93, 58, 0.16);
  --amber: #f0a93a;
  --amber-dim: rgba(240, 169, 58, 0.16);
  --jade: #22b378;
  --jade-dim: rgba(34, 179, 120, 0.16);

  --mist: #8b8fa3;
  --mist-on-paper: #767567;

  --font-body: "IBM Plex Sans Thai", "IBM Plex Sans", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SF Mono", monospace;

  color-scheme: light dark;
}

/* ---------- themeable surface ----------
   Semantic tokens driven by [data-theme] on <html>, so light/dark actually
   swaps every color that matters instead of just a couple of variables.
   Two independent things set [data-theme], per page:
   - join.html / broadcast.html: the ROOM's chosen theme (public-facing),
     applied by applyRoomAppearance() in fonts.js.
   - admin.html / mod.html: the OPERATOR's own personal preference for
     their own dashboard (nothing to do with any room), applied by
     applyUiTheme() in fonts.js and stored in localStorage.
   Each page has its own <html> element, so these never collide. Defaults
   to dark (this app's original "control room" look) until a preference is
   known. */
:root,
:root[data-theme="dark"] {
  --surface-bg: var(--ink);
  --surface-panel: var(--ink-soft);
  --surface-input: #0e1122;
  --surface-text: #f3f2f8;
  --surface-mist: var(--mist);
  --surface-line: var(--ink-line);
  --surface-overlay: rgba(255, 255, 255, 0.05);
}

:root[data-theme="light"] {
  --surface-bg: var(--paper);
  --surface-panel: #ffffff;
  --surface-input: #f7f5f0;
  --surface-text: var(--paper-ink);
  --surface-mist: var(--mist-on-paper);
  --surface-line: var(--paper-line);
  --surface-overlay: rgba(20, 20, 16, 0.04);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button,
input,
textarea {
  font-family: inherit;
}

:focus-visible {
  outline: 2px solid var(--signal);
  outline-offset: 3px;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

.on-air {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  color: var(--signal);
}

.on-air::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--signal);
  box-shadow: 0 0 0 0 var(--signal-glow, rgba(255, 93, 58, 0.55));
  animation: pulse 1.8s ease-out infinite;
}

/* "ผลรวม" — a closed question/poll (ballot + big screen). Steady, not
   blinking like LIVE; the text says it too (not colour alone). */
.final-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
  padding: 0.15em 0.65em;
  border-radius: 999px;
  border: 1px solid var(--jade);
  background: var(--jade-dim);
  color: var(--surface-text);
  font-size: 0.78rem;
  font-weight: 650;
  letter-spacing: 0.02em;
}

/* "รอเริ่ม" — a poll in its waiting room (ballot + big screen) */
.waiting-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
  padding: 0.15em 0.65em;
  border-radius: 999px;
  border: 1px solid var(--surface-line);
  background: var(--surface-overlay);
  color: var(--surface-mist);
  font-size: 0.78rem;
  font-weight: 650;
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 var(--signal-glow, rgba(255, 93, 58, 0.55));
  }
  70% {
    box-shadow: 0 0 0 9px rgba(255, 93, 58, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(255, 93, 58, 0);
  }
}

/* ---------- "scan to join" card (big screens) ---------- */
/* See renderJoinQrCard in qrstyle.js — placed inside each screen's message
   area (OBS crops to that). Always a light card regardless of the room
   theme: a QR needs a light quiet zone to scan reliably. */
.join-qr-card {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 0.45rem;
  padding: 0.7rem 0.7rem 0.6rem;
  border-radius: 14px;
  background: #fff;
  color: #14131c;
}

.join-qr-card.row {
  flex-direction: row;
  gap: 0.9rem;
  padding: 0.6rem 1rem 0.6rem 0.6rem;
}

.join-qr-code-img {
  flex: none;
  width: var(--join-qr-size, 160px);
  height: var(--join-qr-size, 160px);
}

.join-qr-code-img svg,
.join-qr-code-img canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.join-qr-text {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  line-height: 1.25;
}

.join-qr-card.row .join-qr-text {
  align-items: flex-start;
  text-align: left;
}

.join-qr-label {
  font-size: 0.8rem;
  font-weight: 600;
}

.join-qr-code {
  font-family: var(--font-mono);
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: 0.14em;
}

.join-qr-host {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  color: #5d5b6e;
  white-space: nowrap;
}

/* ---------- "new version deployed" banner (bannerOnNewVersion, lib.js) ---------- */
.txtb-update-banner {
  position: fixed;
  left: 50%;
  bottom: 1rem;
  transform: translateX(-50%);
  z-index: 200;
  max-width: calc(100vw - 2rem);
  padding: 0.7rem 1.2rem;
  border: none;
  border-radius: 999px;
  background: var(--amber);
  color: #1b1b18;
  font-weight: 600;
  font-size: 0.85rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  cursor: pointer;
}

/* ---------- event header: key visual / banner / logo (audience pages) ---------- */
/* See txtbRenderEventHeader in fonts.js. Banner: full width, keeps the
   image's own proportions (never crops a key visual). Logo: centred. */
.event-header[hidden] {
  display: none;
}

.event-header.mode-banner {
  width: 100%;
  max-width: 48rem;
  margin: 0 auto;
}

.event-header.mode-banner img {
  display: block;
  width: 100%;
  height: auto;
  max-height: 45vh;
  object-fit: contain;
}

.event-header.mode-logo {
  display: flex;
  justify-content: center;
  padding: 1.25rem 1rem 0;
}

.event-header.mode-logo img {
  display: block;
  max-height: 72px;
  max-width: min(70vw, 280px);
  object-fit: contain;
}

/* inside the invite card (and its print / full-screen modes) */
.invite-card .event-header {
  margin-bottom: 1.25rem;
}

.invite-card .event-header.mode-banner img {
  border-radius: 12px;
}

/* ---------- language switch (i18n.js draws the buttons) ---------- */
.lang-toggle {
  display: inline-flex;
  gap: 2px;
  padding: 2px;
  border-radius: 999px;
  border: 1px solid var(--surface-line, rgba(127, 127, 127, 0.35));
  background: var(--surface-panel, transparent);
  vertical-align: middle;
}

.lang-toggle button {
  border: none;
  background: none;
  color: var(--surface-mist, inherit);
  font: inherit;
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1;
  padding: 0.35rem 0.55rem;
  border-radius: 999px;
  cursor: pointer;
}

.lang-toggle button.active {
  background: var(--signal, #ff5d3a);
  color: var(--on-signal, #fff);
}

/* audience pages: a small bar above everything, right-aligned */
.lang-bar {
  display: flex;
  justify-content: flex-end;
  width: fit-content;
  margin: 0.6rem 0.75rem 0 auto;
}

.lang-bar.lang-toggle {
  display: flex;
}

/* login screens: next to the fixed theme toggle */
.login-lang-toggle {
  position: fixed;
  top: 1.05rem;
  right: 3.4rem;
  z-index: 100;
}

body.signed-in .login-lang-toggle {
  display: none;
}

.brand-tools {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.nav-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

/* ---------- consent / disclaimer box (join + vote pages, lib.js) ---------- */
.consent-box {
  border: 1px solid var(--surface-line);
  border-radius: 10px;
  padding: 0.75rem 0.85rem;
  margin: 0.25rem 0 0.85rem;
  font-size: 0.78rem;
  line-height: 1.55;
  color: var(--surface-mist);
  background: var(--surface-overlay);
}

.consent-text {
  margin: 0 0 0.55rem;
  white-space: pre-line;
}

.consent-check {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  color: var(--surface-text);
  font-size: 0.84rem;
  font-weight: 500;
  cursor: pointer;
  margin-bottom: 0.45rem;
}

.consent-check input {
  width: 1.15rem;
  height: 1.15rem;
  margin: 0.1rem 0 0;
  flex: none;
  accent-color: var(--signal);
}

.consent-link {
  color: var(--surface-mist);
  text-decoration: underline;
  font-size: 0.74rem;
}

/* small legal footer on audience pages */
.legal-footer {
  text-align: center;
  font-size: 0.72rem;
  padding: 1.5rem 1rem 2rem;
}

.legal-footer a {
  color: var(--surface-mist);
}

/* Drill (rehearsal) room/poll notice on the audience pages (join, poll) —
   anyone who wanders in can tell it isn't a live event. */
.drill-badge {
  display: inline-block;
  margin-inline-start: 0.5rem;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  background: rgba(240, 169, 58, 0.16);
  color: #f0a93a;
  font-size: 0.72rem;
  font-weight: 600;
}

/* ---------- room topic, shortened (txtbClampTopic in lib.js) ---------- */
.topic-clamp {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}

.topic-clamp.expanded {
  display: block;
  -webkit-line-clamp: unset;
  overflow: visible;
}

.topic-more {
  border: none;
  background: none;
  padding: 0.2rem 0 0;
  color: var(--signal);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}

.topic-more[hidden] {
  display: none;
}

/* big screens + QR posters: one or two lines, no button */
.topic-1line {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 1;
  overflow: hidden;
}

.topic-2line {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}
