:root {
  color-scheme: light;
  --bg: #f6f7fb;
  --panel: #ffffff;
  --panel-soft: #f2f5f8;
  --line: #d9e0ea;
  --text: #17202a;
  --muted: #667085;
  --accent: #2f7f8f;
  --accent-soft: #dff5f4;
  --accent-warm: #b8603d;
  --accent-warm-soft: #f7e5dd;
  --green: #2d8a57;
  --green-soft: #dff4e7;
  --red: #b93838;
  --red-soft: #f8dddd;
  --amber: #a36b1f;
  --amber-soft: #f8ecd2;
  --blue: #2d5f9a;
  --blue-soft: #e0ebfa;
  --shadow: 0 8px 28px rgba(23, 32, 42, 0.05);
  --radius: 12px;
  --button-height: 44px;
}

* { box-sizing: border-box; }

.hidden {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(47, 127, 143, 0.07), transparent 34%),
    linear-gradient(180deg, #f3f6f9 0%, #f6f8fb 52%, #f8f9fc 100%);
  background-attachment: fixed;
}

.library-topbar {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 26px 36px 18px;
}

.library-topbar-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 12px;
}

.library-brand h1 {
  margin: 4px 0 8px;
  font-size: clamp(28px, 3vw, 36px);
  line-height: 1.05;
}

.library-brand p {
  margin: 0;
  max-width: 640px;
  color: var(--muted);
}

.brand-eyebrow {
  display: inline-flex;
  padding: 6px 10px;
  border-radius: var(--radius);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.app-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.language-switch {
  display: inline-flex;
  align-items: center;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.72);
}

.lang-button {
  min-width: 44px;
  min-height: 36px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 800;
}

.lang-button.active {
  background: var(--text);
  color: #fff;
}

.nav-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--button-height);
  padding: 0 16px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  color: var(--text);
  text-decoration: none;
  background: rgba(255, 255, 255, 0.72);
  font-weight: 700;
}

.nav-pill.active {
  background: var(--text);
  border-color: var(--text);
  color: #fff;
}

.auth-button {
  min-height: var(--button-height);
  display: inline-flex;
  align-items: center;
  gap: 10px;
  max-width: 240px;
  padding: 4px 12px 4px 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
  cursor: pointer;
  font-weight: 700;
}

.auth-button.signed-in {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.auth-button span:last-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.auth-avatar-shell,
.profile-preview-shell {
  position: relative;
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  overflow: hidden;
  border-radius: 999px;
  background: var(--panel-soft);
  color: var(--accent);
  font-weight: 800;
}

.auth-avatar-shell {
  width: 34px;
  height: 34px;
}

.auth-avatar,
.profile-preview {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.auth-avatar-fallback {
  font-size: 13px;
}

.library-shell {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 20px;
  padding: 0 36px 36px;
}

.library-sidebar,
.library-content {
  min-width: 0;
}

.sidebar-card,
.card,
.empty-state {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.sidebar-card {
  padding: 18px;
  margin-bottom: 16px;
}

.field-label,
.section-head h2,
.section-head h3 {
  font-weight: 700;
}

.search-input {
  width: 100%;
  margin-top: 8px;
  min-height: var(--button-height);
  padding: 0 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: #fff;
  font-size: 15px;
}

.status-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
  align-items: center;
}

.status-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  border-radius: var(--radius);
  min-height: var(--button-height);
  padding: 0 14px;
  cursor: pointer;
  font-weight: 600;
}

.status-chip.active {
  background: var(--text);
  border-color: var(--text);
  color: #fff;
}

.stats-card {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.stat-box {
  background: var(--panel-soft);
  border-radius: var(--radius);
  padding: 14px 12px;
}

.stat-box strong {
  display: block;
  margin-top: 6px;
  font-size: 22px;
}

.stat-label,
.result-count,
.meta-line,
.json-hint,
.soft-empty {
  color: var(--muted);
}

.sign-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: calc(100vh - 330px);
  overflow: auto;
  padding-right: 2px;
}

.sign-item {
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  border-left: 4px solid transparent;
  background: #fff;
  border-radius: var(--radius);
  padding: 12px 14px;
  cursor: pointer;
  transition: all 0.22s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Loading skeleton shown while the label catalog is being fetched */
.skeleton-item {
  border: 1px solid var(--line);
  border-left: 4px solid var(--panel-soft);
  border-radius: var(--radius);
  padding: 12px 14px;
  background: #fff;
}

.skeleton-line {
  height: 12px;
  border-radius: 6px;
  background: linear-gradient(
    90deg,
    var(--panel-soft) 25%,
    #e9eef3 37%,
    var(--panel-soft) 63%
  );
  background-size: 400% 100%;
  animation: skeleton-shimmer 1.3s ease-in-out infinite;
}

.skeleton-line.short {
  width: 45%;
  margin-top: 8px;
  height: 10px;
}

@keyframes skeleton-shimmer {
  0% { background-position: 100% 50%; }
  100% { background-position: 0 50%; }
}

@media (prefers-reduced-motion: reduce) {
  .skeleton-line { animation: none; }
}

.sign-item:hover {
  border-color: rgba(47, 127, 143, 0.3) !important;
  border-left-color: rgba(47, 127, 143, 0.6) !important;
  background-color: rgba(47, 127, 143, 0.03) !important;
  box-shadow: 0 6px 16px rgba(47, 127, 143, 0.06) !important;
  transform: translateY(-1px);
}

.sign-item.active {
  border-color: var(--accent) !important;
  border-left-color: var(--accent) !important;
  background: var(--accent-soft) !important;
  box-shadow: 0 6px 18px rgba(47, 127, 143, 0.12) !important;
  transform: none !important;
}

.sign-item.active .sign-item-title {
  color: var(--accent) !important;
}

.list-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-top: 14px;
  margin-top: 14px;
  border-top: 1px solid var(--line);
}

.list-footer .soft-button {
  flex: 0 0 auto;
}

.sign-item-title {
  font-size: 16px;
  font-weight: 700;
}

.sign-item-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
  font-size: 13px;
  color: var(--muted);
}

.tiny-pill,
.status-pill,
.sign-id-pill {
  display: inline-flex;
  align-items: center;
  border-radius: var(--radius);
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 700;
}

.tiny-pill.chosen,
.status-pill.chosen,
.tiny-pill.paired,
.status-pill.paired {
  background: var(--green-soft);
  color: var(--green);
}

.tiny-pill.hybrid,
.status-pill.hybrid,
.tiny-pill.in_editor,
.status-pill.in_editor {
  background: #e0f2fe;
  color: #0369a1;
}

.tiny-pill.unpublished,
.status-pill.unpublished,
.status-pill.needs_review,
.tiny-pill.needs_choice,
.status-pill.needs_choice,
.tiny-pill.suggested,
.status-pill.suggested {
  background: var(--accent-warm-soft);
  color: var(--accent-warm);
}

.tiny-pill.broken_choice,
.status-pill.broken_choice,
.tiny-pill.invalid_json,
.status-pill.invalid_json,
.tiny-pill.missing_video,
.status-pill.missing_video {
  background: var(--red-soft);
  color: var(--red);
}

.tiny-pill.playable,
.status-pill.playable {
  background: var(--blue-soft);
  color: var(--blue);
}

.tiny-pill.correct,
.status-pill.correct {
  background: var(--green-soft);
  color: var(--green);
}

.tiny-pill.pending,
.status-pill.pending {
  background: var(--accent-warm-soft);
  color: var(--accent-warm);
}

.tiny-pill.wrong,
.status-pill.wrong {
  background: var(--red-soft);
  color: var(--red);
}

.tiny-pill.label-type.word {
  background: var(--blue-soft);
  color: var(--blue);
}

.tiny-pill.label-type.sentence {
  background: #ede9fe;
  color: #6d28d9;
}

.type-filters {
  margin-top: 4px;
}

.empty-state {
  min-height: 520px;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 32px;
}

.detail-view {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card {
  padding: 20px;
}

.detail-hero {
  display: grid;
  grid-template-columns: minmax(0, 6fr) minmax(0, 4fr);
  gap: 24px;
  align-items: start;
}

.detail-hero > :first-child,
.hero-summary {
  min-width: 0;
}

.hero-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.detail-hero h2 {
  margin: 0;
  font-size: clamp(26px, 3vw, 34px);
}

.hero-actions {
  display: grid;
  grid-template-columns: minmax(220px, 3fr) minmax(108px, 1fr);
  gap: 16px;
  align-items: start;
  width: 100%;
  min-width: 0;
  align-self: center;
}

.hero-compare-actions {
  width: 100%;
  min-width: 0;
  align-self: center;
}

.detail-hero:has(> .hero-compare-actions) {
  grid-template-columns: minmax(0, 6fr) minmax(220px, 3fr) minmax(108px, 1fr);
}

.detail-hero:has(> .hero-compare-actions) .hero-actions {
  display: block;
}

.avatar-model-picker {
  display: grid;
  gap: 12px;
  width: 100%;
  min-width: 0;
}

.avatar-model-picker .field-label {
  display: block;
  margin: 0;
}

.library-select {
  width: 100%;
  min-width: 0;
  min-height: var(--button-height);
  padding: 0 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  font: inherit;
}

.avatar-model-picker .json-hint {
  font-size: 12px;
}

#previewActiveBtn {
  width: 100%;
  min-width: 108px;
  white-space: nowrap;
}

.action-link,
.soft-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--button-height);
  padding: 0 16px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
  font-weight: 600;
}

.soft-button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.soft-button.success {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}

.soft-button.danger {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
}

.soft-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

/* Loading spinner shown on a button while its action is still preparing
   (e.g. the Play button waiting on motion/avatar to load before it unlocks). */
.soft-button.is-loading::before {
  content: "";
  width: 14px;
  height: 14px;
  margin-right: 8px;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-top-color: transparent;
  opacity: 0.85;
  animation: lib-button-spin 0.7s linear infinite;
  flex: none;
}

.soft-button.is-loading:disabled {
  /* Keep it looking active (not greyed out) while it spins. */
  opacity: 1;
  cursor: wait;
}

@keyframes lib-button-spin {
  to { transform: rotate(360deg); }
}

.action-link.disabled {
  pointer-events: none;
  opacity: 0.45;
}

.preview-grid {
  display: grid;
  /* Source Video : Skeleton = 60 : 40 (Source Video is the wider left card). */
  grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
  gap: 16px;
  align-items: stretch;
}

/* Keep the Source Video and Avatar frames identical in size so the row looks
   balanced. The video shell fills its card via flex; make the avatar shell use
   the same fill model instead of locking to its own 16:10 aspect ratio. */
.preview-grid .avatar-frame-shell,
.preview-grid .video-preview-shell {
  flex: 1;
  aspect-ratio: auto;
  min-height: 360px;
}

.detail-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
}

.samples-grid {
  grid-template-columns: 1fr;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.section-head h2,
.section-head h3 {
  margin: 0;
}

/* Avatar panel view toggle: raw-landmark skeleton (default) <-> VRM avatar. */
.player-view-toggle {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.4;
  color: var(--text, #1f2937);
  background: var(--surface-2, #f1f5f9);
  border: 1px solid var(--border, #d7dde5);
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.player-view-toggle:hover { background: var(--surface-3, #e2e8f0); }
.player-view-toggle[aria-pressed="true"] {
  background: var(--accent-soft, #e0ecff);
  border-color: var(--accent, #4f7cff);
}

.info-grid,
.motion-grid,
.avatar-meta-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin: 0;
}

.compact-grid {
  grid-template-columns: 1fr;
}

.info-grid div,
.motion-grid div,
.avatar-meta-grid div {
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--panel-soft);
}

.info-grid dt,
.motion-grid dt,
.avatar-meta-grid dt {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0;
  color: var(--muted);
}

.info-grid dd,
.motion-grid dd,
.avatar-meta-grid dd {
  margin: 6px 0 0;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.avatar-preview-card,
.video-card {
  display: flex;
  flex-direction: column;
}

.avatar-motion-status {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  max-width: 52%;
  padding: 6px 10px;
  border-radius: var(--radius);
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.avatar-motion-status.ok {
  background: var(--green-soft);
  color: var(--green);
}

.avatar-motion-status.error {
  background: var(--red-soft);
  color: var(--red);
}

.avatar-motion-status.muted {
  background: var(--panel-soft);
  color: var(--muted);
}

.avatar-frame-shell {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 10;
  min-height: 360px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #eef2f7;
}

/* "Currently editing <hand>" badge, centered over the top of the avatar box (edit mode only) */
.pe-hand-indicator {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 6;
  padding: 5px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  background: var(--pe-left);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.28);
  pointer-events: none;
  white-space: nowrap;
}
.pe-hand-indicator.is-left { background: var(--pe-left); }
.pe-hand-indicator.is-right { background: var(--pe-right); }
.pe-hand-indicator.hidden { display: none; }

.library-avatar-frame {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  pointer-events: auto !important;
}

.avatar-control-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 14px 0;
}

.avatar-meta-grid {
  grid-template-columns: minmax(0, 0.7fr) minmax(0, 1fr);
}

.avatar-path-cell {
  grid-column: 1 / -1;
}

.video-preview-shell {
  position: relative;
  display: grid;
  flex: 1;
  min-height: 360px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #111827;
  place-items: center;
}

.preview-video {
  width: 100%;
  height: 100%;
  max-height: 100%;
  border-radius: 0;
  background: #000;
  object-fit: contain;
}

.video-card .soft-empty:not(.hidden) + .video-preview-shell,
.video-card .soft-empty:not(.hidden) + .multicam {
  display: none;
}

/* --- Source Video multicam: three angles at once ---------------------------
   Left column = two stacked side cameras (default L over R); right column = one
   larger camera (default C) that drives the skeleton player. Clicking a side
   camera's button promotes it into the big slot (and the skeleton follows). */
.multicam {
  display: grid;
  grid-template-columns: minmax(0, 0.82fr) minmax(0, 1.6fr);
  gap: 10px;
  flex: 1;
  min-height: 360px;
}

.multicam-side {
  display: grid;
  grid-template-rows: 1fr 1fr;
  gap: 10px;
  min-height: 0;
}

.multicam-cell,
.multicam-main {
  position: relative;
  display: grid;
  place-items: center;
  overflow: hidden;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #111827;
}

.multicam-cell .preview-video,
.multicam-main .preview-video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}

.multicam-caption {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 5;
  max-width: calc(100% - 16px);
  padding: 3px 9px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: #fff;
  background: rgba(17, 24, 39, 0.72);
  border-radius: 999px;
  pointer-events: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.multicam-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 5;
  padding: 3px 9px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #fff;
  background: var(--accent, #4f7cff);
  border-radius: 999px;
  pointer-events: none;
  white-space: nowrap;
}

/* Small icon button (🦴) to promote a side camera into the big/skeleton slot. */
.multicam-promote {
  position: absolute;
  bottom: 6px;
  right: 6px;
  z-index: 6;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  padding: 0;
  font-size: 13px;
  line-height: 1;
  color: #fff;
  background: rgba(17, 24, 39, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s ease;
}

.multicam-promote:hover {
  background: rgba(17, 24, 39, 0.92);
}

.multicam-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  color: rgba(255, 255, 255, 0.55);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.03em;
}

.multicam-cell.is-empty {
  border-style: dashed;
}

.table-shell {
  overflow: auto;
}

.sample-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 780px;
}

.sample-table th,
.sample-table td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.sample-table tbody tr.published-row {
  background: rgba(45, 138, 87, 0.06);
}

.sample-table tbody tr.suggested-row {
  background: rgba(184, 96, 61, 0.07);
}

.sample-table tbody tr.broken-row {
  background: rgba(185, 56, 56, 0.05);
}

.sample-action {
  min-height: 34px;
  padding: 0 12px;
}

/* Keep the per-word "Download JSON" button pinned to the right of the
   representative-sample section head, with the badge staying by the title. */
#downloadActiveJsonBtn {
  margin-left: auto;
}

.sample-action-cell {
  vertical-align: middle;
  white-space: nowrap;
}

.sample-action-stack {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.json-card {
  padding-bottom: 8px;
}

.json-viewer {
  margin: 0;
  max-height: 420px;
  overflow: auto;
  padding: 18px;
  border-radius: var(--radius);
  background: #1f2430;
  color: #f6f1e8;
  font-size: 13px;
  line-height: 1.55;
}

.preview-modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 28px;
}

.preview-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(23, 32, 42, 0.58);
}

.preview-surface {
  position: relative;
  z-index: 1;
  width: min(1280px, 100%);
  max-height: calc(100vh - 56px);
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow: auto;
  padding: 20px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: 0 24px 70px rgba(23, 32, 42, 0.28);
}

.preview-header {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
}

.preview-header-copy {
  display: grid;
  gap: 10px;
  min-width: 0;
  flex: 1 1 auto;
}

.preview-header-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: flex-start;
  gap: 10px;
}

.preview-choose-button {
  flex: 0 0 auto;
}

.preview-header h2 {
  margin: 0 0 6px;
  font-size: clamp(24px, 3vw, 34px);
}

.icon-button {
  width: var(--button-height);
  height: var(--button-height);
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
  cursor: pointer;
  font-size: 20px;
  font-weight: 700;
}

.modal-preview-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
  align-items: stretch;
}

/* Match the detail view: keep both modal frames the same height. */
.modal-preview-grid .avatar-frame-shell,
.modal-preview-grid .video-preview-shell {
  flex: 1;
  aspect-ratio: auto;
}

.preview-panel {
  min-width: 0;
}

.preview-video-stack {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.preview-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
  padding-top: 4px;
}

.preview-modal.sample-mode .preview-surface {
  width: min(920px, 100%);
}

.preview-modal.sample-mode .modal-preview-grid {
  grid-template-columns: 1fr;
}

.auth-modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-surface {
  position: relative;
  z-index: 1;
  width: min(440px, 100%);
  max-height: calc(100vh - 48px);
  overflow: auto;
  display: grid;
  gap: 18px;
  padding: 20px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: 0 24px 70px rgba(23, 32, 42, 0.28);
}

.profile-surface {
  width: min(560px, 100%);
}

.auth-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}

.auth-modal-header h2 {
  margin: 0;
  font-size: 24px;
}

.auth-title-block {
  display: grid;
  gap: 6px;
}

.auth-subcopy,
.auth-note {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.auth-join-surface {
  width: min(560px, 100%);
}

.auth-form {
  display: grid;
  gap: 14px;
}

.auth-field {
  display: grid;
  gap: 8px;
}

.auth-status {
  min-height: 22px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.auth-status.ok {
  color: var(--green);
}

.auth-status.error {
  color: var(--red);
}

.register-photo-panel,
.register-identity-panel {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  background: var(--panel-soft);
}

.auth-field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

@media (max-width: 420px) {
  .auth-field-row {
    grid-template-columns: 1fr;
  }
}

.auth-form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
  padding-top: 4px;
}

.split-actions {
  justify-content: space-between;
}

.profile-preview-row {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.profile-preview-shell {
  width: 76px;
  height: 76px;
}

.profile-preview-fallback {
  font-size: 22px;
}

.upload-button {
  min-width: 138px;
}

.register-photo-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.camera-shell {
  overflow: hidden;
  border: 1px solid var(--line);
  background: #0f172a;
}

.camera-preview {
  display: block;
  width: 100%;
  max-height: 280px;
  object-fit: cover;
}

@media (max-width: 1120px) {
  .library-shell,
  .detail-grid,
  .modal-preview-grid {
    grid-template-columns: 1fr;
  }

  .library-topbar-main {
    display: flex;
    flex-direction: column;
  }

  .topbar-actions {
    justify-content: flex-start;
    width: 100%;
  }

  .auth-button {
    max-width: 100%;
  }

  .sign-list {
    max-height: none;
  }
}

@media (max-width: 720px) {
  .library-topbar,
  .library-shell {
    padding-left: 18px;
    padding-right: 18px;
  }

  .library-topbar {
    flex-direction: column;
    padding-top: 24px;
  }

  .detail-hero {
    grid-template-columns: 1fr;
    align-items: flex-start;
  }

  .hero-compare-actions {
    align-self: stretch;
  }

  .hero-actions {
    align-self: stretch;
  }

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

  .stats-card,
  .info-grid,
  .motion-grid,
  .avatar-meta-grid {
    grid-template-columns: 1fr;
  }

  .avatar-frame-shell,
  .video-preview-shell {
    min-height: 320px;
  }

  .avatar-motion-status {
    max-width: 100%;
  }

  .preview-modal {
    padding: 12px;
  }

  .preview-surface {
    max-height: calc(100vh - 24px);
  }

  .auth-modal {
    padding: 12px;
  }

  .auth-surface {
    max-height: calc(100vh - 24px);
  }

  .register-photo-panel .profile-preview-row {
    align-items: flex-start;
  }

  .split-actions {
    justify-content: flex-start;
  }
}

body {
  background:
    radial-gradient(circle at top left, rgba(47, 127, 143, 0.14), transparent 28%),
    radial-gradient(circle at top right, rgba(184, 96, 61, 0.1), transparent 24%),
    linear-gradient(180deg, #f8f3ea 0%, #eff4f7 46%, #f7f8fb 100%);
}

.library-topbar {
  gap: 22px;
  padding: 32px 34px 18px;
}

.library-topbar-main {
  align-items: flex-start;
}

.library-brand h1 {
  margin: 8px 0 10px;
  font-size: clamp(40px, 4.6vw, 62px);
  letter-spacing: -0.04em;
}

.library-brand p {
  max-width: 760px;
  font-size: 16px;
  line-height: 1.55;
}

.brand-eyebrow {
  border-radius: 999px;
  padding: 8px 12px;
  letter-spacing: 0.08em;
}

.library-shell {
  grid-template-columns: minmax(360px, 450px) minmax(0, 1fr);
  gap: 24px;
  padding: 0 34px 34px;
  align-items: start;
}

.library-sidebar {
  position: sticky;
  top: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: calc(100vh - 24px);
}

.library-content {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* Desktop Dual-Pane Layout */
@media (min-width: 1181px) {
  body.library-mode-index .library-sidebar,
  body.library-mode-detail .library-sidebar {
    display: flex !important;
  }
  body.library-mode-index .library-content,
  body.library-mode-detail .library-content {
    display: flex !important;
    width: 100%;
  }
  .library-shell {
    grid-template-columns: minmax(360px, 450px) minmax(0, 1fr) !important;
  }

  .library-sidebar {
    top: 8px !important;
    max-height: calc(100vh - 16px) !important;
    gap: 8px !important;
  }

  /* Compact Sidebar Optimizations to prevent squishing on 100% zoom desktop screens */
  .control-card {
    padding: 10px 14px !important;
  }
  .control-card .sidebar-card-head {
    display: flex !important;
    align-items: center !important;
    justify-content: flex-end !important;
    margin-bottom: 4px !important;
  }
  .control-card .sidebar-card-head > div:first-child {
    display: none !important;
  }
  .control-card #refreshLibraryBtn {
    min-height: 28px !important;
    padding: 0 10px !important;
    font-size: 12px !important;
    border-radius: 6px !important;
  }
  .control-card .section-copy {
    display: none !important;
  }
  .control-card .field-label {
    display: none !important;
  }
  .control-card .search-input {
    min-height: 32px !important;
    font-size: 13px !important;
    margin-top: 4px !important;
    padding: 0 10px !important;
  }
  .control-card .status-filters {
    margin-top: 6px !important;
    gap: 4px !important;
  }
  .control-card .status-chip {
    min-height: 28px !important;
    padding: 0 8px !important;
    font-size: 12px !important;
    border-radius: 6px !important;
  }
  .status-board-card {
    grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
    gap: 6px !important;
    padding: 8px 10px !important;
  }
  .stat-box {
    min-height: auto !important;
    padding: 6px 4px !important;
    border-radius: 8px !important;
    text-align: center !important;
  }
  .stat-box strong {
    font-size: 16px !important;
    margin-top: 1px !important;
    display: block !important;
  }
  .stat-label {
    font-size: 10px !important;
    display: block !important;
    white-space: nowrap !important;
  }
  .list-card {
    padding: 12px 14px !important;
  }
  .list-card .section-copy {
    display: none !important;
  }
  .list-card .section-head {
    margin-bottom: 6px !important;
  }
  .sign-item {
    padding: 12px !important;
    border-radius: 12px !important;
  }
  .sign-item-title {
    font-size: 15px !important;
  }
  .sign-item-key {
    padding: 3px 7px !important;
    font-size: 10px !important;
  }
  .sign-item-meta {
    margin-top: 8px !important;
    font-size: 12px !important;
  }
  .sign-item-meta > span {
    min-height: 24px !important;
    padding: 0 8px !important;
  }
  .sign-item-note {
    margin-top: 8px !important;
    padding-top: 8px !important;
    font-size: 12px !important;
  }

  /* Right-Pane Detail Area Height Compaction & Player Focus */
  .detail-hero {
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    padding: 10px 18px !important;
    gap: 16px !important;
    border-radius: 14px !important;
  }
  .hero-summary {
    display: flex !important;
    align-items: center !important;
    gap: 14px !important;
  }
  .hero-row {
    margin-bottom: 0 !important;
    display: flex !important;
    align-items: center !important;
    gap: 8px !important;
  }
  .detail-hero h2 {
    font-size: 24px !important;
    margin: 0 !important;
    line-height: 1 !important;
  }
  .detail-hero .meta-line {
    font-size: 13px !important;
    margin: 0 !important;
    white-space: nowrap !important;
  }
  .detail-hero .hero-actions {
    display: flex !important;
    align-items: center !important;
    margin-left: auto !important;
    width: auto !important;
    align-self: center !important;
  }
  .detail-hero .avatar-model-picker {
    display: flex !important;
    align-items: center !important;
    gap: 8px !important;
    width: auto !important;
  }
  .detail-hero .avatar-model-picker .field-label {
    display: inline-block !important;
    margin: 0 !important;
    font-size: 12px !important;
    white-space: nowrap !important;
    color: var(--muted) !important;
  }
  .detail-hero .library-select {
    min-height: 30px !important;
    padding: 0 8px !important;
    font-size: 13px !important;
    border-radius: 6px !important;
    width: 200px !important;
  }
  .detail-hero #libraryModelHint {
    display: none !important;
  }
  .detail-stats-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
    gap: 10px !important;
  }
  .detail-stat-card {
    padding: 6px 12px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    border-radius: 10px !important;
  }
  .detail-stat-label {
    font-size: 10px !important;
    letter-spacing: 0.04em !important;
  }
  .detail-stat-card strong {
    margin-top: 0 !important;
    font-size: 16px !important;
  }
  .preview-grid {
    grid-template-columns: minmax(0, 3fr) minmax(0, 2fr) !important;
    gap: 16px !important;
    align-items: stretch !important;
  }
  .preview-grid .avatar-frame-shell,
  .preview-grid .video-preview-shell {
    height: 480px !important;
    min-height: 480px !important;
    aspect-ratio: auto !important;
    border-radius: 14px !important;
  }
  .player-control-card {
    padding: 8px 14px !important;
    border-radius: 14px !important;
  }
  .player-control-card .soft-button {
    min-height: 32px !important;
    padding: 0 12px !important;
    font-size: 13px !important;
    border-radius: 6px !important;
  }
  .player-controls-middle .meta-line {
    font-size: 13px !important;
  }
  .current-sample-card {
    padding: 12px 14px !important;
    border-radius: 14px !important;
  }
  .current-sample-card .section-head {
    margin-bottom: 8px !important;
  }
  .current-sample-card h3 {
    font-size: 15px !important;
  }
  .info-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
    gap: 8px !important;
  }
  .info-grid div {
    padding: 6px 10px !important;
    border-radius: 8px !important;
  }
  .info-grid dt {
    font-size: 10px !important;
  }
  .info-grid dd {
    font-size: 12px !important;
    margin-top: 2px !important;
  }
  .samples-card {
    padding: 12px 14px !important;
    border-radius: 14px !important;
  }
  .samples-card .section-head {
    margin-bottom: 8px !important;
  }
  .samples-card h3 {
    font-size: 15px !important;
  }
  .sample-table th,
  .sample-table td {
    padding: 6px 8px !important;
    font-size: 12px !important;
  }
  .sample-action {
    min-height: 26px !important;
    padding: 0 8px !important;
    font-size: 11px !important;
    border-radius: 4px !important;
  }
}

/* Mobile/Tablet Single-Pane Responsive Layout */
@media (max-width: 1180px) {
  body.library-mode-index .library-sidebar {
    display: flex !important;
  }
  body.library-mode-index .library-content {
    display: none !important;
  }
  body.library-mode-detail .library-sidebar {
    display: none !important;
  }
  body.library-mode-detail .library-content {
    display: flex !important;
    width: 100%;
  }
  .library-shell {
    grid-template-columns: 1fr !important;
  }
}

/* Player Controls Card Style */
.player-control-card {
  background: rgba(255, 255, 255, 0.75);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(116, 132, 154, 0.16);
  padding: 16px 20px;
}

.player-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.player-controls-left,
.player-controls-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.player-controls-middle {
  flex: 1 1 auto;
  display: grid;
  gap: 6px;
  text-align: center;
  min-width: 180px;
}

.player-controls-middle .meta-line {
  font-size: 14px;
  font-weight: 600;
  margin: 0;
  color: var(--muted);
}

.review-status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid rgba(116, 132, 154, 0.16);
}

.review-status-row .meta-line {
  min-width: 0;
  text-align: right;
}

.sample-table tbody tr.inspecting-row {
  background: rgba(47, 127, 143, 0.1) !important;
  box-shadow: inset 3px 0 0 var(--accent);
}

.sample-table tbody tr.reviewed-row {
  background: rgba(45, 95, 154, 0.05);
}

.json-card .icon-button {
  width: 32px;
  height: 32px;
  font-size: 16px;
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  border-color: rgba(116, 132, 154, 0.2);
  transition: all 0.2s ease;
}

.json-card .icon-button:hover {
  background: var(--red-soft);
  color: var(--red);
  border-color: var(--red-soft);
}


.sidebar-card,
.card,
.empty-state {
  border-radius: 22px;
  border: 1px solid rgba(116, 132, 154, 0.18);
  box-shadow: 0 24px 44px rgba(15, 23, 42, 0.08);
}

.sidebar-card {
  margin-bottom: 0;
  padding: 20px;
}

.sidebar-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.section-kicker {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  background: rgba(23, 32, 42, 0.08);
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.sidebar-card-title {
  margin: 10px 0 0;
  font-size: 26px;
  line-height: 1.05;
}

.section-copy {
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.55;
}

.control-card {
  background: linear-gradient(145deg, #13232f 0%, #224050 100%);
  border-color: rgba(21, 50, 63, 0.92);
  color: #fff;
}

.control-card .section-kicker {
  background: rgba(223, 245, 244, 0.12);
  color: #d4f4f0;
}

.control-card .sidebar-card-title,
.control-card .field-label {
  color: #fff;
}

.control-card .section-copy,
.control-card .json-hint {
  color: rgba(239, 245, 252, 0.76);
}

.control-card .soft-button {
  flex: 0 0 auto;
  border-color: rgba(239, 245, 252, 0.2);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}

.control-card .soft-button:hover {
  border-color: rgba(255, 255, 255, 0.4);
  background: rgba(255, 255, 255, 0.16);
}

.control-card .search-input {
  margin-top: 10px;
  border-color: rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.55);
}

.control-card .status-chip {
  border-color: rgba(239, 245, 252, 0.2);
  background: rgba(255, 255, 255, 0.08);
  color: rgba(245, 248, 251, 0.92);
}

.control-card .status-chip.active {
  background: #fff;
  border-color: #fff;
  color: #15222d;
}

.control-card #refreshStatus {
  display: block;
  margin-top: 14px;
}

.status-board-card {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  background: rgba(255, 255, 255, 0.76);
  backdrop-filter: blur(10px);
}

.stat-box {
  min-height: 112px;
  border: 1px solid rgba(116, 132, 154, 0.12);
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.92), rgba(242, 245, 248, 0.92));
  padding: 16px 14px;
}

.stat-box:nth-child(1) {
  background: linear-gradient(180deg, rgba(224, 235, 250, 0.92), rgba(255, 255, 255, 0.96));
}

.stat-box:nth-child(2) {
  background: linear-gradient(180deg, rgba(223, 244, 231, 0.94), rgba(255, 255, 255, 0.96));
}

.stat-box:nth-child(3) {
  background: linear-gradient(180deg, rgba(247, 229, 221, 0.94), rgba(255, 255, 255, 0.96));
}

.stat-box:nth-child(4) {
  background: linear-gradient(180deg, rgba(248, 221, 221, 0.94), rgba(255, 255, 255, 0.96));
}

.stat-box strong {
  margin-top: 10px;
  font-size: 30px;
  line-height: 1;
}

.list-card {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.list-card .section-head {
  margin-bottom: 8px;
}

.sign-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding-right: 4px;
}

.sign-item {
  display: block;
  padding: 16px;
  border-radius: 18px;
  color: var(--text);
  text-decoration: none;
  transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

.sign-item:hover {
  transform: translateY(-1px);
  border-color: rgba(47, 127, 143, 0.38);
  box-shadow: 0 16px 26px rgba(15, 23, 42, 0.08);
}

.sign-item:focus-visible {
  outline: 0;
  border-color: rgba(47, 127, 143, 0.74);
  box-shadow: 0 0 0 4px rgba(47, 127, 143, 0.16);
}

.sign-item.active {
  border-color: rgba(47, 127, 143, 0.74);
  background: linear-gradient(180deg, rgba(223, 245, 244, 0.85), rgba(255, 255, 255, 0.96));
  box-shadow: 0 0 0 4px rgba(47, 127, 143, 0.12);
}

.sign-item-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.sign-item-title-wrap {
  min-width: 0;
  display: grid;
  gap: 8px;
}

.sign-item-title {
  font-size: 17px;
  line-height: 1.2;
}

.sign-item-key {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  max-width: 100%;
  padding: 5px 9px;
  border-radius: 999px;
  background: rgba(23, 32, 42, 0.06);
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  overflow-wrap: anywhere;
}

.sign-item-meta {
  gap: 10px;
  margin-top: 12px;
}

.sign-item-meta > span {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  background: rgba(23, 32, 42, 0.04);
}

.sign-item-note {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid rgba(116, 132, 154, 0.16);
  font-size: 13px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.empty-state {
  min-height: 640px;
  display: block;
  text-align: left;
  padding: 28px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.92), rgba(244, 247, 251, 0.9));
}

.empty-state-inner {
  display: grid;
  gap: 26px;
  height: 100%;
}

.empty-state-copy {
  max-width: 840px;
}

.empty-eyebrow {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 11px;
  border-radius: 999px;
  background: rgba(47, 127, 143, 0.12);
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.empty-state h2 {
  margin: 16px 0 12px;
  font-size: clamp(34px, 4vw, 52px);
  line-height: 0.98;
  letter-spacing: -0.04em;
}

.empty-state p {
  margin: 0;
  max-width: 860px;
  color: var(--muted);
  line-height: 1.6;
}

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

.empty-tip-card,
.detail-stat-card {
  border: 1px solid rgba(116, 132, 154, 0.14);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.empty-tip-card {
  padding: 18px;
}

.empty-tip-card h3 {
  margin: 0 0 10px;
  font-size: 18px;
}

.legend-stack {
  display: grid;
  gap: 12px;
}

.legend-row {
  display: grid;
  gap: 8px;
}

.legend-row p {
  font-size: 14px;
}

.detail-view {
  gap: 18px;
}

.card {
  padding: 22px;
}

.detail-hero,
.detail-hero:has(> .hero-compare-actions) {
  grid-template-columns: minmax(0, 1fr) minmax(250px, 0.5fr) minmax(120px, 0.22fr);
  gap: 20px;
  align-items: start;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(248, 250, 252, 0.98));
}

.detail-hero h2 {
  letter-spacing: -0.03em;
}

.detail-stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.detail-stat-card {
  padding: 18px;
}

.detail-stat-label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.detail-stat-card strong {
  display: block;
  margin-top: 12px;
  font-size: clamp(26px, 2.2vw, 34px);
  line-height: 1;
}

.preview-grid {
  gap: 18px;
}

.avatar-frame-shell,
.video-preview-shell {
  border-radius: 18px;
}

.table-shell {
  border-radius: 18px;
  border: 1px solid rgba(116, 132, 154, 0.12);
}

.sample-table thead th {
  position: sticky;
  top: 0;
  background: rgba(248, 250, 252, 0.98);
  z-index: 1;
}

@media (max-width: 1180px) {
  .library-shell {
    grid-template-columns: 1fr;
  }

  .library-sidebar {
    position: static;
    max-height: none;
  }

  .sign-list {
    max-height: none;
    overflow: visible;
  }

  body.library-mode-index .library-sidebar {
    grid-template-columns: 1fr;
  }

  body.library-mode-index .control-card,
  body.library-mode-index .status-board-card,
  body.library-mode-index .list-card {
    grid-column: auto;
  }

  .empty-tip-grid,
  .detail-stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .detail-hero,
  .detail-hero:has(> .hero-compare-actions) {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .library-topbar,
  .library-shell {
    padding-left: 18px;
    padding-right: 18px;
  }

  .library-topbar {
    padding-top: 24px;
  }

  .sidebar-card-head {
    flex-direction: column;
  }

  .sidebar-card-head .soft-button,
  #previewActiveBtn {
    width: 100%;
  }

  .status-board-card,
  .empty-tip-grid,
  .detail-stats-grid,
  .stats-card {
    grid-template-columns: 1fr;
  }

  .review-status-row {
    flex-direction: column;
    align-items: flex-start;
  }

  .review-status-row .meta-line {
    text-align: left;
  }

  .empty-state {
    min-height: auto;
    padding: 22px;
  }

  .empty-state h2 {
    font-size: clamp(30px, 10vw, 42px);
  }

  .sign-item-note {
    white-space: normal;
  }
}

/* Sharper, lighter library treatment */
:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --panel-soft: #f6f8fa;
  --line: #ced7e1;
  --shadow: 0 8px 18px rgba(15, 23, 42, 0.04);
  --radius: 0px;
}

body {
  background: linear-gradient(180deg, #f6f7f8 0%, #eef2f4 46%, #f7f8fa 100%);
}

.library-topbar {
  gap: 18px;
  padding: 28px 32px 18px;
}

.library-brand h1,
.empty-state h2,
.detail-hero h2,
.detail-stat-label,
.section-kicker,
.empty-eyebrow,
.sign-item-key {
  letter-spacing: 0 !important;
}

.library-brand h1 {
  margin: 6px 0 8px;
  font-size: 48px !important;
}

.empty-state h2 {
  font-size: 40px !important;
}

.detail-hero h2 {
  font-size: 30px !important;
}

.sidebar-card,
.card,
.empty-state,
.preview-surface,
.auth-surface,
.sign-item,
.stat-box,
.empty-tip-card,
.detail-stat-card,
.avatar-frame-shell,
.video-preview-shell,
.table-shell,
.json-viewer,
.register-photo-panel,
.camera-shell,
.auth-avatar-shell,
.profile-preview-shell,
.language-switch,
.lang-button,
.nav-pill,
.auth-button,
.search-input,
.status-chip,
.library-select,
.soft-button,
.action-link,
.icon-button,
.tiny-pill,
.status-pill,
.sign-id-pill,
.section-kicker,
.empty-eyebrow,
.sign-item-key,
.sign-item-meta > span,
.info-grid div,
.motion-grid div,
.avatar-meta-grid div,
.avatar-motion-status {
  border-radius: 0 !important;
}

.sidebar-card,
.card,
.empty-state,
.preview-surface,
.auth-surface {
  border-color: rgba(116, 132, 154, 0.16) !important;
  box-shadow: var(--shadow) !important;
}

.control-card {
  background: #fff !important;
  color: var(--text) !important;
  border-color: rgba(116, 132, 154, 0.16) !important;
}

.control-card .section-kicker {
  background: rgba(23, 32, 42, 0.06) !important;
  color: var(--muted) !important;
}

.control-card .sidebar-card-title,
.control-card .field-label {
  color: var(--text) !important;
}

.control-card .section-copy,
.control-card .json-hint {
  color: var(--muted) !important;
}

.control-card .soft-button {
  border-color: var(--line) !important;
  background: #fff !important;
  color: var(--text) !important;
}

.control-card .soft-button:hover {
  border-color: rgba(23, 32, 42, 0.18) !important;
  background: var(--panel-soft) !important;
}

.control-card .search-input {
  background: #fff !important;
  border-color: var(--line) !important;
  box-shadow: none !important;
}

.control-card .status-chip {
  border-color: var(--line) !important;
  background: #fff !important;
  color: var(--muted) !important;
}

.control-card .status-chip.active {
  background: var(--text) !important;
  border-color: var(--text) !important;
  color: #fff !important;
}

.detail-hero {
  grid-template-columns: minmax(0, 1fr) minmax(220px, 280px) !important;
}

.hero-summary {
  display: grid;
  gap: 8px;
}

.hero-row {
  align-items: center;
}

.detail-stat-card {
  display: grid !important;
  align-content: center !important;
  justify-items: start !important;
  min-height: 116px !important;
  padding: 18px 18px 16px !important;
  gap: 8px !important;
}

.detail-stat-label {
  font-size: 13px !important;
}

.detail-stat-card strong {
  margin-top: 0 !important;
  font-size: 30px !important;
  line-height: 1.05 !important;
}

.status-board-card {
  grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
  background: rgba(255, 255, 255, 0.94) !important;
  backdrop-filter: none !important;
}

.stat-box {
  min-height: 92px;
  border-color: rgba(116, 132, 154, 0.1) !important;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(246, 248, 250, 0.98)) !important;
}

.detail-hero,
.empty-state,
.empty-tip-card,
.detail-stat-card,
.player-control-card {
  background: rgba(255, 255, 255, 0.96) !important;
  backdrop-filter: none !important;
}

.player-control-card {
  border-color: rgba(116, 132, 154, 0.16) !important;
}



.table-shell,
.avatar-frame-shell,
.video-preview-shell {
  border-color: rgba(116, 132, 154, 0.16);
}

@media (max-width: 1180px) {
  .status-board-card {
    grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
  }
}

@media (max-width: 760px) {
  .library-topbar,
  .library-shell {
    padding-left: 18px;
    padding-right: 18px;
  }

  .library-brand h1 {
    font-size: 36px !important;
  }

  .empty-state h2 {
    font-size: 32px !important;
  }

  .detail-hero h2 {
    font-size: 26px !important;
  }

  .status-board-card {
    grid-template-columns: 1fr !important;
  }

  .detail-hero {
    grid-template-columns: 1fr !important;
  }

  .detail-stat-card {
    min-height: 104px !important;
  }
}

/* High-Density Desktop Compaction (No-Scroll Viewport Alignment) */
@media (min-width: 1180px) {
  body {
    height: 100vh !important;
    overflow: hidden !important;
    display: flex !important;
    flex-direction: column !important;
  }

  .library-topbar {
    padding: 12px 24px 8px !important;
    gap: 6px !important;
    flex: 0 0 auto !important;
    margin-bottom: 0 !important;
  }

  .library-topbar-main {
    gap: 12px !important;
  }

  .library-brand h1 {
    margin: 0 0 2px !important;
    font-size: 24px !important;
  }

  .library-brand p {
    font-size: 12.5px !important;
    margin: 0 !important;
  }

  .app-nav .nav-pill, 
  .language-switch, 
  .auth-button {
    min-height: 36px !important;
    font-size: 13px !important;
    padding: 0 12px !important;
  }

  .auth-avatar-shell {
    width: 28px !important;
    height: 28px !important;
  }

  .library-shell {
    flex: 1 !important;
    height: calc(100vh - 72px) !important;
    padding: 0 24px 12px !important;
    gap: 16px !important;
    grid-template-columns: 330px minmax(0, 1fr) !important;
    overflow: hidden !important;
  }

  .library-sidebar {
    height: 100% !important;
    display: flex !important;
    flex-direction: column !important;
    gap: 10px !important;
    overflow: hidden !important;
  }

  .library-sidebar .sidebar-card {
    margin-bottom: 0 !important;
    padding: 10px 12px !important;
  }

  .library-sidebar .list-card {
    flex: 1 !important;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
    order: -1 !important; /* Keeps list card on top! */
  }

  .library-sidebar .sign-list {
    flex: 1 !important;
    overflow-y: auto !important;
    max-height: none !important;
    gap: 6px !important;
  }

  .library-sidebar .sign-item {
    padding: 10px !important;
  }

  .library-sidebar .sign-item-title {
    font-size: 14.5px !important;
  }

  .library-sidebar .sign-item-meta {
    margin-top: 4px !important;
    font-size: 11.5px !important;
  }

  .library-sidebar .list-footer {
    margin-top: 8px !important;
    padding-top: 8px !important;
  }

  .library-sidebar .list-footer span {
    font-size: 11.5px !important;
  }

  .library-sidebar .list-footer .soft-button {
    min-height: 30px !important;
    font-size: 11.5px !important;
    padding: 0 10px !important;
  }

  .library-sidebar .control-card {
    flex: 0 0 auto !important;
  }

  .library-sidebar .control-card .sidebar-card-head {
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    margin-bottom: 6px !important;
  }

  .library-sidebar .control-card .sidebar-card-head h2 {
    font-size: 15px !important;
  }

  .library-sidebar .control-card .search-input {
    min-height: 34px !important;
    padding: 0 10px !important;
    font-size: 13.5px !important;
    margin-top: 4px !important;
  }

  .library-sidebar .control-card .status-filters {
    margin-top: 8px !important;
    gap: 6px !important;
  }

  .library-sidebar .control-card .status-chip {
    min-height: 30px !important;
    padding: 0 10px !important;
    font-size: 11.5px !important;
    border-radius: 6px !important;
  }

  .library-sidebar .status-board-card {
    flex: 0 0 auto !important;
    grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
    gap: 6px !important;
    padding: 6px !important;
  }

  .library-sidebar .status-board-card .stat-box {
    min-height: auto !important;
    padding: 6px !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
  }

  .library-sidebar .status-board-card .stat-box .stat-label {
    font-size: 10px !important;
    text-align: center !important;
  }

  .library-sidebar .status-board-card .stat-box strong {
    margin-top: 2px !important;
    font-size: 15px !important;
  }

  .library-content {
    height: 100% !important;
    overflow-y: auto !important;
    padding-right: 4px !important;
  }

  .detail-view {
    gap: 12px !important;
  }

  .detail-view .card {
    padding: 12px 16px !important;
    margin-bottom: 0 !important;
  }

  .detail-hero {
    padding: 10px 16px !important;
    grid-template-columns: minmax(0, 1fr) minmax(200px, 250px) !important;
    gap: 12px !important;
    align-items: center !important;
  }

  .detail-hero h2 {
    font-size: 20px !important;
    margin-bottom: 2px !important;
  }

  .detail-hero .hero-summary {
    gap: 4px !important;
  }

  .detail-hero .meta-line {
    font-size: 11.5px !important;
    margin: 0 !important;
  }

  .detail-hero .hero-row {
    margin-bottom: 2px !important;
    gap: 6px !important;
  }

  .detail-hero .status-pill,
  .detail-hero .sign-id-pill {
    padding: 3px 6px !important;
    font-size: 10px !important;
    border-radius: 4px !important;
  }

  .detail-hero .avatar-model-picker {
    gap: 4px !important;
  }

  .detail-hero .avatar-model-picker .field-label {
    font-size: 11.5px !important;
  }

  .detail-hero .library-select {
    min-height: 32px !important;
    padding: 0 10px !important;
    font-size: 12.5px !important;
    border-radius: 6px !important;
  }

  .detail-hero .json-hint {
    font-size: 10.5px !important;
  }

  .player-control-card {
    padding: 8px 16px !important;
  }

  .player-controls {
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    gap: 12px !important;
  }

  .player-controls .soft-button {
    min-height: 32px !important;
    font-size: 12.5px !important;
    padding: 0 12px !important;
    border-radius: 6px !important;
  }

  .player-controls-middle {
    font-size: 12px !important;
    display: flex !important;
    align-items: center !important;
    gap: 10px !important;
  }

  .player-controls-middle #playerMeta,
  .player-controls-middle #reviewHint {
    font-size: 11.5px !important;
    margin: 0 !important;
  }

  .review-status-row {
    margin-top: 4px !important;
    font-size: 11.5px !important;
    display: flex !important;
    align-items: center !important;
    gap: 8px !important;
  }

  .review-status-row .tiny-pill {
    padding: 3px 6px !important;
    font-size: 10px !important;
    border-radius: 4px !important;
  }

  .preview-grid {
    grid-template-columns: minmax(0, 3fr) minmax(0, 2fr) !important;
    gap: 12px !important;
  }

  .preview-grid .card {
    padding: 10px 12px !important;
  }

  .preview-grid .section-head {
    margin-bottom: 6px !important;
  }

  .preview-grid .section-head h3 {
    font-size: 13.5px !important;
  }

  .preview-grid .section-head span {
    font-size: 11px !important;
  }

  .video-preview-shell,
  .avatar-frame-shell {
    min-height: 280px !important;
    height: 290px !important;
    border-radius: 6px !important;
  }

  /* Keep the multicam as two columns (side cameras left, big camera right) at
     every width — just make it more compact on small screens. */
  .multicam {
    min-height: 0 !important;
    gap: 8px !important;
  }
  .multicam-main {
    min-height: 180px !important;
  }
  .multicam-cell {
    min-height: 0 !important;
  }

  .detail-stats-grid {
    display: grid !important;
    grid-template-columns: repeat(4, 1fr) !important;
    gap: 8px !important;
    margin-bottom: 0 !important;
  }

  .detail-stat-card {
    min-height: auto !important;
    padding: 6px 12px !important;
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    justify-content: space-between !important;
    border-radius: 6px !important;
    background: rgba(255, 255, 255, 0.8) !important;
  }

  .detail-stat-label {
    font-size: 11.5px !important;
    margin-bottom: 0 !important;
  }

  .detail-stat-card strong {
    font-size: 18px !important;
    line-height: 1 !important;
    margin-top: 0 !important;
  }

  .samples-grid {
    margin-bottom: 0 !important;
  }

  .current-sample-card {
    padding: 10px 12px !important;
  }

  .current-sample-card .section-head {
    margin-bottom: 6px !important;
  }

  .current-sample-card .section-head h3 {
    font-size: 13.5px !important;
  }

  .current-sample-card .section-head .tiny-pill {
    padding: 3px 6px !important;
    font-size: 10px !important;
    border-radius: 4px !important;
  }

  .info-grid {
    grid-template-columns: repeat(4, 1fr) !important;
    gap: 8px !important;
  }

  .info-grid div {
    padding: 6px 10px !important;
    border-radius: 6px !important;
    background: var(--panel-soft) !important;
  }

  .info-grid dt {
    font-size: 9.5px !important;
    text-transform: uppercase !important;
  }

  .info-grid dd {
    margin-top: 2px !important;
    font-size: 12px !important;
    font-weight: 700 !important;
  }

  .samples-card {
    padding: 10px 12px !important;
  }

  .samples-card .section-head {
    margin-bottom: 6px !important;
  }

  .samples-card .section-head h3 {
    font-size: 13.5px !important;
  }

  .samples-card .section-head .result-count {
    font-size: 11.5px !important;
  }

  .samples-card .table-shell {
    min-height: 360px !important;
    height: min(56vh, 520px) !important;
    max-height: min(56vh, 520px) !important;
    overflow-y: auto !important;
    border: 1px solid var(--line) !important;
    border-radius: 6px !important;
  }

  .sample-table {
    min-width: 100% !important;
    font-size: 12.5px !important;
  }

  .sample-table th,
  .sample-table td {
    padding: 6px 10px !important;
  }

  .sample-table th {
    background: var(--panel-soft) !important;
    font-weight: 700 !important;
  }

  .sample-action {
    min-height: 26px !important;
    padding: 0 8px !important;
    font-size: 11.5px !important;
    border-radius: 4px !important;
  }

  /* Hide static help copies to optimize workspace vertical bounds */
  .library-sidebar .list-card .section-copy,
  .library-sidebar .control-card .sidebar-card-head p,
  .library-sidebar .control-card .field-label {
    display: none !important;
  }
}

/* Wrong Reason input section for high-density audits */
.wrong-reason-section {
  margin-top: 12px;
  padding: 12px;
  border: 1px solid var(--red-soft);
  border-radius: var(--radius);
  background: var(--red-soft);
  backdrop-filter: blur(10px);
  animation: slideDown 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.wrong-reason-section label {
  color: var(--red) !important;
  font-size: 13px !important;
  font-weight: 600 !important;
}

.wrong-reason-section .reason-input-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 6px;
}

.wrong-reason-section .reason-input-row input {
  flex: 1;
  max-width: none !important;
  height: 36px !important;
  font-size: 13px !important;
}

.wrong-reason-section .reason-input-row .soft-button {
  height: 36px !important;
  padding: 0 14px !important;
  font-size: 13px !important;
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Glassmorphic Saving Overlay for Premium Feedback */
.saving-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 20, 24, 0.45);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  animation: fadeInOverlay 0.2s ease-out;
}

.saving-overlay.hidden {
  display: none !important;
}

.saving-overlay-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: rgba(255, 255, 255, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.5);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.15);
  padding: 32px 48px;
  border-radius: 16px;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  animation: scaleInCard 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
  text-align: center;
}

.saving-spinner {
  color: var(--accent, #3ac6a8);
  animation: spin 0.8s linear infinite;
}

.saving-overlay-text {
  font-size: 16px;
  font-weight: 600;
  color: var(--dark, #162421);
  letter-spacing: 0.25px;
}

@keyframes fadeInOverlay {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes scaleInCard {
  from { opacity: 0; transform: scale(0.9); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.samples-card .table-shell {
  min-height: clamp(420px, 56vh, 760px) !important;
  height: clamp(420px, 56vh, 760px) !important;
  max-height: min(72vh, 920px) !important;
  border: 1px solid var(--line) !important;
  border-radius: var(--radius) !important;
  background: #fff;
}

.sample-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #f7fafc;
}

.sample-action-cell {
  min-width: 172px;
}

.preview-modal .video-preview-shell,
.preview-modal .avatar-frame-shell {
  min-height: 420px;
}

.preview-modal.json-mode .preview-surface {
  width: min(1100px, 100%);
}

.preview-modal.json-mode .json-viewer {
  max-height: calc(100vh - 220px);
}

@media (max-width: 900px) {
  .samples-card .table-shell {
    min-height: 320px !important;
    height: min(58vh, 420px) !important;
    max-height: min(58vh, 420px) !important;
  }

  .preview-modal {
    padding: 16px;
  }

  .preview-modal .video-preview-shell,
  .preview-modal .avatar-frame-shell {
    min-height: 280px;
  }
}

/* ============================================================
   Library overview redesign + mobile polish (2026-06-18)
   ============================================================ */

/* Overview panel: progress at a glance + colour-toned stat tiles */
.status-board-card {
  display: flex !important;
  flex-direction: column !important;
  gap: 12px !important;
  grid-template-columns: none !important;
}

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

.overview-title {
  margin: 0;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.01em;
}

.overview-percent {
  font-size: 22px;
  font-weight: 800;
  color: var(--accent);
  line-height: 1;
}

.overview-progress {
  position: relative;
  height: 10px;
  border-radius: 999px;
  background: var(--panel-soft);
  overflow: hidden;
}

.overview-progress-bar {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), #4bb3a6);
  transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.overview-caption {
  margin: 0;
  font-size: 12.5px;
  color: var(--muted);
  font-weight: 600;
}

.status-board-grid {
  display: grid !important;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.status-board-grid .stat-box {
  min-height: auto !important;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px 14px !important;
  border: 1px solid var(--line) !important;
  border-left: 4px solid var(--line) !important;
  border-radius: var(--radius) !important;
  background: #fff !important;
}

.status-board-grid .stat-box .stat-label {
  font-size: 12px;
  font-weight: 700;
}

.status-board-grid .stat-box strong {
  margin-top: 0;
  /* Scale the number down on narrow boxes and break long values instead of
     letting big counts overflow ("ทะลุ") the box. */
  font-size: clamp(16px, 4.2vw, 24px);
  font-weight: 800;
  line-height: 1;
  max-width: 100%;
  overflow-wrap: anywhere;
  font-variant-numeric: tabular-nums;
}

.status-board-grid .tone-total { border-left-color: var(--accent) !important; }
.status-board-grid .tone-total strong { color: var(--accent); }
.status-board-grid .tone-pending { border-left-color: var(--accent-warm) !important; }
.status-board-grid .tone-pending strong { color: var(--accent-warm); }
.status-board-grid .tone-reviewed { border-left-color: var(--green) !important; }
.status-board-grid .tone-reviewed strong { color: var(--green); }
.status-board-grid .tone-broken { border-left-color: var(--red) !important; }
.status-board-grid .tone-broken strong { color: var(--red); }
.status-board-grid .tone-word { border-left-color: var(--blue) !important; }
.status-board-grid .tone-word strong { color: var(--blue); }
.status-board-grid .tone-sentence { border-left-color: #6d28d9 !important; }
.status-board-grid .tone-sentence strong { color: #6d28d9; }
.status-board-grid .tone-in-editor { border-left-color: #0369a1 !important; }
.status-board-grid .tone-in-editor strong { color: #0369a1; }

/* ------------------------------------------------------------
   Single-pane layout (tablet & phone, <= 1180px).
   The shell is already 1 column here and the sidebar is forced to
   display:flex by the mode rules — the bug was it stayed a ROW, so
   the three cards squished side-by-side. Force a vertical stack for
   the whole single-pane range and let the PAGE scroll (no nested
   scroll box that traps the label list).
   ------------------------------------------------------------ */
@media (max-width: 1180px) {
  .library-brand p { display: none; }

  body.library-mode-index .library-sidebar {
    flex-direction: column !important;
    gap: 14px !important;
    align-items: stretch !important;
  }

  .library-sidebar .sidebar-card {
    margin-bottom: 0 !important;
    width: 100% !important;
  }

  /* Overview summary first, then filters, then the full label list */
  .library-sidebar .status-board-card { order: 1 !important; }
  .library-sidebar .control-card { order: 2 !important; }
  .library-sidebar .list-card { order: 3 !important; }

  /* No inner scroll box — the document scrolls so every label is reachable */
  .sign-list {
    max-height: none !important;
    overflow: visible !important;
  }

  /* Filter chips wrap to show every option (nothing hidden off-screen) */
  .status-filters {
    flex-wrap: wrap;
  }
}

@media (max-width: 540px) {
  .library-topbar {
    padding: 16px 16px 10px;
    gap: 12px;
  }

  .library-topbar-main {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 14px;
  }

  .topbar-actions {
    width: 100%;
    flex-wrap: wrap;
    justify-content: flex-start;
    gap: 10px;
  }

  .auth-button {
    max-width: none;
    flex: 1 1 auto;
  }

  .overview-percent {
    font-size: 20px;
  }

  .status-board-grid .stat-box strong {
    font-size: 22px;
  }

  .sign-item {
    padding: 14px;
  }

  /* Make the review buttons comfortable to tap */
  .player-controls-left,
  .player-controls-right {
    flex: 1 1 auto;
    justify-content: center;
  }

  .player-controls .soft-button {
    flex: 1 1 auto;
  }
}

/* ============================================================
   Theme toggle button + Dark theme (2026-06-18)
   ============================================================ */
.theme-toggle {
  min-width: 44px;
  min-height: var(--button-height);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.72);
  color: var(--text);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
}

.theme-toggle:hover {
  background: var(--panel-soft);
}

@media (min-width: 1180px) {
  .theme-toggle {
    min-height: 36px !important;
    min-width: 36px;
    font-size: 16px;
  }
}

/* ---- Dark palette ---- */
html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f141b;
  --panel: #161d27;
  --panel-soft: #1f2935;
  --line: #2c3947;
  --text: #e8edf3;
  --muted: #9aa7b6;
  --accent: #5bb9c6;
  --accent-soft: #11313a;
  --accent-warm: #e79468;
  --accent-warm-soft: #3a2820;
  --green: #54c489;
  --green-soft: #14301f;
  --red: #e87878;
  --red-soft: #3a1e1e;
  --amber: #d8a948;
  --amber-soft: #322713;
  --blue: #71a6e6;
  --blue-soft: #15263a;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

html[data-theme="dark"] body {
  background:
    radial-gradient(circle at top left, rgba(91, 185, 198, 0.08), transparent 36%),
    linear-gradient(180deg, #0d1219 0%, #0f141b 60%, #11161e 100%);
}

/* Surfaces */
html[data-theme="dark"] .sidebar-card,
html[data-theme="dark"] .card,
html[data-theme="dark"] .empty-state,
html[data-theme="dark"] .preview-surface,
html[data-theme="dark"] .auth-surface,
html[data-theme="dark"] .control-card,
html[data-theme="dark"] .status-board-card,
html[data-theme="dark"] .detail-hero,
html[data-theme="dark"] .empty-tip-card,
html[data-theme="dark"] .detail-stat-card,
html[data-theme="dark"] .player-control-card {
  background: var(--panel) !important;
  border-color: var(--line) !important;
  color: var(--text);
}

html[data-theme="dark"] .stat-box,
html[data-theme="dark"] .status-board-grid .stat-box {
  background: var(--panel-soft) !important;
  border-color: var(--line) !important;
}

html[data-theme="dark"] .overview-progress {
  background: #0c1117;
}

/* List items */
html[data-theme="dark"] .sign-item,
html[data-theme="dark"] .skeleton-item {
  background: var(--panel-soft);
  border-color: var(--line);
}

html[data-theme="dark"] .sign-item:hover {
  border-color: rgba(91, 185, 198, 0.45) !important;
  border-left-color: rgba(91, 185, 198, 0.7) !important;
  background-color: rgba(91, 185, 198, 0.08) !important;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.35) !important;
}

html[data-theme="dark"] .sign-item.active {
  background: var(--accent-soft) !important;
  border-color: var(--accent) !important;
  border-left-color: var(--accent) !important;
}

/* Inputs + chips + nav controls */
html[data-theme="dark"] .search-input,
html[data-theme="dark"] .library-select,
html[data-theme="dark"] .control-card .search-input,
html[data-theme="dark"] .reason-input-row input,
html[data-theme="dark"] #wrongReasonInput {
  background: var(--panel-soft) !important;
  color: var(--text) !important;
  border-color: var(--line) !important;
}

html[data-theme="dark"] .status-chip,
html[data-theme="dark"] .control-card .status-chip,
html[data-theme="dark"] .nav-pill,
html[data-theme="dark"] .auth-button,
html[data-theme="dark"] .soft-button,
html[data-theme="dark"] .control-card .soft-button,
html[data-theme="dark"] .icon-button {
  background: var(--panel-soft) !important;
  color: var(--text) !important;
  border-color: var(--line) !important;
}

html[data-theme="dark"] .language-switch {
  background: var(--panel-soft) !important;
  border-color: var(--line) !important;
}

html[data-theme="dark"] .theme-toggle {
  background: var(--panel-soft);
  border-color: var(--line);
  color: var(--text);
}

html[data-theme="dark"] .status-chip.active,
html[data-theme="dark"] .control-card .status-chip.active,
html[data-theme="dark"] .nav-pill.active,
html[data-theme="dark"] .lang-button.active {
  background: var(--accent) !important;
  border-color: var(--accent) !important;
  color: #06222a !important;
}

html[data-theme="dark"] .auth-button.signed-in {
  background: var(--accent-soft) !important;
  border-color: var(--accent) !important;
}

html[data-theme="dark"] .control-card .section-kicker {
  background: rgba(232, 237, 243, 0.08) !important;
  color: var(--muted) !important;
}

/* Buttons that carry intent colours stay readable */
html[data-theme="dark"] .soft-button.primary {
  background: var(--accent) !important;
  border-color: var(--accent) !important;
  color: #06222a !important;
}

html[data-theme="dark"] .soft-button.success {
  background: var(--green) !important;
  border-color: var(--green) !important;
  color: #06220f !important;
}

html[data-theme="dark"] .soft-button.danger {
  background: var(--red) !important;
  border-color: var(--red) !important;
  color: #2a0c0c !important;
}

/* Media + data surfaces */
html[data-theme="dark"] .table-shell,
html[data-theme="dark"] .avatar-frame-shell,
html[data-theme="dark"] .video-preview-shell,
html[data-theme="dark"] .json-viewer {
  background: #0c1117 !important;
  border-color: var(--line) !important;
}

html[data-theme="dark"] .json-viewer {
  color: var(--text);
}

html[data-theme="dark"] .sample-table th {
  background: var(--panel-soft);
  color: var(--muted);
}

html[data-theme="dark"] .sample-table td {
  border-color: var(--line);
}

html[data-theme="dark"] .preview-backdrop {
  background: rgba(0, 0, 0, 0.62);
}

html[data-theme="dark"] .saving-overlay-card {
  background: var(--panel) !important;
  color: var(--text) !important;
  border-color: var(--line) !important;
}

/* Badges sit on their own row under the label title (long labels stay readable) */
.sign-item-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.sign-item-badges:empty {
  display: none;
}

.sign-item-badges .tiny-pill {
  padding: 4px 9px;
  font-size: 11px;
}

@media (min-width: 1180px) {
  .library-sidebar .sign-item-badges {
    margin-top: 6px !important;
  }
}

/* ============================================================
   Filter panel — simplified, clearly grouped (2026-06-18)
   ============================================================ */
.control-card .filter-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.filter-title {
  margin: 0;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.01em;
}

.control-card .search-input {
  margin-top: 0;
}

.filter-group {
  margin-top: 14px;
}

.filter-group-label {
  display: block;
  margin-bottom: 8px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.filter-group .status-filters {
  margin-top: 0 !important;
}

/* Compact spacing on the no-scroll desktop layout */
@media (min-width: 1181px) {
  .control-card .filter-head {
    margin-bottom: 8px !important;
  }
  .filter-group {
    margin-top: 8px !important;
  }
  .filter-group-label {
    margin-bottom: 4px !important;
    font-size: 10px !important;
  }
}

/* ============================================================
   Detail / review page on phones (2026-06-18)
   - kill horizontal overflow (long filenames + flex/grid children)
   - stack video & avatar at a height where BOTH are visible for
     easy side-by-side-ish comparison without endless scrolling
   ============================================================ */
@media (max-width: 720px) {
  html, body {
    overflow-x: hidden;
    max-width: 100%;
  }

  /* Flex/grid children default to min-width:auto and refuse to shrink,
     which is the usual cause of a page wider than the screen. */
  .library-content,
  .detail-view,
  .detail-view .card,
  .preview-grid,
  .player-control-card,
  .player-controls,
  .player-controls-left,
  .player-controls-middle,
  .player-controls-right,
  .detail-stats-grid,
  .detail-grid,
  .review-status-row {
    min-width: 0 !important;
    max-width: 100% !important;
  }

  /* Long unbroken filenames / reviewer strings must wrap, not overflow */
  .meta-line,
  .json-hint,
  #playerMeta,
  #reviewMeta,
  .player-controls-middle {
    overflow-wrap: anywhere;
    word-break: break-word;
    white-space: normal !important;
  }

  /* Source video + avatar: stacked, compact, both on screen to compare */
  .preview-grid {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }

  .preview-grid .video-preview-shell,
  .preview-grid .avatar-frame-shell {
    min-height: 0 !important;
    height: 42vh !important;
    max-height: 320px !important;
    aspect-ratio: auto !important;
  }

  /* Tidy the player controls into a clean stacked block */
  .player-controls {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 12px !important;
  }

  .player-controls-left,
  .player-controls-right {
    justify-content: center !important;
  }

  .player-controls .soft-button {
    flex: 1 1 auto !important;
  }
}

/* ============================================================
   Desktop sidebar: give the Labels list the most height by keeping
   the Filter + Overview cards compact (2026-06-18)
   ============================================================ */
@media (min-width: 1180px) {
  /* Labels list takes all remaining height */
  .library-sidebar .list-card {
    flex: 1 1 auto !important;
  }
  .library-sidebar .sign-list {
    flex: 1 1 auto !important;
    max-height: none !important;
    overflow-y: auto !important;
  }

  /* --- Filter card: compact, no title row (just keep Refresh) --- */
  .library-sidebar .control-card {
    flex: 0 0 auto !important;
    padding: 8px 12px !important;
  }
  .library-sidebar .control-card .filter-title {
    display: none !important;
  }
  .library-sidebar .control-card .filter-head {
    margin-bottom: 6px !important;
    justify-content: flex-end !important;
  }
  .library-sidebar .control-card .search-input {
    min-height: 30px !important;
    font-size: 13px !important;
  }
  .library-sidebar .control-card .filter-group {
    margin-top: 6px !important;
  }
  .library-sidebar .control-card .filter-group-label {
    margin-bottom: 3px !important;
    font-size: 9.5px !important;
  }
  .library-sidebar .control-card .status-filters {
    gap: 4px !important;
  }
  .library-sidebar .control-card .status-chip {
    min-height: 26px !important;
    padding: 0 8px !important;
    font-size: 11.5px !important;
  }

  /* --- Overview card: single compact row of tiles, no caption --- */
  .library-sidebar .status-board-card {
    flex: 0 0 auto !important;
    padding: 8px 12px !important;
    gap: 6px !important;
  }
  .library-sidebar .overview-title {
    font-size: 12px !important;
  }
  .library-sidebar .overview-percent {
    font-size: 16px !important;
  }
  .library-sidebar .overview-progress {
    height: 7px !important;
  }
  .library-sidebar .overview-caption {
    display: none !important;
  }
  .library-sidebar .status-board-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    gap: 6px !important;
  }
  .library-sidebar .status-board-grid .stat-box {
    padding: 6px 4px !important;
    align-items: center !important;
    text-align: center !important;
    border-left-width: 1px !important;
    border-top: 3px solid var(--line) !important;
  }
  .library-sidebar .status-board-grid .tone-total { border-top-color: var(--accent) !important; }
  .library-sidebar .status-board-grid .tone-pending { border-top-color: var(--accent-warm) !important; }
  .library-sidebar .status-board-grid .tone-reviewed { border-top-color: var(--green) !important; }
  .library-sidebar .status-board-grid .tone-broken { border-top-color: var(--red) !important; }
  .library-sidebar .status-board-grid .tone-word { border-top-color: var(--blue) !important; }
  .library-sidebar .status-board-grid .tone-sentence { border-top-color: #6d28d9 !important; }
  .library-sidebar .status-board-grid .stat-box strong {
    font-size: 18px !important;
  }
  .library-sidebar .status-board-grid .stat-box .stat-label {
    font-size: 11px !important;
    line-height: 1.15 !important;
    white-space: normal !important;
  }
}

/* ============================================================
   Compact filter panel — search + Refresh on one row (2026-06-18)
   ============================================================ */
.control-card .filter-search-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.control-card .filter-search-row .search-input {
  flex: 1 1 auto;
  margin-top: 0;
}

.control-card .refresh-btn {
  flex: 0 0 auto;
  white-space: nowrap;
}

.control-card .filter-group {
  margin-top: 10px;
}

.control-card .filter-group-label {
  margin-bottom: 6px;
}

@media (min-width: 1180px) {
  .library-sidebar .control-card {
    padding: 8px 12px !important;
  }
  .library-sidebar .control-card .refresh-btn {
    min-height: 30px !important;
    padding: 0 10px !important;
    font-size: 12px !important;
  }
  .library-sidebar .control-card .filter-group {
    margin-top: 6px !important;
  }
}

/* ---------------- Pose Editor ---------------- */
.pose-editor-card.hidden { display: none; }
.pose-editor-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  border: 1px solid var(--accent);
  box-shadow: 0 6px 22px rgba(47, 127, 143, 0.12);
}
.pose-editor-head { display: flex; align-items: center; gap: 12px; }
.pose-editor-head h3 { margin: 0; }
.pose-editor-head #poseEditorStatus { margin-left: auto; }
.pose-editor-hint { margin: 0; line-height: 1.5; }
.pose-editor-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 8px 10px;
  background: var(--accent-soft);
  border-radius: 10px;
}
.pe-group-label { font-weight: 600; color: var(--accent); font-size: 13px; }
.pe-slider { vertical-align: middle; accent-color: var(--accent); }
.pe-slider.grow, .pose-scrubber .pe-slider { flex: 1 1 200px; min-width: 160px; }
.mono { font-variant-numeric: tabular-nums; font-family: ui-monospace, "SFMono-Regular", Menlo, monospace; }
.soft-button.tiny { padding: 4px 10px; font-size: 12px; }
.pe-hand-tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.pe-master { margin-left: auto; display: flex; align-items: center; gap: 8px; font-size: 13px; }
.pe-master .pe-slider { width: 120px; }
.pe-fingers { display: grid; grid-template-columns: 1fr; gap: 6px; }
.pe-finger-row {
  display: grid;
  grid-template-columns: 70px 1fr 46px 1fr 46px;
  align-items: center;
  gap: 8px;
  padding: 4px 10px;
}
.pe-finger-row .pe-finger-name { font-weight: 600; font-size: 13px; }
.pe-finger-row .pe-chan-label { font-size: 11px; color: var(--muted); text-align: right; }
.pe-finger-row .pe-val { font-size: 12px; text-align: right; }
.pose-offset label, .pose-hand-tabs .pe-master { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
.pose-offset .pe-slider { width: 110px; }
/* X axis = horizontal slider, Y axis = vertical slider (spatially intuitive) */
.pose-offset .pe-axis-y { flex-direction: column; align-items: center; gap: 4px; }
.pose-offset .pe-yslider {
  writing-mode: vertical-lr;
  direction: rtl;            /* max (up) at top, min (down) at bottom */
  -webkit-appearance: slider-vertical;  /* legacy Chromium/Safari fallback */
  appearance: slider-vertical;
  width: 26px;
  height: 104px;
}

/* Aim / straighten finger controls */
.pose-aim { display: flex; flex-direction: column; gap: 6px; }
.pe-aim-hint { font-size: 11px; color: var(--muted); }
.pe-aim-list { display: grid; grid-template-columns: 1fr; gap: 5px; }
.pe-aim-row {
  display: grid;
  grid-template-columns: minmax(96px, 130px) minmax(0, 1fr) minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  padding: 3px 8px;
  border-radius: 8px;
}
.pe-aim-row.on { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.pe-aim-toggle { justify-self: start; white-space: nowrap; }
.pe-aim-toggle.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.pe-aim-ch { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; min-width: 0; }
.pe-aim-ch .pe-slider { flex: 1 1 60px; min-width: 0; }
.pe-aim-ch .pe-val { min-width: 30px; text-align: right; }
.pe-aim-ch input:disabled { opacity: 0.4; }
.pe-aim-row:not(.on) .pe-aim-ch { opacity: 0.55; }

/* Drag-to-select edit range */
.pose-range { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.pe-range-track {
  position: relative;
  flex: 1 1 220px;
  min-width: 160px;
  height: 16px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--accent) 10%, var(--card-bg, #fff));
  border: 1px solid var(--border, #d9e0e6);
  cursor: crosshair;
  touch-action: none;
}
.pe-range-fill {
  position: absolute;
  top: 0; bottom: 0;
  background: color-mix(in srgb, var(--accent) 42%, transparent);
  border-radius: 7px;
  cursor: grab;
}
.pe-range-h {
  position: absolute;
  top: -2px;
  width: 10px;
  height: 20px;
  margin-left: -5px;
  border-radius: 4px;
  background: var(--accent);
  border: 2px solid #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
  cursor: ew-resize;
}
.pe-range-h.hidden, .pe-range-fill.hidden { display: none; }
#peRangeLabel { font-size: 12px; white-space: nowrap; }

/* Per-frame editing cues */
.pose-frame-note { padding-top: 0; padding-bottom: 0; }
.pe-frame-note-text { font-size: 11.5px; color: var(--muted); line-height: 1.4; }
.pe-frame-note-text b { color: var(--accent); }
#peFrameNum.pe-frame-edited { color: var(--accent); font-weight: 600; }
.pose-actions { background: transparent; padding-left: 0; }
.pose-actions #peSaveStatus { margin-left: 6px; }
.pose-editor-card.busy { opacity: 0.6; pointer-events: none; }

/* Handshape presets + copy/mirror-hand */
.pose-handshapes, .pose-hand-transfer { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.pe-hs-grid { display: flex; flex-wrap: wrap; gap: 5px; flex: 1 1 240px; }
.pe-hs-btn { padding: 4px 9px; font-size: 12px; }
.pe-hs-custom { border-color: #2ca06b; color: #1f8a5b; }
.pe-hs-custom:hover { background: color-mix(in srgb, #2ca06b 14%, transparent); border-color: #2ca06b; }

/* Editable number inputs (type a value next to any slider) */
.pe-num {
  box-sizing: border-box;
  width: 46px;
  padding: 2px 4px;
  font-size: 12px;
  text-align: right;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
  font-variant-numeric: tabular-nums;
  -moz-appearance: textfield;
}
.pe-num::-webkit-outer-spin-button,
.pe-num::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.pe-num:disabled { opacity: 0.4; }
.pe-finger-row .pe-num { width: 100%; }
.pe-aim-ch .pe-num { width: 44px; flex: 0 0 auto; }
.pose-wrist .pe-num, .pose-offset .pe-num { width: 48px; margin-left: 4px; }

/* Saved-version (backup) restore panel */
.pe-backup-panel { flex-direction: column; align-items: stretch; gap: 8px; }
.pe-backup-panel.hidden { display: none; }
.pe-backup-head { display: flex; align-items: center; gap: 10px; }
.pe-backup-head #peBackupStatus { margin-left: auto; }
.pe-backup-hint { margin: 0; font-size: 11.5px; color: var(--muted); line-height: 1.4; }
.pe-backup-list { display: flex; flex-direction: column; gap: 5px; max-height: 220px; overflow-y: auto; }
.pe-backup-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.pe-backup-item .pe-backup-when { font-weight: 600; font-size: 13px; color: var(--text); }
.pe-backup-item .pe-backup-size { font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.pe-backup-item .soft-button { margin-left: auto; }
.pe-backup-empty { font-size: 12.5px; color: var(--muted); padding: 6px 4px; }

/* Edit workspace: transparent when idle; a 2-column "compare" layout while editing —
   video+avatar on the left (kept in view), the sticky control panel on the right. */
.edit-workspace { display: contents; }
/* Edit mode = a single screen: [ video | avatar ] on the left filling the height, and ALL controls
   on the right in a compact grid — everything visible and adjustable, no page scroll. */
.edit-workspace.editing {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(280px, 1fr) 8px var(--pe-panel-w, clamp(300px, 24%, 380px));
  gap: 0 6px;
  overflow: hidden;
}
/* preview = wide left column, then the draggable gutter, then the control panel (resizable) */
.edit-workspace.editing .preview-grid { order: 1; }
.edit-workspace.editing .pe-resizer { order: 2; display: block; }
.edit-workspace.editing #poseEditorCard { order: 3; }
.edit-workspace.editing .preview-grid {
  margin: 0;
  height: 100%;
  min-height: 0;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}
.edit-workspace.editing .preview-grid .card { min-height: 0; height: 100%; display: flex; flex-direction: column; }
.edit-workspace.editing .preview-grid .avatar-frame-shell,
.edit-workspace.editing .preview-grid .video-preview-shell { min-height: 0 !important; flex: 1 1 auto; }
/* Pose editor only edits one clip at a time: collapse the multicam to the big
   camera and drop the side column. */
.edit-workspace.editing .multicam { display: block; height: 100%; min-height: 0; }
.edit-workspace.editing .multicam-side { display: none; }
.edit-workspace.editing .multicam-main { height: 100%; }
.edit-workspace.editing .preview-grid .preview-video,
.edit-workspace.editing .preview-grid .library-avatar-frame { height: 100%; min-height: 0; }
.edit-workspace.editing #poseEditorCard {
  height: 100%;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-auto-rows: min-content;
  align-content: start;
  gap: 8px;
  padding: 12px;
}
/* wide groups span both columns; hand-tabs/trim/wrist/offset pair up in the two columns */
.edit-workspace.editing #poseEditorCard > .pose-editor-head,
.edit-workspace.editing #poseEditorCard > .pose-sample-row,
.edit-workspace.editing #poseEditorCard > .pose-scrubber,
.edit-workspace.editing #poseEditorCard > #peFingerControls,
.edit-workspace.editing #poseEditorCard > .pose-actions { grid-column: 1 / -1; }
.edit-workspace.editing #poseEditorCard > .pose-editor-hint { display: none; }
/* compact rows so everything fits without scrolling */
.edit-workspace.editing #poseEditorCard .pose-editor-row { padding: 6px 8px; gap: 6px; }
.edit-workspace.editing #poseEditorCard .pe-finger-row { padding: 2px 8px; gap: 5px; }
.edit-workspace.editing #poseEditorCard > .pose-aim { grid-column: 1 / -1; }
.edit-workspace.editing #poseEditorCard > .pose-frame-note { grid-column: 1 / -1; }
.edit-workspace.editing #poseEditorCard > .pose-range { grid-column: 1 / -1; }
.edit-workspace.editing #poseEditorCard > .pose-handshapes { grid-column: 1 / -1; }
.edit-workspace.editing #poseEditorCard > .pose-hand-transfer { grid-column: 1 / -1; }
.edit-workspace.editing #poseEditorCard .pose-aim { gap: 4px; }
.edit-workspace.editing #poseEditorCard .pe-aim-row { padding: 2px 8px; gap: 6px; }

/* draggable column divider (between preview and the control panel) */
.pe-resizer { display: none; }
.edit-workspace.editing .pe-resizer {
  align-self: stretch;
  width: 8px;
  cursor: col-resize;
  border-radius: 5px;
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  opacity: 0.55;
  transition: opacity 0.15s ease;
}
.edit-workspace.editing .pe-resizer:hover,
body.pe-resizing .pe-resizer { opacity: 1; }
body.pe-resizing { cursor: col-resize; user-select: none; }
/* let the drag glide over the avatar iframe / video instead of being swallowed by them */
body.pe-resizing iframe, body.pe-resizing video { pointer-events: none; }

/* Small screens: relax the lock — let the edit page scroll normally instead of clipping. */
@media (max-width: 1099px) {
  body.pose-editing-active { display: block; height: auto; overflow: visible; }
  body.pose-editing-active .library-shell { height: auto; overflow: visible; }
  body.pose-editing-active .library-content,
  body.pose-editing-active #detailView { height: auto; min-height: 0; overflow: visible; display: block; }
  .edit-workspace.editing { display: block; overflow: visible; }
  .edit-workspace.editing .preview-grid { height: auto; margin: 0 0 14px; }
  .edit-workspace.editing .preview-grid .avatar-frame-shell,
  .edit-workspace.editing .preview-grid .video-preview-shell { min-height: 300px !important; }
  .edit-workspace.editing #poseEditorCard { height: auto; overflow: visible; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
  .edit-workspace.editing .pe-resizer { display: none; }
}

/* Active-hand color cue: blue = left, orange = right. Colors the panel frame,
   the finger-control box frame, the active tab, and a text badge. */
:root { --pe-left: #2f6fed; --pe-right: #e0772b; }
#peSkeletonToggle[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.pose-editor-card.pe-side-left { border-color: var(--pe-left); border-width: 2px; }
.pose-editor-card.pe-side-right { border-color: var(--pe-right); border-width: 2px; }
.pe-hand-tab[data-pe-hand="left"].active { background: var(--pe-left); border-color: var(--pe-left); color: #fff; }
.pe-hand-tab[data-pe-hand="right"].active { background: var(--pe-right); border-color: var(--pe-right); color: #fff; }
#peFingerControls { border: 3px solid transparent; border-radius: 10px; padding: 6px 4px; transition: border-color .15s ease; }
.pose-editor-card.pe-side-left #peFingerControls { border-color: var(--pe-left); }
.pose-editor-card.pe-side-right #peFingerControls { border-color: var(--pe-right); }
.pe-hand-badge { font-weight: 700; font-size: 12px; padding: 3px 12px; border-radius: 999px; color: #fff; white-space: nowrap; }
.pose-editor-card.pe-side-left .pe-hand-badge { background: var(--pe-left); }
.pose-editor-card.pe-side-right .pe-hand-badge { background: var(--pe-right); }
.pose-editor-card.pe-side-left .pe-hand-badge::before { content: "🟦 กำลังแก้: มือซ้าย (Left)"; }
.pose-editor-card.pe-side-right .pe-hand-badge::before { content: "🟧 กำลังแก้: มือขวา (Right)"; }

/* Keep every control inside the panel frame. Range inputs carry an intrinsic min-width, and
   grid/flex tracks default to min-width:auto — so sliders overflow ("ทะลุกรอบ") unless we let
   the tracks shrink and force the sliders to 0 min-width / full track width. */
#poseEditorCard, #poseEditorCard * { box-sizing: border-box; }
#poseEditorCard { overflow-x: hidden; }
.pose-editor-card .pe-slider { min-width: 0; max-width: 100%; }
.pe-finger-row { grid-template-columns: 58px minmax(0, 1fr) 38px minmax(0, 1fr) 38px; gap: 6px; }
.pe-finger-row .pe-slider { width: 100%; }
.pose-scrubber .pe-slider,
.pose-editor-card .pe-slider.grow { flex: 1 1 80px; min-width: 0; }
.pose-offset .pe-slider { width: 92px; }
.pe-master .pe-slider { width: 100px; }

/* candidate / chosen-json selector */
.pe-sample-select { flex: 1 1 220px; min-width: 0; max-width: 100%; }

/* loading overlay (raw load + save) — centered spinner that flips to a check on success */
.pe-loading-toast { position: fixed; inset: 0; z-index: 9999; display: flex; align-items: center; justify-content: center; background: rgba(15, 30, 35, 0.30); backdrop-filter: blur(2px); }
.pe-loading-toast.hidden { display: none; }
.pe-loading-box { display: flex; flex-direction: column; align-items: center; gap: 14px; background: #fff; color: #1f2d36; padding: 26px 38px; border-radius: 16px; box-shadow: 0 18px 50px rgba(0, 0, 0, 0.25); min-width: 210px; }
.pe-spinner { width: 44px; height: 44px; border-radius: 50%; border: 4px solid var(--accent-soft); border-top-color: var(--accent); animation: pe-spin 0.8s linear infinite; }
@keyframes pe-spin { to { transform: rotate(360deg); } }
.pe-check { display: none; font-size: 44px; line-height: 1; color: #2f9e6f; font-weight: 700; }
.pe-loading-toast.pe-loading-done .pe-spinner { display: none; }
.pe-loading-toast.pe-loading-done .pe-check { display: block; animation: pe-pop 0.3s ease; }
@keyframes pe-pop { from { transform: scale(0.5); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.pe-loading-text { font-weight: 600; color: #1f2d36; }

/* Hide the left sidebar entirely while editing a pose (more room to compare video + avatar) */
/* ================= Desktop edit mode: one no-scroll screen ================= */
/* Hide the left sidebar (beats the desktop dual-pane rule of equal specificity via !important). */
body.pose-editing-active .library-sidebar { display: none !important; }
/* Turn the page into a fixed-height flex column so the workspace fills the viewport exactly. */
body.pose-editing-active { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }
body.pose-editing-active .library-topbar { flex: 0 0 auto; }
body.pose-editing-active .library-shell {
  flex: 1 1 auto;
  min-height: 0;
  grid-template-columns: minmax(0, 1fr) !important;
  gap: 0 !important;
  overflow: hidden;
  padding-bottom: 12px;
}
body.pose-editing-active .library-content { grid-column: 1 / -1 !important; min-height: 0; height: 100%; overflow: hidden; }
body.pose-editing-active #detailView { min-height: 0; height: 100%; display: flex; flex-direction: column; overflow: hidden; }
/* show ONLY the edit workspace — hero, review bar, candidate table, etc. are hidden while editing */
body.pose-editing-active #detailView > *:not(.edit-workspace) { display: none !important; }

/* Label filters relocated into a dropdown popover anchored at the top-right of the Labels card */
.list-card .section-head { position: relative; }
.list-head-right { display: flex; align-items: center; gap: 8px; }
.filter-toggle { padding: 4px 12px; font-size: 13px; white-space: nowrap; }
.list-head-right .refresh-btn { padding: 4px 12px; font-size: 13px; white-space: nowrap; }
.list-result-count { display: block; margin: 2px 0 0; font-size: 13px; }
.filter-popover {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 60;
  width: 300px;
  max-width: 86vw;
  background: var(--panel, #fff);
  border: 1px solid var(--accent-soft);
  border-radius: 12px;
  box-shadow: 0 16px 44px rgba(0, 0, 0, 0.20);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.filter-popover.hidden { display: none; }
.pose-sample-row .pe-sample-select { flex: 1 1 180px; }
.pose-offset .pe-z-slider { width: 150px; }
.pose-offset #peZVal { min-width: 34px; text-align: right; }
.pose-wrist label { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
.pose-wrist .pe-slider { width: 96px; }
.pose-wrist .pe-val { min-width: 30px; text-align: right; }

/* ---- Square corners + fix the slight Source Video / Skeleton misalignment ---
   Keep the original panel heights. The only problem was `.multicam` carrying its
   own min-height (360px) taller than the big camera / Skeleton shells (~290px),
   so the stacked L+R column ran a bit lower than the big camera. Drop that extra
   min-height and let the big camera fill the multicam, so all bottoms line up.
   Scoped to the normal detail view (the pose editor sizes itself). */
.edit-workspace:not(.editing) .preview-grid .video-preview-shell,
.edit-workspace:not(.editing) .preview-grid .avatar-frame-shell,
.edit-workspace:not(.editing) .preview-grid .multicam-cell,
.edit-workspace:not(.editing) .preview-grid .multicam-main {
  border-radius: 0 !important;
}

@media (min-width: 721px) {
  .edit-workspace:not(.editing) .preview-grid .multicam { min-height: 0 !important; }
  /* Big camera fills the multicam, which now matches the Skeleton frame height. */
  .edit-workspace:not(.editing) .preview-grid .multicam-main {
    height: 100% !important;
    min-height: 0 !important;
    max-height: none !important;
  }
  /* The two side cameras split that same height, so their bottoms align. */
  .edit-workspace:not(.editing) .preview-grid .multicam-side {
    height: 100%;
    min-height: 0;
  }
}
