:root {
  color-scheme: light dark;
  --bg: #f6f3ee;
  --surface: #ffffff;
  --surface-2: #ece6dd;
  --ink: #1c1a17;
  --dim: #6a645c;
  --line: #e1dad0;
  --track: #cfc7bb;
  --accent: #c93c20;
  --on-accent: #ffffff;
  --danger: #b3261e;
  --shadow: 0 1px 2px rgba(40, 30, 20, 0.06), 0 6px 20px rgba(40, 30, 20, 0.06);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --round: ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, system-ui, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141210;
    --surface: #201d1a;
    --surface-2: #2c2824;
    --ink: #f3efe9;
    --dim: #a59f96;
    --line: #35302b;
    --track: #4a443e;
    --accent: #ff7a59;
    --on-accent: #1a0e08;
    --danger: #ff8a80;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; overscroll-behavior: none; }
body {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  background: var(--bg); color: var(--ink);
  font: 16px/1.4 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}
/* iOS paints the band behind the status bar in body's colour: match whatever is at the top of the screen. */
body:has(#clip[open]) { background: #000; }
body:has(dialog.sheet[open]) { background: color-mix(in srgb, var(--bg) 45%, #000); }
body:has(#clip[open]):has(dialog.sheet[open]) { background: #000; }

button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
svg { display: block; }
[hidden] { display: none !important; }
/* file pickers are opened from buttons; kept in the page (not display:none) so every browser lets them open */
.picker { position: fixed; left: -200px; top: 0; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
h1, h2, h3 { font-family: var(--round); }
.dim { color: var(--dim); }
.small { font-size: 14px; }

/* ---------- bars, panes, buttons ---------- */
.bar {
  flex: none;
  display: flex; align-items: center; gap: 8px;
  min-height: 56px; padding: 6px 16px;
}
#top { max-width: 1132px; width: 100%; margin: 0 auto; }
#top h1 { flex: 1; margin: 0; font-size: 32px; font-weight: 800; letter-spacing: -0.02em; line-height: 1.1; }
.bar h2 { flex: 1; margin: 0; text-align: center; font-size: 17px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-gap { width: 76px; flex: none; }

.pane {
  flex: 1; min-height: 0;
  overflow-y: auto; overflow-x: hidden;
  overscroll-behavior: none; touch-action: pan-y;
  outline: none;
}
.wrap { max-width: 1132px; margin: 0 auto; padding: 0 16px 128px; }
.wrap.narrow { max-width: 720px; padding-bottom: 24px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 52px; padding: 0 20px;
  border: 0; border-radius: 16px;
  background: var(--surface); color: var(--ink);
  font-size: 17px; font-weight: 600;
  box-shadow: var(--shadow);
}
.btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.btn.primary { background: var(--accent); color: var(--on-accent); }
.btn:disabled { opacity: 0.45; }
.btn.danger { background: none; box-shadow: none; color: var(--danger); width: 100%; margin-top: 8px; }
.btn.danger-fill { background: var(--danger); color: #fff; }
@media (prefers-color-scheme: dark) { .btn { background: var(--surface-2); } .btn.danger-fill { color: #1a0a08; } }
.btn:active { transform: scale(0.98); }
.rec { width: 14px; height: 14px; border-radius: 50%; background: currentColor; box-shadow: 0 0 0 3px color-mix(in srgb, currentColor 35%, transparent); }

.pill {
  min-height: 44px; padding: 0 16px;
  border: 0; border-radius: 22px;
  background: var(--surface-2); color: var(--ink);
  font-size: 15px; font-weight: 600;
}
#select-toggle[aria-pressed="true"] { background: var(--ink); color: var(--bg); }
.icon-btn {
  display: inline-grid; place-items: center;
  width: 44px; height: 44px; flex: none;
  border: 0; border-radius: 22px; background: transparent; color: inherit;
}
.icon-btn svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.back {
  display: inline-flex; align-items: center; gap: 2px;
  min-height: 44px; width: 76px; padding: 0; flex: none;
  border: 0; background: none; color: var(--accent);
  font-size: 17px; font-weight: 600;
}
.back svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }

/* the action bar floating over the bottom of the list (clear of the home indicator) */
.dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  padding: 18px 16px 24px;
  background: linear-gradient(to bottom, color-mix(in srgb, var(--bg) 0%, transparent), var(--bg) 45%);
  pointer-events: none;
}
.dock-in { display: flex; gap: 10px; max-width: 520px; margin: 0 auto; pointer-events: auto; }
.dock-in .btn { flex: 1; }
.dock.inline { position: static; flex: none; padding: 10px 16px 24px; background: var(--bg); border-top: 1px solid var(--line); pointer-events: auto; }

/* ---------- library ---------- */
.day { margin: 6px 0 22px; }
.day-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 0 2px 10px; min-height: 44px; }
.day-head h2 { margin: 0; font-size: 21px; font-weight: 750; letter-spacing: -0.01em; line-height: 1.2; }
.day-head p { margin: 2px 0 0; color: var(--dim); font-size: 14px; }
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
@media (min-width: 560px) { .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; } }

.tile {
  position: relative; display: block;
  aspect-ratio: 3 / 4; width: 100%;
  padding: 0; border: 0; border-radius: 12px; overflow: hidden;
  background: var(--surface-2);
  transition: transform 0.15s;
}
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile, .rows .thumb { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; } /* no image menu on long press */
.tile::after { content: ""; position: absolute; inset: auto 0 0 0; height: 44%; background: linear-gradient(to top, rgba(0, 0, 0, 0.55), transparent); pointer-events: none; }
.tile .t, .tile .len {
  position: absolute; bottom: 6px; z-index: 1;
  font-size: 12px; font-weight: 600; color: #fff; line-height: 1.2;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
}
.tile .t { left: 8px; }
.tile .len { right: 8px; }
.tile .len.cut::before { /* scissors: this clip is trimmed */
  content: ""; display: inline-block; width: 11px; height: 11px; margin-right: 3px; vertical-align: -1px;
  background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.6' stroke-linecap='round'%3E%3Ccircle cx='6' cy='6' r='3'/%3E%3Ccircle cx='6' cy='18' r='3'/%3E%3Cpath d='M20 4 8.12 15.88M14.47 14.48 20 20M8.12 8.12 12 12'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.6' stroke-linecap='round'%3E%3Ccircle cx='6' cy='6' r='3'/%3E%3Ccircle cx='6' cy='18' r='3'/%3E%3Cpath d='M20 4 8.12 15.88M14.47 14.48 20 20M8.12 8.12 12 12'/%3E%3C/svg%3E") center / contain no-repeat;
}
.tile .check {
  position: absolute; top: 7px; right: 7px; z-index: 1;
  width: 26px; height: 26px; border-radius: 50%;
  border: 2px solid #fff; background: rgba(0, 0, 0, 0.25);
  display: none;
}
.selecting .tile .check { display: block; }
.tile[aria-pressed="true"] { transform: scale(0.94); }
.tile[aria-pressed="true"] .check { background: var(--accent); border-color: var(--accent); }
.tile[aria-pressed="true"] .check::after {
  content: ""; position: absolute; left: 7px; top: 3px; width: 6px; height: 11px;
  border: solid var(--on-accent); border-width: 0 2.5px 2.5px 0; transform: rotate(45deg);
}
.tile .num {
  position: absolute; top: 7px; left: 7px; z-index: 1; display: none;
  min-width: 26px; height: 26px; padding: 0 6px; border-radius: 13px;
  background: rgba(0, 0, 0, 0.55); color: #fff; font-size: 13px; font-weight: 700; line-height: 26px; text-align: center;
}
.tile[aria-pressed="true"] .num { display: block; }

.empty { text-align: center; max-width: 360px; margin: 9vh auto 0; padding: 0 8px; }
.empty svg { width: 132px; height: 110px; margin: 0 auto 10px; }
.empty .e1 { fill: var(--surface-2); }
.empty .e2 { fill: color-mix(in srgb, var(--accent) 30%, var(--surface)); }
.empty .e3 { fill: var(--surface); stroke: var(--line); stroke-width: 1.5; }
.empty .e4 { fill: var(--accent); stroke: var(--accent); stroke-width: 4; stroke-linejoin: round; }
.empty h2 { margin: 0 0 8px; font-size: 24px; font-weight: 800; }
.empty p { margin: 0 0 10px; color: var(--dim); }

.adding, .problem {
  display: flex; align-items: center; gap: 12px;
  margin: 4px 0 16px; padding: 14px 16px;
  border-radius: 16px; background: var(--surface); box-shadow: var(--shadow);
}
.problem { color: var(--ink); border-left: 4px solid var(--danger); display: block; }
.spinner { width: 22px; height: 22px; flex: none; border-radius: 50%; border: 3px solid var(--surface-2); border-top-color: var(--accent); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.foot { text-align: center; color: var(--dim); font-size: 13px; margin: 8px 0 0; }

/* ---------- full-screen dialogs ---------- */
dialog { color: var(--ink); }
dialog.screen {
  position: fixed; inset: 0;
  width: 100%; height: 100dvh; max-width: none; max-height: none;
  margin: 0; padding: 0; border: 0;
  background: var(--bg);
  overflow: hidden; overscroll-behavior: none;
}
dialog.screen::backdrop { background: var(--bg); }
.screen-in { display: flex; flex-direction: column; height: 100%; }

/* ---------- one clip (always dark, like a photo viewer) ---------- */
.viewer { --v-ink: #f5f2ee; --v-dim: #aaa49c; --v-panel: #161514; --v-field: #262422; --v-line: #3a3632; --v-accent: #ff7a59; color-scheme: dark; }
dialog.viewer { background: #000; color: var(--v-ink); }
dialog.viewer::backdrop { background: #000; }
.viewer .bar { background: #000; }
.stage { position: relative; background: #000; height: min(52dvh, 120vw); overflow: hidden; }
.stage video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; display: block; background: #000; }
.play {
  position: absolute; left: 50%; top: 50%; translate: -50% -50%;
  width: 68px; height: 68px; border-radius: 50%; border: 0;
  display: grid; place-items: center;
  background: rgba(20, 20, 20, 0.55); color: #fff;
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
}
.play svg { width: 30px; height: 30px; fill: currentColor; }
.play .i-pause { display: none; }
.playing .play { opacity: 0; }
.playing .play .i-play { display: none; }
.playing .play .i-pause { display: block; }
.tools { max-width: 640px; margin: 0 auto; padding: 14px 16px 32px; }
.trim-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.trim-head h3 { margin: 0; font-size: 17px; }
.trim-label { margin: 0; color: var(--v-dim); font-size: 14px; font-variant-numeric: tabular-nums; }
.trim { position: relative; height: 60px; margin: 12px 0 16px; touch-action: none; user-select: none; -webkit-user-select: none; }
.trim .strip { position: absolute; inset: 4px 14px; border-radius: 8px; overflow: hidden; background: var(--v-field); }
.trim .strip canvas { width: 100%; height: 100%; display: block; object-fit: cover; }
.trim .shade { position: absolute; top: 4px; bottom: 4px; background: rgba(0, 0, 0, 0.62); pointer-events: none; }
.trim .shade.left { left: 14px; border-radius: 8px 0 0 8px; }
.trim .shade.right { right: 14px; border-radius: 0 8px 8px 0; }
.trim .window { position: absolute; top: 0; bottom: 0; border: 4px solid var(--v-accent); border-radius: 10px; cursor: grab; }
.trim .handle {
  position: absolute; top: 0; bottom: 0; width: 28px; margin-left: -14px;
  display: grid; place-items: center; cursor: ew-resize; outline: none;
}
.trim .handle::before { content: ""; position: absolute; inset: 0 -8px; } /* a wider place to grab */
.trim .handle::after { content: ""; width: 6px; height: 26px; border-radius: 3px; background: #fff; box-shadow: 0 0 0 1.5px rgba(0, 0, 0, 0.3); }
.trim .handle:focus-visible::after { box-shadow: 0 0 0 3px var(--v-accent); }
.trim .playhead { position: absolute; top: 6px; bottom: 6px; width: 3px; margin-left: -1.5px; border-radius: 2px; background: #fff; display: none; pointer-events: none; }
.playing .trim .playhead { display: block; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.chip { min-height: 44px; padding: 0 16px; border: 0; border-radius: 22px; background: var(--v-field); color: var(--v-ink); font-size: 15px; font-weight: 600; }
.chip[aria-pressed="true"] { background: var(--v-accent); color: #1a0e08; }
.viewer .field > span { color: var(--v-dim); }
.viewer input[type] { background: var(--v-field); border-color: var(--v-line); color: var(--v-ink); }
.viewer .btn.danger { color: #ff8a80; }

/* ---------- fields ---------- */
.field { display: block; margin: 0 0 14px; }
.field:last-child { margin-bottom: 4px; }
.field > span { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 6px; font-size: 14px; font-weight: 600; color: var(--dim); }
.field > span b { font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; }
.field.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; }
.field.row > span { margin: 0; font-size: 16px; color: var(--ink); font-weight: 500; flex-direction: column; gap: 0; min-width: 0; }
.field.row > span b { color: var(--dim); font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-btns { display: flex; gap: 8px; flex: none; }
input[type="text"], input[type="datetime-local"] {
  display: block; width: 100%; min-height: 46px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--bg); color: var(--ink);
  font: 16px var(--font);
  -webkit-appearance: none; appearance: none;
}
input[type="datetime-local"] { padding-top: 11px; padding-bottom: 11px; }
input[type="range"] { display: block; width: 100%; height: 44px; margin: -6px 0; accent-color: var(--accent); background: transparent; }
.hint { margin: 2px 0 4px; font-size: 13px; color: var(--dim); }

.switch { position: relative; width: 60px; height: 44px; flex: none; border: 0; padding: 0; background: none; }
.switch::before { content: ""; position: absolute; left: 4px; top: 6px; width: 52px; height: 32px; border-radius: 16px; background: var(--track); transition: background 0.2s; }
.switch::after { content: ""; position: absolute; left: 6px; top: 8px; width: 28px; height: 28px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3); transition: transform 0.2s; }
.switch[aria-checked="true"]::before { background: var(--accent); }
.switch[aria-checked="true"]::after { transform: translateX(20px); }

.segment { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 3px; padding: 3px; border-radius: 13px; background: var(--surface-2); }
.segment button { min-height: 44px; padding: 0 6px; border: 0; border-radius: 10px; background: transparent; font-size: 15px; font-weight: 600; color: var(--dim); }
.segment button[aria-checked="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }
.segment button:disabled { opacity: 0.4; }
@media (prefers-color-scheme: dark) { .segment button[aria-checked="true"] { background: #48413a; } }

.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch { position: relative; width: 44px; height: 44px; padding: 0; border-radius: 50%; border: 1px solid rgba(0, 0, 0, 0.15); background: var(--c); }
@media (prefers-color-scheme: dark) { .swatch { border-color: rgba(255, 255, 255, 0.2); } }
.swatch[aria-checked="true"] { box-shadow: 0 0 0 3px var(--surface), 0 0 0 5.5px var(--accent); }
.swatch.custom { background: conic-gradient(#ff5e57, #ffd60a, #2ec27e, #3a86ff, #b45cff, #ff5e57); overflow: hidden; }
.swatch.custom input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; border: 0; padding: 0; }
.swatch.custom i { position: absolute; inset: 12px; border-radius: 50%; background: var(--c); border: 2px solid #fff; display: none; }
.swatch.custom.on { box-shadow: 0 0 0 3px var(--surface), 0 0 0 5.5px var(--accent); }
.swatch.custom.on i { display: block; }
.swatch.custom:focus-within { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---------- the movie editor ---------- */
.preview { position: sticky; top: 0; z-index: 2; background: var(--bg); padding: 4px 16px 2px; }
.preview-box { height: clamp(150px, 28dvh, 320px); display: flex; align-items: center; justify-content: center; }
.preview-box canvas { display: block; border-radius: 10px; background: #000; box-shadow: 0 4px 18px rgba(0, 0, 0, 0.18); }
@media (prefers-color-scheme: dark) { .preview-box canvas { box-shadow: 0 0 0 1px var(--line), 0 4px 18px rgba(0, 0, 0, 0.5); } }
.stepper { display: flex; align-items: center; justify-content: center; gap: 4px; }
.stepper p { margin: 0; min-width: 150px; text-align: center; font-size: 14px; font-weight: 600; color: var(--dim); }
.card { margin: 12px 0; padding: 6px 16px 14px; border-radius: 18px; background: var(--surface); box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 48px; }
.card-head h3 { margin: 0; font-size: 18px; font-weight: 750; }
.card-head p { margin: 0; font-size: 14px; }
.card.off .fields { display: none; }
.rows { list-style: none; margin: 0; padding: 0; }
.rows li { display: grid; grid-template-columns: 56px minmax(0, 1fr) auto; gap: 8px 12px; align-items: center; padding: 10px 0 12px; border-top: 1px solid var(--line); }
.rows li.current .thumb { box-shadow: 0 0 0 3px var(--accent); }
.rows .thumb { width: 56px; height: 56px; padding: 0; border: 0; border-radius: 10px; overflow: hidden; background: var(--surface-2); }
.rows .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.rows .meta { min-width: 0; }
.rows .meta b { display: block; font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rows .meta button { margin: 0; padding: 0; min-height: 30px; border: 0; background: none; color: var(--accent); font-size: 14px; font-weight: 600; }
.rows .meta button span { color: var(--dim); font-weight: 500; }
.rows input { grid-column: 1 / -1; }
.rows .icon-btn { color: var(--dim); }

/* while typing in the editor, give the keyboard room: a smaller preview, no bottom bar */
.typing .preview-box { height: 112px; }
.typing .stepper, .typing .dock.inline { display: none; }

/* ---------- small sheets (making the movie, confirm) ---------- */
dialog.sheet {
  width: min(440px, calc(100% - 32px)); max-width: none; max-height: calc(100dvh - 32px);
  margin: auto; padding: 0; border: 0; border-radius: 24px;
  background: var(--surface); color: var(--ink);
  overflow: hidden; overscroll-behavior: none;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}
dialog.sheet::backdrop { background: rgba(0, 0, 0, 0.55); }
.sheet-in { max-height: calc(100dvh - 32px); overflow-y: auto; overflow-x: hidden; overscroll-behavior: none; padding: 22px 20px 20px; }
.sheet-in h2 { margin: 0 0 12px; font-size: 22px; font-weight: 800; }
.sheet-in p { margin: 0 0 12px; }
.sheet-in .btn { width: 100%; }
.sheet-btns { display: grid; gap: 10px; margin-top: 16px; }
.meter { height: 12px; border-radius: 6px; background: var(--surface-2); overflow: hidden; margin: 8px 0 12px; }
.meter i { display: block; height: 100%; width: 0; border-radius: 6px; background: var(--accent); transition: width 0.25s; }
.result { border-radius: 14px; overflow: hidden; background: #000; margin-bottom: 10px; }
.result video { display: block; width: 100%; max-height: 50dvh; background: #000; }
@media (prefers-color-scheme: dark) { .sheet-in .btn:not(.primary):not(.danger-fill) { background: var(--surface-2); } }

.toast {
  position: fixed; left: 50%; bottom: 104px; z-index: 20;
  max-width: calc(100% - 32px); width: max-content;
  padding: 12px 18px; border-radius: 14px;
  background: var(--ink); color: var(--bg);
  font-size: 15px; font-weight: 600; text-align: center;
  transform: translate(-50%, 12px); opacity: 0; pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }

install-prompt {
  --ip-bg: var(--surface); --ip-fg: var(--ink); --ip-muted: var(--dim); --ip-line: var(--line); --ip-chip: var(--surface-2);
  --ip-accent: var(--accent); --ip-on-accent: var(--on-accent); --ip-arrow: var(--accent); --ip-arrow-outline: var(--surface);
  --ip-font: var(--font); --ip-radius: 24px; --ip-radius-inner: 12px; --ip-card-border: 1px solid var(--line);
}

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation-duration: 0.01s !important; } }
