/* Selfie Timelapse — cool, quiet chrome so the photos (and the orange date stamp) carry the page. */
:root {
  --paper: #EDEFF1;
  --card: #FFFFFF;
  --ink: #17202B;
  --muted: #5D6976;
  --line: #D2D7DD;
  --stage: #000000;
  --stamp: #FF7A1A;
  --danger: #B8382B;
  --focus: #2E6BE6;
  --radius-sheet: 18px;
  --radius-btn: 10px;
  --radius-photo: 6px;
  --font: "Schibsted Grotesk", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #14181D;
    --card: #1D232A;
    --ink: #E6EAEE;
    --muted: #97A3AF;
    --line: #2D353E;
    --danger: #EF6A5B;
    --focus: #7EA6FF;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 16px/1.5 var(--font);
  font-feature-settings: "tnum" 1;
  min-height: 100dvh;
}
h1, h2 { line-height: 1.15; margin: 0 0 .5em; letter-spacing: -0.015em; }
h1 { font-size: clamp(1.6rem, 1.2rem + 1.6vw, 2.2rem); font-weight: 700; }
h2 { font-size: 1.15rem; font-weight: 600; }
p { margin: 0 0 .75em; max-width: 62ch; }
a { color: inherit; }
img { display: block; max-width: 100%; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.error { color: var(--danger); }
.spacer { flex: 1; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- top bar & navigation ---------- */
.topbar {
  display: flex; align-items: center; gap: 24px;
  padding: max(14px, env(safe-area-inset-top)) 20px 14px;
  max-width: 1100px; margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; font-weight: 700; font-size: 1.05rem; }
.brand-mark {
  width: 22px; height: 22px; border-radius: 50%;
  background: radial-gradient(circle at 50% 50%, var(--stamp) 0 32%, transparent 33%), var(--ink);
}
.tabs { display: flex; gap: 4px; margin-left: auto; }
.tabs a {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 999px;
  text-decoration: none; color: var(--muted); font-weight: 500; font-size: .95rem;
}
.tabs a svg { width: 18px; height: 18px; fill: currentColor; stroke: currentColor; stroke-width: 0; }
.tabs a[href="#/add"] svg, .tabs a[href="#/settings"] svg { fill: none; stroke-width: 2.2; stroke-linecap: round; }
.tabs a[href="#/frames"] svg, .tabs a[href="#/compare"] svg { fill: none; stroke-width: 2; }
.tabs a:hover { color: var(--ink); }
.tabs a[aria-current="page"] { color: var(--ink); background: var(--card); }
.tabs .tab-add { background: var(--ink); color: var(--paper); }
.tabs .tab-add:hover, .tabs .tab-add[aria-current="page"] { background: var(--ink); color: var(--paper); }

@media (max-width: 720px) {
  .topbar { padding-left: 16px; padding-right: 16px; }
  .tabs {
    position: fixed; inset: auto 0 0 0; z-index: 20; margin: 0; gap: 0;
    justify-content: space-around; background: var(--card); border-top: 1px solid var(--line);
    padding: 6px 4px max(6px, env(safe-area-inset-bottom));
  }
  .tabs a { flex-direction: column; gap: 2px; padding: 6px 4px; font-size: .72rem; border-radius: 10px; flex: 1; }
  .tabs a svg { width: 22px; height: 22px; }
  .tabs a[aria-current="page"] { background: transparent; color: var(--ink); }
  .tabs .tab-add, .tabs .tab-add:hover, .tabs .tab-add[aria-current="page"] { background: transparent; color: var(--ink); }
  .tabs .tab-add svg {
    width: 40px; height: 40px; padding: 9px; margin-top: -14px; border-radius: 50%;
    background: var(--ink); stroke: var(--paper);
  }
  main { padding-bottom: calc(84px + env(safe-area-inset-bottom)); }
}

main { max-width: 1100px; margin: 0 auto; padding: 8px 20px 48px; outline: none; }
@media (max-width: 720px) { main { padding-left: 16px; padding-right: 16px; } }
.page { display: flex; flex-direction: column; gap: 20px; }

/* ---------- buttons & fields ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px; border-radius: var(--radius-btn);
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  font: 500 .95rem/1 var(--font); text-decoration: none; cursor: pointer;
}
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.btn-primary:hover { border-color: var(--ink); opacity: .9; }
.btn-danger { color: var(--danger); }
.btn-quiet { border-color: transparent; background: transparent; padding: 0 10px; }
.btn-quiet:hover { background: var(--card); border-color: transparent; }
.btn-icon { width: 44px; padding: 0; font-size: 1.5rem; border-color: transparent; background: transparent; }
.btn-big { min-height: 56px; font-size: 1.05rem; padding: 0 24px; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: .9rem; color: var(--muted); cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--ink); }
input[type="password"], input[type="datetime-local"], select {
  min-height: 44px; padding: 0 12px; border: 1px solid var(--line); border-radius: var(--radius-btn);
  background: var(--card); color: var(--ink); font: 400 1rem var(--font); max-width: 100%;
}
.field { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; color: var(--muted); }
.field-inline { display: flex; align-items: center; gap: 10px; font-size: .85rem; color: var(--muted); }
.seg { display: inline-flex; padding: 3px; gap: 2px; background: var(--card); border: 1px solid var(--line); border-radius: 999px; }
.seg-btn {
  border: 0; background: transparent; color: var(--muted); font: 500 .85rem var(--font);
  min-height: 34px; padding: 0 12px; border-radius: 999px; cursor: pointer;
}
.seg-btn[aria-pressed="true"] { background: var(--ink); color: var(--paper); }

/* ---------- the date stamp ---------- */
.stamp {
  position: absolute; right: 5%; bottom: 4.5%;
  display: flex; flex-direction: column; align-items: flex-end; gap: .45em;
  pointer-events: none; font-size: clamp(9px, 2.6cqi, 22px);
}
.stamp-line { height: 1.55em; }
.stamp-time { height: 1.2em; opacity: .9; }
.stamp-svg {
  height: 100%; width: auto; display: block;
  fill: var(--stamp);
  filter: drop-shadow(0 0 .12em rgba(255, 122, 26, .85)) drop-shadow(0 0 .45em rgba(255, 90, 0, .45));
}

/* ---------- player ---------- */
.player { display: flex; flex-direction: column; gap: 12px; width: min(100%, 560px, calc(64dvh * var(--ar, 0.75))); margin: 0 auto; }
@media (max-width: 720px) { .player { width: 100%; } }
.stage {
  position: relative; width: 100%; background: var(--stage); border-radius: var(--radius-photo);
  overflow: hidden; container-type: inline-size; cursor: pointer; max-height: 72dvh; margin: 0 auto;
}
.stage-canvas { width: 100%; height: 100%; display: block; object-fit: contain; }
.buffering {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  background: rgba(0,0,0,.6); color: #fff; padding: 6px 12px; border-radius: 999px; font-size: .85rem;
}
.transport { display: flex; align-items: center; gap: 6px; }
.btn-play {
  width: 52px; height: 52px; padding: 0; border-radius: 50%; flex: none;
  background: var(--ink); border-color: var(--ink); color: var(--paper);
}
.btn-play svg { width: 22px; height: 22px; fill: currentColor; }
.scrubber { flex: 1; min-width: 0; accent-color: var(--ink); height: 32px; }
.caption-date { font-size: 1.25rem; font-weight: 600; letter-spacing: -0.01em; }
.caption-meta { display: flex; flex-wrap: wrap; gap: 4px 16px; color: var(--muted); font-size: .9rem; }
.player-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.notice { text-align: center; margin: 0 auto; color: var(--muted); }

/* ---------- photos in boxes ---------- */
.frame-box { position: relative; width: 100%; background: var(--stage); border-radius: var(--radius-photo); overflow: hidden; container-type: inline-size; }
.frame-box > img { width: 100%; height: 100%; object-fit: cover; }

/* ---------- compare ---------- */
.compare-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 16px; }
.compare-head h1 { margin: 0; }
.compare-span { margin: 0; color: var(--muted); font-size: 1.1rem; }
.compare-controls { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; }
.compare-controls select { max-width: 220px; }
.compare-side { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 380px) { .compare-side { gap: 6px; } }
.compare-fig { margin: 0; display: flex; flex-direction: column; gap: 8px; }
.compare-fig figcaption { display: flex; flex-direction: column; font-size: .9rem; }
.compare-fig figcaption span { color: var(--muted); }
.wipe { max-width: 560px; margin: 0 auto; }
.wipe > img { position: absolute; inset: 0; }
.wipe-line { position: absolute; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.25); pointer-events: none; }
.wipe-range { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: ew-resize; }
.wipe-labels { display: flex; justify-content: space-between; max-width: 560px; width: 100%; margin: 0 auto; color: var(--muted); font-size: .9rem; }

/* ---------- all photos ---------- */
.year h2, .attention h2 { display: flex; align-items: baseline; gap: 10px; }
.count { color: var(--muted); font-weight: 400; font-size: .9rem; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 6px; }
@media (max-width: 720px) { .grid { grid-template-columns: repeat(4, 1fr); gap: 4px; } }
.thumb { position: relative; padding: 0; border: 0; background: var(--stage); border-radius: 4px; overflow: hidden; cursor: pointer; aspect-ratio: 4/5; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb-date {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 10px 6px 4px; text-align: left;
  font-size: .7rem; color: #fff; background: linear-gradient(transparent, rgba(0,0,0,.55));
}
.thumb-bad { outline: 2px solid var(--stamp); outline-offset: -2px; }
.attention { background: var(--card); border-radius: 14px; padding: 16px; }

/* ---------- add ---------- */
.drop {
  display: flex; flex-direction: column; align-items: flex-start; gap: 12px;
  padding: 24px; background: var(--card); border: 2px dashed var(--line); border-radius: 16px;
}
.drop.over { border-color: var(--ink); }
.drop.disabled { opacity: .6; pointer-events: none; }
.drop .btn-big { width: 100%; max-width: 360px; }
.progress { background: var(--card); border-radius: 16px; padding: 20px; }
.bar { height: 8px; background: var(--line); border-radius: 999px; overflow: hidden; margin-bottom: 12px; }
.bar-fill { height: 100%; width: 0; background: var(--ink); transition: width .25s; }
.progress-line { font-weight: 600; margin-bottom: 4px; }
.errors { margin: 8px 0 0; padding-left: 18px; color: var(--danger); font-size: .85rem; }
.add-result { display: flex; flex-direction: column; gap: 14px; }
.result-fig { margin: 0; max-width: 420px; display: flex; flex-direction: column; gap: 8px; }

/* ---------- settings & setup ---------- */
.panel { background: var(--card); border-radius: 16px; padding: 20px; }
.ref-row { display: grid; grid-template-columns: minmax(120px, 200px) 1fr; gap: 20px; align-items: start; }
@media (max-width: 520px) { .ref-row { grid-template-columns: 1fr; } .ref-thumb { max-width: 220px; } }
.ref-thumb { position: relative; border-radius: var(--radius-photo); overflow: hidden; background: var(--stage); }
.ref-thumb img { width: 100%; height: 100%; object-fit: cover; }
.ref-eye { position: absolute; width: 14px; height: 14px; margin: -7px 0 0 -7px; border: 2px solid var(--stamp); border-radius: 50%; }
.setup { max-width: 640px; }
.ref-picker { display: flex; flex-direction: column; gap: 14px; }
.ref-preview { max-width: 360px; margin: 12px 0; }
.ref-canvas { width: 100%; height: auto; border-radius: var(--radius-photo); display: block; }
.login { max-width: 360px; margin: 12vh auto 0; display: flex; flex-direction: column; gap: 10px; }
.empty { max-width: 460px; margin: 10vh auto; text-align: center; display: flex; flex-direction: column; align-items: center; }

/* ---------- sheets ---------- */
.sheet {
  border: 0; padding: 0; border-radius: var(--radius-sheet); background: var(--paper); color: var(--ink);
  width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 24px);
}
.sheet-wide { width: min(980px, calc(100vw - 24px)); }
.sheet::backdrop { background: rgba(10, 14, 20, .55); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 12px 0 20px; }
.sheet-head h2 { margin: 0; }
.sheet-body { padding: 12px 20px 20px; }
@media (max-width: 720px) {
  .sheet, .sheet-wide { width: 100vw; max-width: 100vw; max-height: 94dvh; margin: auto 0 0; border-radius: var(--radius-sheet) var(--radius-sheet) 0 0; }
  .sheet-body { padding-bottom: max(20px, env(safe-area-inset-bottom)); }
}
.frame-detail { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; align-items: start; }
@media (max-width: 720px) { .frame-detail { grid-template-columns: 1fr; } .frame-detail .frame-box { max-width: 420px; } }
.frame-info { display: flex; flex-direction: column; gap: 10px; }
.frame-date { font-size: 1.1rem; font-weight: 600; margin: 0; }
.frame-date .muted { font-size: .9rem; font-weight: 400; }
.more summary { cursor: pointer; color: var(--muted); padding: 6px 0; }
.more .row { margin-top: 10px; }

/* ---------- hand alignment ---------- */
.fix-grid { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 20px; align-items: start; }

.fix-wrap { position: relative; touch-action: none; user-select: none; -webkit-user-select: none; }
.fix-photo { width: min(100%, calc(70dvh * var(--ar, 0.75))); height: auto; display: block; margin: 0 auto; border-radius: var(--radius-photo); }
.eye-marker {
  position: absolute; width: 40px; height: 40px; margin: -20px 0 0 -20px; padding: 0; border-radius: 50%;
  background: transparent; border: 2px solid var(--stamp); cursor: grab; touch-action: none;
  box-shadow: 0 0 0 1px rgba(0,0,0,.4), inset 0 0 0 1px rgba(0,0,0,.4);
}
.eye-marker::after { content: ""; position: absolute; left: 50%; top: 50%; width: 4px; height: 4px; margin: -2px; border-radius: 50%; background: var(--stamp); }
.loupe { position: absolute; width: 140px; height: 140px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 6px 24px rgba(0,0,0,.4); pointer-events: none; z-index: 2; }
.fix-side { display: flex; flex-direction: column; gap: 12px; }
.fix-preview-box { position: relative; width: 100%; max-width: 360px; border-radius: var(--radius-photo); overflow: hidden; background: #000; }
.fix-preview, .fix-ghost { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.fix-ghost { pointer-events: none; }
@media (max-width: 720px) {
  .fix-grid { grid-template-columns: 1fr; gap: 12px; }
  .fix-photo { width: min(100%, calc(52dvh * var(--ar, 0.75))); }
  /* Preview sits above the photo on phones so it stays visible while you drag. */
  .fix-side { order: -1; display: grid; grid-template-columns: 38% 1fr; gap: 6px 12px; align-items: start; }
  .fix-side .fix-preview-box { grid-row: span 3; }
  .fix-side .field-inline { flex-direction: column; align-items: stretch; gap: 4px; }
  .fix-side .row { flex-direction: column; align-items: stretch; }
}

/* ---------- toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 50;
  background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: 12px; font-size: .9rem;
  max-width: calc(100vw - 32px); box-shadow: 0 8px 30px rgba(0,0,0,.2);
}
#toast[data-kind="error"] { background: var(--danger); color: #fff; }
@media (min-width: 721px) { #toast { bottom: 24px; } }

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