/* Filmify — dark, warm, built for a phone held in one hand. */

:root {
  --bg: #0e0d0b;
  --surface: #181614;
  --surface-2: #23201d;
  --surface-3: #2d2924;
  --line: #2b2723;
  --text: #ede7dd;
  --text-dim: #9a9186;
  --text-faint: #6a635b;
  --accent: #ff5c14;
  --accent-ink: #1a0c04;
  --accent-soft: rgba(255, 92, 20, 0.16);
  --accent-line: rgba(255, 92, 20, 0.55);
  --danger: #e5484d;
  --radius: 12px;
  --radius-sm: 8px;
  --sa-top: env(safe-area-inset-top, 0px);
  --sa-bottom: env(safe-area-inset-bottom, 0px);
  --sa-left: env(safe-area-inset-left, 0px);
  --sa-right: env(safe-area-inset-right, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Inter, Roboto, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

body {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  touch-action: manipulation;
}

button, input, output, summary { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }

/* ---- top bar ----------------------------------------------------------- */

.topbar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(var(--sa-top) + 10px) calc(var(--sa-right) + 14px) 10px calc(var(--sa-left) + 14px);
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; letter-spacing: 0.01em; font-size: 16px; }
.brand-mark { width: 18px; height: 18px; color: var(--accent); }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.count { color: var(--text-dim); font-size: 12px; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 34px; height: 34px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-dim);
}
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn:active { background: var(--surface-2); }
.icon-btn.small { width: 32px; height: 32px; flex: none; }

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

#app { flex: 1; min-height: 0; display: flex; flex-direction: column; }

/* ---- empty state ------------------------------------------------------- */

.empty {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 20px calc(var(--sa-right) + 20px) calc(var(--sa-bottom) + 24px) calc(var(--sa-left) + 20px);
  overflow-y: auto;
}
.drop {
  width: min(100%, 440px);
  border: 1.5px dashed var(--surface-3);
  border-radius: 20px;
  padding: 32px 24px 24px;
  text-align: center;
  transition: border-color .15s, background .15s;
}
.drop.over { border-color: var(--accent-line); background: var(--accent-soft); }
.drop-icon { width: 52px; height: 52px; color: var(--accent); margin-bottom: 12px; }
.drop h1 { font-size: 20px; font-weight: 650; margin: 0 0 8px; letter-spacing: -0.01em; }
.drop .lede { color: var(--text-dim); margin: 0 auto 20px; max-width: 34ch; font-size: 14px; }
.paths { display: grid; gap: 12px; margin-top: 24px; text-align: left; }
.path { display: grid; gap: 3px; padding: 12px 14px; background: var(--surface); border-radius: var(--radius); font-size: 13px; color: var(--text-dim); line-height: 1.45; }
.path b { color: var(--text); font-weight: 600; }
.path-k { color: var(--accent); font-size: 11px; font-weight: 650; letter-spacing: .08em; text-transform: uppercase; }

/* ---- workspace --------------------------------------------------------- */

.workspace { flex: 1; min-height: 0; display: flex; flex-direction: column; }

.stage {
  flex: 1;
  min-height: 160px;
  position: relative;
  display: grid;
  place-items: center;
  background: #070605;
  overflow: hidden;
  -webkit-touch-callout: none;
  user-select: none; -webkit-user-select: none;
  touch-action: none;
}
#preview {
  /* fill the stage and let object-fit letterbox the bitmap: percentage
     max-height doesn't resolve reliably inside a flex-sized box in WebKit,
     which clipped portrait photos */
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: contain;
  display: block;
}
.stage-badges { position: absolute; left: 10px; bottom: 10px; display: flex; gap: 6px; pointer-events: none; }
.badge {
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(14, 13, 11, 0.72);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase;
  color: var(--text);
}
.badge.night { color: #ffb48a; }
.badge.dim { color: var(--text-dim); font-weight: 500; letter-spacing: .02em; text-transform: none; }
.badge:empty { display: none; }

.stage-busy {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  background: rgba(7, 6, 5, 0.35);
  opacity: 0; pointer-events: none;
  transition: opacity .12s;
}
.stage.busy .stage-busy { opacity: 1; }
.stage-busy span {
  width: 26px; height: 26px;
  border-radius: 50%;
  border: 2.5px solid rgba(255,255,255,.18);
  border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- filmstrip --------------------------------------------------------- */

.filmstrip-wrap {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px calc(var(--sa-right) + 10px) 8px calc(var(--sa-left) + 10px);
  border-top: 1px solid var(--line);
  background: var(--surface);
}
.filmstrip { flex: 1; min-width: 0; display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding: 2px; }
.filmstrip::-webkit-scrollbar { display: none; }
.thumb {
  flex: none;
  position: relative;
  width: 54px; height: 54px;
  border-radius: 9px;
  border: 2px solid transparent;
  background: var(--surface-2);
  padding: 0;
  overflow: hidden;
  transition: border-color .12s;
}
.thumb canvas { width: 100%; height: 100%; display: block; object-fit: cover; }
.thumb.selected { border-color: var(--accent); }
.thumb .moon { position: absolute; right: 3px; top: 3px; width: 12px; height: 12px; color: #ffb48a; filter: drop-shadow(0 0 2px rgba(0,0,0,.8)); }
.thumb.add { display: grid; place-items: center; color: var(--text-dim); border: 1.5px dashed var(--surface-3); background: transparent; }
.thumb.add svg { width: 20px; height: 20px; }
.thumb .remove {
  position: absolute; left: 0; bottom: 0; right: 0;
  height: 18px;
  display: none; place-items: center;
  background: rgba(14,13,11,.8);
  color: var(--text); font-size: 10px; font-weight: 600; letter-spacing: .04em;
}
.thumb.selected .remove { display: grid; }

/* ---- controls ---------------------------------------------------------- */

.controls {
  flex: none;
  display: grid;
  gap: 10px;
  padding: 12px calc(var(--sa-right) + 14px) 6px calc(var(--sa-left) + 14px);
  background: var(--surface);
  max-height: 46vh;
  overflow-y: auto;
}
.row { display: flex; align-items: center; gap: 8px; }
.row > label { flex: none; width: 76px; font-size: 13px; color: var(--text-dim); }

.films { gap: 6px; }
.film {
  flex: 1;
  display: flex; align-items: center; justify-content: center; gap: 7px;
  height: 40px;
  padding: 0 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  font-size: 13.5px; font-weight: 600;
  color: var(--text-dim);
  transition: background .12s, border-color .12s, color .12s;
}
.film .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; background: var(--swatch); box-shadow: 0 0 0 1px rgba(0,0,0,.35) inset; }
.film.on { background: var(--surface-3); border-color: var(--accent-line); color: var(--text); }
.film:active { background: var(--surface-3); }

.effects { gap: 6px; }
.toggle {
  flex: 1;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text-dim);
  font-size: 13px; font-weight: 600;
  transition: background .12s, border-color .12s, color .12s;
}
.toggle.on { background: var(--accent-soft); border-color: var(--accent-line); color: #ffc29f; }

.slider input[type=range] { flex: 1; min-width: 0; }
.slider output { width: 42px; text-align: right; font-size: 13px; color: var(--text-dim); }

input[type=range] {
  -webkit-appearance: none; appearance: none;
  height: 28px; background: transparent; margin: 0;
}
input[type=range]::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: var(--surface-3); }
input[type=range]::-moz-range-track { height: 4px; border-radius: 2px; background: var(--surface-3); }
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px; height: 22px; margin-top: -9px;
  border-radius: 50%;
  background: var(--text);
  border: 0;
  box-shadow: 0 1px 4px rgba(0,0,0,.5);
}
input[type=range]::-moz-range-thumb { width: 22px; height: 22px; border-radius: 50%; background: var(--text); border: 0; }

.segmented {
  flex: 1;
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  padding: 3px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--line);
}
.segmented button {
  height: 30px;
  border: 0; border-radius: 6px;
  background: transparent;
  color: var(--text-dim);
  font-size: 13px; font-weight: 600;
}
.segmented button.on { background: var(--surface-3); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.4); }

.more { border-top: 1px solid var(--line); padding-top: 4px; }
.more summary {
  list-style: none;
  cursor: pointer;
  padding: 6px 0;
  font-size: 13px; color: var(--text-dim);
  display: flex; align-items: center; gap: 6px;
  user-select: none; -webkit-user-select: none;
}
.more summary::-webkit-details-marker { display: none; }
.more summary::before { content: ""; width: 6px; height: 6px; border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor; transform: rotate(-45deg); transition: transform .15s; margin-left: 2px; }
.more[open] summary::before { transform: rotate(45deg); }
.more > .row { margin-top: 8px; }
.seed input[type=number] {
  flex: 1; min-width: 0;
  height: 34px; padding: 0 10px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--text);
  -moz-appearance: textfield;
}
.seed input::-webkit-outer-spin-button, .seed input::-webkit-inner-spin-button { -webkit-appearance: none; }
.note { margin: 10px 0 4px; font-size: 12px; line-height: 1.45; color: var(--text-faint); }

/* ---- actions ----------------------------------------------------------- */

.actions {
  flex: none;
  display: grid; grid-template-columns: 1fr 1.4fr; gap: 10px;
  padding: 10px calc(var(--sa-right) + 14px) calc(var(--sa-bottom) + 12px) calc(var(--sa-left) + 14px);
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.btn {
  height: 46px;
  padding: 0 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
  font-size: 15px; font-weight: 650;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: background .12s, opacity .12s;
}
.btn:active { background: var(--surface-3); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:active { background: #e6500f; }
.btn.big { height: 50px; padding: 0 28px; font-size: 16px; }
.btn.tiny { height: 34px; padding: 0 12px; font-size: 13px; border-radius: var(--radius-sm); }
.btn[disabled] { opacity: .5; pointer-events: none; }
.btn.working { pointer-events: none; }
.btn .spin { width: 16px; height: 16px; border-radius: 50%; border: 2px solid rgba(0,0,0,.2); border-top-color: currentColor; animation: spin .8s linear infinite; }
.btn.ready { background: #2ea043; border-color: #2ea043; color: #06120a; }

/* ---- dialog + toast ---------------------------------------------------- */

.help {
  width: min(92vw, 460px);
  max-height: 86vh;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 22px 22px 18px;
  background: var(--surface);
  color: var(--text);
  overflow-y: auto;
}
.help::backdrop { background: rgba(0,0,0,.6); }
.help h2 { font-size: 16px; margin: 0 0 10px; }
.help h2 + * { margin-top: 0; }
.help h2:not(:first-child) { margin-top: 20px; }
.help ol { padding-left: 20px; margin: 0; display: grid; gap: 8px; font-size: 14px; color: var(--text-dim); }
.help p { font-size: 14px; color: var(--text-dim); margin: 10px 0; }
.help b { color: var(--text); font-weight: 600; }
.help .btn { width: 100%; margin-top: 16px; }

.toast {
  position: fixed;
  left: 50%; bottom: calc(var(--sa-bottom) + 84px);
  transform: translateX(-50%);
  max-width: min(90vw, 420px);
  padding: 10px 14px;
  border-radius: 10px;
  background: #f3ede4; color: #1a1613;
  font-size: 13.5px; font-weight: 500;
  box-shadow: 0 6px 24px rgba(0,0,0,.45);
  z-index: 50;
  animation: toast-in .18s ease-out;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 6px); } }

/* ---- wide screens: preview beside the controls ------------------------- */

@media (min-width: 820px) {
  .workspace {
    display: grid;
    grid-template-columns: 1fr 340px;
    grid-template-rows: 1fr auto;
    grid-template-areas: "stage controls" "strip actions";
  }
  .stage { grid-area: stage; }
  .filmstrip-wrap { grid-area: strip; border-right: 1px solid var(--line); }
  .controls { grid-area: controls; max-height: none; border-left: 1px solid var(--line); padding: 16px 16px 8px; align-content: start; gap: 12px; }
  .actions { grid-area: actions; border-left: 1px solid var(--line); }
  .film { height: 42px; }
  .drop { padding: 40px 32px 28px; }
}
