/* The manual harness for X (public/x-harness.js, docs/X_MANUAL_HARNESS.md).
   Uses the app's theme tokens from style.css, so it follows light and dark. */

html.xh-open,
html.xh-open body { overflow: hidden; }

.xh-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  justify-content: center;
  overflow-y: auto;
  /* Opaque, in the theme's own background, so every theme token reads. */
  background: var(--bg);
  padding: 20px 16px 40px;
}

.xh-shell {
  width: 100%;
  max-width: 460px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  color: var(--text);
}

.xh-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.xh-kicker {
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.xh-title {
  margin: 2px 0 0;
  font-size: 20px;
  line-height: 1.2;
  color: var(--text);
}

.xh-sub {
  margin: 4px 0 0;
  font-size: 12.5px;
  color: var(--text-secondary);
}

.xh-close {
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}
.xh-close:hover { border-color: var(--border-hover); }

/* ── The stack ─────────────────────────────────────────────────────── */
.xh-stage {
  position: relative;
  display: flex;
  justify-content: center;
}

.xh-stack {
  position: relative;
  /* The body is zoomed 1.25 above 768px (style.css), so 50vh here is about
     62% of the window. */
  width: min(100%, calc(50vh * 9 / 16));
  aspect-ratio: 9 / 16;
}

.xh-card {
  position: absolute;
  inset: 0;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: #000;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-glass);
  transition: transform 380ms cubic-bezier(0.2, 0.8, 0.2, 1), opacity 380ms ease;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
}

.xh-depth-0 { z-index: 3; cursor: grab; }
.xh-depth-1 { z-index: 2; transform: translateY(10px) scale(0.95); opacity: 0.7; }
.xh-depth-2 { z-index: 1; transform: translateY(20px) scale(0.9); opacity: 0.4; }
.xh-depth-1 .xh-video,
.xh-depth-2 .xh-video { visibility: hidden; }

.xh-card.xh-dragging { transition: none; cursor: grabbing; }

.xh-card.xh-out-right {
  transform: translateX(140%) rotate(16deg) !important;
  opacity: 0;
}
.xh-card.xh-out-left {
  transform: translateX(-140%) rotate(-16deg) !important;
  opacity: 0;
}

.xh-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  background: #000;
}

.xh-card.xh-loading::after {
  content: "Loading video…";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #ddd;
  font-size: 13px;
}
.xh-card.xh-broken .xh-video { opacity: 0.2; }

.xh-name {
  position: absolute;
  left: 10px;
  bottom: 10px;
  margin: 0;
  padding: 3px 8px;
  border-radius: var(--radius-full);
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 11.5px;
  pointer-events: none;
}

.xh-sound {
  position: absolute;
  right: 10px;
  top: 10px;
  padding: 5px 10px;
  border-radius: var(--radius-full);
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 12px;
  cursor: pointer;
}

.xh-stamp {
  position: absolute;
  top: 28px;
  padding: 4px 12px;
  border: 3px solid;
  border-radius: 8px;
  font-weight: 800;
  font-size: 26px;
  letter-spacing: 0.08em;
  pointer-events: none;
  opacity: 0;
  transition: opacity 120ms ease;
}
.xh-stamp-queue {
  left: 18px;
  color: var(--success);
  border-color: var(--success);
  transform: rotate(-14deg);
  opacity: var(--xh-queue, 0);
}
.xh-stamp-skip {
  right: 18px;
  color: var(--danger);
  border-color: var(--danger);
  transform: rotate(14deg);
  opacity: var(--xh-skip, 0);
}
.xh-out-right .xh-stamp-queue,
.xh-out-left .xh-stamp-skip { opacity: 1; }

.xh-nudge { animation: xh-nudge 360ms ease; }
@keyframes xh-nudge {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-8px); }
  75% { transform: translateX(8px); }
}

.xh-empty {
  width: 100%;
  min-height: 180px;
  padding: 28px 20px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  text-align: center;
}
.xh-done-title { margin: 0 0 6px; font-size: 18px; color: var(--text); }
.xh-done-sub { margin: 0; color: var(--text-secondary); font-size: 13.5px; line-height: 1.5; }

.xh-picker { display: grid; gap: 10px; text-align: left; }
.xh-pick {
  display: grid;
  gap: 2px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--glass);
  color: var(--text);
  cursor: pointer;
  text-align: left;
}
.xh-pick span { font-size: 12px; color: var(--text-secondary); }
.xh-pick:hover { border-color: var(--border-hover); }

/* ── Caption ───────────────────────────────────────────────────────── */
.xh-compose {
  display: grid;
  gap: 8px;
  padding: 12px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--surface);
}
.xh-compose[hidden] { display: none; }

/* What's said in the video, to read instead of listen. */
.xh-transcript {
  padding: 10px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--glass-border);
  background: var(--glass);
}
.xh-transcript[hidden] { display: none; }
.xh-transcript-label {
  margin: 0 0 4px;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}
/* Only the words scroll; the label stays put. */
.xh-transcript-text {
  max-height: 7.5em;
  overflow-y: auto;
  margin: 0;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  white-space: pre-line;
  overflow-wrap: anywhere;
}

.xh-caption {
  width: 100%;
  box-sizing: border-box;
  min-height: 72px;
  max-height: 40vh;
  overflow-y: auto;
  resize: vertical;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-2);
  color: var(--text);
  font: inherit;
  font-size: 15px;
  line-height: 1.45;
}
.xh-caption:focus { outline: none; border-color: var(--border-focus); box-shadow: 0 0 0 3px var(--accent-dim); }

.xh-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 12px;
  font-size: 11.5px;
  color: var(--text-muted);
}
.xh-count { font-variant-numeric: tabular-nums; color: var(--text-secondary); }
.xh-count.xh-over { color: var(--danger); font-weight: 700; }
.xh-link-hint { color: var(--warm); }
.xh-keys { margin-left: auto; }

.xh-actions { display: flex; gap: 8px; }
.xh-btn {
  flex: 1;
  min-height: 40px;
  padding: 8px 10px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--glass);
  color: var(--text);
  font: inherit;
  font-size: 13.5px;
  cursor: pointer;
}
.xh-btn:hover:not(:disabled) { border-color: var(--border-hover); }
.xh-btn:disabled { opacity: 0.45; cursor: default; }
.xh-btn-queue {
  flex: 1.4;
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg);
  font-weight: 700;
}
.xh-btn-queue:hover:not(:disabled) { background: var(--accent-hover); }

.xh-error { margin: 0; min-height: 1em; font-size: 12.5px; color: var(--danger); }
.xh-error:empty { display: none; }

/* ── Up next ───────────────────────────────────────────────────────── */
.xh-queue {
  padding: 12px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--surface);
}
.xh-queue[hidden] { display: none; }
.xh-queue-title { margin: 0 0 8px; font-size: 13px; letter-spacing: 0.04em; color: var(--text-secondary); }

.xh-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.xh-none { font-size: 12.5px; color: var(--text-muted); }

.xh-row {
  display: grid;
  gap: 4px;
  padding: 8px 10px;
  border-radius: var(--radius-md);
  background: var(--glass);
  border: 1px solid var(--glass-border);
}
.xh-row-pending { opacity: 0.7; }
.xh-row-main { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 10px; font-size: 12.5px; }
.xh-row-name { font-weight: 600; color: var(--text); overflow-wrap: anywhere; }
.xh-row-state { color: var(--text-secondary); }
.xh-state-submitted { color: var(--success); }
.xh-state-failed-safe,
.xh-state-ambiguous { color: var(--danger); }
.xh-row-caption {
  margin: 0;
  font-size: 12.5px;
  color: var(--text-secondary);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.xh-row-actions { display: flex; gap: 12px; justify-content: flex-end; font-size: 12px; }
.xh-row-actions:empty { display: none; }
.xh-row-actions a { color: var(--accent); }

.xh-link-btn {
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  font-size: 12.5px;
  text-decoration: underline;
  cursor: pointer;
}

.xh-done { margin-top: 10px; }
.xh-done summary { cursor: pointer; font-size: 12.5px; color: var(--text-secondary); }
.xh-done .xh-list { margin-top: 8px; }

.xh-toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  z-index: 2001;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: calc(100vw - 32px);
  padding: 10px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface-raised);
  color: var(--text);
  font-size: 13px;
  box-shadow: var(--shadow-glass-sm);
}
.xh-toast[hidden] { display: none; }

/* Wide screens: the video on the left at full height, the caption and the
   queue beside it, so nothing needs a scroll. */
/* From 960px of window (768 CSS px at the body's 1.25 zoom) the video sits
   beside a 340px column; the video narrows to fit (see .xh-stack below). */
@media (min-width: 960px) {
  .xh-overlay { align-items: flex-start; padding: 24px; }
  .xh-shell {
    max-width: 1000px;
    display: grid;
    grid-template-columns: auto minmax(340px, 440px);
    grid-template-areas: "stage head" "stage compose" "stage queue";
    grid-template-rows: auto auto 1fr;
    column-gap: 32px;
    row-gap: 14px;
    align-items: start;
  }
  .xh-head { grid-area: head; }
  .xh-stage { grid-area: stage; }
  .xh-compose { grid-area: compose; }
  /* The shell is the window's height (80vh at the body's 1.25 zoom, less
     the overlay's padding); the queue takes whatever the transcript and
     caption leave and scrolls inside it. */
  .xh-shell { height: calc(80vh - 48px); grid-template-rows: auto auto minmax(0, 1fr); }
  .xh-queue {
    grid-area: queue;
    min-height: 0;
    max-height: 100%;
    overflow-y: auto;
  }
  /* As tall as the window allows, and never wider than what the 340px
     column, the 32px gap and the 48px of padding leave (80vw is the window
     at the 1.25 zoom). */
  .xh-stack { width: min(calc(min(80vh - 48px, 760px) * 9 / 16), calc(80vw - 420px)); }
}

/* Short wide windows (720 to 820px tall): a tighter right column, so the
   caption box and buttons still fit beside the video. */
@media (min-width: 960px) and (max-height: 820px) {
  .xh-transcript-text { max-height: 4.5em; font-size: 14px; }
  .xh-caption { min-height: 56px; }
  .xh-keys { display: none; }
  .xh-btn { min-height: 34px; padding: 6px 8px; }
  .xh-shell { row-gap: 10px; }
  .xh-compose { gap: 6px; padding: 10px; }
}

@media (max-width: 480px) {
  .xh-overlay { padding: 12px 16px 32px; }
  /* Three lines on a phone and a smaller video, so the caption box stays on
     the first screen. */
  .xh-transcript-text { max-height: 4.5em; font-size: 14px; }
  .xh-stack { width: min(100%, calc(42vh * 9 / 16)); }
  .xh-keys { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .xh-card { transition-duration: 1ms; }
  .xh-nudge { animation: none; }
}

.xh-open-btn { margin-top: 10px; }
