:root {
  color-scheme: dark;
  --bg: #101214;
  --panel: #191c1f;
  --border: #383d42;
  --text: #f1f3f4;
  --muted: #a5abb1;
  --brand: #5fd9cb;
  --danger: #f17d89;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--text); }
button, input { font: inherit; }
button {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: .55rem 1rem;
  background: #36c6b4;
  color: #04111c;
  font-weight: 700;
  cursor: pointer;
}
button.secondary { background: transparent; color: var(--text); border-color: var(--border); }
button:disabled { opacity: .45; cursor: not-allowed; }
.lab-main { padding: 64px 20px 24px; max-width: 1400px; margin: 0 auto; }
.work-layout {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}
.collections {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  max-height: calc(100vh - 96px);
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  position: sticky;
  top: 64px;
}
.collections h2 {
  margin: 0 0 10px;
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
}
.collection-item {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  width: 100%;
  padding: 8px;
  margin: 0 0 6px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: inherit;
  font-weight: 600;
  text-align: left;
  contain: layout style;
  content-visibility: auto;
  contain-intrinsic-size: 0 56px;
  touch-action: manipulation;
}
.collection-item:hover { background: #12181b; }
.collection-item:active { background: #152226; }
.collection-item.active { border-color: var(--brand); background: #152226; }
.collection-item img,
.cover-empty {
  width: 56px;
  height: 40px;
  object-fit: cover;
  border-radius: 4px;
  background: #0b0d0f;
}
.collection-item .title {
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.collection-item .meta { font-size: 12px; color: var(--muted); font-weight: 500; }
@media (max-width: 800px) {
  .work-layout { grid-template-columns: 1fr; }
  .collections { position: static; max-height: 220px; }
}
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 1.2rem; }
.muted { color: var(--muted); }
.hint-flash {
  margin: 0 0 8px;
  color: var(--muted);
  animation: hint-pulse 1.6s ease-in-out infinite;
}
@keyframes hint-pulse {
  0%, 100% { opacity: 0.35; }
  50% { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .hint-flash { animation: none; opacity: 0.85; }
}
.stitch-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 0 0 12px; }
.cp-panel {
  margin: 0 0 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #14181c;
  color: var(--text);
}
.cp-panel > summary {
  cursor: pointer;
  padding: 10px 12px;
  font-weight: 600;
  list-style: none;
}
.cp-panel > summary::-webkit-details-marker { display: none; }
.cp-panel.is-locked {
  opacity: 0.55;
}
.cp-panel.is-locked > summary { cursor: not-allowed; }
.cp-body { padding: 0 12px 12px; display: grid; gap: 10px; }
.cp-pair-label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.cp-pair-label select {
  width: min(360px, 100%);
  padding: .45rem .6rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #101214;
  color: var(--text);
}
.cp-pair-view { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.cp-viewport {
  position: relative;
  height: min(42vh, 340px);
  min-height: 220px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #0b0d0f;
  overflow: hidden;
  touch-action: none;
  cursor: crosshair;
  user-select: none;
}
.cp-viewport.is-aim { cursor: crosshair; }
.cp-viewport.is-panning {
  cursor: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='32' height='32'><text y='24' font-size='24'>👋</text></svg>") 16 16, grab;
}
.cp-world {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 0 0;
  will-change: transform;
}
.cp-viewport img {
  display: block;
  width: 100%;
  height: 100%;
  max-width: none;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}
.cp-marks {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 4;
  overflow: visible;
}
.cp-mark {
  position: absolute;
  width: 0;
  height: 0;
  --cp: #e11d48;
  z-index: 4;
  overflow: visible;
}
.cp-mark-ui {
  position: absolute;
  left: 0;
  top: 0;
  width: 36px;
  height: 36px;
  margin: -18px 0 0 -18px;
}
.cp-cross-h,
.cp-cross-v {
  position: absolute;
  background: var(--cp);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .55);
}
.cp-cross-h { left: 10px; top: 17px; width: 16px; height: 2px; }
.cp-cross-v { left: 17px; top: 10px; width: 2px; height: 16px; }
.cp-swatch-mark {
  position: absolute;
  left: 28px;
  top: 22px;
  width: 12px;
  height: 12px;
  border-radius: 2px;
  background: var(--cp);
  box-shadow: 0 0 0 1px #fff, 0 0 0 2px rgba(0, 0, 0, .55);
}
.cp-badge {
  position: absolute;
  left: 28px;
  top: 4px;
  min-width: 16px;
  padding: 0 4px;
  border-radius: 3px;
  background: var(--cp);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .45);
}
.cp-mark.is-pending { opacity: 0.72; }
.cp-mark.is-pending .cp-badge { outline: 1px dashed #fff; }
.cp-swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: 6px;
  border-radius: 2px;
  vertical-align: -1px;
}
.cp-caption { margin-top: 6px; font-size: 12px; color: var(--muted); }
.cp-list { margin: 0; padding-left: 0; list-style: none; font-size: 13px; color: var(--muted); }
.cp-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 6px;
}
.cp-pick {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
  cursor: pointer;
}
.cp-pick input { flex: 0 0 auto; }
.cp-list button {
  margin-left: 8px;
  min-height: 28px;
  padding: 0 8px;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}
.cp-actions { display: flex; gap: 8px; flex-wrap: wrap; }
@media (max-width: 720px) {
  .cp-pair-view { grid-template-columns: 1fr; }
}
#seal { background: #f3c96b; color: #241802; }
.status { min-height: 1.4em; margin: .8rem 0 0; }
.status.error { color: var(--danger); }
.gate { max-width: 420px; margin: 48px auto 0; }
.gate form { display: grid; gap: 12px; }
.gate input { width: 100%; padding: .7rem .8rem; border-radius: 8px; border: 1px solid var(--border); background: #101214; color: var(--text); }
.toolbar { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.strip {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  padding: 8px 0 16px;
  min-height: 120px;
}
.strip-loading {
  margin: 28px 0 0;
  white-space: nowrap;
}
.thumb {
  flex: 0 0 auto;
  width: 120px;
  text-align: center;
  contain: layout style;
  content-visibility: auto;
  contain-intrinsic-size: 120px 104px;
}
.thumb img {
  width: 120px;
  height: 80px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #0b0d0f;
}
.thumb .name { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thumb:hover img,
.thumb.menu-open img { border-color: var(--brand); }
.thumb-menu {
  position: fixed;
  z-index: 20;
  min-width: 132px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #1c2024;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .35);
}
.thumb-menu.hidden { display: none; }
.thumb-menu button {
  display: block;
  width: 100%;
  min-height: 36px;
  margin: 0;
  padding: .4rem .7rem;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  font-weight: 600;
  text-align: left;
}
.thumb-menu button:hover { background: #152226; }
.progress-wrap { margin: 4px 0 12px; }
.progress-label {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  font-size: 13px;
  color: var(--muted);
}
.progress-bar {
  height: 8px;
  border-radius: 999px;
  background: #0b0d0f;
  border: 1px solid var(--border);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, #2aa89a, #5fd9cb);
  transition: width .25s ease;
}
.pano-wrap {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #0b0d0f;
  min-height: 280px;
  height: min(56vh, 640px);
}
.pano-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 24px;
  text-align: center;
  color: var(--text);
  opacity: 0.38;
  pointer-events: none;
  z-index: 1;
}
.pano-wrap.is-ready .pano-placeholder { display: none; }
.pano-world {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 100%;
  min-height: 100%;
}
.pano-spin {
  position: relative;
  flex: 0 0 auto;
  transform-origin: center center;
}
.pano-tiles {
  position: relative;
  min-width: 100%;
  min-height: 100%;
}
.pano-tile {
  position: absolute;
  display: block;
  pointer-events: none;
}
.pano-stage {
  width: 100%;
  height: 100%;
  overflow: auto;
  cursor: grab;
  touch-action: none;
}
.pano-stage.dragging { cursor: grabbing; user-select: none; }
.pano-canvas {
  display: flex;
  align-items: center;
  justify-content: center;
  width: max-content;
  height: max-content;
  min-width: 0;
  min-height: 0;
}
.pano-stage img {
  display: block;
  max-width: none;
  height: auto;
  transform-origin: 0 0;
  user-select: none;
  -webkit-user-drag: none;
}
.pano-tools {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 3;
  display: flex;
  gap: 10px;
  align-items: center;
  pointer-events: none;
}
.pano-tools.hidden { display: none; }
.pano-rotate {
  position: relative;
  width: 72px;
  height: 72px;
  flex: 0 0 72px;
  pointer-events: auto;
  touch-action: none;
  cursor: grab;
  user-select: none;
}
.pano-rotate.is-dragging { cursor: grabbing; }
.pano-rotate svg {
  display: block;
  width: 72px;
  height: 72px;
  overflow: visible;
}
.pano-rotate-track {
  fill: rgba(11, 13, 15, 0.55);
  stroke: #5fd9cb;
  stroke-width: 6;
}
.pano-rotate-arm {
  stroke: #f1f3f4;
  stroke-width: 2;
}
.pano-rotate-handle {
  fill: #5fd9cb;
  stroke: #04111c;
  stroke-width: 2;
}
.pano-rotate-deg {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: var(--text);
  pointer-events: none;
}
.pano-zoom {
  display: flex;
  gap: 6px;
  align-items: center;
  pointer-events: auto;
}
.pano-zoom button {
  min-height: 32px;
  min-width: 32px;
  padding: 0;
  background: rgba(25, 28, 31, 0.9);
  color: var(--text);
  border: 1px solid var(--border);
}
.pano-size {
  font-size: 12px;
  color: var(--muted);
  background: rgba(11, 13, 15, 0.72);
  padding: 4px 8px;
  border-radius: 6px;
}
.pano-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}
.pano-actions.hidden { display: none; }
.pano-download {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 0 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #191c1f;
  color: var(--text);
  text-decoration: none;
}
.dialog-mask {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 10, 12, 0.62);
  padding: 20px;
}
.dialog {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 18px 14px;
}
.dialog h3 { margin: 0 0 8px; font-size: 1.05rem; }
.dialog .muted { margin: 0 0 12px; font-size: 13px; color: var(--muted); }
.dialog-label { display: block; font-size: 13px; color: var(--muted); }
.dialog-label input {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: .55rem .7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #101214;
  color: var(--text);
}
.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}
.hidden { display: none; }
