/* System fonts only: loading web fonts would contact a third-party server,
   which goes against the "nothing leaves your device" promise. */
:root {
  --bg: #eef1f5;
  --panel: #ffffff;
  --ink: #1b2433;
  --muted: #5a6577;
  --line: #d4dae3;
  --accent: #e5a00d;        /* film-leader amber */
  --accent-ink: #1b2433;
  --film: #22262e;          /* film base around each frame */
  --error: #b42318;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light dark;
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #151a22;
    --panel: #1e2530;
    --ink: #e7ebf1;
    --muted: #9aa5b6;
    --line: #313b4a;
    --accent: #f0b429;
    --film: #0c0f14;
    --error: #ff8a80;
  }
}
:root[data-theme="dark"] {
  --bg: #151a22; --panel: #1e2530; --ink: #e7ebf1; --muted: #9aa5b6;
  --line: #313b4a; --accent: #f0b429; --film: #0c0f14; --error: #ff8a80;
}

*, *::before, *::after { box-sizing: inherit; }
[hidden] { display: none !important; }
html { scroll-padding-top: env(safe-area-inset-top, 0px); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
h1, h2 { margin: 0; line-height: 1.2; }
h1 { font-size: clamp(1.6rem, 1.2rem + 1.5vw, 2.3rem); font-weight: 750; letter-spacing: -0.02em; }
h2 { font-size: 1.15rem; font-weight: 650; }

.top { max-width: 1200px; margin: 0 auto; padding: 28px 20px 8px; }
.privacy { margin: 6px 0 0; color: var(--muted); }

.layout {
  max-width: 1200px; margin: 0 auto; padding: 16px 20px 40px;
  display: grid; gap: 20px;
  grid-template-columns: minmax(0, 1fr) 340px;
  align-items: start;
}
@media (max-width: 860px) { .layout { grid-template-columns: minmax(0, 1fr); } }

/* ---------- Images ---------- */
.images-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.summary { margin: 0; color: var(--muted); font-variant-numeric: tabular-nums; }
.images-head .link-btn { margin-left: auto; }

.dropzone {
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 22px 20px;
  text-align: center;
  transition: border-color .15s, background-color .15s;
}
.dropzone.dragging { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--panel)); }
.hint { margin: 10px auto 0; max-width: 60ch; color: var(--muted); font-size: .92rem; }
.touch-hint { display: none; }
@media (pointer: coarse) {
  .desktop-hint { display: none; }
  .touch-hint { display: inline; }
}

.notice { margin: 12px 0 0; padding: 10px 14px; border-radius: 8px; background: var(--panel); border: 1px solid var(--line); font-size: .92rem; }
.notice-error { color: var(--error); border-color: currentColor; }

/* The film strip: each image sits in a frame with sprocket holes. */
.strip {
  list-style: none; margin: 16px 0 0; padding: 0;
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}
.frame {
  --hole: color-mix(in srgb, var(--bg) 85%, transparent);
  background: var(--film);
  border-radius: 6px;
  padding: 16px 8px;
  position: relative;
  color: #e9edf3;
  background-image:
    radial-gradient(circle, var(--hole) 0 3px, transparent 3.5px),
    radial-gradient(circle, var(--hole) 0 3px, transparent 3.5px);
  background-size: 16px 16px, 16px 16px;
  background-position: 4px -3px, 4px calc(100% + 3px);
  background-repeat: repeat-x;
}
.frame-num {
  position: absolute; top: 20px; left: 12px; z-index: 1;
  background: var(--accent); color: var(--accent-ink);
  font-weight: 700; font-size: .78rem; line-height: 1;
  padding: 4px 7px; border-radius: 4px;
  font-variant-numeric: tabular-nums;
}
.frame-remove {
  position: absolute; top: 20px; right: 12px; z-index: 1;
  width: 28px; height: 28px; border-radius: 50%;
  border: 0; background: rgba(0,0,0,.6); color: #fff;
  font-size: 18px; line-height: 1; cursor: pointer;
}
.frame-remove:hover { background: var(--error); }
.frame img {
  display: block; width: 100%; aspect-ratio: 16 / 10;
  object-fit: contain; background: #000; border-radius: 3px;
}
.frame-name {
  margin: 6px 2px 4px; font-size: .8rem; color: #b7c0cd;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.frame input {
  width: 100%; font: inherit; font-size: .85rem;
  padding: 6px 8px; border-radius: 5px;
  border: 1px solid #3a4352; background: #11151b; color: #e9edf3;
}
.frame input::placeholder { color: #7d8898; }

/* ---------- Settings panel ---------- */
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
}

.settings { display: grid; gap: 14px; margin-top: 14px; }
.field { display: grid; gap: 5px; margin: 0; padding: 0; border: 0; min-width: 0; }
.field > span, .field > legend { font-size: .88rem; font-weight: 600; padding: 0; }
.field small { color: var(--muted); font-size: .8rem; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field-row .field.is-disabled { opacity: .45; }

select, input[type="number"] {
  width: 100%; font: inherit; font-size: .95rem; color: var(--ink);
  background: var(--bg); border: 1px solid var(--line);
  border-radius: 7px; padding: 8px 10px; min-height: 40px;
}

.segmented { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.segmented label { position: relative; display: grid; }
.segmented input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.segmented span {
  display: grid; place-items: center; text-align: center; padding: 8px 6px;
  font-size: .86rem; background: var(--bg); cursor: pointer;
}
.segmented label + label span { border-left: 1px solid var(--line); }
.segmented input:checked + span { background: var(--ink); color: var(--panel); font-weight: 600; }
.segmented input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: -3px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  font: inherit; font-weight: 650; text-decoration: none;
  min-height: 44px; padding: 10px 20px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--bg); color: var(--ink);
  cursor: pointer;
}
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover:not(:disabled) { filter: brightness(1.06); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-wide { width: 100%; }
.link-btn { background: none; border: 0; padding: 4px; color: var(--muted); font: inherit; text-decoration: underline; cursor: pointer; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---------- Render / result ---------- */
.render { display: grid; gap: 12px; margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--line); }
.bar { height: 10px; background: var(--bg); border-radius: 5px; overflow: hidden; border: 1px solid var(--line); }
.bar-fill { height: 100%; width: 0; background: var(--accent); transition: width .15s linear; }
.status { margin: 6px 0 0; font-size: .88rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.result video { width: 100%; border-radius: 8px; background: #000; display: block; }
.result-info { margin: 8px 0; font-size: .88rem; color: var(--muted); word-break: break-all; }

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

@media (max-width: 480px) {
  .strip { gap: 10px; }
  .frame { padding: 14px 6px; }
  .frame-num { top: 18px; left: 9px; }
  .frame-remove { top: 18px; right: 9px; }
}

/* ---------- Narration ---------- */
.script { margin-top: 28px; }
.hint-left { text-align: left; margin: 0 0 10px; max-width: 70ch; }
.script textarea {
  width: 100%; min-height: 160px; resize: vertical;
  font: inherit; font-size: .95rem; line-height: 1.5; color: var(--ink);
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; padding: 12px 14px;
}
.script-status { margin: 8px 0 0; font-size: .88rem; color: var(--muted); }
.script-status.is-warning { color: var(--error); }
.frame-voice {
  margin: 6px 2px 0; font-size: .78rem; color: #c9d2de;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.frame-voice::before { content: "🔊 "; }
.voice-box { gap: 8px; }
.voice-options { display: grid; gap: 10px; }
.btn-small { min-height: 36px; padding: 6px 14px; font-size: .9rem; justify-self: start; }
