/* viewer-v2.css — design-v2 Viewer port (public /fire page).
 *
 * Mirrors docs/designs/design-v2/components/viewer.jsx: DanmuHero lockup on
 * top, scrollable body with the seven fields (nickname, color, font, size +
 * opacity 2-col, speed, effects, layout), pill send bar at the bottom with
 * an emoji popover. Uses shared tokens — no hardcoded hex.
 */

/* ───────── Page shell (light theme — matches prototype TWEAK_DEFAULTS) ─────
 * Prototype renders Viewer with theme="light" by default. We redefine the
 * shared tokens inside the viewer scope so every downstream rule (card,
 * inputs, sendbar, preview) picks up the hudTokens.light* palette without
 * per-rule overrides. Cyan accent stays the same in both themes.
 *
 * Viewport-filling flex column: body scrolls inside, sendbar pins bottom. */
html:has(body.viewer-body-v2) {
  height: 100%;
  color-scheme: light;
}

body.viewer-body-v2 {
  /* hudTokens light palette (viewer.jsx:32–37) — default */
  --color-bg-deep: #f8fafc;              /* lightBg0 — page */
  --color-bg-base: #ffffff;              /* lightBg1 — card */
  --color-bg-elevated: #f1f5f9;          /* lightBg2 — raised (inputs, pill) */
  --color-text-primary: #0f172a;         /* lightText */
  --color-text-secondary: #475569;       /* lightTextDim */
  --color-text-bright: #0f172a;
  --hud-line: rgba(15, 23, 42, 0.12);    /* lightLine */
  --hud-line-strong: rgba(15, 23, 42, 0.22);
  background: var(--color-bg-deep);
  color: var(--color-text-primary);
  color-scheme: light;
  font-family: var(--font-ui);
  margin: 0;
  /* Viewport-bound flex column — prototype viewer.jsx:73–78 unifies desktop
   * + mobile: `overflow:hidden, display:flex, flexDirection:column` with the
   * scrollable body in the middle and the sendbar pinned to the bottom. */
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Dark theme — prototype viewer.jsx:32–37 (isDark branch).
 * Switches the same scoped tokens to the hudTokens.bg0/bg1/bg2 dark palette. */
body.viewer-body-v2.is-dark {
  --color-bg-deep: #020617;              /* slate-950 — page */
  --color-bg-base: #0f172a;              /* slate-900 — panel */
  --color-bg-elevated: #1e293b;          /* slate-800 — raised */
  --color-text-primary: #f1f5f9;         /* slate-100 */
  --color-text-secondary: #94a3b8;       /* slate-400 */
  --color-text-bright: #e2e8f0;
  --hud-line: rgba(148, 163, 184, 0.18);
  --hud-line-strong: rgba(148, 163, 184, 0.32);
  color-scheme: dark;
}

/* Full-width per prototype viewer.jsx — `width: inBrowser ? '100%' : ...`.
 * No card, no max-width, no side padding — content's own hero/body padding
 * provides the 28–32px breathing room. Viewport-bound flex column so the
 * sendbar pins to the bottom on every viewport (desktop + mobile unified). */
.viewer-page-shell {
  width: 100%;
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.viewer-main-card {
  flex: 1 1 0;
  min-height: 0;
  background: var(--color-bg-base);
  border: none;
  border-radius: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: none;
}

/* Preset color swatch buttons — 6 circles + 1 custom (matches viewer.jsx:146) */
.viewer-swatch-preset {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  padding: 0;
  border: 1px solid var(--hud-line);
  background-clip: padding-box;
  transition: transform 0.12s, border-color 0.12s;
}

.viewer-swatch-preset:hover {
  transform: scale(1.08);
}

.viewer-swatch-preset.is-active {
  border: 2px solid var(--color-primary);
  outline: 1px solid var(--color-primary);
  outline-offset: 2px;
}

/* FIRE button arrow — matches prototype `FIRE ▶` */
.viewer-fire-arrow {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1;
  letter-spacing: 0;
}

.viewer-shell {
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0;
}

/* Hero · 2-col layout matching the 2026-04-25 prototype
 * (docs/designs/design-v2/components/viewer.jsx:88–113):
 *   left  — DanmuHero (lockup left-aligned, theme-aware drop-shadow)
 *   right — ConnChip stack (伺服器 / Overlay) + (desktop) Lang Seg + Theme Seg
 *
 * padding: '28px 32px 22px' desktop / '18px 16px 16px' mobile
 * gap: 24 desktop / 10 mobile
 * Mobile keeps both columns side-by-side (NOT stacked) — chip stack uses
 * mini variant. */
.viewer-hero {
  padding: 28px 32px 22px;
  border-bottom: 1px solid var(--hud-line);
  background: transparent;
  display: flex;
  align-items: center;
  gap: 24px;
  /* DanmuMarquee runs absolutely-positioned behind the hero content; clip
   * overflow so chips that haven't scrolled in yet stay invisible. */
  position: relative;
  overflow: hidden;
}

.viewer-hero-lockup {
  /* Logo is flexShrink:0 so it doesn't compete with the chip column for
   * space — a center spacer (.viewer-hero-spacer) absorbs the slack. */
  flex: 0 0 auto;
  min-width: 0;
  text-align: left;
  position: relative;
  z-index: 2;
}

.viewer-hero-utility {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  position: relative;
  z-index: 2;
}

/* Marquee — 12 fake danmu chips scroll right→left across the hero. Pure
 * decoration; mask gradient on the left so the logo stays legible. */
.viewer-hero-marquee {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
  -webkit-mask-image: linear-gradient(90deg, transparent 0, transparent 22%, #000 38%, #000 88%, transparent 100%);
          mask-image: linear-gradient(90deg, transparent 0, transparent 22%, #000 38%, #000 88%, transparent 100%);
}

/* Light theme — design v4 brief 0518-v3 #3 fix (2026-05-18).
   Marquee chips use inline pale colors (sky-300, amber-300, lime-400 etc.)
   tuned for dark backdrop. On white they look washed out. Apply a global
   filter that effectively shifts pale -300/-400 shades into -600/-700
   territory: lower brightness, bump contrast + saturate. Cheaper than
   overriding 12 inline-style declarations with !important. */
body.viewer-body-v2:not(.is-dark) .viewer-hero-marquee {
  filter: brightness(0.7) saturate(1.15) contrast(1.15);
}

.viewer-mq-item {
  position: absolute;
  left: 100%;
  font-family: var(--font-sans, sans-serif);
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.02em;
  white-space: nowrap;
  animation: viewer-mq-scroll 16s linear infinite;
  text-shadow: 0 0 8px currentColor;
  /* per-chip y/opacity/duration via :nth-child overrides below */
}

@keyframes viewer-mq-scroll {
  0%   { transform: translateX(0); }
  100% { transform: translateX(-1100px); }
}

@media (max-width: 599px) {
  .viewer-mq-item {
    font-size: 12px;
    animation-name: viewer-mq-scroll-mobile;
  }
  @keyframes viewer-mq-scroll-mobile {
    0%   { transform: translateX(0); }
    100% { transform: translateX(-500px); }
  }
}

/* Per-chip stagger: y / delay / duration / opacity. Matches prototype
 * viewer.jsx:526 items array. Mobile clamps y to ≤38 so chips don't fall
 * outside the shorter mobile hero. */
.viewer-mq-i0  { top: 16px; opacity: 0.32; animation-delay: 0s;     animation-duration: 14s; }
.viewer-mq-i1  { top: 44px; opacity: 0.28; animation-delay: 1.8s;   animation-duration: 17s; }
.viewer-mq-i2  { top: 6px;  opacity: 0.36; animation-delay: 3.4s;   animation-duration: 16s; }
.viewer-mq-i3  { top: 56px; opacity: 0.32; animation-delay: 5.0s;   animation-duration: 13s; }
.viewer-mq-i4  { top: 28px; opacity: 0.26; animation-delay: 6.4s;   animation-duration: 19s; }
.viewer-mq-i5  { top: 4px;  opacity: 0.30; animation-delay: 7.8s;   animation-duration: 15s; }
.viewer-mq-i6  { top: 50px; opacity: 0.26; animation-delay: 9.0s;   animation-duration: 16s; }
.viewer-mq-i7  { top: 22px; opacity: 0.36; animation-delay: 10.4s;  animation-duration: 13s; }
.viewer-mq-i8  { top: 38px; opacity: 0.28; animation-delay: 11.6s;  animation-duration: 17s; }
.viewer-mq-i9  { top: 12px; opacity: 0.32; animation-delay: 13.0s;  animation-duration: 14s; }
.viewer-mq-i10 { top: 60px; opacity: 0.30; animation-delay: 14.2s;  animation-duration: 18s; }
.viewer-mq-i11 { top: 32px; opacity: 0.26; animation-delay: 15.6s;  animation-duration: 16s; }

@media (max-width: 599px) {
  .viewer-mq-i3  { top: 38px; }
  .viewer-mq-i6  { top: 38px; }
  .viewer-mq-i10 { top: 38px; }
}

@media (prefers-reduced-motion: reduce) {
  .viewer-mq-item { animation: none; opacity: 0; }
}

/* Center spacer pushes chip column flush right while marquee owns the
 * middle area visually. */
.viewer-hero-spacer {
  flex: 1 1 0;
  min-width: 0;
}

@media (max-width: 599px) {
  .viewer-hero {
    padding: 18px 16px 16px;
    gap: 10px;
  }
}

/* Prototype tokens.jsx HERO_SIZE.hero = clamp(3.2rem, 8vw, 6rem).
 * Mobile in new prototype uses 'medium' = '2rem' (smaller than the prior
 * 'large' clamp). Light-theme drop-shadow (matches DanmuHero light branch). */
.viewer-hero-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(3.2rem, 8vw, 6rem);
  font-weight: 400;
  color: #7dd3fc;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  line-height: 1;
  filter:
    drop-shadow(0 10px 15px rgba(0, 0, 0, 0.45))
    drop-shadow(0 4px 6px rgba(0, 0, 0, 0.3));
}

/* Light theme — design v4 brief 0518-v3 #3 fix (2026-05-18).
   Dark theme's heavy black drop-shadow makes the sky-300 cyan text look
   muddy on white. Swap to sky-600 + a subtle shadow that lifts the text
   without competing with the page chrome. WCAG: sky-600 on slate-50 = 4.6:1 ✓ AA. */
body.viewer-body-v2:not(.is-dark) .viewer-hero-title {
  color: #0284c7;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.08));
}

@media (max-width: 599px) {
  .viewer-hero-title {
    font-size: 2rem;
  }
}

/* Prototype subtitle override (viewer.jsx:101 subStyle):
 * desktop: margin '10px 0 0' / inherits HERO_SLATE_300 / no maxWidth lock
 * mobile: margin '6px 0 0' / fontSize 12 */
.viewer-hero-subtitle {
  margin: 10px 0 0;
  color: var(--color-text-secondary);
  font-size: clamp(1rem, 2vw, 1.25rem);
  line-height: 1.6;
  font-weight: 400;
}

@media (max-width: 599px) {
  .viewer-hero-subtitle {
    margin: 6px 0 0;
    font-size: 12px;
  }
}

/* ConnChip — 伺服器 / Overlay status pill matching the 2026-04-25
 * prototype viewer.jsx ConnChip (lines 376–399 of new bundle):
 *   padding: '4px 10px' / mini '2px 7px'
 *   borderRadius: 999
 *   background: online ? cyanSoft : transparent
 *   border: 1px online cyanLine / offline line
 *   font-mono 10px / mini 9px, letter-spacing 1px / mini 0.5px
 *   gap: 6 / mini 4
 *
 * Online state is signalled by `.connection-dot--connected` /
 * `.connection-dot--live` on the dot child; the parent gets is-online
 * via JS (or fall back to scoped child selector). */
.viewer-conn-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--hud-line);
  /* Solid panel bg so the DanmuMarquee scrolling behind the hero doesn't
   * bleed through. Prototype viewer.jsx:427 layers cyanSoft on top of bg
   * for the online state — we approximate with a single panel-coloured
   * solid here and let .is-online / :has() override with the cyan tint. */
  background: var(--color-bg-base);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 1px;
  color: var(--color-text-primary);
  white-space: nowrap;
}

/* Online — stacked gradient: cyanSoft tint on top of the solid panel bg. */
.viewer-conn-chip:has(.connection-dot--connected),
.viewer-conn-chip:has(.connection-dot--live) {
  background:
    linear-gradient(var(--hud-cyan-soft), var(--hud-cyan-soft)),
    var(--color-bg-base);
  border-color: var(--hud-cyan-line, rgba(56, 189, 248, 0.45));
}

.viewer-conn-chip-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #94a3b8;
  flex-shrink: 0;
}

.viewer-conn-chip-dot.connection-dot--connected,
.viewer-conn-chip-dot.connection-dot--live {
  background: var(--color-primary);
  box-shadow: 0 0 6px var(--color-primary);
  animation: viewer-conn-pulse 2s ease-in-out infinite;
}

.viewer-conn-chip-dot.connection-dot--connecting {
  background: var(--color-warning);
  box-shadow: 0 0 4px var(--color-warning);
}

.viewer-conn-chip-dot.connection-dot--disconnected,
.viewer-conn-chip-dot.connection-dot--failed {
  background: #f87171;
}

.viewer-conn-chip-label {
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.viewer-conn-chip-value {
  font-weight: 500;
}

@media (max-width: 599px) {
  .viewer-conn-chip {
    /* prototype mini variant: 2px 7px / 9px / 0.5px / gap 4 */
    font-size: 9px;
    padding: 2px 7px;
    letter-spacing: 0.5px;
    gap: 4px;
  }
  .viewer-conn-chip-label { display: none; }
}

@keyframes viewer-conn-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: 0.65; transform: scale(0.88); }
}

/* Lang select + theme toggle row — prototype viewer.jsx:184-185
 * (LangSelect line 519, ThemeToggle line 553). Visible on every viewport;
 * mobile uses the prototype `mini` variant (22px instead of 26px). */
.viewer-hero-seg-row {
  display: flex;
  align-items: center;
  gap: 6px; /* prototype gap: 6 */
  margin-top: 4px;
}

/* LangSelect — prototype viewer.jsx:519. Native <select> overlay so
 * the user gets all 4 languages (zh / en / ja / ko); visible label is
 * the current selection in monospace + dropdown arrow. */
.viewer-lang-select {
  position: relative;
  display: inline-flex;
  align-items: center;
  height: 26px;
  padding: 0 18px 0 10px;
  background: var(--color-bg-elevated);
  border: 1px solid var(--hud-line);
  border-radius: 6px;
}
.viewer-lang-current {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.3px;
  color: var(--color-text-primary);
  white-space: nowrap;
}
.viewer-lang-arrow {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  font-family: var(--font-mono);
  font-size: 8px;
  color: var(--color-text-secondary);
  pointer-events: none;
}
.viewer-lang-native {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  border: none;
  background: transparent;
}

/* ThemeToggle — prototype viewer.jsx:553. Single icon button, ◐ when
 * dark / ◑ when light, click to flip. */
.viewer-theme-toggle {
  width: 26px;
  height: 26px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border-radius: 6px;
  border: 1px solid var(--hud-line);
  background: var(--hud-cyan-soft);
  color: var(--color-primary);
  font-family: var(--font-mono);
  font-size: 12px;
  cursor: pointer;
}
.viewer-theme-toggle:hover {
  background: rgba(56, 189, 248, 0.16);
}

/* Mobile mini variant — prototype LangSelect mini: padding 0 16px 0 8px,
 * height 22, font-size 10. ThemeToggle mini: 22×22, font-size 11. */
@media (max-width: 599px) {
  .viewer-lang-select {
    height: 22px;
    padding: 0 16px 0 8px;
  }
  .viewer-lang-current { font-size: 10px; }
  .viewer-lang-arrow {
    right: 5px;
  }
  .viewer-theme-toggle {
    width: 22px;
    height: 22px;
    font-size: 11px;
  }
}

/* Viewer Fire/Poll tabs + pane switcher. */
.viewer-tabbar {
  display: flex;
  align-items: flex-end;
  gap: 0;
  padding: 0 12px;
  border-bottom: 1px solid var(--hud-line);
}

.viewer-tab {
  appearance: none;
  border: none;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--color-text-primary);
  padding: 10px 18px;
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  cursor: pointer;
  margin-bottom: -1px;
  transition: border-color 0.15s, color 0.15s;
}

.viewer-tab-label {
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.2px;
}

.viewer-tab-sub {
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--color-text-secondary);
}

.viewer-tab:hover {
  border-bottom-color: var(--hud-line-strong);
  color: var(--color-text-primary);
}

.viewer-tab.is-active,
.viewer-tab[aria-selected="true"] {
  border-bottom-color: #38bdf8;
  color: #38bdf8;
}

.viewer-tab.is-active .viewer-tab-label,
.viewer-tab[aria-selected="true"] .viewer-tab-label {
  font-weight: 700;
}

.viewer-tab.is-active .viewer-tab-sub,
.viewer-tab[aria-selected="true"] .viewer-tab-sub {
  color: #38bdf8;
}

.viewer-pane {
  flex: 1 1 0;
  min-height: 0;
  display: none;
}

.viewer-pane.is-active {
  display: flex;
  flex-direction: column;
}

.viewer-pane[hidden] {
  display: none !important;
}

/* Poll pane */
.viewer-poll-card {
  margin: 20px 24px 24px;
  padding: 16px;
  border: 1px solid rgba(125, 211, 252, 0.25);
  border-radius: 10px;
  background: rgba(125, 211, 252, 0.06);
  box-shadow: 0 8px 24px rgba(2, 6, 23, 0.08);
}

.viewer-poll-kicker {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 1.4px;
  color: var(--color-text-secondary);
  text-transform: uppercase;
  margin-bottom: 8px;
}

.viewer-poll-question {
  margin: 0;
  font-size: 24px;
  font-weight: 700;
  line-height: 1.35;
  color: var(--color-text-primary);
}

.viewer-poll-meta {
  margin: 8px 0 0;
  color: var(--color-text-secondary);
  font-size: 13px;
}

.viewer-poll-options {
  margin-top: 14px;
  display: grid;
  gap: 10px;
}

.viewer-poll-option {
  width: 100%;
  border: 1px solid var(--hud-line);
  border-radius: 8px;
  background: var(--color-bg-elevated);
  color: var(--color-text-primary);
  padding: 10px 12px;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s;
}

.viewer-poll-option:hover {
  border-color: rgba(56, 189, 248, 0.68);
  background: rgba(56, 189, 248, 0.08);
  transform: translateY(-1px);
}

.viewer-poll-option-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.viewer-poll-option-key {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 1.2px;
  color: #38bdf8;
  min-width: 22px;
}

.viewer-poll-option-text {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  font-weight: 600;
}

@media (max-width: 599px) {
  .viewer-tabbar {
    padding: 0 10px;
  }

  .viewer-tab {
    padding: 9px 12px;
    gap: 6px;
  }

  .viewer-tab-label {
    font-size: 13px;
  }

  .viewer-tab-sub {
    font-size: 8px;
  }

  .viewer-poll-card {
    margin: 16px;
    padding: 14px;
  }

  .viewer-poll-question {
    font-size: 20px;
  }
}

/* Body — prototype viewer.jsx:129 — `flex:1, overflow:auto, padding: pad`.
 * Inner scroll on every viewport so the sendbar pins to the bottom. */
.viewer-body {
  flex: 1 1 0;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 24px 24px 30px; /* prototype viewer.jsx:111 desktop */
}

@media (max-width: 599px) {
  .viewer-body {
    padding: 16px 16px 22px; /* prototype mobile: pad=16, pad+6=22 */
  }
}

/* Live preview strip — 模擬「投到螢幕上」.
 * Per 2026-04-25 prototype viewer.jsx:118–143 (light branch):
 * gradient 135deg #0f172a → #1e293b, cyan glow border, soft inset shadow
 * with scanline texture pseudo-element. Stays dark even in light theme so
 * danmu colors (white/cyan/amber/etc.) remain legible. */
.viewer-preview {
  position: relative;
  overflow: hidden;
  min-height: 72px;
  padding: 18px 14px;
  margin-bottom: 1rem;
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
  border: 1px solid rgba(125, 211, 252, 0.25);
  border-radius: 8px;
  color: #f1f5f9;
  box-shadow:
    0 4px 14px rgba(15, 23, 42, 0.18),
    inset 0 0 40px rgba(125, 211, 252, 0.08);
}

/* Subtle scanline texture overlay — sells the "screen" feel. */
.viewer-preview::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    0deg,
    transparent 0,
    transparent 3px,
    rgba(255, 255, 255, 0.015) 3px,
    rgba(255, 255, 255, 0.015) 4px
  );
}

.viewer-preview-kicker {
  position: absolute;
  top: 6px;
  left: 10px;
  right: 10px;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: rgba(148, 163, 184, 0.7);
  letter-spacing: 1.4px;
}

/* Speed badge inside the kicker — sits flush right, faint cyan so it
   reads as "current speed" without competing with the kicker label. */
.viewer-preview-speed {
  margin-left: auto;
  color: rgba(125, 211, 252, 0.5);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.5px;
}

/* 2026-05-16 marquee preview (design v3-r8): preview text actually
   scrolls right→left so viewers see the speed change live. Duration
   = max(2, 8 / speed)s, set as a CSS variable by main.js whenever the
   speed slider moves. The row has a fixed height (font-size + line)
   so the scrolling text never collapses the panel. */
.viewer-preview-row {
  margin-top: 10px;
  position: relative;
  overflow: hidden;
  height: calc(var(--viewer-preview-font-size, 32px) * 1.4);
  /* Enable container query units (cqw) for the keyframe below — the
     track starts at 100cqw (container's right edge) regardless of how
     short the inner content is. Without this, translateX(100%) only
     offsets by the track's own width, so short messages appear to
     start halfway in. */
  container-type: inline-size;
}

.viewer-preview-track {
  position: absolute;
  top: 0;
  left: 0;
  display: inline-flex;
  align-items: baseline;
  gap: 10px;
  font-weight: 600;
  white-space: nowrap;
  animation: dm-preview-scroll var(--viewer-preview-duration, 8s) linear infinite;
}

@keyframes dm-preview-scroll {
  /* 0% — track sits one container-width to the right of its origin, so
     the left edge is exactly at the container's right edge (fully off-
     screen on the right). */
  0%   { transform: translateX(100cqw); }
  /* 100% — track moves -100% of its own width, so the right edge ends
     at the container's left edge (fully off-screen on the left). */
  100% { transform: translateX(-100%); }
}

@media (prefers-reduced-motion: reduce) {
  /* Respect users who prefer no motion — keep the panel static. */
  .viewer-preview-track { animation: none; transform: none; }
}

.viewer-preview-nick {
  font-family: var(--font-mono);
  font-weight: 500;
  opacity: 0.75;
  letter-spacing: 0.5px;
}

/* Default preview shadow — prototype viewer.jsx:125 fallback when glow off:
 *   '0 2px 4px rgba(0,0,0,0.55)'. Glow-effect handler in main.js may add
 *   a coloured halo on top via inline style.
 * 2026-05-17: `display: inline-block` so transform-based effects
 * (spin / bounce / zoom / wave / shake) actually animate the span. */
.viewer-preview-text {
  display: inline-block;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.55);
  transition: font-size 0.2s, opacity 0.2s;
}

/* 2026-05-17 preview-side effect keyframes (vp- prefix to avoid
   colliding with overlay's de- set in shared/danmu-effects.js).
   `selectedEffects` is multi-select, so updatePreview() in main.js
   joins matching animations into a comma-separated list and applies
   to .viewer-preview-text. The marquee transform on the parent
   .viewer-preview-track is independent and doesn't conflict. */
/* 2026-05-17 design v3-r10: effect keyframes read CSS custom
   properties on .viewer-preview-text so the parameter sliders on
   each cyan card retune the animation live. Defaults match the
   spec values in main.js EFFECT_PARAM_SPEC. */
@keyframes vp-blink   { 0%, 100% { opacity: 1; } 50% { opacity: var(--vp-blink-min, 0); } }
@keyframes vp-shake   {
  0%, 100% { transform: translateX(0); }
  25%      { transform: translateX(calc(var(--vp-shake-strength, 4px) * -1)); }
  75%      { transform: translateX(var(--vp-shake-strength, 4px)); }
}
@keyframes vp-bounce  { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(var(--vp-bounce-height, -16px)); } }
@keyframes vp-spin    { to { transform: rotate(360deg); } }
@keyframes vp-rainbow { to { filter: hue-rotate(360deg) saturate(var(--vp-rainbow-sat, 0.9)); } }
@keyframes vp-wave    {
  0%, 100% { transform: translateY(0); }
  25%      { transform: translateY(calc(var(--vp-wave-amplitude, 8px) * -1)); }
  75%      { transform: translateY(var(--vp-wave-amplitude, 8px)); }
}
@keyframes vp-zoom    { 0%, 100% { transform: scale(1); } 50% { transform: scale(var(--vp-zoom-max, 1.5)); } }

@media (prefers-reduced-motion: reduce) {
  /* All decorative preview effects respect the system motion preference. */
  .viewer-preview-text { animation: none !important; }
}

/* 2026-05-17 design v3-r10: per-effect parameter cards. Sits under the
   8 effect pill buttons; each selected effect renders one cyan-tinted
   card with a 2-col slider grid (1-col when only one param). */
.viewer-effect-params {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}
.viewer-effect-params[hidden] { display: none; }

.viewer-effect-params-card {
  padding: 10px 14px;
  border-radius: 6px;
  border: 1px solid rgba(56, 189, 248, 0.20); /* accent + 0x33 alpha */
  background: rgba(56, 189, 248, 0.05);       /* hudTokens.cyanSoft */
}

.viewer-effect-params-card__title {
  font-size: 11px;
  font-weight: 600;
  color: var(--viewer-accent, #38bdf8);
  margin-bottom: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 1px;
}

.viewer-effect-params-card__grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.viewer-effect-params-card__grid.is-single {
  grid-template-columns: 1fr;
}

.viewer-effect-params-card__row-head {
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
}

.viewer-effect-params-card__label {
  font-size: 10px;
  color: var(--viewer-text-dim, rgba(148, 163, 184, 0.85));
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0.5px;
}

.viewer-effect-params-card__value {
  font-size: 10px;
  color: var(--viewer-accent, #38bdf8);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.viewer-effect-params-card__slider {
  width: 100%;
  accent-color: var(--viewer-accent, #38bdf8);
}

/* Field — 9px mono tracked uppercase label above control. */
.viewer-field {
  margin-bottom: 0.875rem;
}

.viewer-field.is-nomb {
  margin-bottom: 0;
}

.viewer-field-label {
  display: block;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 1.4px;
  color: var(--color-text-secondary);
  margin-bottom: 6px;
  text-transform: uppercase;
}

.viewer-field-label__value {
  color: var(--color-text-bright);
}

/* Identity chip — prototype #18 (2026-04-27).
 * Display: `[@nick · fp:xxxxxxxx]`. Click → inline edit input replaces nick.
 * Esc cancels, Enter / blur saves. 0.4s confirm flash on save. */
.viewer-identity-chip {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 6px;
  background: var(--color-bg-elevated);
  border: 1px solid var(--hud-line);
  cursor: text;
  transition: border-color 0.15s, background 0.15s;
  min-height: 40px;
  box-sizing: border-box;
}

.viewer-identity-chip[data-mode="edit"] {
  border-color: var(--color-primary);
}

.viewer-identity-chip:hover[data-mode="display"] {
  border-color: var(--hud-line-strong);
}

.viewer-identity-chip-nick {
  font-family: var(--font-sans, sans-serif);
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text-primary);
  letter-spacing: 0.01em;
}

.viewer-identity-chip-fp {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.05em;
  color: var(--color-text-secondary);
  transition: opacity 0.15s;
  margin-left: auto;
}

.viewer-identity-chip-input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  outline: none;
  color: var(--color-text-primary);
  font-size: 14px;
  font-weight: 600;
  font-family: var(--font-sans, sans-serif);
  padding: 0;
}

/* Save confirm flash — 0.4s pale-cyan fade per Design spec. */
.viewer-identity-chip.is-confirm {
  background: var(--hud-cyan-soft);
  border-color: var(--color-primary);
  animation: viewer-identity-confirm 0.4s ease-out;
}

@keyframes viewer-identity-confirm {
  0%   { background: var(--hud-cyan-soft); border-color: var(--color-primary); }
  100% { background: var(--color-bg-elevated); border-color: var(--hud-line); }
}

@media (prefers-reduced-motion: reduce) {
  .viewer-identity-chip.is-confirm { animation: none; }
}

/* Text input — raised background + hairline border. */
.viewer-input {
  width: 100%;
  background: var(--color-bg-elevated);
  border: 1px solid var(--hud-line);
  color: var(--color-text-primary);
  padding: 0.7rem 0.85rem;
  border-radius: 6px;
  outline: none;
  font-size: 15px;
  box-sizing: border-box;
}

.viewer-input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px var(--glow-primary-ring);
}

/* Color swatches — 6 preset + 1 custom with dashed ring. */
.viewer-color-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}

.viewer-swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  padding: 0;
  border: 1px solid var(--hud-line);
  background-clip: padding-box;
}

.viewer-swatch.is-active {
  border: 2px solid var(--color-primary);
  outline: 1px solid var(--color-primary);
  outline-offset: 2px;
}

.viewer-swatch--custom {
  position: relative;
  border-style: dashed;
  color: var(--color-text-secondary);
  background: transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 14px;
}

.viewer-swatch--custom input[type="color"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.viewer-color-hex {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.5px;
  color: var(--color-text-secondary);
  text-transform: uppercase;
}

/* Select — chevron rendered via ::after absolute overlay. */
.viewer-select-wrap {
  position: relative;
}

.viewer-select {
  width: 100%;
  padding: 11px 36px 11px 14px;
  border-radius: 6px;
  background: var(--color-bg-elevated);
  border: 1px solid var(--hud-line);
  color: var(--color-text-primary);
  font-size: 15px;
  outline: none;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
}

.viewer-select-wrap::after {
  content: "▾";
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  color: var(--color-text-secondary);
  font-family: var(--font-mono);
  font-size: 10px;
}

/* Range slider — Tailwind preflight sets `input { background-color: #0000 }`
 * which would erase the track if applied on the input itself. WebKit also
 * renders the track via the ::-webkit-slider-runnable-track pseudo-element,
 * not the input bg. So:
 *   - input itself: just sizing + appearance reset
 *   - WebKit: track gets the gradient via ::-webkit-slider-runnable-track
 *   - Firefox: track + progress via ::-moz-range-track + ::-moz-range-progress
 * Progress fill is driven by an inline --progress CSS var set by main.js. */
.viewer-range {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 16px;                /* tall enough to fit the thumb hit area */
  background: transparent;     /* defeat Tailwind's input bg-color reset */
  outline: none;
  cursor: pointer;
  margin: 0;
  padding: 0;
}

/* WebKit / Blink (Safari, Chrome, Edge) */
.viewer-range::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 999px;
  background:
    linear-gradient(var(--color-primary), var(--color-primary)) no-repeat,
    var(--hud-line);
  background-size: var(--progress, 50%) 100%;
  transition: background-size 0.12s;
}

.viewer-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--color-primary);
  border: 2px solid var(--color-bg-base);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  cursor: pointer;
  margin-top: -5px;            /* center 16px thumb on 6px track */
  transition: transform 0.12s;
}

/* Firefox */
.viewer-range::-moz-range-track {
  height: 6px;
  border-radius: 999px;
  background: var(--hud-line);
}

.viewer-range::-moz-range-progress {
  height: 6px;
  border-radius: 999px 0 0 999px;
  background: var(--color-primary);
}

.viewer-range::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--color-primary);
  border: 2px solid var(--color-bg-base);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  cursor: pointer;
}

.viewer-range:hover::-webkit-slider-thumb,
.viewer-range:focus::-webkit-slider-thumb {
  transform: scale(1.15);
}

/* 2026-05-16 RWD per design v3-r8:
   Desktop: size / opacity / speed in a single 3-col row.
   Mobile (≤599px): drops to 2-col so size + opacity stay together
   and speed wraps below as a full-width row (grid auto-wrap). */
.viewer-grid-fields {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 0.875rem;
}

@media (max-width: 599px) {
  .viewer-grid-fields {
    grid-template-columns: 1fr 1fr;
  }
  .viewer-grid-fields > #speedControl {
    /* Span both columns so the speed slider keeps its full handle width. */
    grid-column: 1 / -1;
  }
}

/* 2026-05-16 RWD per design v3-r8: cap fire-pane form width on desktop
   so the slider/composer don't stretch the full pane. Mobile keeps the
   pane padding for full width (no max-width). The wrapping sendbar
   sits outside .viewer-body and stays full-width. */
.viewer-fire-content {
  max-width: 560px;
  margin: 0 auto;
}

@media (max-width: 599px) {
  .viewer-fire-content {
    max-width: 100%;
    margin: 0;
  }
}

/* Effects/Layout chip grid. */
.viewer-chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
}

.viewer-chip {
  min-width: 64px;
  min-height: 44px;            /* WCAG 44×44 touch target */
  padding: 0.375rem 0.875rem;
  border-radius: var(--radius-pill);
  border: 1px solid var(--hud-line);
  background: transparent;
  color: var(--color-text-primary);
  cursor: pointer;
  font-size: 12px;
  font-weight: 400;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
}

.viewer-chip:hover {
  border-color: var(--hud-line-strong);
}

.viewer-chip.is-active,
.viewer-chip[aria-pressed="true"] {
  border-color: var(--color-primary);
  background: var(--hud-cyan-soft);
  color: var(--color-primary);
  font-weight: 600;
}

/* Layout 5-column grid (title + monospace sub-label). */
.viewer-layout-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.375rem;
}

.viewer-layout-btn {
  min-height: 56px;
  padding: 0.5rem 0.25rem;
  border-radius: 6px;
  cursor: pointer;
  border: 1px solid var(--hud-line);
  background: transparent;
  color: var(--color-text-primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.1875rem;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.viewer-layout-btn:hover {
  border-color: var(--hud-line-strong);
}

.viewer-layout-btn.is-active,
.viewer-layout-btn[aria-pressed="true"] {
  border-color: var(--color-primary);
  background: var(--hud-cyan-soft);
  color: var(--color-primary);
}

.viewer-layout-btn__zh {
  font-size: 12px;
  font-weight: 500;
}

.viewer-layout-btn__sub {
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.5px;
  color: var(--color-text-secondary);
  text-transform: uppercase;
}

.viewer-layout-btn.is-active .viewer-layout-btn__sub {
  color: var(--color-primary);
}

/* Send bar — pill container with emoji ☺ button + input + FIRE.
 * flex:0 0 auto pins it to the bottom of the shell/viewport. */
.viewer-sendbar {
  flex: 0 0 auto;
  position: relative;
  padding: 0.625rem 1.25rem 0.75rem;
  border-top: 1px solid var(--hud-line);
  background: var(--color-bg-base);
}

.viewer-sendbar-pill {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 4px 4px 4px 10px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--hud-line);
  background: var(--color-bg-elevated); /* lightBg2 in light theme */
  transition: border-color 0.15s;
}

/* 2026-05-17 design v3-r10: inline send-status banner anchored above the
   pill. Lime when sent (signals "delivered"), crimson when blocked. JS
   toggles [hidden] + is-sent / is-blocked, then auto-clears. */
.viewer-sendbar { position: relative; }
.viewer-sendbar-banner {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 8px);
  transform: translateX(-50%);
  z-index: 10;
  padding: 8px 14px;
  border-radius: 999px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  white-space: nowrap;
  pointer-events: none;
  animation: viewer-banner-in 240ms cubic-bezier(0.34, 1.56, 0.64, 1);
}
.viewer-sendbar-banner[hidden] { display: none; }
.viewer-sendbar-banner.is-sent {
  background: #84e100;
  color: #001428;
  box-shadow: 0 4px 20px rgba(132, 225, 0, 0.4);
}
.viewer-sendbar-banner.is-blocked {
  background: #ff4d4f;
  color: #fff;
  box-shadow: 0 4px 20px rgba(255, 77, 79, 0.4);
}
@keyframes viewer-banner-in {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}
@media (prefers-reduced-motion: reduce) {
  .viewer-sendbar-banner { animation: none; }
}

/* Sendbar hint state colors — design v3-r10 line 478-489. JS sets
   data-state on the hint span; CSS recolors. */
.viewer-sendbar-meta > [data-i18n="sendbarHint"][data-state="sent"]     { color: #84e100; }
.viewer-sendbar-meta > [data-i18n="sendbarHint"][data-state="blocked"]  { color: #ff4d4f; }
.viewer-sendbar-meta > [data-i18n="sendbarHint"][data-state="cooldown"] { color: #fbbf24; }

.viewer-sendbar-pill.is-active {
  border-color: var(--color-primary);
}

.viewer-emoji-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--color-text-secondary);
  cursor: pointer;
  font-size: 16px;
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}

.viewer-emoji-btn.is-active {
  background: var(--hud-cyan-soft);
  color: var(--color-primary);
}

.viewer-sendbar-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  font-size: 14px;
  padding: 10px 0;
  font-weight: 500;
  color: var(--color-text-primary);
  min-width: 0;
}

.viewer-sendbar-input::placeholder {
  color: var(--color-text-secondary);
}

.viewer-fire-btn {
  padding: 9px 16px;
  border-radius: var(--radius-pill);
  background: var(--color-bg-elevated);
  border: none;
  color: var(--color-text-secondary);
  cursor: default;
  font-size: 12px;
  font-weight: 700;
  font-family: var(--font-mono);
  letter-spacing: 1.5px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s, color 0.15s, transform 0.15s;
  flex-shrink: 0;
}

.viewer-fire-btn:not([disabled]) {
  background: var(--color-primary);
  color: #000;
  cursor: pointer;
}

.viewer-fire-btn:not([disabled]):hover {
  transform: translateY(-1px);
}

.viewer-fire-btn:not([disabled]):active {
  transform: translateY(0);
}

.viewer-fire-btn .btn-spinner {
  width: 14px;
  height: 14px;
}

.viewer-sendbar-meta {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  padding: 0 4px;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--color-text-secondary);
  letter-spacing: 1px;
}

.viewer-sendbar-meta__count.is-near {
  color: var(--color-warning);
}

/* Emoji popover — absolute above the send bar pill. */
.viewer-emoji-popover {
  position: absolute;
  left: 1.25rem;
  right: 1.25rem;
  bottom: 100%;
  margin-bottom: 0.375rem;
  background: var(--color-bg-base);
  border: 1px solid var(--hud-line);
  border-radius: 8px;
  padding: 0.5rem;
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.4);
  display: none;
  z-index: 30;
}

.viewer-emoji-popover.is-open {
  display: block;
}

.viewer-emoji-popover-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 0.25rem;
}

@media (max-width: 520px) {
  .viewer-emoji-popover-grid {
    grid-template-columns: repeat(8, 1fr);
  }
}

/* Image-emoji tiles inside the popover + the legacy #emojiPicker grid. */
.viewer-emoji-tile {
  padding: 0.375rem 0;
  min-height: 36px;
  border-radius: 4px;
  cursor: pointer;
  border: 1px solid var(--hud-line);
  background: transparent;
  font-size: 18px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s;
}

.viewer-emoji-tile:hover {
  background: var(--hud-cyan-soft);
  border-color: var(--color-primary);
}

.viewer-emoji-tile img {
  width: 22px;
  height: 22px;
}

/* Header bar — prototype viewer omits this when inBrowser=true, so we
 * hide it by default. Language picker + connection status still render
 * but are tucked away; re-show by toggling `.viewer-has-topstrip` on body. */
.viewer-topstrip {
  display: none;
}

body.viewer-has-topstrip .viewer-topstrip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.5rem 1.25rem 0;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 1.5px;
  color: var(--color-text-secondary);
  text-transform: uppercase;
}

.viewer-topstrip-status {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.viewer-topstrip-status + .viewer-topstrip-status {
  margin-left: 0.75rem;
}

.viewer-topstrip-select {
  background: var(--color-bg-elevated);
  border: 1px solid var(--hud-line);
  color: var(--color-text-secondary);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.1em;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  cursor: pointer;
}

.viewer-topstrip-select:focus {
  outline: none;
  border-color: var(--color-primary);
}

/* Reduced motion — kill hover transforms. */
@media (prefers-reduced-motion: reduce) {
  .viewer-chip,
  .viewer-layout-btn,
  .viewer-fire-btn,
  .viewer-preview-text,
  .viewer-emoji-btn {
    transition: none;
  }
  .viewer-fire-btn:not([disabled]):hover {
    transform: none;
  }
}

/* Offline full-panel (P2-1). */
.viewer-offline-card {
  min-height: 260px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 12px;
  padding: 20px;
  border-radius: 12px;
  border: 1px solid rgba(248, 113, 113, 0.35);
  background: linear-gradient(
    180deg,
    rgba(248, 113, 113, 0.08) 0%,
    rgba(15, 23, 42, 0.75) 100%
  );
}
.viewer-offline-lockup {
  margin: 0;
  font-family: var(--font-display);
  letter-spacing: 0.04em;
  font-size: clamp(2rem, 6vw, 2.8rem);
  color: #fca5a5;
}
.viewer-offline-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid rgba(248, 113, 113, 0.45);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 1.2px;
  color: #fecaca;
}
.viewer-offline-chip-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #f87171;
  box-shadow: 0 0 8px rgba(248, 113, 113, 0.7);
}
.viewer-offline-message {
  margin: 0;
  font-size: 14px;
  line-height: 1.6;
  color: var(--color-text-primary);
}
.viewer-offline-message small {
  display: block;
  margin-top: 6px;
  color: var(--color-text-secondary);
}
.viewer-offline-countdown {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 1px;
  color: var(--color-text-secondary);
}
.viewer-offline-countdown #offlineCountdownValue {
  font-size: 20px;
  color: #fca5a5;
  font-weight: 700;
}
.viewer-offline-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.viewer-offline-btn {
  border: 1px solid rgba(248, 113, 113, 0.45);
  background: rgba(248, 113, 113, 0.12);
  color: #fecaca;
  padding: 8px 12px;
  border-radius: 8px;
  font-family: var(--font-mono);
  font-size: 11px;
  text-decoration: none;
  cursor: pointer;
}
.viewer-offline-btn:hover {
  background: rgba(248, 113, 113, 0.2);
}
.viewer-offline-btn.is-secondary {
  border-color: rgba(56, 189, 248, 0.45);
  background: rgba(56, 189, 248, 0.12);
  color: #7dd3fc;
}

/* ─── Viewer states (P3 Group B, 2026-04-27) ──────────────────────── */
/* Full-screen overlays for ViewerBanned + ViewerPollThankYou. Replaces
   the chat surface when triggered (data-viewer-state on body). */
.viewer-state-root {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
  z-index: 100;
}
body[data-viewer-state] .viewer-state-root { pointer-events: auto; }
body[data-viewer-state] .viewer-page-shell { display: none; }
body[data-viewer-state] {
  background: var(--color-bg-deep, #050910);
  min-height: 100vh;
}

.viewer-state {
  position: relative;
  width: 100%; max-width: 480px;
  margin: 0 auto;
  padding: 32px 28px 40px;
  display: flex; flex-direction: column; align-items: center;
  text-align: center;
  font-family: var(--font-sans);
  color: var(--color-text-bright);
}

/* Banned variant */
.viewer-state-frame {
  position: absolute; inset: 12px;
  border: 1px solid rgba(248, 113, 113, 0.40);
  border-radius: 8px;
  pointer-events: none;
}
.viewer-state-corner {
  position: absolute;
  width: 16px; height: 16px;
  border-color: #f87171;
  border-style: solid;
  border-width: 0;
  pointer-events: none;
}
.viewer-state-corner--tl { top: 12px; left: 12px; border-top-width: 2px; border-left-width: 2px; }
.viewer-state-corner--tr { top: 12px; right: 12px; border-top-width: 2px; border-right-width: 2px; }
.viewer-state-corner--bl { bottom: 12px; left: 12px; border-bottom-width: 2px; border-left-width: 2px; }
.viewer-state-corner--br { bottom: 12px; right: 12px; border-bottom-width: 2px; border-right-width: 2px; }

.viewer-state-banned-icon {
  position: relative;
  width: 110px; height: 110px;
  margin: 24px 0;
  border-radius: 50%;
  border: 3px solid #f87171;
  background: rgba(248, 113, 113, 0.06);
  display: flex; align-items: center; justify-content: center;
  color: #f87171;
  font-size: 56px; font-weight: 700;
  box-shadow: 0 0 32px rgba(248, 113, 113, 0.20);
}
.viewer-state-banned-icon .slash {
  position: absolute; left: 50%; top: 50%;
  width: 70%; height: 4px;
  background: #f87171;
  transform: translate(-50%, -50%) rotate(-45deg);
  border-radius: 2px;
}

.viewer-state-kicker {
  font-family: var(--font-mono);
  font-size: 10px; letter-spacing: 2.5px;
  color: #f87171;
  margin-bottom: 8px;
}
.viewer-state-title {
  margin: 0; font-size: 22px; font-weight: 600;
  letter-spacing: 0.5px;
}
.viewer-state-title--center { text-align: center; }
.viewer-state-desc {
  font-size: 13px; line-height: 1.7;
  color: var(--color-text-secondary);
  margin-top: 12px;
  max-width: 380px;
}
.viewer-state-desc--center { text-align: center; }

.viewer-state-info {
  margin-top: 24px; padding: 12px 16px;
  background: var(--color-bg-card, rgba(15, 23, 42, 0.75));
  border: 1px solid var(--color-border);
  border-radius: 4px;
  display: flex; flex-direction: column; gap: 8px;
  font-family: var(--font-mono); font-size: 11px;
  color: var(--color-text-muted, #64748b);
  letter-spacing: 0.4px;
  width: 100%;
}
.viewer-state-info .row {
  display: flex; justify-content: space-between; gap: 16px;
}
.viewer-state-info .v { color: var(--color-text-bright); }

.viewer-state-tip {
  margin-top: 18px; padding: 10px 14px;
  background: rgba(56, 189, 248, 0.08);
  border: 1px solid rgba(56, 189, 248, 0.40);
  border-radius: 4px;
  font-size: 11px; line-height: 1.6;
  color: var(--color-text-bright);
  max-width: 380px;
  text-align: left;
}
.viewer-state-tip .kicker {
  display: block;
  color: var(--color-primary);
  font-family: var(--font-mono); font-size: 9px; letter-spacing: 1.5px;
  margin-bottom: 4px;
}

/* Thank-you variant */
.viewer-state-thanks-icon {
  position: relative;
  width: 96px; height: 96px;
  margin-top: 40px;
  margin-bottom: 18px;
  border-radius: 50%;
  background: rgba(56, 189, 248, 0.08);
  border: 2px solid var(--color-primary);
  display: flex; align-items: center; justify-content: center;
  color: var(--color-primary);
  font-size: 48px;
  box-shadow: 0 0 40px rgba(56, 189, 248, 0.35), inset 0 0 24px rgba(56, 189, 248, 0.14);
}
.viewer-state-thanks-icon .ring {
  position: absolute; border-radius: 50%;
  pointer-events: none;
}
.viewer-state-thanks-icon .ring-1 {
  inset: -10px; border: 1px solid rgba(56, 189, 248, 0.35);
}
.viewer-state-thanks-icon .ring-2 {
  inset: -22px; border: 1px solid rgba(56, 189, 248, 0.14);
}

.viewer-state-recap {
  width: 100%; max-width: 380px;
  margin-top: 16px; padding: 16px;
  background: var(--color-bg-card, rgba(15, 23, 42, 0.75));
  border: 1px solid var(--color-border);
  border-radius: 8px;
  text-align: left;
}
.viewer-state-recap .kicker {
  font-family: var(--font-mono); font-size: 9px; letter-spacing: 1.2px;
  color: var(--color-text-muted, #64748b);
  margin-bottom: 6px;
}
.viewer-state-recap .question {
  font-size: 14px; font-weight: 600; line-height: 1.5;
  margin-bottom: 12px;
}
.viewer-state-recap .choice {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  background: rgba(56, 189, 248, 0.08);
  border: 1px solid var(--color-primary);
  border-radius: 4px;
}
.viewer-state-recap .choice .check {
  width: 20px; height: 20px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--color-primary);
  color: #000;
  border-radius: 50%;
  font-size: 12px; font-weight: 700;
  flex-shrink: 0;
}
.viewer-state-recap .choice .lbl {
  flex: 1; font-size: 14px; font-weight: 600;
}
.viewer-state-recap .choice .ts {
  font-family: var(--font-mono); font-size: 10px;
  color: var(--color-text-muted, #64748b);
}
.viewer-state-recap .meta {
  margin-top: 10px;
  font-family: var(--font-mono); font-size: 10px;
  line-height: 1.7; letter-spacing: 0.3px;
  color: var(--color-text-muted, #64748b);
}
.viewer-state-recap .meta .dot {
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--color-text-muted, #64748b);
  margin-right: 6px;
}
.viewer-state-recap .meta .dot.is-good { background: #86efac; box-shadow: 0 0 4px #86efac; }

.viewer-state-action {
  margin-top: 16px;
  width: 100%; max-width: 380px;
  padding: 14px;
  background: var(--color-primary);
  color: #000;
  border: none; border-radius: 8px;
  font-size: 14px; font-weight: 600;
  letter-spacing: 0.4px;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(56, 189, 248, 0.35);
  transition: transform 140ms ease;
}
.viewer-state-action:hover { transform: translateY(-1px); }
.viewer-state-trace {
  margin-top: 14px;
  font-family: var(--font-mono); font-size: 10px;
  letter-spacing: 0.3px;
  color: var(--color-text-muted, #64748b);
}

/* Rate-limit variant */
.viewer-state-ratelimit-icon {
  border-color: #fbbf24;
  background: rgba(251, 191, 36, 0.08);
  color: #fbbf24;
  box-shadow: 0 0 40px rgba(251, 191, 36, 0.3), inset 0 0 24px rgba(251, 191, 36, 0.14);
}
.viewer-state-kicker--warn {
  color: #fbbf24;
}
.viewer-state-action--warn {
  background: #fbbf24;
  color: #111827;
  box-shadow: 0 4px 16px rgba(251, 191, 36, 0.35);
}

/* ═══════════════════════════════════════════════════════════════════
 * Nickname chip + floating popover (design v4 brief 0518-4c, 2026-05-18)
 * Replaces the bare input with a tappable chip that opens an in-place
 * popover for editing. Source input stays in DOM (hidden) so existing
 * fire flow / localStorage logic is untouched.
 * ═══════════════════════════════════════════════════════════════════ */
.viewer-nickname-row {
  display: flex;
  align-items: center;
  gap: 10px;
  position: relative;
}
.viewer-nickname-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(56, 189, 248, 0.10);
  border: 1px solid rgba(56, 189, 248, 0.45);
  font-family: var(--font-mono, "JetBrains Mono", ui-monospace, monospace);
  font-size: 13px;
  font-weight: 600;
  color: var(--color-primary);
  cursor: pointer;
  transition: background var(--motion-fast) var(--ease-out, ease),
              border-color var(--motion-fast) var(--ease-out, ease);
}
.viewer-nickname-chip:hover,
.viewer-nickname-chip[aria-expanded="true"] {
  background: rgba(56, 189, 248, 0.18);
  border-color: rgba(56, 189, 248, 0.6);
}

/* Light theme — design v4 brief 0518-v3 #3 fix (2026-05-18).
   sky-400 chip border is too pale on white. Swap to sky-600 (-2 shade
   for AA contrast) and bump border opacity 0.25 → 0.35 per audit. */
body.viewer-body-v2:not(.is-dark) .viewer-nickname-chip {
  background: rgba(2, 132, 199, 0.08);
  border-color: rgba(2, 132, 199, 0.35);
  color: #0284c7;
}
body.viewer-body-v2:not(.is-dark) .viewer-nickname-chip:hover,
body.viewer-body-v2:not(.is-dark) .viewer-nickname-chip[aria-expanded="true"] {
  background: rgba(2, 132, 199, 0.14);
  border-color: rgba(2, 132, 199, 0.55);
}

.viewer-nickname-chip-text {
  letter-spacing: 0.3px;
}
.viewer-nickname-chip-edit {
  font-size: 11px;
  opacity: 0.7;
}
.viewer-nickname-hint {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--color-text-muted);
  letter-spacing: 0.3px;
}

/* Hide the source input but keep it in DOM (so fire flow + listeners work). */
.viewer-nickname-source[hidden] { display: none !important; }

/* Inline edit input — replaces chip in-place on click */
.viewer-nickname-inline-input {
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(56, 189, 248, 0.10);
  border: 1px solid var(--color-primary);
  font-family: var(--font-mono, "JetBrains Mono", ui-monospace, monospace);
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text-primary);
  outline: none;
  width: 140px;
}
body.viewer-body-v2:not(.is-dark) .viewer-nickname-inline-input {
  background: rgba(2, 132, 199, 0.08);
  border-color: #0284c7;
}
.viewer-nickname-inline-input[hidden] { display: none; }

/* Narrow viewer — hide the "← 點擊改名" hint, chip is self-explanatory */
@media (max-width: 480px) {
  .viewer-nickname-hint { display: none; }
}

/* ═══════════════════════════════════════════════════════════════════
 * Mobile hamburger + settings bottom sheet
 * (design v4 brief 0518-4a, 2026-05-18)
 *
 * Desktop hides the hamburger entirely — theme + lang stay system-driven
 * with admin override per Viewer page settings. Mobile shows the
 * hamburger in viewer-hero-utility; tapping opens a bottom sheet with
 * theme tri-state (深色/淺色/系統) + lang quad-state (中/EN/日/한).
 * ═══════════════════════════════════════════════════════════════════ */
.viewer-hamburger {
  display: none;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid rgba(56, 189, 248, 0.35);
  background: rgba(56, 189, 248, 0.08);
  color: var(--color-primary);
  font-size: 16px;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.viewer-hamburger:active {
  background: rgba(56, 189, 248, 0.2);
}

/* Visible on mobile only */
@media (max-width: 768px) {
  .viewer-hamburger { display: inline-flex; }
}

/* Bottom sheet container */
.viewer-mobile-sheet {
  position: fixed;
  inset: 0;
  z-index: 100;
  pointer-events: none;
}
.viewer-mobile-sheet[hidden] { display: none; }
.viewer-mobile-sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0;
  transition: opacity var(--motion-normal, 180ms) var(--ease-in-out, ease);
  pointer-events: auto;
}
.viewer-mobile-sheet.is-open .viewer-mobile-sheet-backdrop {
  opacity: 1;
}
.viewer-mobile-sheet-panel {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--hud-bg1);
  border-top: 2px solid var(--color-primary);
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -12px 48px rgba(0, 0, 0, 0.6);
  transform: translateY(100%);
  transition: transform var(--motion-normal, 180ms) var(--ease-out, ease);
  pointer-events: auto;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.viewer-mobile-sheet.is-open .viewer-mobile-sheet-panel {
  transform: translateY(0);
}
.viewer-mobile-sheet-grabber {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--color-border, rgba(255, 255, 255, 0.18));
  margin: 8px auto 4px;
}
.viewer-mobile-sheet-head {
  padding: 10px 16px;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  gap: 8px;
}
.viewer-mobile-sheet-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text-primary);
  flex: 1;
}
.viewer-mobile-sheet-close {
  font-size: 16px;
  color: var(--color-text-muted);
  background: transparent;
  border: 0;
  cursor: pointer;
  padding: 4px 8px;
}
.viewer-mobile-sheet-row {
  padding: 14px 16px;
  border-bottom: 1px solid var(--color-border, rgba(255, 255, 255, 0.06));
  display: flex;
  align-items: center;
  gap: 12px;
}
.viewer-mobile-sheet-row:last-of-type { border-bottom: 0; }
.viewer-mobile-sheet-label {
  font-size: 13px;
  color: var(--color-text-primary);
}
.viewer-mobile-sheet-spacer { flex: 1; }
.viewer-mobile-sheet-segment {
  display: flex;
  gap: 4px;
}
.viewer-mobile-sheet-seg {
  padding: 6px 12px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.5px;
  border: 1px solid var(--color-border);
  background: transparent;
  color: var(--color-text-muted);
  cursor: pointer;
  transition: all var(--motion-fast) var(--ease-out, ease);
}
.viewer-mobile-sheet-seg.is-active {
  border-color: var(--color-primary);
  background: rgba(56, 189, 248, 0.10);
  color: var(--color-primary);
}
.viewer-mobile-sheet-foot {
  padding: 16px;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 9px;
  color: var(--color-text-muted);
}

/* Desktop — bottom sheet never opens (hamburger is display:none anyway). */
@media (min-width: 769px) {
  .viewer-mobile-sheet { display: none !important; }
}

/* ═══════════════════════════════════════════════════════════════════
 * Desktop theme chip (design v4 brief 0518-v3 #1, 2026-05-18)
 * 3-segment ☼/◐/☾ toggle in viewer-hero-utility. Hidden on mobile
 * (replaced by hamburger bottom sheet). Reuses theme-mode storage key.
 * ═══════════════════════════════════════════════════════════════════ */
.viewer-theme-chip {
  display: inline-flex;
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--hud-line, rgba(15, 23, 42, 0.12));
  flex-shrink: 0;
}
.viewer-theme-chip-seg {
  padding: 5px 10px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0;
  color: var(--color-text-secondary, #475569);
  background: transparent;
  border: 0;
  border-right: 1px solid var(--hud-line, rgba(15, 23, 42, 0.12));
  cursor: pointer;
  /* Background + color use ease-out (snap hover); transform uses spring
     (slight overshoot when going active). 2026-05-18 motion language. */
  transition: background var(--motion-fast) var(--ease-out, ease),
              color var(--motion-fast) var(--ease-out, ease),
              transform var(--motion-normal, 180ms) var(--ease-spring, ease);
  min-width: 32px;
  text-align: center;
  transform: scale(1);
}
.viewer-theme-chip-seg.is-active {
  transform: scale(1.05);
}
.viewer-theme-chip-seg:last-child { border-right: 0; }
.viewer-theme-chip-seg:hover {
  color: var(--color-text-primary, #0f172a);
}
.viewer-theme-chip-seg.is-active {
  background: rgba(2, 132, 199, 0.08);
  color: var(--color-primary, #0284c7);
}
/* Dark theme variant — accent color shift for slightly brighter sky-400 */
body.viewer-body-v2.is-dark .viewer-theme-chip-seg.is-active {
  background: rgba(56, 189, 248, 0.10);
  color: var(--hud-cyan);
}
body.viewer-body-v2.is-dark .viewer-theme-chip,
body.viewer-body-v2.is-dark .viewer-theme-chip-seg {
  border-color: rgba(148, 163, 184, 0.18);
}

/* Mobile (≤768px) — hide desktop chip; hamburger sheet covers same flow */
@media (max-width: 768px) {
  .viewer-theme-chip { display: none; }
}

/* ═══════════════════════════════════════════════════════════════════
 * Viewer poll multi-Q (design v4 brief P1 #1, 2026-05-18)
 * Image hero · progress dots · auto-mode timer bar.
 * Counts/percentages stay polestar-locked (admin-only).
 * ═══════════════════════════════════════════════════════════════════ */

.viewer-poll-image {
  width: 100%;
  max-height: 200px;
  margin-bottom: 12px;
  border-radius: 8px;
  overflow: hidden;
  background: var(--color-bg-elevated, #f1f5f9);
  border: 1px solid var(--hud-line, rgba(15, 23, 42, 0.12));
}
.viewer-poll-image[hidden] { display: none; }
.viewer-poll-image-img {
  width: 100%;
  height: auto;
  max-height: 200px;
  object-fit: cover;  /* 16:9 fit; long images crop, short images letterbox */
  display: block;
}

@media (max-width: 599px) {
  .viewer-poll-image,
  .viewer-poll-image-img {
    max-height: 160px;
  }
}

/* Progress dots — current cyan + wider; past dim; future neutral. */
.viewer-poll-dots {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 14px;
}
.viewer-poll-dots[hidden] { display: none; }
.viewer-poll-dot {
  width: 8px;
  height: 8px;
  border-radius: 4px;
  background: var(--color-bg-elevated);
  transition: width var(--motion-normal, 180ms) var(--ease-out, ease),
              background var(--motion-fast) var(--ease-out, ease);
}
.viewer-poll-dot.is-past {
  background: var(--color-text-muted);
}
.viewer-poll-dot.is-current {
  background: var(--color-primary);
  width: 20px;
  box-shadow: 0 0 8px rgba(56, 189, 248, 0.5);
}

/* Auto-mode timer bar — sits between options and dots. */
.viewer-poll-timer {
  margin-top: 14px;
  height: 4px;
  border-radius: 2px;
  background: var(--color-bg-elevated);
  overflow: hidden;
}
.viewer-poll-timer[hidden] { display: none; }
.viewer-poll-timer-fill {
  height: 100%;
  background: var(--hud-lime, #86efac);
  border-radius: 2px;
  /* No CSS transition — JS rAF updates width every frame for smooth
     countdown. transition would fight the rAF updates. */
}
