/* Care viewer
   Reading-room palette: graphite chrome around true-black viewports so the
   surround never competes with grayscale detail. One accent (film-viewer
   blue) for interaction; green / red are reserved for the latency verdict. */

@font-face { font-family: "Plex"; src: url("../fonts/ibm-plex-sans-latin-400-normal.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Plex"; src: url("../fonts/ibm-plex-sans-latin-500-normal.woff2") format("woff2"); font-weight: 500; font-display: swap; }
@font-face { font-family: "Plex"; src: url("../fonts/ibm-plex-sans-latin-600-normal.woff2") format("woff2"); font-weight: 600; font-display: swap; }

:root {
  --chrome: #1a1f26;
  --panel: #20262e;
  --raised: #29313b;
  --line: #313a46;
  --text: #dce2ea;
  --muted: #8d98a6;
  --faint: #5f6a78;
  --accent: #7fb2e5;
  --accent-ink: #0f1a26;
  --pass: #5cc394;
  --fail: #ea6a73;
  --warn: #e2b25b;
  --viewport: #000;

  --radius-sm: 4px;
  --radius: 6px;
  --side: 340px;
  --font: "Plex", "IBM Plex Sans", "Segoe UI", system-ui, -apple-system, sans-serif;

  --step--1: 0.75rem;   /* 12 */
  --step-0: 0.8125rem;  /* 13 */
  --step-1: 0.9375rem;  /* 15 */
  --step-2: 1.25rem;    /* 20 */
  --step-3: 1.75rem;    /* 28 */
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--chrome);
  color: var(--text);
  font: 400 var(--step-0)/1.45 var(--font);
  font-variant-numeric: tabular-nums;
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, p { margin: 0; }
button, select, input { font: inherit; color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Top bar ---------- */
.topbar {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark { width: 30px; height: 30px; flex: none; fill: none; stroke-linecap: round; }
.brand-mark circle { fill: #000; stroke: var(--line); stroke-width: 1.5; }
.brand-mark .v { stroke: var(--accent); stroke-width: 2.2; }
.brand h1 { font-size: var(--step-1); font-weight: 600; letter-spacing: 0.005em; }
.file-line { color: var(--muted); font-size: var(--step--1); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 60vw; }
.file-line strong { color: var(--text); font-weight: 500; }
.topbar-actions { display: flex; align-items: center; gap: 14px; }
.run-state { color: var(--muted); font-size: var(--step--1); }

.progress { position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; background: transparent; }
.progress-fill { height: 100%; width: 0; background: var(--accent); transition: width 0.2s linear; }
.progress.indeterminate .progress-fill { width: 30%; animation: slide 1.1s ease-in-out infinite; }
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(340%); } }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 32px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--raised); color: var(--text);
  font-weight: 500; text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--faint); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: #95c0ea; border-color: #95c0ea; }
.btn-small { height: 30px; padding: 0 10px; font-size: var(--step--1); justify-content: flex-start; }
label.btn:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }

.icon-btn, .text-btn {
  height: 28px; min-width: 28px; padding: 0 6px;
  border: 0; border-radius: var(--radius-sm); background: transparent; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; color: var(--text);
}
.icon-btn:hover, .text-btn:hover { background: var(--raised); }
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn.play svg { fill: currentColor; stroke: none; }
.text-btn { font-size: var(--step--1); color: var(--muted); padding: 0 8px; }
.text-btn:hover { color: var(--text); }

/* ---------- Workspace ---------- */
.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--side);
  min-height: 0;
}
.viewer { display: grid; grid-template-rows: auto 1fr auto; min-width: 0; min-height: 0; }

.toolbar {
  display: flex; align-items: center; gap: 20px;
  padding: 8px 12px; border-bottom: 1px solid var(--line);
}
.toolbar.is-disabled { opacity: 0.45; pointer-events: none; }
.segmented { display: inline-flex; padding: 2px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.segmented button {
  border: 0; background: transparent; padding: 3px 12px; border-radius: var(--radius-sm);
  color: var(--muted); cursor: pointer; font-size: var(--step--1); font-weight: 500;
}
.segmented button[aria-checked="true"] { background: var(--raised); color: var(--text); }
.tool-group { display: inline-flex; align-items: center; gap: 2px; }
.zoom-readout { min-width: 48px; text-align: center; font-size: var(--step--1); color: var(--muted); }
.toggle { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: var(--step--1); cursor: pointer; }
.toggle input { accent-color: var(--accent); width: 14px; height: 14px; margin: 0; }

/* ---------- Stage & panes ---------- */
.stage { position: relative; min-height: 0; background: var(--viewport); }
.panes { position: absolute; inset: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 2px; background: var(--line); }
.panes.is-swipe { grid-template-columns: 1fr; }
.panes.is-swipe #paneB { display: none; }
.pane { position: relative; margin: 0; background: var(--viewport); overflow: hidden; cursor: grab; touch-action: none; }
.pane.is-dragging { cursor: grabbing; }
.pane canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.pane-label, .pane-meta, .pane-latency {
  position: absolute; z-index: 2; pointer-events: none;
  font-size: var(--step--1); line-height: 1;
  padding: 5px 7px; border-radius: var(--radius-sm);
  background: rgba(10, 13, 17, 0.72); color: var(--text);
}
.pane-label { top: 10px; left: 10px; font-weight: 600; }
.pane-label-right { left: auto; right: 10px; }
.pane-meta { bottom: 10px; color: var(--muted); }
.pane-meta:empty, .pane-latency:empty { display: none; }
.pane-meta-left { left: 10px; }
.pane-meta-right { right: 10px; }
.pane-latency { top: 10px; right: 10px; font-weight: 500; }
.pane-latency.ok { color: var(--pass); }
.pane-latency.slow { color: var(--fail); }
.pane-notice {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 2;
  max-width: 70%; text-align: center; color: var(--muted);
  background: rgba(10, 13, 17, 0.8); padding: 10px 14px; border-radius: var(--radius);
}

.swipe-handle {
  position: absolute; top: 0; bottom: 0; left: 50%; z-index: 3; width: 24px; margin-left: -12px;
  cursor: ew-resize; display: flex; justify-content: center;
}
.swipe-handle::before { content: ""; width: 2px; height: 100%; background: var(--accent); opacity: 0.9; }
.swipe-handle span {
  position: absolute; top: 50%; width: 22px; height: 36px; margin-top: -18px;
  border-radius: 11px; background: var(--accent); box-shadow: 0 0 0 3px rgba(0,0,0,0.45);
}
.swipe-handle span::before, .swipe-handle span::after {
  content: ""; position: absolute; top: 13px; border: 5px solid transparent;
}
.swipe-handle span::before { left: 0; border-right-color: var(--accent-ink); }
.swipe-handle span::after { right: 0; border-left-color: var(--accent-ink); }

/* ---------- Empty / message states ---------- */
.empty, .message { position: absolute; inset: 0; display: grid; place-items: center; padding: 24px; background: var(--chrome); }
.drop-target {
  width: min(560px, 100%);
  padding: 40px 36px;
  border: 1.5px dashed var(--line); border-radius: 10px;
  display: grid; justify-items: start; gap: 12px;
  transition: border-color 0.15s, background-color 0.15s;
}
.drop-target.is-over { border-color: var(--accent); background: rgba(127, 178, 229, 0.05); }
.drop-icon { width: 44px; height: 44px; fill: none; stroke: var(--accent); stroke-width: 1.8; stroke-linecap: round; }
.drop-target h2, .message h2 { font-size: var(--step-2); font-weight: 600; }
.drop-target p, .message p { color: var(--muted); max-width: 60ch; }
.drop-target .btn { margin-top: 6px; }
.formats { font-size: var(--step--1); color: var(--faint) !important; }
.drop-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.drop-actions .btn { margin-top: 0; }
.samples { width: 100%; display: grid; gap: 6px; }
.samples-title { font-size: var(--step--1); }
.samples ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.samples li button {
  width: 100%; display: flex; justify-content: space-between; gap: 12px;
  padding: 6px 10px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: transparent; color: var(--text); font: inherit; font-size: var(--step--1);
  text-align: left; cursor: pointer;
}
.samples li button:hover { border-color: var(--accent); background: var(--raised); }
.samples li button span:last-child { color: var(--faint); flex: none; }
.message { justify-items: center; text-align: center; align-content: center; gap: 10px; }
.message h2 { color: var(--fail); }

.drop-overlay {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center;
  background: rgba(16, 20, 26, 0.82); border: 2px solid var(--accent);
}
.drop-overlay p { font-size: var(--step-2); font-weight: 600; color: var(--accent); }

/* ---------- Transport + latency trace ---------- */
.transport {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 12px;
  padding: 8px 12px; border-top: 1px solid var(--line);
}
.transport-buttons { display: inline-flex; gap: 2px; }
.icon-btn.play { width: 34px; height: 34px; border-radius: 50%; background: var(--raised); }
.icon-btn.play:hover { background: var(--line); }
.icon-btn.play .i-pause, .icon-btn.play.is-playing .i-play { display: none; }
.icon-btn.play.is-playing .i-pause { display: block; }

.trace { position: relative; height: 64px; min-width: 0; }
.trace canvas { width: 100%; height: 100%; display: block; cursor: pointer; border-radius: var(--radius-sm); }
.trace-tip {
  position: absolute; bottom: calc(100% + 6px); transform: translateX(-50%);
  padding: 4px 8px; border-radius: var(--radius-sm); white-space: nowrap; pointer-events: none;
  background: var(--raised); border: 1px solid var(--line); font-size: var(--step--1);
}
.transport-meta { display: inline-flex; align-items: center; gap: 10px; }
.frame-readout { font-weight: 500; min-width: 72px; text-align: right; }
.fps-note { color: var(--faint); font-size: var(--step--1); min-width: 56px; }
select {
  height: 28px; padding: 0 6px; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius-sm); font-size: var(--step--1);
}

/* ---------- Sidebar ---------- */
.sidebar {
  border-left: 1px solid var(--line);
  background: var(--panel);
  overflow-y: auto; min-height: 0;
  display: flex; flex-direction: column;
}
.block { padding: 16px 18px; border-top: 1px solid var(--line); }
.block h3 { font-size: var(--step-0); font-weight: 600; margin-bottom: 10px; }

.verdict { padding: 18px 18px 16px; }
.verdict h2 { font-size: var(--step-3); font-weight: 600; line-height: 1.1; letter-spacing: -0.01em; margin-bottom: 6px; color: var(--muted); }
.verdict p { color: var(--muted); }
.verdict[data-state="met"] h2 { color: var(--pass); }
.verdict[data-state="missed"] h2 { color: var(--fail); }
.verdict[data-state="running"] h2 { color: var(--text); }
.verdict[data-state="met"] { box-shadow: inset 3px 0 0 var(--pass); }
.verdict[data-state="missed"] { box-shadow: inset 3px 0 0 var(--fail); }


.metrics { margin: 0; display: grid; }
.metrics > div { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px solid rgba(49, 58, 70, 0.6); }
.metrics > div:last-child { border-bottom: 0; }
.metrics dt { color: var(--muted); }
.metrics dd { margin: 0; font-weight: 500; text-align: right; }
.metrics dd .unit { color: var(--muted); font-weight: 400; margin-left: 2px; }
.metrics dd.ok { color: var(--pass); }
.metrics dd.bad { color: var(--fail); }
.metrics .is-current dt { color: var(--text); }
.metrics.compact > div { padding: 4px 0; }
.metrics.compact dd { font-weight: 400; max-width: 60%; overflow-wrap: anywhere; }
.footnote { margin-top: 10px; font-size: var(--step--1); color: var(--faint); max-width: 48ch; }

.notes { margin: 8px 0 0; padding-left: 16px; color: var(--muted); font-size: var(--step--1); }
.notes:empty { display: none; }
.notes li + li { margin-top: 4px; }


.side-footer { margin-top: auto; padding: 14px 18px 18px; border-top: 1px solid var(--line); color: var(--faint); font-size: var(--step--1); display: grid; gap: 6px; }

/* ---------- Responsive ---------- */
@media (max-width: 1080px) {
  :root { --side: 300px; }
}
@media (max-width: 860px) {
  body { overflow: auto; grid-template-rows: auto auto; }
  .workspace { grid-template-columns: 1fr; }
  .viewer { height: 78vh; }
  .panes { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
  .panes.is-swipe { grid-template-rows: 1fr; }
  .sidebar { border-left: 0; border-top: 1px solid var(--line); overflow: visible; }
  .toolbar { flex-wrap: wrap; gap: 10px 16px; }
  .transport { grid-template-columns: auto 1fr; }
  .transport-meta { grid-column: 1 / -1; justify-content: flex-end; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
