/* ============================================================
   Video Compare — a DmytroOS app (apps/videocompare.html)
   Colours, type and radii come from ../css/tokens.css; the controls copy the OS look
   (pill buttons, segmented groups, 4px range tracks) without loading the desktop CSS.
   ============================================================ */

:root {
  --stage: #0b0b0d;
  --vc-warn: #c2410c;
  --vc-gap: 8px;
  --vc-hit: 28px;
}
:root[data-theme="dark"] { --vc-warn: #ff9f5a; }
@media (pointer: coarse) { :root { --vc-hit: 40px; } }

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: var(--win-bg);
  color: var(--text-1);
  font: var(--fs-body)/1.35 var(--font-sys);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
.num { font-variant-numeric: tabular-nums; }
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
::selection { background: var(--selection); }
svg { flex: none; }
.vc-sprite { position: absolute; width: 0; height: 0; overflow: hidden; } /* not display:none — its gradients must resolve */

/* ---------- controls ---------- */
.vc-btn, .vc-round, .vc-mini {
  display: inline-flex; align-items: center; justify-content: center; gap: 5px;
  min-height: var(--vc-hit);
  border: 1px solid var(--control-border);
  background: var(--control-surface);
  box-shadow: var(--control-shine), 0 1px 2px rgba(0, 0, 0, .06);
  color: var(--text-1);
  white-space: nowrap;
}
.vc-btn { padding: 0 12px; border-radius: 999px; font-weight: 600; }
.vc-btn svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; }
.vc-btn.vc-icon { width: var(--vc-hit); padding: 0; }
.vc-round { width: var(--vc-hit); border-radius: 50%; padding: 0; }
.vc-round svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.vc-btn.is-on, .vc-round.is-on { background: var(--accent); border-color: var(--accent); color: #fff; box-shadow: none; }
.vc-btn:disabled, .vc-round:disabled, .vc-mini:disabled, .vc-play:disabled, .vc-seg button:disabled { opacity: .4; cursor: default; }
.vc-btn:active:not(:disabled), .vc-round:active:not(:disabled), .vc-mini:active:not(:disabled) { filter: brightness(.92); box-shadow: none; }

/* segmented control — the OS "os-group" look */
.vc-seg {
  display: inline-flex; align-items: center; gap: 2px;
  padding: 2px;
  border: 1px solid var(--control-border);
  border-radius: 999px;
  background: var(--ctl-bg);
  box-shadow: var(--control-shine);
}
.vc-seg button {
  display: inline-flex; align-items: center; justify-content: center; gap: 5px;
  min-height: calc(var(--vc-hit) - 6px);
  padding: 0 11px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: none;
  color: var(--text-1);
  font-weight: 500;
  white-space: nowrap;
}
.vc-seg button svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2.1; stroke-linecap: round; stroke-linejoin: round; }
.vc-seg button.is-on {
  border-color: var(--control-border);
  background: var(--control-surface);
  box-shadow: var(--control-shine), 0 1px 3px rgba(0, 0, 0, .15);
  font-weight: 600;
}

.vc-input {
  min-height: var(--vc-hit);
  padding: 0 9px;
  border: 1px solid var(--control-border);
  border-radius: var(--r-ctl);
  background: var(--control-surface);
  box-shadow: var(--control-shine);
  color: var(--text-1);
}
select.vc-input { padding-right: 6px; cursor: pointer; }
.vc-input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* range: the OS 4px track; JS paints the filled part through --lo / --hi */
.vc-range {
  -webkit-appearance: none; appearance: none;
  display: block; width: 100%; height: 22px; margin: 0; padding: 0;
  background: transparent; cursor: pointer;
  --fill: var(--accent);
  --track: linear-gradient(to right, var(--range-track) var(--lo, 0%), var(--fill) var(--lo, 0%),
    var(--fill) var(--hi, 0%), var(--range-track) var(--hi, 0%));
}
.vc-range::-webkit-slider-runnable-track { height: 4px; border-radius: 999px; background: var(--track); }
.vc-range::-moz-range-track { height: 4px; border-radius: 999px; background: var(--track); }
.vc-range::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 16px; height: 16px; margin-top: -6px;
  border: 1px solid var(--control-border); border-radius: 50%;
  background: var(--range-thumb); box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
}
.vc-range::-moz-range-thumb {
  width: 16px; height: 16px; box-sizing: border-box;
  border: 1px solid var(--control-border); border-radius: 50%;
  background: var(--range-thumb); box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
}
.vc-range:disabled { opacity: .45; cursor: default; }

@media (hover: hover) and (pointer: fine) {
  .vc-btn:hover:not(:disabled):not(.is-on), .vc-round:hover:not(:disabled):not(.is-on),
  .vc-mini:hover:not(:disabled) { background: var(--ctl-bg-hover); }
  .vc-seg button:hover:not(:disabled):not(.is-on) { background: var(--ctl-bg-hover); }
  .vc-range:hover:not(:disabled) { --range-thumb: var(--win-chrome); }
}

/* ---------- top bar ---------- */
.vc-bar {
  display: flex; align-items: center; gap: 8px 10px; flex-wrap: wrap;
  min-height: var(--toolbar-h);
  padding: 10px 14px;
  background: var(--win-chrome);
  border-bottom: 1px solid var(--separator);
}
.vc-brand {
  display: inline-flex; align-items: center; gap: 9px; margin-right: 6px;
  color: inherit; text-decoration: none;
}
.vc-brand svg { width: 30px; height: 30px; border-radius: 22.5%; box-shadow: 0 2px 6px rgba(0, 0, 0, .2); }
.vc-brand span { display: flex; flex-direction: column; line-height: 1.15; }
.vc-brand h1 { margin: 0; font-size: var(--fs-md); font-weight: 700; }
.vc-brand i { font-style: normal; font-size: var(--fs-xs); color: var(--text-3); }
/* text version for crawlers and no-JS visitors (generated by tools/build_seo.js) */
.vc-noscript {
  position: fixed; inset: 0; z-index: 20; overflow: auto;
  padding: 40px max(24px, calc(50% - 380px)) 60px;
  background: var(--win-bg); color: var(--text-1); line-height: 1.5;
}
.vc-noscript h1 { font-size: var(--fs-xxl); margin: 0 0 6px; }
.vc-noscript h2 { font-size: var(--fs-lg); margin: 26px 0 8px; }
.vc-noscript p, .vc-noscript li { color: var(--text-2); font-size: var(--fs-md); }
.vc-noscript a { color: var(--accent); }
.is-embedded .vc-brand { display: none; }   /* the DmytroOS window title already says it */
#popout { display: none; text-decoration: none; }   /* only inside DmytroOS: on its own page it is already "the new window" */
.is-embedded #popout { display: inline-flex; }
.vc-field { display: inline-flex; align-items: center; gap: 6px; color: var(--text-2); font-weight: 500; }
#fps { width: 74px; }
.vc-pair { display: inline-flex; align-items: center; gap: 5px; }
.vc-pair select { max-width: 190px; }
.vc-note { color: var(--vc-warn); font-weight: 600; }
.vc-spacer { flex: 1; }
.vc-local {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 10px; border-radius: 999px;
  background: var(--ctl-bg); color: var(--text-2); font-size: var(--fs-sm);
}
.vc-local svg { width: 13px; height: 13px; fill: none; stroke: currentColor; stroke-width: 2; }

/* ---------- video area ---------- */
#area {
  display: grid; gap: var(--vc-gap); padding: var(--vc-gap); min-height: 0;
  grid-template-columns: repeat(var(--cols, 3), minmax(0, 1fr));
  grid-template-rows: repeat(var(--rows, 1), minmax(0, 1fr));
  background: var(--sidebar-bg);
}
.slot {
  --slot: #0a84ff; --slot-ink: #fff;
  display: flex; flex-direction: column; min-height: 0; min-width: 0;
  background: var(--win-bg);
  border: 1px solid var(--separator);
  border-radius: 14px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .08);
  overflow: hidden;
}
.slot[data-i="1"] { --slot: #ff9f0a; --slot-ink: #1d1d1f; }
.slot[data-i="2"] { --slot: #30d158; --slot-ink: #1d1d1f; }
.slot[data-i="3"] { --slot: #bf5af2; --slot-ink: #fff; }
.head {
  display: flex; align-items: center; gap: 6px;
  min-width: 0; padding: 7px 8px 7px 10px;
  border-bottom: 1px solid var(--separator);
}
.letter {
  flex: none; display: grid; place-items: center;
  width: 20px; height: 20px; border-radius: 6px;
  background: var(--slot); color: var(--slot-ink);
  font-weight: 700; font-size: var(--fs-xs);
}
.name { flex: 1 1 auto; min-width: 40px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.slot.is-empty .name { color: var(--text-3); font-weight: 500; }
.meta { flex: 0 100 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-3); font-size: var(--fs-sm); }
.vc-mini {
  width: calc(var(--vc-hit) - 2px); min-height: calc(var(--vc-hit) - 2px); padding: 0;
  border-radius: 50%; border-color: transparent; background: var(--ctl-bg); box-shadow: none; color: var(--text-2);
}
.vc-mini svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.vc-mini.is-on { background: var(--accent); color: #fff; }
.snd .if-on, .snd.is-on .if-off { display: none; }
.snd.is-on .if-on { display: block; }

.stage { position: relative; flex: 1; min-height: 60px; background: var(--stage); overflow: hidden; }
.stage video {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; display: block;
  transform: translate(var(--sx, 0%), var(--sy, 0%)) scale(var(--sz, 1)); transform-origin: 0 0;   /* own zoom */
}
.stage:not(.empty) { touch-action: pan-x pan-y; }   /* page scroll stays; a pinch reaches the zoom */
.stage.zoomed { cursor: grab; touch-action: none; }
.stage.panning { cursor: grabbing; }
.zchip {
  position: absolute; top: 8px; right: 8px; z-index: 1;
  display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px 3px 7px;
  border: 1px solid rgba(255, 255, 255, .22); border-radius: 999px;
  background: rgba(30, 30, 34, .72); color: #fff; font-size: var(--fs-sm); font-weight: 600;
  -webkit-backdrop-filter: var(--glass-blur); backdrop-filter: var(--glass-blur);
}
.zchip svg { width: 13px; height: 13px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
@media (hover: hover) and (pointer: fine) { .zchip:hover { background: rgba(10, 132, 255, .9); } }
#area.wipe .zchip { display: none; }   /* wipe uses its shared zoom (#zoominfo) */
.stage.empty { cursor: pointer; background: var(--win-chrome); }
.stage.empty::before {
  content: ""; position: absolute; inset: 10px;
  border: 1.5px dashed var(--control-border); border-radius: 10px; opacity: .6;
  pointer-events: none; transition: border-color .15s, background .15s;
}
.stage.drag::before, .stage.empty:hover::before { border-color: var(--accent); background: var(--selection); opacity: 1; }
.stage.drag:not(.empty) { outline: 3px dashed var(--accent); outline-offset: -8px; }
.hint {
  position: absolute; inset: 0; padding: 18px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  text-align: center; color: var(--text-3); pointer-events: none;
}
.hint svg { width: 30px; height: 30px; margin-bottom: 4px; fill: none; stroke: currentColor; stroke-width: 1.6; opacity: .8; }
.hint b { color: var(--text-2); font-size: var(--fs-md); }
.hint span { font-size: var(--fs-sm); }
.shade {
  position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none;
  background: rgba(0, 0, 0, .55);
}
.badge {
  max-width: calc(100% - 24px); padding: 6px 14px; border-radius: 999px;
  background: rgba(30, 30, 34, .82); color: #fff; font-size: var(--fs-sm); font-weight: 600; text-align: center;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .3);
}
.badge.err { color: #ffb4ab; border-radius: 12px; }

.foot { display: flex; flex-direction: column; gap: 4px; padding: 8px 10px 7px; border-top: 1px solid var(--separator); }
.offrow { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
.lbl { color: var(--text-2); font-weight: 500; }
.off { width: 84px; text-align: right; font-family: var(--font-mono); font-size: var(--fs-sm); }
.offfr { min-width: 58px; color: var(--text-3); font-size: var(--fs-sm); }
.vc-nudge { margin-left: auto; }
.vc-nudge button { padding: 0 8px; font-size: var(--fs-sm); font-variant-numeric: tabular-nums; }
.offrange { --fill: var(--slot); }
.ltime { color: var(--text-3); font-size: var(--fs-sm); }
#area.nofoot .foot { display: none; }

/* ---------- wipe: two videos in one frame — the left one up to the divider, the right one after it ---------- */
#area.wipe {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-rows: auto minmax(0, 1fr) auto; row-gap: 0;
}
#area.wipe .slot { display: contents; }
#area.wipe .head, #area.wipe .foot { background: var(--win-bg); border: 1px solid var(--separator); }
#area.wipe .head { grid-row: 1; border-radius: 14px 14px 0 0; border-bottom: 0; }
#area.wipe .foot { grid-row: 3; border-radius: 0 0 14px 14px; border-top: 0; }
#area.wipe .wl > * { grid-column: 1; }
#area.wipe .wr > * { grid-column: 2; }
#area.wipe .slot .stage { grid-area: 2 / 1 / 3 / 3; }
#area.wipe .wr .stage { clip-path: inset(0 0 0 var(--split, 50%)); z-index: 1; }
#area.wipe .stage video { transform: translate(var(--zx, 0%), var(--zy, 0%)) scale(var(--z, 1)); transform-origin: 0 0; }
#wipe { grid-area: 2 / 1 / 3 / 3; position: relative; z-index: 2; cursor: ew-resize; touch-action: none; }
#wipe::before {
  content: ""; position: absolute; top: 0; bottom: 0; left: var(--split, 50%);
  width: 2px; margin-left: -1px; background: #fff; box-shadow: 0 0 0 1px rgba(0, 0, 0, .35), 0 0 12px rgba(0, 0, 0, .35);
}
#wipe::after {
  content: "‹ ›"; position: absolute; top: 50%; left: var(--split, 50%); transform: translate(-50%, -50%);
  display: grid; place-items: center; width: 46px; height: 30px; border-radius: 999px;
  background: rgba(255, 255, 255, .92); color: #1d1d1f; font: 700 17px/1 var(--font-sys); letter-spacing: 4px;
  padding-left: 4px; box-shadow: 0 0 0 1px rgba(0, 0, 0, .25), 0 4px 14px rgba(0, 0, 0, .35);
  -webkit-backdrop-filter: var(--glass-blur); backdrop-filter: var(--glass-blur);
}
#zoominfo {
  position: absolute; left: 10px; bottom: 10px; padding: 3px 10px; border-radius: 999px; pointer-events: none;
  background: rgba(30, 30, 34, .78); color: #fff; font-size: var(--fs-sm);
}

/* ---------- transport ---------- */
.vc-foot { position: relative; background: var(--win-chrome); border-top: 1px solid var(--separator); }
.transport { display: flex; align-items: center; gap: 8px 12px; flex-wrap: wrap; padding: 9px 14px; }
.vc-tr { display: inline-flex; align-items: center; gap: 6px; }
.vc-play {
  display: grid; place-items: center;
  width: calc(var(--vc-hit) + 10px); height: calc(var(--vc-hit) + 10px); padding: 0;
  border: 0; border-radius: 50%;
  background: var(--accent); color: #fff;
  box-shadow: 0 2px 8px rgba(10, 132, 255, .35), inset 0 1px 0 rgba(255, 255, 255, .25);
}
.vc-play svg { width: 18px; height: 18px; }
.vc-play .if-playing, .vc-play.is-playing .if-paused { display: none; }
.vc-play.is-playing .if-playing { display: block; }
.vc-play:active:not(:disabled) { filter: brightness(.92); }
@media (hover: hover) and (pointer: fine) { .vc-play:hover:not(:disabled) { filter: brightness(1.08); } }
.vc-loop button { font-size: var(--fs-sm); }
#tlwrap { flex: 1; min-width: 200px; position: relative; display: flex; align-items: center; }
/* the range thumb is 16px wide: its centre travels between 8px and 100% − 8px */
#loopbar {
  position: absolute; bottom: -2px; height: 4px; border-radius: 2px; background: #ff9f0a; pointer-events: none;
  left: calc(8px + (100% - 16px) * var(--la, 0)); width: calc((100% - 16px) * (var(--lb, 1) - var(--la, 0)));
}
#loopbar.off { opacity: .4; }
#tc { display: inline-grid; grid-template-columns: auto auto; align-items: baseline; min-width: 168px; text-align: right; }
#tc-now { font-family: var(--font-mono); font-size: var(--fs-md); font-weight: 600; }
#tc-total { font-family: var(--font-mono); color: var(--text-3); font-size: var(--fs-sm); }
#tc-frame { grid-column: 1 / -1; font-style: normal; font-size: var(--fs-xs); color: var(--text-3); }

#help {
  position: absolute; right: 12px; bottom: calc(100% + 8px); z-index: 5;
  width: min(380px, calc(100vw - 24px)); padding: 14px 16px;
  border: 1px solid var(--glass-border); border-radius: var(--r-panel);
  background: var(--glass); -webkit-backdrop-filter: var(--glass-blur); backdrop-filter: var(--glass-blur);
  box-shadow: var(--glass-edge), 0 18px 50px rgba(0, 0, 0, .3);
  line-height: 1.5;
}
#help h2 { margin: 0 0 8px; font-size: var(--fs-md); }
#help dl { display: grid; grid-template-columns: auto 1fr; gap: 5px 12px; margin: 0 0 10px; align-items: baseline; }
#help dt { white-space: nowrap; }
#help dd { margin: 0; color: var(--text-2); }
#help p { margin: 6px 0 0; color: var(--text-2); }
kbd {
  display: inline-block; min-width: 22px; padding: 1px 6px; border-radius: 6px; text-align: center;
  border: 1px solid var(--separator); border-bottom-width: 2px; background: var(--win-bg);
  font: 600 var(--fs-xs)/1.5 var(--font-sys); color: var(--text-1);
}

/* ---------- view mode: only the videos and the transport ---------- */
body.view { grid-template-rows: minmax(0, 1fr) auto; }
body.view .vc-bar, body.view .head, body.view .foot { display: none; }
body.view #area { padding: 0; gap: 2px; background: #000; }
body.view .slot { border: 0; border-radius: 0; box-shadow: none; }

/* ---------- narrow (iOS sheet / phone): one video per row, the area scrolls ---------- */
@media (max-width: 640px) {
  #area { overflow: auto; }
  #area:not(.wipe) { grid-template-columns: minmax(0, 1fr); grid-template-rows: none; grid-auto-rows: max-content; align-content: start; }
  #area:not(.wipe) .stage { flex: none; aspect-ratio: 16 / 9; }
  .vc-local, .vc-spacer { display: none; }
  .vc-nudge { margin-left: 0; }
  #tc { min-width: 0; }
  .transport { justify-content: center; }
  #tlwrap { order: -1; flex-basis: 100%; }
}

@media (prefers-reduced-transparency: reduce), (prefers-contrast: more) {
  #help { background: var(--win-bg); -webkit-backdrop-filter: none; backdrop-filter: none; }
}
@media (forced-colors: active) {
  .vc-btn.is-on, .vc-seg button.is-on, .vc-play, .vc-mini.is-on { background: Highlight; color: HighlightText; forced-color-adjust: none; }
  .vc-range { -webkit-appearance: auto; appearance: auto; }
}
