/* Stretch: dark "body scan" chrome, calm seascapes during exercises, and a hotter,
   faster palette in full workout mode. System fonts only (offline). The accent
   and scan speed follow the selected mode via body[data-mode]. */

:root {
  --bg: #04070e;
  --bg-glow: #0b2238;
  --surface: rgba(14, 24, 42, .78);
  --surface-2: #14223a;
  --text: #e4f0ff;
  --muted: #8292ad;
  --border: #1c2d4a;
  --warn: #ffb35c;
  --danger: #ff6b7d;

  /* mode accent: stretch = scanner cyan */
  --accent: #4fe3ff;
  --accent-2: #7cf5d4;
  --accent-text: #03131c;
  --accent-soft: rgba(79, 227, 255, .14);
  --accent-glow: rgba(79, 227, 255, .45);
  --scan-speed: 4.8s;

  --radius: 14px;
  --tap: 44px;
  --nav-h: 64px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", "SF Mono", Consolas, monospace;
  color-scheme: dark;
}

body[data-mode="warmup"] {
  --accent: #ffc247;
  --accent-2: #ff8f5a;
  --accent-text: #1c1000;
  --accent-soft: rgba(255, 194, 71, .15);
  --accent-glow: rgba(255, 194, 71, .45);
  --bg-glow: #2a1c0c;
  --scan-speed: 3.2s;
}

body[data-mode="workout"] {
  --accent: #ff3d9a;
  --accent-2: #ff8a3d;
  --accent-text: #1a0010;
  --accent-soft: rgba(255, 61, 154, .16);
  --accent-glow: rgba(255, 61, 154, .55);
  --bg-glow: #2c0830;
  --scan-speed: 1.6s;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; background: var(--bg); }

body {
  margin: 0;
  color: var(--text);
  font: 16px/1.45 var(--font);
  min-height: 100dvh;
  background:
    radial-gradient(120% 60% at 50% -10%, var(--bg-glow), transparent 70%),
    linear-gradient(color-mix(in srgb, var(--accent) 4%, transparent) 1px, transparent 1px) 0 0 / 28px 28px,
    linear-gradient(90deg, color-mix(in srgb, var(--accent) 4%, transparent) 1px, transparent 1px) 0 0 / 28px 28px,
    var(--bg);
  background-attachment: fixed;
  transition: background-color .6s;
}

#view {
  max-width: 1100px;
  margin: 0 auto;
  padding: 12px 16px calc(var(--nav-h) + 24px + env(safe-area-inset-bottom));
}

h1 { font-size: 1.5rem; line-height: 1.15; margin: 0; letter-spacing: -.01em; font-weight: 800; }
h2 { font-size: 1.1rem; margin: 0 0 8px; }
h3 { font-size: 1rem; margin: 12px 0 4px; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.warn { color: var(--warn); }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.label, .hud {
  font-family: var(--mono); font-size: .72rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: .16em; color: var(--accent);
  margin: 18px 0 8px; opacity: .85;
}
.hud { margin: 0; display: flex; gap: 14px; flex-wrap: wrap; }
.hud span::before { content: "▮ "; opacity: .6; }

/* ---------- buttons and controls ---------- */

button, input, select, textarea { font: inherit; color: inherit; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: var(--tap); padding: 0 18px;
  border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface); color: var(--text);
  text-decoration: none; font-weight: 600; cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: linear-gradient(90deg, var(--accent), var(--accent-2)); border-color: transparent; color: var(--accent-text); box-shadow: 0 0 20px color-mix(in srgb, var(--accent) 30%, transparent); }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.small { min-height: 36px; padding: 0 14px; font-size: .9rem; }
.btn.on { background: var(--accent-soft); border-color: var(--accent); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn small { display: block; font-weight: 400; color: var(--muted); font-size: .8rem; }

.icon-btn {
  width: 40px; height: 40px; flex: none;
  display: inline-grid; place-items: center;
  border: 1px solid var(--border); border-radius: 50%;
  background: var(--surface); cursor: pointer; font-size: 1.05rem;
}
.icon-btn:disabled { opacity: .35; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 40px; padding: 0 14px;
  border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface); cursor: pointer; font-size: .95rem;
}
.chip.small { min-height: 34px; padding: 0 12px; font-size: .875rem; }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.chip:disabled { opacity: .4; cursor: not-allowed; }
.chip .count { font-size: .75rem; opacity: .7; }
.chip.custom input { width: 4.5em; border: 0; background: transparent; text-align: right; padding: 0; }
.chip.custom input:focus { outline: none; }

.segmented {
  display: inline-flex; padding: 3px; gap: 2px;
  border-radius: 999px; background: var(--surface-2);
}
.segmented button {
  min-height: 40px; padding: 0 16px; border: 0; border-radius: 999px;
  background: transparent; cursor: pointer; font-weight: 600; color: var(--muted);
}
.segmented button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgb(0 0 0 / .15); }
.segmented.small button { min-height: 34px; padding: 0 12px; font-size: .875rem; }

input[type="number"], input:not([type]), textarea, select {
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); padding: 8px 10px; min-height: 40px;
}
input.tiny { width: 5em; }
textarea { width: 100%; resize: vertical; }
.check { display: flex; align-items: center; gap: 6px; min-height: 40px; cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---------- layout pieces ---------- */

.page-head { display: flex; align-items: center; gap: 12px; margin: 4px 0 16px; justify-content: space-between; }
.page-head > div { flex: 1; min-width: 0; }
.back { align-self: flex-start; font-size: 2rem; line-height: 1; text-decoration: none; padding: 0 6px; color: var(--text); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.note { background: var(--accent-soft); border-radius: 10px; padding: 10px 14px; margin: 8px 0; font-size: .925rem; }
.banner { display: block; background: var(--surface-2); border-radius: 10px; padding: 10px 14px; margin-bottom: 12px; color: var(--text); text-decoration: none; font-size: .925rem; }
.banner::after { content: " ›"; color: var(--accent); }

.empty-state { max-width: 520px; margin: 12vh auto 0; text-align: center; }
.empty-state .row { justify-content: center; margin: 20px 0 12px; flex-wrap: wrap; }

#nav {
  position: fixed; inset: auto 0 0 0; z-index: 10;
  display: flex; justify-content: space-around;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: rgba(6, 12, 24, .82); border-top: 1px solid var(--border); backdrop-filter: blur(12px);
}
#nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: .75rem; font-weight: 600;
}
#nav a svg { width: 24px; height: 24px; fill: currentColor; }
#nav a.active { color: var(--accent); }
body.bare #nav { display: none; }
body.bare #view { padding: 0; max-width: none; }

/* ---------- home: body scan ---------- */

.home-grid { display: grid; gap: 12px; }
.map-wrap { position: relative; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.bodymap { width: 100%; max-width: 460px; height: auto; touch-action: manipulation; user-select: none; overflow: visible; }

.bodymap .silhouette { fill: url(#bm-fill); stroke: none; }
.bodymap .bm-fill-a { stop-color: var(--accent); stop-opacity: .16; }
.bodymap .bm-fill-b { stop-color: #02050b; stop-opacity: .9; }
.bodymap .bm-contour-line { stroke: var(--accent); stroke-opacity: .26; stroke-width: .6; fill: none; }
.bodymap .bm-grid-line { stroke: var(--accent); stroke-opacity: .12; stroke-width: .5; fill: none; }
.bodymap .bm-texture { pointer-events: none; }
.bodymap .outline { fill: none; stroke: var(--accent); stroke-width: 1.1; filter: url(#bm-glow); pointer-events: none; }
.bodymap .bm-hud path { fill: none; stroke: var(--accent); stroke-width: 1.4; opacity: .55; }
.bodymap .fig-label { fill: var(--accent); font: 600 10px var(--mono); letter-spacing: .28em; opacity: .75; }

.bodymap .region {
  fill: var(--accent); fill-opacity: .05;
  stroke: var(--accent); stroke-opacity: .5; stroke-width: .8;
  cursor: pointer; transition: fill-opacity .2s, stroke-opacity .2s;
}
.bodymap .region:hover { fill-opacity: .2; stroke-opacity: .9; }
.bodymap .region.on {
  fill: var(--accent); fill-opacity: .62; stroke: #fff; stroke-opacity: .95; stroke-width: 1.1;
  filter: url(#bm-glow); animation: region-pulse 2.2s ease-in-out infinite;
}
.bodymap .region.empty { fill: none; stroke-opacity: .14; stroke-dasharray: 2 3; cursor: default; }
.bodymap .hit { fill: none; stroke: transparent; pointer-events: stroke; cursor: pointer; }
.bodymap .hit.empty { pointer-events: none; }

.bodymap .bm-beam { pointer-events: none; animation: scan-beam var(--scan-speed) linear infinite; }
.bodymap .bm-beam-a { stop-color: var(--accent); stop-opacity: 0; }
.bodymap .bm-beam-b { stop-color: var(--accent); stop-opacity: .28; }
.bodymap .bm-beam-c { stop-color: #fff; stop-opacity: .85; }

@keyframes scan-beam { from { transform: translateY(0); } to { transform: translateY(560px); } }
@keyframes region-pulse { 50% { fill-opacity: .38; } }

@media (prefers-reduced-motion: reduce) {
  .bodymap .bm-beam { animation: none; opacity: 0; }
  .bodymap .region.on { animation: none; }
}

.scan-readout { width: 100%; max-width: 460px; justify-content: space-between; }

.region-chips { margin-top: 4px; }
.selection-summary { margin: 16px 0 8px; min-height: 1.4em; font-family: var(--mono); font-size: .8rem; letter-spacing: .06em; }
.go {
  width: 100%; min-height: 58px; font-size: 1.15rem; letter-spacing: .2em; text-transform: uppercase;
  background: linear-gradient(90deg, var(--accent), var(--accent-2)); border: 0; color: var(--accent-text);
  box-shadow: 0 0 28px var(--accent-glow);
}
.go:disabled { box-shadow: none; }

.home-head { display: flex; flex-direction: column; gap: 6px; margin: 4px 0 12px; }

@media (min-width: 820px) {
  .home-grid { grid-template-columns: minmax(340px, 1.1fr) minmax(320px, 1fr); align-items: start; gap: 36px; }
  .home-controls { position: sticky; top: 16px; }
}

/* ---------- session preview ---------- */

.session-list { list-style: none; padding: 0; margin: 8px 0 90px; counter-reset: s; }
.session-item {
  display: flex; gap: 12px; align-items: center; justify-content: space-between;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px; margin-bottom: 8px; counter-increment: s;
}
.si-main { min-width: 0; flex: 1; }
.si-name { font-weight: 700; }
.si-name::before { content: counter(s) ". "; color: var(--muted); font-weight: 400; }
.si-meta { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: .875rem; margin-top: 2px; }
.si-actions { display: grid; grid-template-columns: repeat(2, 40px); gap: 6px; }
.stepper { display: inline-flex; align-items: center; gap: 8px; margin-top: 6px; font-variant-numeric: tabular-nums; }
.stepper .icon-btn { width: 32px; height: 32px; }
.tag { display: inline-block; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); font-size: .8rem; }
.sticky-actions {
  position: fixed; left: 0; right: 0; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom));
  display: flex; gap: 10px; justify-content: center; padding: 12px 16px;
  background: linear-gradient(transparent, var(--bg) 30%);
}
.sticky-actions .btn { min-height: 52px; min-width: 140px; }
.sticky-actions .btn.primary { flex: 1; max-width: 360px; font-size: 1.1rem; }

@media (min-width: 560px) {
  .si-actions { grid-template-columns: repeat(4, 40px); }
}

/* ---------- player: seascape behind the clip, readable from 2 m ---------- */

.play {
  --p-text: #fff; --p-muted: rgba(255, 255, 255, .78); --p-rest: #ffd08a;
  position: fixed; inset: 0; overflow: hidden;
  display: grid; grid-template-rows: auto minmax(0, 1fr) auto auto;
  color: var(--p-text); background: #0b1a2c;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.play > * { position: relative; z-index: 1; }
.play > .scene { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 0; display: block; }
.play > .scene[hidden] { display: none; }
.play > .bg-layer { position: absolute; inset: 0; z-index: 0; overflow: hidden; background: #0b1a2c; }
.bg-video {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover;
  opacity: 0; transition: opacity 1.4s ease;
}
.bg-video.on { opacity: 1; }

.play-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px; }
.play > .play-top { position: relative; z-index: 4; }
.play-status {
  font: 600 .85rem var(--mono); letter-spacing: .06em; color: var(--p-text);
  padding: 5px 12px; border-radius: 999px; background: rgba(3, 10, 22, .28); backdrop-filter: blur(8px);
}
.play-menu {
  position: absolute; top: calc(100% - 2px); right: 12px; z-index: 5;
  display: flex; flex-direction: column; gap: 8px; padding: 12px; border-radius: 16px;
  background: rgba(3, 10, 22, .72); backdrop-filter: blur(14px); border: 1px solid rgba(255, 255, 255, .15);
}
.play-menu[hidden] { display: none; }
.play-menu .vol { display: flex; align-items: center; gap: 8px; font-size: .85rem; }
.play-menu input[type="range"] { width: 130px; accent-color: #fff; }
.pill {
  min-height: 40px; padding: 0 14px; border-radius: 999px; cursor: pointer; font-weight: 600;
  border: 1px solid rgba(255, 255, 255, .28); background: rgba(3, 10, 22, .35); color: var(--p-text);
  backdrop-filter: blur(8px);
}
.pill.on { background: #fff; color: #06121f; }

.play-video { position: relative; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 6px 16px; }
.clip-frame {
  --s: 1; --flip: 1;
  position: relative; flex: none; overflow: hidden; border-radius: 22px; background: #000;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .45), 0 0 0 1px rgba(255, 255, 255, .12);
  transform: scale(var(--s)) scaleX(var(--flip));
  transition: opacity .8s, transform .8s, filter .8s;
}
.clip-frame.mirror { --flip: -1; }
/* sized and offset by layoutCropped() so only the crop shows */
.clip-frame video { position: absolute; display: block; max-width: none; max-height: none; object-fit: fill; }
.play[data-phase="rest"] .clip-frame, .play[data-phase="ready"] .clip-frame { --s: .94; opacity: .15; filter: blur(2px); }

.phase-badge {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%); z-index: 2;
  padding: 6px 18px; border-radius: 999px; font: 800 .95rem var(--mono); letter-spacing: .22em;
  background: rgba(255, 255, 255, .92); color: #0a1a2c;
}
.phase-badge:empty { display: none; }

/* breathing ring during rests: 4s in, 6s out */
.breathe {
  position: absolute; z-index: 2; width: min(46vw, 46vh); aspect-ratio: 1; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .85); box-shadow: 0 0 40px rgba(255, 255, 255, .35), inset 0 0 40px rgba(255, 255, 255, .2);
  display: grid; place-items: center; font: 700 1.1rem var(--mono); letter-spacing: .35em; text-transform: uppercase; text-shadow: 0 1px 12px rgba(0, 0, 0, .5);
  opacity: 0; pointer-events: none; transition: opacity .8s;
  animation: breathe 10s ease-in-out infinite;
}
.play[data-phase="rest"] .breathe, .play[data-phase="ready"] .breathe { opacity: 1; }
@keyframes breathe { 0% { transform: scale(.6); } 40% { transform: scale(1); } 100% { transform: scale(.6); } }

.play-info { padding: 6px 20px 0; text-align: center; text-shadow: 0 1px 3px rgba(0, 0, 0, .55), 0 2px 18px rgba(0, 0, 0, .35); }
.play-kicker { font: 600 .75rem var(--mono); letter-spacing: .2em; text-transform: uppercase; opacity: .85; margin-bottom: 2px; }
.play-name { font-size: clamp(1.5rem, 6vw, 2.6rem); font-weight: 800; line-height: 1.12; letter-spacing: -.01em; }
.play-dose { color: var(--p-text); opacity: .9; font-size: clamp(1rem, 3.5vw, 1.35rem); margin-top: 4px; }
.play-count {
  font-size: clamp(4.6rem, 24vw, 10rem); font-weight: 800; line-height: 1; margin: 8px 0 4px;
  font-variant-numeric: tabular-nums; letter-spacing: -.03em;
  text-shadow: 0 2px 6px rgba(0, 0, 0, .35), 0 6px 40px rgba(0, 0, 0, .3);
}
.play[data-phase="rest"] .play-count, .play[data-phase="ready"] .play-count { color: var(--p-rest); }
.play.paused .play-count { opacity: .45; }
.play > .bar { position: absolute; top: 0; left: 0; right: 0; z-index: 3; height: 4px; background: rgba(255, 255, 255, .18); overflow: hidden; }
.bar-fill { height: 100%; background: #fff; transform-origin: left; transform: scaleX(0); }
.play[data-phase="rest"] .bar-fill, .play[data-phase="ready"] .bar-fill { background: var(--p-rest); }
.play-notes { color: var(--p-muted); min-height: 1.4em; margin-top: 8px; font-style: italic; }

.play-controls { display: flex; justify-content: center; align-items: center; gap: 18px; padding: 14px 12px 20px; }
.ctl {
  width: 64px; height: 64px; border-radius: 50%; cursor: pointer; font-size: 1.45rem; color: #fff;
  border: 1px solid rgba(255, 255, 255, .3); background: rgba(3, 10, 22, .35); backdrop-filter: blur(8px);
}
.ctl.big { width: 84px; height: 84px; font-size: 2rem; background: #fff; color: #06121f; border: 0; box-shadow: 0 8px 30px rgba(0, 0, 0, .3); }

/* ---- full workout: synthwave, neon, pulsing ---- */
.play[data-mode="workout"] { --p-rest: #7df9ff; background: #12021f; }
.play[data-mode="workout"] .play-name { text-transform: uppercase; letter-spacing: .02em; font-style: italic; }
.play[data-mode="workout"] .play-count {
  color: #fff; font-style: italic;
  text-shadow: 0 0 12px #ff3d9a, 0 0 36px #ff3d9a, 3px 3px 0 #29d8ff;
}
.play[data-mode="workout"][data-phase="rest"] .play-count { text-shadow: 0 0 14px #29d8ff, 0 0 36px #29d8ff; color: #eaffff; }
.play[data-mode="workout"] .bar-fill { background: linear-gradient(90deg, #29d8ff, #ff3d9a, #ff8a3d); box-shadow: 0 0 12px #ff3d9a; }
.play[data-mode="workout"] .clip-frame { box-shadow: 0 0 0 2px #ff3d9a, 0 0 40px rgba(255, 61, 154, .55); border-radius: 10px; }
.play[data-mode="workout"] .phase-badge { background: #29d8ff; color: #12021f; }
.play[data-mode="workout"] .ctl.big { background: linear-gradient(135deg, #ff3d9a, #ff8a3d); color: #fff; box-shadow: 0 0 30px rgba(255, 61, 154, .6); }
.play[data-mode="workout"] .breathe { border-color: #29d8ff; box-shadow: 0 0 40px rgba(41, 216, 255, .5), inset 0 0 40px rgba(41, 216, 255, .25); animation-duration: 6s; }
.play-count.beat { animation: beat .35s ease-out; }
@keyframes beat { 0% { transform: scale(1.08); } 100% { transform: scale(1); } }

/* ---- warm-up: sunrise, a touch brisker ---- */
.play[data-mode="warmup"] .play-count { text-shadow: 0 2px 24px rgba(255, 170, 60, .6); }
.play[data-mode="warmup"] .bar-fill { background: linear-gradient(90deg, #ffe08a, #ff9d5c); }

@media (prefers-reduced-motion: reduce) {
  .breathe, .play-count.beat { animation: none; }
}

/* landscape: phone on its side, laptop, TV. Clip left, timer right. */
@media (orientation: landscape) and (min-aspect-ratio: 5/4) {
  .play { grid-template-columns: 1.25fr 1fr; grid-template-rows: auto 1fr auto; }
  .play-top { grid-column: 1 / -1; }
  .play-video { grid-row: 2 / 4; padding: 8px 8px 24px 24px; }
  .play-info { align-self: center; padding-right: 32px; }
  .play-count { font-size: clamp(3rem, 18vh, 9rem); }
  .breathe { width: min(34vw, 60vh); }
}

.summary { max-width: 520px; margin: 10vh auto; padding: 0 16px; text-align: center; }
.summary h1 { font-size: 2.4rem; letter-spacing: .2em; text-transform: uppercase; color: var(--accent); text-shadow: 0 0 24px var(--accent-glow); }
.summary .row { justify-content: center; margin-top: 24px; }
.summary ul { text-align: left; }
.stats { display: flex; gap: 12px; margin: 16px 0; }
.stats > div { flex: 1; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; display: flex; flex-direction: column; }
.stats strong { font-size: 1.6rem; font-family: var(--mono); color: var(--accent); }
.stats span { color: var(--muted); font-size: .8rem; }
ul.plain { list-style: none; padding: 0; }
ul.plain li { padding: 8px 0; border-bottom: 1px solid var(--border); }

/* ---------- library ---------- */

.dropzone {
  display: block; border: 2px dashed var(--border); border-radius: var(--radius);
  padding: 22px; text-align: center; cursor: pointer; margin-bottom: 16px; color: var(--muted);
}
.dropzone:hover { border-color: var(--accent); }
.dropzone input { display: none; }
.dropzone strong { color: var(--text); }
.clip-card {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 14px; margin-bottom: 8px;
}
.clip-card.missing { border-style: dashed; }
.clip-main { flex: 1; min-width: 0; color: var(--text); text-decoration: none; }
.clip-name { font-weight: 700; overflow-wrap: anywhere; }
.clip-meta { color: var(--muted); font-size: .875rem; }
.clip-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.clip-actions { display: flex; gap: 8px; align-items: center; }

.drop-overlay {
  position: fixed; inset: 0; z-index: 50; display: none; place-items: center;
  background: rgb(11 122 100 / .85); color: #fff; font-size: 1.4rem; font-weight: 700;
}
.drop-overlay.show { display: grid; }

/* ---------- mark mode ---------- */

.clip-title { font-size: 1.15rem; overflow-wrap: anywhere; }
.mark-grid { display: grid; gap: 16px; }
.mark-player { min-width: 0; }
.video-box { background: #000; border-radius: var(--radius); overflow: hidden; display: grid; place-items: center; }
.video-box video { width: 100%; max-height: 45vh; display: block; }
@media (min-width: 900px) { .video-box video { max-height: 62vh; } }
video.mirror { transform: scaleX(-1); }
.timeline { position: relative; height: 30px; margin: 10px 0 4px; background: var(--surface-2); border-radius: 6px; }
.timeline .seg {
  position: absolute; top: 3px; bottom: 3px; border: 0; border-radius: 4px; padding: 0;
  background: var(--surface-2); color: var(--text); font-size: .75rem; cursor: pointer; overflow: hidden;
}
.timeline .seg.on { background: var(--accent); color: var(--accent-text); }
.timeline .playhead { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--danger); pointer-events: none; }
.timeline .pending { position: absolute; top: 0; bottom: 0; width: 3px; background: var(--warn); }
.scrub { width: 100%; accent-color: var(--accent); height: 28px; }
.transport { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 6px 0; }
.transport select { min-height: 40px; }
.mark-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 10px 0; }
.mark-btn { min-width: 140px; font-family: var(--mono); }
.keys { display: none; }
@media (hover: hover) and (pointer: fine) { .keys { display: block; } }

.ex-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 12px; margin-bottom: 8px; cursor: pointer;
}
.ex-card.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); cursor: default; }
.ex-head { display: flex; align-items: center; gap: 8px; }
.ex-num { width: 26px; height: 26px; border-radius: 50%; background: var(--surface-2); display: grid; place-items: center; font-size: .8rem; flex: none; }
.ex-card.selected .ex-num { background: var(--accent); color: var(--accent-text); }
.ex-name { flex: 1; min-width: 0; font-weight: 700; }
.edge { display: flex; align-items: center; gap: 4px; margin-top: 6px; flex-wrap: wrap; border-radius: 8px; padding: 2px; }
.edge.active { background: var(--accent-soft); }
.edge-label { width: 2.4em; font-size: .8rem; color: var(--muted); }
.edge .stamp { min-width: 5.5em; text-align: center; }
.nudge {
  min-height: 34px; min-width: 44px; padding: 0 6px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); font-size: .8rem; font-family: var(--mono);
}
.field { margin-top: 10px; }
.field-label { display: block; font-size: .8rem; color: var(--muted); margin-bottom: 4px; }
.field summary { cursor: pointer; color: var(--muted); font-size: .9rem; padding: 4px 0; }
.field label { display: inline-flex; align-items: center; gap: 4px; }
.notes { margin-top: 10px; }
.ex-summary { margin-top: 6px; }

@media (min-width: 900px) {
  .mark-grid { grid-template-columns: minmax(0, 1.1fr) minmax(360px, 1fr); align-items: start; }
  .mark-player { position: sticky; top: 12px; }
}

/* ---------- history ---------- */

.region-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 6px; }
.region-cell { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; display: flex; flex-direction: column; }
.region-cell small { color: var(--muted); }
.region-cell.recent { background: var(--accent-soft); border-color: var(--accent); }
.history-list { list-style: none; padding: 0; }
.history-list li { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 14px; margin-bottom: 8px; }

/* ---------- settings ---------- */

.mode-table { border-collapse: collapse; margin: 8px 0 12px; }
.mode-table th, .mode-table td { padding: 4px 8px 4px 0; text-align: left; }
.mode-table th { font-weight: 600; font-size: .9rem; }
.settings .row label { display: inline-flex; align-items: center; gap: 6px; }
.autobackup { border-top: 1px solid var(--border); margin-top: 14px; padding-top: 4px; }

/* ---------- dialogs and toasts ---------- */

.dialog {
  border: 1px solid var(--border); border-radius: 16px; padding: 20px;
  background: var(--surface); color: var(--text); width: min(460px, calc(100vw - 32px));
}
.dialog::backdrop { background: rgb(0 0 0 / .5); }
.dialog p { color: var(--muted); }
.dialog-options { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }
.dialog-options .btn { flex-direction: column; padding: 8px 16px; border-radius: 12px; }

#toasts { position: fixed; left: 16px; right: 16px; bottom: calc(var(--nav-h) + 16px); z-index: 60; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast { background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; max-width: 480px; font-size: .925rem; transition: opacity .4s; }
.toast.out { opacity: 0; }
.range { accent-color: var(--accent); width: 160px; }
.bg-section { margin-top: 28px; }
.bg-card .segmented { flex: none; }
.save-state { flex: none; align-self: flex-start; font: 600 .75rem var(--mono); letter-spacing: .08em; color: var(--accent-2); padding: 6px 10px; border-radius: 999px; background: var(--accent-soft); }
.save-state::before { content: "✓ "; }
.save-state.busy { color: var(--muted); background: transparent; }
.save-state.busy::before { content: "… "; }

/* ---------- crop ---------- */
.video-box { position: relative; }
.crop-overlay { position: absolute; overflow: hidden; pointer-events: none; touch-action: none; }
.crop-overlay[hidden] { display: none; }
.crop-rect { position: absolute; border: 2px dashed var(--accent); border-radius: 4px; }
.crop-overlay.editing { pointer-events: auto; }
.crop-overlay.editing .crop-rect { border-style: solid; box-shadow: 0 0 0 9999px rgba(0, 0, 0, .55); cursor: move; }
.crop-rect .handle { display: none; position: absolute; width: 22px; height: 22px; background: var(--accent); border: 2px solid #fff; border-radius: 50%; }
.crop-overlay.editing .handle { display: block; }
.handle.nw { left: -11px; top: -11px; cursor: nwse-resize; }
.handle.ne { right: -11px; top: -11px; cursor: nesw-resize; }
.handle.sw { left: -11px; bottom: -11px; cursor: nesw-resize; }
.handle.se { right: -11px; bottom: -11px; cursor: nwse-resize; }
.handle.n { left: calc(50% - 11px); top: -11px; cursor: ns-resize; }
.handle.s { left: calc(50% - 11px); bottom: -11px; cursor: ns-resize; }
.handle.e { right: -11px; top: calc(50% - 11px); cursor: ew-resize; }
.handle.w { left: -11px; top: calc(50% - 11px); cursor: ew-resize; }
.crop-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 10px 0; }
.crop-bar[hidden] { display: none; }

/* ---------- seamless loops: two copies of the clip dissolve at the join ---------- */
.loop-video { transition: opacity .4s linear; }
.loop-video:not(.on) { opacity: 0; }
.video-box .twin { position: absolute; inset: 0; width: 100%; height: 100%; max-height: none; }

/* region picker in mark mode: the same body scan as the home screen */
.region-picker .bodymap { display: block; max-width: 380px; margin: 4px auto 8px; }
.region-picker .picked { min-height: 34px; }
.sync-bar .note.warn-note { background: color-mix(in srgb, var(--warn) 18%, transparent); }
.sync-bar { margin-bottom: 12px; }
