/**
 * AI Live Studio — one stylesheet for the front door, the studio and the viewer.
 *
 * MOBILE FIRST, and not as a slogan: the link a sales engineer sends a customer
 * is opened on a phone far more often than on a laptop, and the page this
 * replaces had ZERO media queries and a hardcoded 1fr + 320px grid. Everything
 * below is written for a narrow screen, with `@media (min-width: 880px)` adding
 * the second column.
 *
 * Tokens are the portal's (apps/portal/app/globals.css) so this does not read as
 * a different company's product: brand #006EFF, the demo-dark surfaces for the
 * stage. Light chrome, dark stage.
 */

:root {
  --brand: #006EFF;
  --brand-hover: #0052D9;
  --brand-pressed: #003CAB;
  --brand-100: #E0EFFF;
  --brand-50: #F2F8FF;
  --navy: #001A45;

  --stage-bg: #0A0F1E;
  --stage-surface: #0D1426;
  --stage-elevated: #1C2B3A;

  --bg: #FFFFFF;
  --bg-muted: #F5F7FA;
  --surface: #FFFFFF;
  --border: #E3E6EB;
  --border-strong: #C9CED6;

  --fg1: #0F1F3D;
  --fg2: #4E5969;
  --fg3: #86909C;

  --success: #00A870;
  --warning: #ED7B2F;
  --error: #E34D59;

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --radius-pill: 999px;

  --shadow-1: 0 1px 2px rgba(15, 31, 61, .06), 0 1px 1px rgba(15, 31, 61, .04);
  --shadow-2: 0 4px 12px rgba(15, 31, 61, .08), 0 1px 2px rgba(15, 31, 61, .04);
  --shadow-3: 0 12px 32px rgba(15, 31, 61, .10), 0 2px 6px rgba(15, 31, 61, .06);

  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC',
    'Noto Sans SC', 'Noto Sans Thai', Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font);
  color: var(--fg1);
  background: var(--bg-muted);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}

:lang(th) {
  line-height: 1.7;
}

a {
  color: var(--brand);
  text-decoration: none;
}

button,
select,
input,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
}

[hidden] {
  display: none !important;
}

/* ── Chrome ───────────────────────────────────────────────────────────────── */

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-mark {
  width: 30px;
  height: 30px;
  flex: none;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--brand), #00C8FF);
}

.brand-title {
  font-size: 15px;
  font-weight: 650;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

.meter {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: var(--fg2);
  white-space: nowrap;
}

.meter-remaining.is-low {
  color: var(--error);
  font-weight: 600;
}

.lang-switch {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius-pill);
  padding: 6px 28px 6px 12px;
  font-size: 13px;
  color: var(--fg2);
  background-image: linear-gradient(45deg, transparent 50%, var(--fg3) 50%),
    linear-gradient(135deg, var(--fg3) 50%, transparent 50%);
  background-position: calc(100% - 15px) 14px, calc(100% - 10px) 14px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

/* ── Buttons ──────────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 18px;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--fg1);
  font-size: 15px;
  font-weight: 550;
  transition: background .15s, border-color .15s, color .15s, box-shadow .15s;
}

.btn:hover:not(:disabled) {
  border-color: var(--brand);
  color: var(--brand);
}

.btn:disabled {
  opacity: .5;
}

.btn-primary {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
  box-shadow: 0 8px 20px rgba(0, 110, 255, .22);
}

.btn-primary:hover:not(:disabled) {
  background: var(--brand-hover);
  border-color: var(--brand-hover);
  color: #fff;
}

.btn-primary:disabled {
  box-shadow: none;
}

.btn-danger {
  color: var(--error);
  border-color: rgba(227, 77, 89, .5);
}

.btn-danger:hover:not(:disabled) {
  background: rgba(227, 77, 89, .08);
  color: var(--error);
  border-color: var(--error);
}

.btn-quiet {
  min-height: 36px;
  padding: 6px 12px;
  font-size: 13px;
  border-color: var(--border);
  color: var(--fg2);
}

.btn-block {
  width: 100%;
}

/* ── Front door ───────────────────────────────────────────────────────────── */

.home {
  flex: 1;
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  padding: 28px 16px 64px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.home-hero h1 {
  font-size: 30px;
  line-height: 1.2;
  letter-spacing: -0.02em;
  font-weight: 700;
}

.home-hero p {
  margin-top: 10px;
  color: var(--fg2);
  font-size: 16px;
  max-width: 54ch;
}

.home-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}

.effect-gallery {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

/* ── Effect cards ─────────────────────────────────────────────────────────── */

.effect-card {
  display: grid;
  gap: 4px;
  text-align: left;
  padding: 14px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-1);
  transition: border-color .15s, box-shadow .15s, transform .15s;
  color: inherit;
}

.effect-card:hover:not(:disabled) {
  border-color: var(--brand);
  box-shadow: var(--shadow-2);
}

.effect-card.is-active {
  border-color: var(--brand);
  background: var(--brand-50);
  box-shadow: inset 0 0 0 1px var(--brand);
}

.effect-card.is-unavailable,
.effect-card:disabled {
  opacity: .45;
  box-shadow: none;
}

.effect-tag {
  justify-self: start;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--brand);
  background: var(--brand-100);
  border-radius: var(--radius-pill);
  padding: 2px 8px;
}

.effect-title {
  font-size: 15px;
  font-weight: 650;
}

.effect-desc {
  font-size: 13px;
  color: var(--fg2);
}

/* ── Studio layout ────────────────────────────────────────────────────────── */

.studio-main {
  flex: 1;
  width: 100%;
  max-width: 1440px;
  margin: 0 auto;
  padding: 12px 12px 24px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  align-content: start;
}

.stage-column {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

/* ── The stage ────────────────────────────────────────────────────────────── */

.stage {
  --wipe: 0%;
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: var(--stage-bg);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-3);
  touch-action: pan-y;
  user-select: none;
}

.stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* The raw camera, clipped to the left of the wipe. Presentation only — the
   audience receives the canvas, never this layer. */
.stage-before {
  position: absolute;
  inset: 0;
  clip-path: inset(0 calc(100% - var(--wipe)) 0 0);
  display: none;
}

.stage.before-camera .stage-before,
.stage.before-engine .stage-before {
  display: block;
}

.stage-before > * {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: none;
}

.stage.before-camera #stage-camera,
.stage.before-engine #stage-engine-preview {
  display: block;
}

.stage-before video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: var(--stage-bg);
}

#stage-camera {
  transform: scaleX(-1);
  object-fit: cover;
}

/* The vendor's output element has to stay in the layout to keep decoding, but
   it must never be what the presenter looks at — the canvas is. */
.offstage {
  position: fixed;
  left: -10000px;
  top: 0;
  width: 320px;
  height: 180px;
  overflow: hidden;
  pointer-events: none;
}

.stage-wipe {
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--wipe);
  width: 2px;
  margin-left: -1px;
  background: rgba(255, 255, 255, .9);
  cursor: ew-resize;
  display: none;
  touch-action: none;
}

.stage.is-comparable .stage-wipe {
  display: block;
}

.stage-wipe::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 40px;
  height: 40px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: rgba(255, 255, 255, .92);
  box-shadow: 0 2px 10px rgba(0, 0, 0, .35);
}

.stage-wipe:focus-visible {
  outline: 3px solid var(--brand);
  outline-offset: 2px;
}

.stage-status {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 3;
  font-size: 12px;
  font-weight: 600;
  color: #fff;
  background: rgba(10, 15, 30, .72);
  border-radius: var(--radius-pill);
  padding: 5px 12px;
  backdrop-filter: blur(6px);
}

/* Failure is a caption over a picture that never dropped. */
.stage-caption {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 10px;
  z-index: 4;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: rgba(10, 15, 30, .86);
  color: #fff;
  backdrop-filter: blur(8px);
  border-left: 3px solid var(--brand);
}

.stage-caption[data-kind='warn'] {
  border-left-color: var(--warning);
}

.stage-caption[data-kind='error'] {
  border-left-color: var(--error);
}

.stage-caption-text {
  flex: 1;
  min-width: 0;
}

.stage-caption-title {
  font-size: 14px;
  font-weight: 600;
}

.stage-caption-fix {
  display: block;
  font-size: 12px;
  color: rgba(255, 255, 255, .78);
  margin-top: 2px;
}

.stage-caption-dismiss {
  flex: none;
  min-height: 28px;
  padding: 2px 10px;
  font-size: 12px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 255, 255, .3);
  background: transparent;
  color: #fff;
}

.stage-idle {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-align: center;
  padding: 24px;
  color: rgba(255, 255, 255, .86);
  background: radial-gradient(120% 120% at 50% 0%, #142244 0%, var(--stage-bg) 70%);
}

.stage-idle h2 {
  font-size: 18px;
  font-weight: 650;
  color: #fff;
}

.stage-idle p {
  font-size: 14px;
  max-width: 44ch;
  color: rgba(255, 255, 255, .7);
}

/* ── Controls ─────────────────────────────────────────────────────────────── */

.controls {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow-1);
}

.card > h2 {
  font-size: 13px;
  font-weight: 650;
  color: var(--fg2);
  letter-spacing: .02em;
  margin-bottom: 10px;
}

.effect-list {
  display: grid;
  gap: 8px;
}

.hint {
  font-size: 12px;
  color: var(--fg3);
  margin-top: 8px;
}

.ref-drop {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  color: var(--fg3);
  font-size: 13px;
}

.ref-drop:hover {
  border-color: var(--brand);
  color: var(--brand);
}

.ref-drop img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: none;
}

.ref-drop.has-image img {
  display: block;
}

.ref-drop.has-image .ref-placeholder {
  display: none;
}

.field {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 14px;
}

.field:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-100);
}

textarea.field {
  min-height: 84px;
  resize: vertical;
}

.stack {
  display: grid;
  gap: 8px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.chip {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius-pill);
  padding: 6px 12px;
  font-size: 12px;
  color: var(--fg2);
}

.chip:hover {
  border-color: var(--brand);
  color: var(--brand);
}

/* The primary action stays reachable on a phone without scrolling back up. */
.actions {
  position: sticky;
  bottom: 0;
  z-index: 10;
  display: grid;
  gap: 8px;
  padding: 12px 0 max(12px, env(safe-area-inset-bottom));
  /* Solid, not a fade: on a phone this bar sits ON TOP of the cards behind it,
     and a gradient let their text show through the reason line — which is the
     one line that has to be readable. */
  background: var(--bg-muted);
  box-shadow: 0 -10px 18px -10px rgba(15, 31, 61, .25);
}

.actions-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.start-reason {
  font-size: 12px;
  color: var(--warning);
  text-align: center;
}

/* ── Share ────────────────────────────────────────────────────────────────── */

.share-body {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 12px;
  align-items: center;
}

.qr {
  width: 96px;
  height: 96px;
  background: #fff;
  border-radius: var(--radius-sm);
  padding: 4px;
  border: 1px solid var(--border);
}

.qr svg {
  display: block;
  width: 100%;
  height: 100%;
}

.share-link {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--fg2);
}

/* ── Preflight ────────────────────────────────────────────────────────────── */

.checks {
  list-style: none;
  display: grid;
  gap: 6px;
}

.check {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 10px;
  font-size: 13px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}

.check:last-child {
  border-bottom: 0;
}

.check-state {
  font-size: 12px;
  font-weight: 600;
  color: var(--fg3);
}

.check-ok .check-state {
  color: var(--success);
}

.check-warn .check-state {
  color: var(--warning);
}

.check-blocked .check-state {
  color: var(--error);
}

.check-fix {
  grid-column: 1 / -1;
  font-size: 12px;
  color: var(--fg2);
}

.preflight-summary {
  font-size: 12px;
  color: var(--fg2);
  margin-bottom: 10px;
}

.preflight-panel.is-blocked .preflight-summary {
  color: var(--error);
}

/* ── Engineer panel (?debug=1) ────────────────────────────────────────────── */

.debug-panel {
  width: 100%;
  max-width: 1440px;
  margin: 0 auto 24px;
  padding: 0 12px;
  display: grid;
  gap: 10px;
}

.debug-box {
  background: var(--stage-surface);
  color: #cfe0ff;
  border-radius: var(--radius);
  padding: 10px 12px;
  font-family: var(--mono);
  font-size: 11px;
  max-height: 220px;
  overflow: auto;
}

.debug-line {
  display: flex;
  gap: 8px;
  padding: 1px 0;
}

.debug-time {
  color: #6f86b5;
  flex: none;
}

.debug-fact {
  display: flex;
  gap: 10px;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255, 255, 255, .06);
  padding: 2px 0;
}

.debug-fact span:first-child {
  color: #6f86b5;
}

.debug-fact span:last-child {
  word-break: break-all;
  text-align: right;
}

/* ── Viewer ───────────────────────────────────────────────────────────────── */

.viewer-main {
  flex: 1;
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 12px 12px 32px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.viewer-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-3);
}

.viewer-stage video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}

.viewer-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-align: center;
  padding: 24px;
  color: #fff;
  background: radial-gradient(120% 120% at 50% 0%, #142244 0%, var(--stage-bg) 70%);
}

.viewer-overlay[data-kind='action'] {
  background: rgba(10, 15, 30, .82);
  cursor: pointer;
}

.viewer-overlay-title {
  font-size: 17px;
  font-weight: 650;
}

.viewer-overlay-fix {
  font-size: 14px;
  color: rgba(255, 255, 255, .72);
  max-width: 40ch;
}

.viewer-status {
  font-size: 13px;
  color: var(--fg2);
  text-align: center;
}

.viewer-join {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.viewer-join .field {
  max-width: 220px;
}

/* ── The gallery ──────────────────────────────────────────────────────────── */

.gallery-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.gallery-head h2 {
  font-size: 13px;
  font-weight: 650;
  color: var(--fg2);
  letter-spacing: .02em;
}

/* Only a sheet can be closed; in the column the card simply sits there. */
.gallery-close {
  display: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--fg2);
  font-size: 14px;
}

.grid-label {
  font-size: 11px;
  font-weight: 650;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--fg3);
}

/*
 * ?presenter=1 only — built by src/studio.js, absent from the DOM otherwise.
 * Two compact segments above the tabs: the one place a vendor name is shown.
 */
.engine-switch {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
  font-size: 12px;
  color: var(--fg3);
}

.engine-switch-label {
  font-weight: 650;
  flex: none;
}

.engine-switch-options {
  display: inline-flex;
  flex: 1 1 auto;
  min-width: 0;
  padding: 2px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: var(--bg-muted);
}

.engine-switch-option {
  flex: 1 1 0;
  min-width: 0;
  min-height: 32px;
  padding: 4px 10px;
  border: 0;
  border-radius: var(--radius-pill);
  background: none;
  font-size: 12px;
  font-weight: 600;
  color: var(--fg2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.engine-switch-option[aria-checked='true'] {
  background: var(--surface);
  color: var(--brand);
  box-shadow: 0 1px 2px rgba(15, 23, 42, .12);
}

.engine-switch-option:disabled {
  opacity: .45;
  cursor: not-allowed;
}

.engine-switch-option:focus-visible {
  outline: 3px solid var(--brand);
  outline-offset: 1px;
}

.gallery-tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
  scrollbar-width: none;
}

.gallery-tabs::-webkit-scrollbar {
  display: none;
}

.gallery-tab {
  position: relative;
  flex: 1 0 auto;
  min-height: 44px;
  padding: 8px 8px;
  white-space: nowrap;
  border: 0;
  border-bottom: 2px solid transparent;
  background: none;
  font-size: 13px;
  font-weight: 600;
  color: var(--fg2);
  scroll-snap-align: start;
}

.gallery-tab.is-active {
  color: var(--brand);
  border-bottom-color: var(--brand);
}

/* Where the selected look lives, after browsing elsewhere. */
.gallery-tab.has-selection::after {
  content: '';
  position: absolute;
  top: 10px;
  right: 3px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--brand);
}

.gallery-tab.is-locked {
  color: var(--fg3);
}

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

.gallery-grid[data-shape='wide'] {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid-label {
  grid-column: 1 / -1;
  margin-top: 4px;
}

.grid-label:first-child {
  margin-top: 0;
}

/* One component for every tile: preset, own picture, words, upload. */
.tile {
  position: relative;
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--stage-elevated);
  color: #fff;
  text-align: left;
  aspect-ratio: 1 / 1;
  box-shadow: inset 0 0 0 1px rgba(15, 31, 61, .08);
  transition: transform .12s, box-shadow .12s;
}

.tile-portrait {
  aspect-ratio: 3 / 4;
}

.tile-wide {
  aspect-ratio: 16 / 9;
}

.tile:hover:not([aria-disabled='true']) {
  transform: translateY(-1px);
}

.tile:active:not([aria-disabled='true']) {
  transform: scale(.98);
}

.tile:focus-visible,
.gallery-tab:focus-visible {
  outline: 3px solid var(--brand);
  outline-offset: 2px;
}

.tile-art {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  /* The placeholder a failed thumbnail degrades to: tinted, with an initial. */
  background: linear-gradient(135deg, #1C2B3A 0%, #24406B 100%);
}

.tile-art img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.tile-initial {
  font-size: 26px;
  font-weight: 700;
  color: rgba(255, 255, 255, .55);
}

.tile-name {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 18px 8px 6px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  background: linear-gradient(transparent, rgba(0, 0, 0, .72));
}

.tile-check {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: none;
  background: var(--brand);
  box-shadow: 0 1px 4px rgba(0, 0, 0, .35);
}

.tile-check::after {
  content: '';
  position: absolute;
  left: 7px;
  top: 4px;
  width: 5px;
  height: 9px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.tile.is-selected {
  box-shadow: 0 0 0 2px var(--brand), 0 4px 12px rgba(0, 110, 255, .25);
}

.tile.is-selected .tile-check {
  display: block;
}

/* On its way to air: a thin moving arc around the ring. Additive over a
   picture that never stops — never a spinner in the middle of anything. */
.tile.is-pending::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 2;
  border-radius: inherit;
  padding: 2px;
  background: conic-gradient(from var(--arc, 0deg), transparent 0 55%, var(--brand) 80%, transparent 100%);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  animation: tile-arc 1.1s linear infinite;
  pointer-events: none;
}

@property --arc {
  syntax: '<angle>';
  initial-value: 0deg;
  inherits: false;
}

@keyframes tile-arc {
  to {
    --arc: 360deg;
  }
}

.tile.is-unavailable,
.tile.is-locked {
  opacity: .38;
  cursor: not-allowed;
}

.tile-text {
  background: linear-gradient(135deg, var(--brand) 0%, #00A3FF 100%);
}

.tile-text-mark {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  font-weight: 700;
  font-style: italic;
  color: rgba(255, 255, 255, .85);
}

.tile-upload {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 8px;
  text-align: center;
  background: var(--bg-muted);
  color: var(--fg2);
  box-shadow: none;
  border: 2px dashed var(--border-strong);
}

.tile-upload:hover {
  border-color: var(--brand);
  color: var(--brand);
}

.tile-plus {
  font-size: 24px;
  line-height: 1;
  font-weight: 400;
}

.tile-upload-label {
  font-size: 12px;
  font-weight: 650;
}

.tile-upload-hint {
  display: none;
  font-size: 11px;
  color: var(--fg3);
}

/*
 * An effect with no catalog (today: backgrounds). One line says this tab works
 * from the presenter's own picture, then "your photo" and "paste a link" sit
 * side by side with their hints showing — a deliberate choice, not a hole.
 */
.grid-empty {
  grid-column: 1 / -1;
  margin: 0;
  font-size: 13px;
  line-height: 1.45;
  color: var(--fg2);
}

.grid-empty ~ .tile-upload {
  aspect-ratio: auto;
  min-height: 112px;
}

.grid-empty ~ .tile-upload .tile-upload-hint {
  display: block;
}

.gallery-describe {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.gallery-link {
  margin-top: 10px;
}

.gallery-link-row {
  margin-top: 8px;
}

.btn-text {
  border: 0;
  background: none;
  padding: 6px 0;
  min-height: 32px;
  font-size: 13px;
  font-weight: 550;
  color: var(--brand);
}

.presenter-hint {
  margin-top: 10px;
  font-size: 11px;
  color: var(--fg3);
  font-family: var(--mono);
}

/* ── The stage: badge, incoming chip, peek ───────────────────────────────── */

/* Over the AI side of the wipe (the right). Gone when the real camera shows. */
.stage-ai-badge {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 3;
  display: none;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .03em;
  color: #fff;
  background: rgba(0, 110, 255, .82);
  border-radius: var(--radius-pill);
  padding: 4px 10px;
  backdrop-filter: blur(6px);
}

.stage.is-comparable .stage-ai-badge {
  display: block;
}

.stage-incoming {
  position: absolute;
  top: 44px;
  left: 10px;
  z-index: 4;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: calc(100% - 20px);
  padding: 4px 12px 4px 4px;
  border-radius: var(--radius-pill);
  background: rgba(10, 15, 30, .82);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  backdrop-filter: blur(8px);
  overflow: hidden;
  transition: opacity .4s;
}

.stage-incoming-thumb {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  flex: none;
  background: var(--stage-elevated);
}

.stage-incoming-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* The 4 s shimmer: time is passing on purpose. */
.stage-incoming[data-phase='coming']::after {
  content: '';
  position: absolute;
  left: 0;
  bottom: 0;
  height: 2px;
  width: 100%;
  background: linear-gradient(90deg, transparent, var(--brand), #7FB6FF, transparent);
  background-size: 200% 100%;
  animation: incoming-shimmer 1.2s linear infinite;
}

.stage-incoming[data-phase='arrived'] {
  box-shadow: inset 0 0 0 1px rgba(0, 168, 112, .8);
}

@keyframes incoming-shimmer {
  from {
    background-position: 200% 0;
  }
  to {
    background-position: -200% 0;
  }
}

/* One faint diagonal sheen across the picture when a look is sent. */
.stage::after {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background: linear-gradient(115deg, transparent 35%, rgba(255, 255, 255, .14) 50%, transparent 65%);
  transform: translateX(-120%);
  opacity: 0;
}

.stage.is-switching::after {
  animation: stage-sheen 1.4s ease-out 1;
}

@keyframes stage-sheen {
  0% {
    transform: translateX(-120%);
    opacity: 1;
  }
  100% {
    transform: translateX(120%);
    opacity: 1;
  }
}

.stage-peek {
  position: absolute;
  right: 10px;
  bottom: 10px;
  z-index: 3;
  display: none;
  min-height: 36px;
  padding: 6px 12px;
  border-radius: var(--radius-pill);
  border: 1px solid rgba(255, 255, 255, .35);
  background: rgba(10, 15, 30, .7);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.stage.is-comparable .stage-peek {
  display: block;
}

/* A caption sits at the bottom too; the peek button yields to it. */
.stage:has(.stage-caption:not([hidden])) .stage-peek {
  bottom: auto;
  top: 44px;
  right: 10px;
}

.start-look-thumb {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid rgba(255, 255, 255, .85);
  flex: none;
}

#btn-start span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Confirmation sheet ───────────────────────────────────────────────────── */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(10, 15, 30, .45);
  padding: 16px;
}

.sheet {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: var(--shadow-3);
  display: grid;
  gap: 10px;
}

.sheet h2 {
  font-size: 16px;
  font-weight: 650;
}

.sheet p {
  font-size: 14px;
  color: var(--fg2);
}

.sheet-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-top: 4px;
}

/* ── Phones, while live: the gallery becomes a bottom sheet ──────────────── */

@media (max-width: 879px) {
  body.is-live .gallery {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    max-height: 55dvh;
    overflow-y: auto;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    padding-bottom: max(14px, env(safe-area-inset-bottom));
    box-shadow: 0 -12px 32px rgba(15, 31, 61, .22);
    transform: translateY(105%);
    transition: transform .25s ease-out;
    visibility: hidden;
  }

  body.is-live.sheet-open .gallery {
    transform: none;
    visibility: visible;
  }

  body.is-live .gallery-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
}

.btn-looks {
  display: inline-flex;
}

/* ── Wide screens ─────────────────────────────────────────────────────────── */

@media (min-width: 560px) {
  .effect-gallery {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .gallery-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .sheet-actions {
    grid-template-columns: 1fr 1fr;
  }

  .sheet-backdrop {
    align-items: center;
  }

  .home-hero h1 {
    font-size: 36px;
  }
}

@media (min-width: 880px) {
  .topbar {
    padding: 12px 24px;
  }

  .studio-main {
    grid-template-columns: minmax(0, 1fr) 372px;
    padding: 18px 24px 32px;
    gap: 20px;
  }

  .controls {
    max-height: calc(100dvh - 90px);
    overflow-y: auto;
    padding-right: 4px;
    position: sticky;
    top: 74px;
  }

  /* Still sticky, now to the bottom of the scrolling column rather than the
     viewport. It used to be static here, which was fine while a tab held a
     dozen looks; with the full catalog the Characters tab alone is ~1400px and
     Go live landed around y=1730 on a 1280×800 laptop — below the fold on the
     screen a presenter drives the demo from. */
  .actions {
    padding: 12px 0 4px;
    box-shadow: 0 -12px 16px -12px rgba(15, 31, 61, .22);
  }

  /* The column has room for three; the sheet button has no job here. */
  .gallery-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .btn-looks {
    display: none !important;
  }

  .debug-panel {
    grid-template-columns: 1fr 320px;
    padding: 0 24px;
  }

  .home {
    padding: 48px 24px 72px;
  }
}

@media (min-width: 1180px) {
  .effect-gallery {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: .001ms !important;
    transition-duration: .001ms !important;
  }
}
