:root {
  color-scheme: light;
  --bg: #f4f4f2; --fg: #1d1d1b; --muted: #5d5d58; --panel: #ffffff; --line: #c9c9c2;
  --accent: #b5341f; --accent-fg: #ffffff; --error: #b00020; --warn-bg: #fff4d6; --warn-line: #d9a514;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #161615; --fg: #e8e8e3; --muted: #a3a39c; --panel: #222220; --line: #3e3e3a;
    --accent: #e0573f; --accent-fg: #141414; --error: #ff6b6b; --warn-bg: #3a3014; --warn-line: #b8891a;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #161615; --fg: #e8e8e3; --muted: #a3a39c; --panel: #222220; --line: #3e3e3a;
  --accent: #e0573f; --accent-fg: #141414; --error: #ff6b6b; --warn-bg: #3a3014; --warn-line: #b8891a;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 16px/1.5 system-ui, sans-serif; }
main { max-width: 720px; margin: 0 auto; padding: 32px 16px 48px; }
h1 { margin: 0 0 8px; font-size: 28px; line-height: 1.2; }
.lead, .hint, .hints, footer { color: var(--muted); }
.hint, .hints { font-size: 14px; }
.hints { margin: 8px 0 0; padding-left: 20px; }
.hints strong { color: var(--fg); font-weight: 600; }
.drop {
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 40px 16px;
  border: 2px dashed var(--line); border-radius: 8px; background: var(--panel); cursor: pointer; text-align: center;
}
.drop:hover, .drop:focus, .drop.over { border-color: var(--accent); outline: none; }
.drop.disabled { cursor: default; opacity: 0.6; }
.drop span { color: var(--muted); font-size: 14px; }
.drop .source { color: var(--fg); overflow-wrap: anywhere; }
.options { display: flex; flex-wrap: wrap; gap: 16px; margin: 16px 0 4px; }
.options label { display: flex; flex-direction: column; font-size: 14px; color: var(--muted); }
select, input { font: inherit; color: var(--fg); background: var(--panel); border: 1px solid var(--line); border-radius: 4px; padding: 4px 6px; }
input[type=number] { width: 120px; }
.actions { margin: 20px 0 12px; }
.button {
  display: inline-block; padding: 8px 20px; border: 0; border-radius: 4px; background: var(--accent); color: var(--accent-fg);
  font: inherit; font-weight: 600; cursor: pointer;
}
.button:disabled { opacity: 0.5; cursor: default; }
.button.secondary { background: transparent; color: var(--fg); border: 1px solid var(--line); }
progress { width: 100%; height: 12px; accent-color: var(--accent); }
#progress-text { margin: 4px 0 0; }
#status.error { color: var(--error); }
#result { margin-top: 16px; padding: 16px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
pre { margin: 0 0 12px; font: 14px/1.5 ui-monospace, monospace; white-space: pre-wrap; }
.warning { margin: 0 0 12px; padding: 8px 12px; border-left: 4px solid var(--warn-line); background: var(--warn-bg); font-size: 14px; }
code { font: 14px ui-monospace, monospace; }
footer { margin-top: 32px; font-size: 14px; border-top: 1px solid var(--line); padding-top: 12px; }
a { color: var(--accent); }
#preview { margin-top: 16px; }
.stills { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; }
.stills figure { margin: 0; }
.stills img { display: block; width: 100%; height: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 4px; }
.stills figcaption { font-size: 13px; color: var(--muted); }
#estimate { margin: 8px 0 0; font-weight: 600; }
#preview[data-state="running"] #estimate, #preview[data-state="pending"] #estimate { color: var(--muted); font-weight: 400; }
#estimate-warning { margin-top: 8px; }
#preview-progress-box { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
#preview-progress-box progress { flex: 1; }
#preview-progress-box .hint { white-space: nowrap; }
#preview[data-state="running"] .stills, #preview[data-state="pending"] .stills, #preview[data-state="slow"] .stills { opacity: 0.5; }
#preview-slow { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.still { display: block; width: 100%; padding: 0; border: 0; background: none; cursor: zoom-in; }
.still:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
html.lightbox-open, body.lightbox-open { overflow: hidden; }
body.lightbox-open { position: fixed; left: 0; right: 0; }
.lightbox {
  position: fixed; inset: 0; z-index: 10; display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, 0.9); color: #fff;
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); overscroll-behavior: contain; touch-action: pan-y pinch-zoom;
  padding: calc(16px + env(safe-area-inset-top, 0px)) 16px calc(16px + env(safe-area-inset-bottom, 0px));
}
.lb-stage { flex: 1; min-width: 0; height: 100%; display: flex; align-items: center; justify-content: center; }
.lb-figure { margin: 0; text-align: center; }
.lb-figure img {
  display: block; margin: 0 auto; width: auto; height: auto;
  max-width: calc(100vw - 32px); max-height: calc(100vh - 120px); max-height: calc(100dvh - 120px);
  image-rendering: auto; background: #000;
}
.lb-figure figcaption { margin-top: 8px; font-size: 15px; color: #f2f2f2; text-shadow: 0 1px 2px #000; }
.lb-btn {
  position: absolute; z-index: 1; width: 48px; height: 48px; border: 0; border-radius: 24px;
  background: rgba(255, 255, 255, 0.15); color: #fff; font: 32px/48px system-ui, sans-serif; cursor: pointer;
}
.lb-btn:hover, .lb-btn:focus-visible { background: rgba(255, 255, 255, 0.3); outline: none; }
.lb-close { top: calc(12px + env(safe-area-inset-top, 0px)); right: 12px; }
.lb-prev { left: 12px; top: 50%; transform: translateY(-50%); }
.lb-next { right: 12px; top: 50%; transform: translateY(-50%); }
