/* Video Frame Picker — dark only: the video is the work area (common spec 9, plan B). */

:root {
  --bg: #111317;
  --card: #1c2027;
  --panel: #171a1f;
  --text: #e8eaed;
  --muted: #9aa3ae;
  --border: #2c323b;
  --accent: #60a5fa;
  --danger: #f87171;
  --ok: #4ade80;
  --warn: #facc15;
  --miss: #ff6b4a;
  --shadow-run: 0 6px 22px rgba(0, 0, 0, .45);
  --radius: 16px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP",
               "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

/* ---------- header ---------- */

.app-header {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  min-width: 0;
}

/* App name + version: the same look in every yukmmz.github.io app. */
.app-brand { display: flex; align-items: baseline; gap: .45em; white-space: nowrap; min-width: 0; }
.app-title {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", "Segoe UI", Roboto, sans-serif;
  font-size: 16px; font-weight: 700; margin: 0; letter-spacing: .02em; line-height: 1.2; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.app-version { font-size: 11px; font-weight: 400; opacity: .55; white-space: nowrap; cursor: pointer; }
.app-version:hover { text-decoration: underline; }

.tools { display: flex; gap: 6px; margin-left: 8px; flex-wrap: nowrap; }
.tools .btn { padding: 6px 10px; font-size: .85rem; white-space: nowrap; }

.mode-label {
  margin-left: auto;
  font-size: .75rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  flex: 0 1 auto;
}

/* ---------- buttons ---------- */

.btn {
  font: inherit;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 14px;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  transition: background .12s ease, border-color .12s ease, transform .06s ease;
}
.btn:hover { border-color: #3e4652; }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .4; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #0b1220; font-weight: 600; }
.btn-danger { color: var(--danger); font-size: .9rem; }

.btn-round {
  width: 36px; height: 36px; padding: 0; border-radius: 50%;
  font-size: 1.1rem; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
}

.btn-icon {
  width: 36px; height: 36px; padding: 0; border-radius: 10px;
  color: var(--muted); font-size: 1.1rem; line-height: 1; flex: 0 0 auto;
  display: inline-flex; align-items: center; justify-content: center;
}

#settings-btn { font-size: 2.1rem; line-height: 1; overflow: visible; }
#help-btn { font-size: 1.35rem; font-weight: 700; }

/* "FB" packed edge to edge inside the 36x36 key. */
#feedback-btn .fb-mark {
  display: inline-block;
  font-size: 1.44rem;
  font-weight: 384;
  letter-spacing: -.05em;
  line-height: 1;
  transform: scaleX(.74);
}

#fullscreen-btn[hidden] { display: none; }
.fs-icon {
  width: 22px; height: 22px; fill: none; stroke: currentColor;
  stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round;
}
#fullscreen-btn .fs-exit,
#fullscreen-btn.is-fullscreen .fs-enter { display: none; }
#fullscreen-btn.is-fullscreen .fs-exit { display: block; }

a.btn { text-decoration: none; display: inline-block; }

/* ---------- main ---------- */

main {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.empty {
  margin: auto;
  max-width: 560px;
  padding: 24px;
  text-align: center;
}
.empty[hidden] { display: none; }
.empty h2 { font-size: 1.3rem; margin: 0 0 8px; }
.empty-actions { display: flex; gap: 10px; justify-content: center; margin: 18px 0 10px; flex-wrap: wrap; }
.empty-actions .btn { padding: 12px 22px; font-size: 1rem; }
.empty-note { font-size: .85rem; color: var(--muted); margin: 6px 0; }

.stage {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.stage[hidden] { display: none; }

.video-box {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  background: #000;
  overflow: hidden;
}

.viewport {
  position: absolute;
  inset: 0;
  transform-origin: 50% 50%;
  will-change: transform;
}

#video, .ghost {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}
.ghost { background: transparent; opacity: .45; pointer-events: none; }
.ghost[hidden] { display: none; }
.video-box { touch-action: none; cursor: default; }
.video-box.zoomed { cursor: grab; }
.video-box.panning { cursor: grabbing; }

.zoom-badge {
  position: absolute;
  right: 14px;
  bottom: 12px;
  padding: 3px 8px;
  background: rgba(0, 0, 0, .6);
  border-radius: 6px;
  font-family: var(--mono);
  font-size: 12px;
  pointer-events: none;
}
.zoom-badge[hidden] { display: none; }

.list-panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(340px, 80%);
  display: flex;
  flex-direction: column;
  background: rgba(23, 26, 31, .94);
  border-left: 1px solid var(--border);
  z-index: 5;
}
.list-panel[hidden] { display: none; }
.list-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 8px 6px 12px;
             border-bottom: 1px solid var(--border); font-size: .9rem; font-weight: 700; }
.list-close { width: 30px; height: 30px; }
.list-body { overflow-y: auto; -webkit-overflow-scrolling: touch; flex: 1 1 auto; min-height: 0; }
.list-row {
  display: grid;
  grid-template-columns: 2.2em minmax(0, 1fr) auto;
  gap: 2px 8px;
  width: 100%;
  padding: 6px 10px;
  border: 0;
  border-bottom: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.list-row:hover { background: #222831; }
.list-row.current { background: #1e3a5f; }
.list-num { color: var(--muted); font-family: var(--mono); font-size: .8rem; }
.list-name { font-family: var(--mono); font-size: .82rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-status { font-size: .72rem; font-weight: 700; padding: 1px 6px; border-radius: 5px; align-self: center; }
.list-status.ok { background: #14532d; color: var(--ok); }
.list-status.excluded { background: #7f1d1d; color: #fecaca; }
.list-status.todo { background: #3a3f48; color: var(--muted); }
.list-picks { grid-column: 2 / -1; font-family: var(--mono); font-size: .72rem; color: var(--muted);
              overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.ctl-play { min-width: 52px; }
.speed-panel {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px 10px;
  padding: 8px 12px;
  background: var(--panel);
  border-top: 1px solid var(--border);
}
.speed-panel[hidden] { display: none; }
.speed-label { font-size: .85rem; color: var(--muted); }
.speed-range { width: min(320px, 60vw); accent-color: var(--accent); }
.speed-input { width: 72px; text-align: right; font-family: var(--mono); font-size: 1rem; }
.speed-x { margin-left: -6px; color: var(--muted); }
.speed-presets { display: flex; flex-wrap: wrap; gap: 4px; }
.speed-preset { padding: 5px 8px; font-family: var(--mono); font-size: .85rem; min-width: 46px; }
.speed-preset.on { background: #1e3a5f; border-color: var(--accent); }
.ctl-speed { min-width: 52px; font-family: var(--mono); font-size: .95rem; }
.ctl[aria-pressed="true"] { background: #1e3a5f; border-color: var(--accent); }
.info-panel .l-d { color: #9fd3ff; }

/* The Python version's text panel, top-left over the video. */
.info-panel {
  position: absolute;
  top: 10px;
  left: 10px;
  max-width: calc(100% - 20px);
  padding: 6px 10px;
  background: rgba(0, 0, 0, .55);
  border-radius: 6px;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.6;
  white-space: pre;
  overflow: hidden;
  pointer-events: none;
}
.info-panel .l-y { color: var(--warn); }
.info-panel .l-r { color: var(--miss); }
.info-panel .l-g { color: var(--ok); }
.info-panel .fps-link {
  pointer-events: auto;
  cursor: pointer;
  text-decoration: underline dotted;
}

.saved-badge {
  position: absolute;
  top: 12px;
  right: 14px;
  padding: 6px 12px;
  background: rgba(0, 120, 0, .8);
  color: #fff;
  border-radius: 6px;
  font-family: var(--mono);
  font-weight: 700;
  font-size: 14px;
  pointer-events: none;
}
.saved-badge.err { background: rgba(160, 30, 30, .85); }
.saved-badge[hidden] { display: none; }

.help-panel {
  position: absolute;
  left: 10px;
  bottom: 10px;
  max-width: calc(100% - 20px);
  padding: 6px 10px;
  background: rgba(0, 0, 0, .55);
  border-radius: 6px;
  color: #c8c8c8;
  font-family: var(--mono);
  font-size: 11.5px;
  line-height: 1.55;
  white-space: pre;
  overflow: hidden;
  pointer-events: none;
}
.help-panel[hidden] { display: none; }

.video-msg {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  max-width: 80%;
  padding: 10px 16px;
  background: rgba(0, 0, 0, .7);
  border-radius: 8px;
  text-align: center;
  font-size: .95rem;
  pointer-events: none;
}
.video-msg[hidden] { display: none; }

/* Seek bar: the Python version's marker strip, made clickable. */
.seek-bar {
  position: relative;
  flex: 0 0 auto;
  height: 30px;
  background: #000;
  border-top: 1px solid var(--border);
  cursor: pointer;
  touch-action: none;
}
.seek-fill {
  position: absolute;
  left: 0; top: 13px; height: 4px;
  background: #3a4250;
  width: 100%;
  border-radius: 2px;
  pointer-events: none;
}
.seek-marks { position: absolute; inset: 0; pointer-events: none; }
.seek-mark {
  position: absolute;
  top: 0;
  width: 3px;
  height: 13px;
  margin-left: -1px;
}
.seek-mark span {
  position: absolute;
  top: 12px;
  left: -3px;
  font-size: 11px;
  font-weight: 700;
  font-family: var(--mono);
  line-height: 1.4;
}
.seek-head {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  margin-left: -1px;
  background: #fff;
  pointer-events: none;
}

/* ---------- controls (mouse / touch) ---------- */

.controls {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  align-items: center;
  justify-content: center;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  background: var(--panel);
  border-top: 1px solid var(--border);
}
.ctl-group { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: center; }
.ctl {
  min-width: 44px;
  height: 44px;
  padding: 0 10px;
  font-size: 1.25rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.ctl-sm { min-width: 36px; padding: 0 6px; font-size: 1.1rem; }
.step-box { display: flex; gap: 2px; align-items: center; }
.step-value { min-width: 56px; font-family: var(--mono); font-size: 1rem; }
.ctl-exclude { font-size: .95rem; font-weight: 700; letter-spacing: .04em; }
.ctl-exclude.on { background: #7f1d1d; border-color: var(--danger); color: #fff; }

.slot {
  position: relative;
  display: inline-flex;
  align-items: stretch;
  height: 44px;
  border-radius: 10px;
  border: 1px solid var(--border);
  overflow: hidden;
}
.slot .slot-rec {
  border: 0;
  border-radius: 0;
  min-width: 54px;
  height: 100%;
  padding: 0 8px;
  font-family: var(--mono);
  font-size: .95rem;
  line-height: 1.1;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-left: 5px solid var(--slot-color, #888);
}
.slot .slot-rec small { font-size: .7rem; color: var(--muted); }
.slot.is-empty .slot-rec small { color: var(--miss); }
.slot .slot-clear {
  border: 0;
  border-left: 1px solid var(--border);
  border-radius: 0;
  width: 30px;
  height: 100%;
  padding: 0;
  color: var(--muted);
  font-size: .9rem;
}
.slot.is-empty .slot-clear { visibility: hidden; }

/* ---------- toast / drop ---------- */

.toast {
  position: absolute;
  left: 50%;
  bottom: 120px;
  transform: translateX(-50%);
  max-width: min(640px, calc(100% - 32px));
  padding: 10px 16px;
  background: rgba(28, 32, 39, .95);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: .9rem;
  z-index: 50;
  box-shadow: var(--shadow-run);
  white-space: pre-line;
}
.toast.err { border-color: var(--danger); }
.toast[hidden] { display: none; }

.drop-hint {
  position: absolute;
  inset: 12px;
  border: 3px dashed var(--accent);
  border-radius: 16px;
  background: rgba(96, 165, 250, .08);
  pointer-events: none;
  z-index: 40;
}
.drop-hint[hidden] { display: none; }

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

.backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(0, 0, 0, .5);
}
.backdrop[hidden] { display: none; }

.sheet {
  position: fixed;
  z-index: 30;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(440px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-run);
  padding: 16px;
}
.sheet[hidden] { display: none; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.sheet-title { font-size: 1rem; margin: 0; }
.sheet-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-top: 1px solid var(--border);
}
.sheet-label { font-size: .9rem; }
.sheet-label small { color: var(--muted); font-size: .75rem; }
.sheet-note { margin: -4px 0 8px; font-size: .8rem; color: var(--warn); }
.sheet-note[hidden] { display: none; }

.select, .text-input {
  font: inherit;
  font-size: .9rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 7px 10px;
  max-width: 60%;
}
.num-input { width: 110px; text-align: right; }
.check { width: 22px; height: 22px; accent-color: var(--accent); }

.stepper { display: flex; align-items: center; gap: 8px; }
.stepper-value { min-width: 2.4em; text-align: center; font-variant-numeric: tabular-nums; font-weight: 700; }

kbd {
  font-family: var(--mono);
  font-size: .8em;
  padding: 1px 5px;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--bg);
}
code { font-family: var(--mono); font-size: .85em; }

/* ---------- overlays (QR / changelog / help / feedback) ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, .5);
}
.overlay[hidden] { display: none; }

.qrcard {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-run);
  padding: 20px;
  max-width: min(560px, calc(100vw - 32px));
  text-align: center;
}
.qrrow { display: flex; gap: 20px; justify-content: center; flex-wrap: wrap; }
.qrcol { flex: 0 1 210px; }
.qrlabel { font-size: .82rem; font-weight: 700; color: var(--muted); margin-bottom: 6px; }
.qrImg { width: 100%; max-width: 190px; height: auto; background: #fff; border-radius: 8px; }
.qrurl { font-size: .7rem; color: var(--muted); word-break: break-all; margin-top: 4px; }
#qrClose { margin-top: 16px; }

.changelog-card {
  width: min(520px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  display: flex;
  flex-direction: column;
  text-align: left;
}
.help-card { width: min(640px, calc(100vw - 32px)); }
.changelog-title { font-size: 1rem; margin: 0 0 8px; }
.changelog-list { overflow-y: auto; -webkit-overflow-scrolling: touch; flex: 1 1 auto; min-height: 0; }
.changelog-entry + .changelog-entry { border-top: 1px solid var(--border); margin-top: 8px; padding-top: 8px; }
.changelog-version { font-size: .9rem; margin: 0 0 4px; }
.changelog-entry ul { margin: 0; padding-left: 1.2em; font-size: .85rem; color: var(--muted); }
#changelogClose, #helpClose { margin-top: 12px; align-self: center; }

.help-body { font-size: .9rem; line-height: 1.6; }
.help-body p { margin: 6px 0; }
.help-body h3 { font-size: .95rem; margin: 14px 0 4px; }
.help-body .hint { font-size: .8rem; color: var(--muted); }
.help-body table.keys { border-collapse: collapse; font-size: .85rem; }
.help-body table.keys td { padding: 3px 10px 3px 0; vertical-align: top; }
.help-body table.keys td:first-child { white-space: nowrap; }

.feedback-card, .fps-card { gap: 8px; }
.fps-reason { margin: 0; font-size: .9rem; }
.fps-help, .fps-suggest { margin: 0; font-size: .82rem; color: var(--muted); }
.fps-suggest:empty { display: none; }
.fps-row { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.fps-row .text-input { max-width: none; flex: 1 1 auto; font-size: 1.05rem; }
.info-panel .fps-missing { color: var(--miss); font-weight: 700; }
.fpsc-card { gap: 10px; width: min(640px, calc(100vw - 32px)); }
.fpsc-all { font-size: 1.6rem; font-weight: 700; font-family: var(--mono); padding: 8px 12px; text-align: right; }
.fpsc-presets { display: flex; flex-wrap: wrap; gap: 6px; }
.fpsc-preset { padding: 6px 10px; font-family: var(--mono); font-size: .9rem; min-width: 52px; }
.fpsc-toggle { align-self: flex-start; padding: 5px 10px; font-size: .85rem; }
.fpsc-slowmo { margin: 0; padding: 8px 10px; border: 1px solid var(--warn); border-radius: 8px; font-size: .85rem; color: var(--warn); }
.fpsc-slowmo[hidden] { display: none; }
.fpsc-table { display: flex; flex-direction: column; gap: 4px; overflow-y: auto; max-height: 40vh; min-height: 0; }
.fpsc-table[hidden] { display: none; }
.fpsc-row { display: grid; grid-template-columns: minmax(0, 1fr) 110px; gap: 2px 10px; align-items: center;
            padding: 6px 8px; border: 1px solid var(--border); border-radius: 8px; }
.fpsc-row.warn { border-color: var(--warn); }
.fpsc-row.missing { border-color: var(--miss); }
.fpsc-name { font-family: var(--mono); font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fpsc-input { max-width: none; width: 110px; text-align: right; font-family: var(--mono); font-size: 1rem; }
.fpsc-input.invalid { border-color: var(--danger); }
.fpsc-note { grid-column: 1 / -1; font-size: .75rem; color: var(--muted); }
.fpsc-row.warn .fpsc-note { color: var(--warn); }
.fpsc-row.missing .fpsc-note { color: var(--miss); }
.feedback-lead, .feedback-note { margin: 0; font-size: .85rem; color: var(--muted); }
.feedback-message, .feedback-contact {
  width: 100%;
  font: inherit;
  font-size: .95rem;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: inherit;
}
.feedback-message { resize: vertical; min-height: 120px; }
.feedback-hp { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }
.feedback-status { margin: 0; min-height: 1.2em; font-size: .85rem; font-weight: 700; }
.feedback-status.ok { color: var(--ok); }
.feedback-status.err { color: var(--danger); }
.feedback-actions { display: flex; gap: 8px; justify-content: flex-end; }
#feedbackSend { background: var(--accent); border-color: var(--accent); color: #0b1220; }
#feedbackSend:disabled { opacity: .6; }

/* Quick tooltip: the button's title after 0.5 s, mouse only (common spec §10). Long titles in this app
   wrap instead of running out of the box. */
.quick-tip {
  position: fixed;
  z-index: 100;
  max-width: 280px;
  padding: 4px 8px;
  border-radius: 6px;
  background: var(--text);
  color: var(--bg);
  font-size: .8rem;
  line-height: 1.4;
  white-space: normal;
  pointer-events: none;
  box-shadow: var(--shadow-run);
}
.quick-tip[hidden] { display: none; }

/* A small dot on ⚙ and on the changelog button until the new version's changelog was opened. */
#settings-btn, #changelogBtn { position: relative; }
#settings-btn.has-news::after,
#changelogBtn.has-news::after {
  content: '';
  position: absolute;
  top: 2px;
  right: 2px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--danger);
}

/* ---------- narrow screens (iPad portrait and below) ---------- */

@media (max-width: 900px) {
  .mode-label { display: none; }
  .tools { margin-left: auto; }
}

@media (max-width: 700px) {
  .app-header { gap: 4px; padding: 6px 8px; }
  .tools { gap: 4px; }
  .tools .btn { padding: 5px 7px; font-size: .75rem; }
  .info-panel { font-size: 11px; }
  .help-panel { display: none; }
}
