/* ============================================================
   Live Translation — app components
   Load order: colors_and_type.css → dark-theme.css → app.css
   References semantic tokens only (--fg-*, --bg-*, --border-*),
   per the design handoff, so themes stay swappable.
   ============================================================ */

html, body { margin: 0; min-height: 100%; }
/* Paint the root too: iOS Safari uses it for overscroll and the areas behind
   its translucent toolbars — otherwise those render as default gray. */
html { background: var(--bg-base); }

/* Class display rules (flex/grid) must never beat the hidden attribute. */
[hidden] { display: none !important; }

/* The page must never scroll or pan sideways, whatever the zoom level.
   `clip` (not `hidden`) — hidden would break position:sticky on the top bar. */
html, body { overflow-x: clip; }

/* Light mode (attendee accessibility toggle). Dark stays the default. */
html[data-theme='light'] {
  --fg-primary:   #0f0f0f;
  --fg-secondary: #4a4a4a;
  --fg-tertiary:  #a0a0a0;
  --fg-accent:    #0078f8;
  --bg-base:      #ffffff;
  --bg-subtle:    #f8f8f8;
  --bg-muted:     #f0f0f0;
  --border-subtle:  #f0f0f0;
  --border-default: #e0e0e0;
  --border-strong:  #c8c8c8;
  --border-accent:  #0078f8;
}

button { font-family: var(--font-sans); }
:focus-visible { outline: 2px solid var(--border-accent); outline-offset: 2px; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px;
  background: transparent; border: none; cursor: pointer;
  color: var(--fg-secondary); border-radius: var(--radius-pill);
  transition: color var(--duration-fast) var(--ease-out),
              background var(--duration-fast) var(--ease-out);
}
.icon-btn:hover { color: var(--fg-primary); background: var(--bg-muted); }

/* --- LIVE indicator ---------------------------------------- */
.live-indicator {
  display: inline-flex; align-items: center; gap: var(--space-2);
  font-size: var(--text-xs); font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-wider); text-transform: uppercase;
  color: var(--fg-secondary);
}
.live-indicator .dot {
  width: 8px; height: 8px; border-radius: var(--radius-pill);
  background: var(--fg-tertiary); flex: none;
}
/* Long status labels ("Waiting for the service to begin") must truncate,
   never widen the bar past the screen. */
.topbar .live-indicator { min-width: 0; overflow: hidden; }
.topbar .live-indicator span:last-child {
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar .lang-pill { flex: none; }
.live-indicator.is-live { color: var(--fg-accent); }
.live-indicator.is-live .dot { background: var(--fg-accent); animation: pulse 2s var(--ease-inout) infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }
@keyframes spin { to { transform: rotate(360deg); } }
.spin { display: inline-flex; animation: spin 1s linear infinite; color: var(--fg-secondary); }

/* --- Attendee view ------------------------------------------ */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: var(--space-4);
  height: 56px; padding: 0 var(--space-4);
  background: var(--bg-base);
  border-bottom: 1px solid var(--border-subtle);
}
.topbar .logo-h { height: 22px; display: block; flex: none; }
.topbar .logo-mark { height: 26px; display: none; flex: none; }
@media (max-width: 560px) {
  .topbar { gap: var(--space-2); padding: 0 var(--space-3); }
  .topbar .logo-h { display: none; }
  .topbar .logo-mark { display: block; }
}
html[data-theme='light'] .topbar img { filter: invert(1); }
.topbar .spacer { flex: 1; }

.lang-pill {
  display: inline-flex; align-items: center; gap: var(--space-2);
  min-height: 44px; padding: 0 var(--space-4);
  background: var(--bg-muted);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-pill);
  color: var(--fg-primary);
  font-size: var(--text-sm); font-weight: var(--weight-semibold);
  cursor: pointer;
  transition: border-color var(--duration-fast) var(--ease-out);
}
.lang-pill:hover { border-color: var(--border-strong); }
.lang-pill svg { color: var(--fg-secondary); }

/* Language sheet: bottom sheet on mobile, dropdown on desktop */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 30;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0; pointer-events: none;
  transition: opacity var(--duration-normal) var(--ease-out);
}
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 31;
  background: var(--bg-subtle);
  border: 1px solid var(--border-subtle); border-bottom: none;
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  padding: var(--space-3) var(--space-2) max(var(--space-3), env(safe-area-inset-bottom));
  max-height: 70vh; overflow-y: auto;
  transform: translateY(16px); opacity: 0; pointer-events: none;
  transition: transform var(--duration-normal) var(--ease-out),
              opacity var(--duration-normal) var(--ease-out);
}
.sheet-open .sheet, .sheet-open .sheet-backdrop { opacity: 1; pointer-events: auto; }
.sheet-open .sheet { transform: translateY(0); }
@media (min-width: 700px) {
  .sheet {
    left: auto; right: var(--space-4); bottom: auto; top: 60px;
    width: 320px; border-bottom: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    transform: translateY(-8px);
  }
  .sheet-open .sheet { transform: translateY(0); }
  .sheet-backdrop { background: transparent; }
}
.sheet .sheet-title {
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-xs); font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-wider); text-transform: uppercase;
  color: var(--fg-tertiary);
}
.lang-option {
  display: flex; align-items: center; gap: var(--space-3);
  width: 100%; min-height: 48px; padding: var(--space-2) var(--space-4);
  background: transparent; border: none; border-radius: var(--radius-md);
  cursor: pointer; text-align: left; color: var(--fg-primary);
}
.lang-option:hover { background: var(--bg-muted); }
.lang-option .names { flex: 1; min-width: 0; }
.lang-option .endonym { font-size: var(--text-base); font-weight: var(--weight-medium); }
.lang-option .english { font-size: var(--text-sm); color: var(--fg-tertiary); }
.lang-option .tick { color: var(--fg-accent); visibility: hidden; }
.lang-option.active .tick { visibility: visible; }

/* Captions */
.captions {
  max-width: calc(40ch + 2 * var(--space-5));
  margin: 0 auto;
  padding: var(--space-5) var(--space-5) 45vh;
  font-size: var(--caption-fs, 24px);
  font-weight: var(--weight-medium);
  line-height: var(--leading-normal);
  color: var(--fg-primary);
}
.captions p {
  font-size: inherit; font-weight: inherit; line-height: inherit;
  margin: 0 0 var(--space-4);
  transition: color var(--duration-fast) var(--ease-out);
}
.captions p.interim { color: var(--fg-secondary); }
.captions p.fresh { animation: fadeIn var(--duration-fast) var(--ease-out); }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.captions.switching { opacity: 0; transition: opacity 125ms var(--ease-out); }
.captions.caps { text-transform: uppercase; }

.jump-pill {
  position: fixed; bottom: var(--space-5); left: 50%; transform: translateX(-50%);
  z-index: 25;
}

/* Empty / message states */
.state-msg {
  display: flex; flex-direction: column; align-items: center; gap: var(--space-4);
  padding: 18vh var(--space-5) 0; text-align: center;
}
.state-msg img { height: 48px; }
html[data-theme='light'] .state-msg img { filter: invert(1); }
.state-msg p {
  font-size: var(--text-md); color: var(--fg-secondary);
  max-width: 26ch; margin: 0;
}

/* Connect card (post-service) */
.connect-card {
  max-width: 380px; margin: var(--space-5) auto 0;
  padding: var(--space-5);
  background: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  text-align: center;
}
.connect-card h2 {
  font-size: var(--text-lg); letter-spacing: var(--tracking-normal);
  margin-bottom: var(--space-4);
}
.connect-card form { display: flex; flex-direction: column; gap: var(--space-3); }
.connect-card input {
  padding: var(--space-3);
  font-family: var(--font-sans); font-size: var(--text-base);
  background: var(--bg-muted); color: var(--fg-primary);
  border: 1px solid var(--border-default); border-radius: var(--radius-md);
}
.connect-card input:focus { outline: none; border-color: var(--border-accent); }
.connect-card input::placeholder { color: var(--fg-tertiary); }
.c-thanks { color: var(--fg-secondary); margin: 0; }

/* Settings popover */
.settings-pop {
  position: fixed; right: var(--space-4); top: 60px; z-index: 31;
  width: 260px; padding: var(--space-4);
  background: var(--bg-subtle);
  border: 1px solid var(--border-subtle); border-radius: var(--radius-lg);
  display: none;
}
.settings-pop.open { display: block; }
.settings-row { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); min-height: 44px; }
.settings-row .lbl { font-size: var(--text-sm); color: var(--fg-secondary); }
.seg {
  display: inline-flex; background: var(--bg-muted);
  border: 1px solid var(--border-default); border-radius: var(--radius-pill);
  padding: 2px;
}
.seg button {
  border: none; background: transparent; color: var(--fg-secondary);
  border-radius: var(--radius-pill); cursor: pointer;
  min-width: 40px; min-height: 32px; font-weight: var(--weight-semibold);
}
.seg button.active { background: var(--bg-accent); color: var(--fg-on-dark); }
.seg .sz-s { font-size: 12px; }
.seg .sz-m { font-size: 15px; }
.seg .sz-l { font-size: 18px; }

/* --- Join / landing ----------------------------------------- */
.landing {
  min-height: 100dvh; display: flex; align-items: center; justify-content: center;
  padding: var(--space-5);
}
.join-card {
  width: min(400px, 100%);
  display: flex; flex-direction: column; align-items: center; gap: var(--space-5);
  background: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  padding: var(--space-7) var(--space-6);
  text-align: center;
}
.join-card img { max-height: 72px; max-width: 70%; object-fit: contain; }
.join-card h1 {
  font-size: var(--text-2xl); letter-spacing: var(--tracking-snug);
  margin: 0;
}
.join-card form { display: flex; flex-direction: column; gap: var(--space-4); width: 100%; }
.code-input {
  width: 100%; padding: var(--space-3);
  font-family: var(--font-sans); font-size: var(--text-xl);
  font-weight: var(--weight-semibold); text-align: center;
  letter-spacing: var(--tracking-widest); text-transform: uppercase;
  background: var(--bg-muted); color: var(--fg-primary);
  border: 1px solid var(--border-default); border-radius: var(--radius-md);
  transition: border-color var(--duration-fast) var(--ease-out);
}
.code-input:focus { outline: none; border-color: var(--border-accent); }
.code-input::placeholder { color: var(--fg-tertiary); }

/* --- Presenter / admin -------------------------------------- */
.admin { max-width: 1200px; margin: 0 auto; padding: 0 var(--space-5) var(--space-6); }
.admin-header {
  display: flex; align-items: center; gap: var(--space-4);
  min-height: 64px; padding: var(--space-2) 0;
}
.admin-header .logo-h { height: 26px; display: block; }
.admin-header .title {
  font-size: var(--text-base); font-weight: var(--weight-semibold);
  border-left: 1px solid var(--border-default);
  padding-left: var(--space-4);
  line-height: 1.6;
}
.admin-header .spacer { flex: 1; }

.admin-main { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: var(--space-5); }
@media (max-width: 980px) { .admin-main { grid-template-columns: 1fr; } }

.panel-card {
  background: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  margin-bottom: var(--space-5);
}
.panel-card .card-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.field-select {
  width: 100%; padding: var(--space-3);
  font-family: var(--font-sans); font-size: var(--text-base);
  background: var(--bg-muted); color: var(--fg-primary);
  border: 1px solid var(--border-default); border-radius: var(--radius-md);
}
.field-select:focus { outline: none; border-color: var(--border-accent); }

/* Level meter: thin vertical segments, the operator's #1 signal */
.meter { display: flex; gap: 3px; height: 36px; margin-top: var(--space-4); }
.meter i {
  flex: 1; border-radius: 2px; background: var(--bg-muted);
  transition: background 80ms linear;
}
.meter i.on { background: var(--fg-accent); }

.transcript-body {
  height: 340px; overflow-y: auto;
  font-size: var(--text-md); font-weight: var(--weight-medium);
  line-height: var(--leading-normal); color: var(--fg-primary);
}
.transcript-body p { font-size: inherit; line-height: inherit; margin: 0 0 var(--space-3); }
.transcript-body .interim { color: var(--fg-secondary); }

/* Language toggle rows */
.lang-row {
  display: flex; align-items: center; gap: var(--space-3);
  min-height: 52px; border-bottom: 1px solid var(--border-subtle);
}
.lang-row:last-child { border-bottom: none; }
.lang-row .names { flex: 1; min-width: 0; line-height: var(--leading-snug); }
.lang-row .endonym { font-size: var(--text-base); font-weight: var(--weight-medium); }
.lang-row .english { font-size: var(--text-xs); color: var(--fg-tertiary); }
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 8px; border-radius: var(--radius-sm);
  background: var(--bg-muted); color: var(--fg-secondary);
  font-size: var(--text-xs);
}
.chip[hidden] { display: none; }

.switch { position: relative; width: 36px; height: 20px; flex: none; cursor: pointer; }
.switch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.switch .track {
  position: absolute; inset: 0; border-radius: var(--radius-pill);
  background: var(--border-default);
  transition: background var(--duration-fast) var(--ease-out);
}
.switch .track::after {
  content: ''; position: absolute; top: 2px; left: 2px;
  width: 16px; height: 16px; border-radius: var(--radius-pill);
  background: #fff;
  transition: transform var(--duration-fast) var(--ease-out);
}
.switch input:checked + .track { background: var(--bg-accent); }
.switch input:checked + .track::after { transform: translateX(16px); }

/* QR / share card */
.qr-tile {
  background: #ffffff; border-radius: var(--radius-lg);
  padding: var(--space-3); display: inline-block; line-height: 0;
}
.qr-tile img { width: 200px; max-width: 100%; }
.share-card { text-align: center; }
.room-code-lg {
  font-size: var(--text-2xl); font-weight: var(--weight-bold);
  letter-spacing: var(--tracking-wider);
  margin: var(--space-3) 0 0;
}
.share-url { font-size: var(--text-xs); color: var(--fg-tertiary); word-break: break-all; }
.share-actions { display: flex; justify-content: center; gap: var(--space-4); margin-top: var(--space-2); }

.stats-strip {
  display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-5);
  font-size: var(--text-xs); color: var(--fg-tertiary);
}

/* Setup (pre-session) */
.setup-wrap { min-height: calc(100dvh - 64px); display: flex; align-items: center; justify-content: center; }

.error-log { font-size: var(--text-xs); color: var(--fg-secondary); min-height: 1.2em; }

/* --- Projection display (the one intentionally light screen) -- */
.display-page {
  min-height: 100dvh; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: var(--space-5);
  background: #ffffff; color: #0f0f0f; text-align: center;
  padding: var(--space-6);
}
.display-page h2 { color: #0f0f0f; margin: 0; }
.display-page img { width: min(360px, 70vw); }
.display-page .code {
  font-size: var(--text-3xl); font-weight: var(--weight-bold);
  letter-spacing: var(--tracking-wider); color: #0f0f0f;
}
