:root {
  --bg: #0b0d12;
  --bg-grad-1: #11141c;
  --bg-grad-2: #0b0d12;
  --surface: #161a23;
  --surface-2: #1d2230;
  --surface-3: #232a3a;
  --line: #2a3140;
  --line-soft: #222838;
  --text: #eef1f7;
  --muted: #99a2b3;
  --accent: #6b9bff;
  --accent-strong: #5b8cff;
  --accent-2: #36c08a;
  --danger: #ef6a57;
  --radius: 16px;
  --radius-sm: 11px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.3);
  --shadow-md: 0 8px 24px rgba(0,0,0,.35);
  --shadow-lg: 0 20px 50px rgba(0,0,0,.5);
  --ring: 0 0 0 3px rgba(91,140,255,.28);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(91,140,255,.10), transparent 60%),
    linear-gradient(180deg, var(--bg-grad-1), var(--bg-grad-2));
  background-attachment: fixed;
  color: var(--text);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  letter-spacing: -0.01em;
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

button, .filebtn {
  cursor: pointer;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  font-family: inherit;
  font-size: 15px;
  padding: 11px 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
  transition: transform .08s ease, background .15s ease, border-color .15s ease, box-shadow .15s ease, opacity .15s ease;
}
button.primary, .primary.filebtn {
  background: linear-gradient(180deg, var(--accent), var(--accent-strong));
  color: #fff;
  border-color: transparent;
  box-shadow: 0 6px 18px rgba(91,140,255,.32);
}
button.primary:hover, .primary.filebtn:hover { filter: brightness(1.05); }
button.ghost, .ghost.filebtn {
  background: var(--surface-2);
  color: var(--text);
}
button.ghost:hover, .ghost.filebtn:hover { background: var(--surface-3); border-color: #34405580; }
button:active, .filebtn:active { transform: translateY(1px) scale(.99); }
button:focus-visible, .filebtn:focus-within { outline: none; box-shadow: var(--ring); }

.linkbtn {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  padding: 6px;
  text-align: center;
  width: 100%;
  transition: color .15s ease;
}
.linkbtn:hover { color: #9bbcff; }

input, select {
  width: 100%;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 11px 13px;
  font-family: inherit;
  font-size: 16px; /* >=16px avoids iOS zoom on focus */
  transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}
input:focus, select:focus {
  outline: none;
  border-color: var(--accent-strong);
  box-shadow: var(--ring);
  background: var(--surface-3);
}
input::placeholder { color: #5d6577; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; font-weight: 500; }
label > input, label > select { margin-top: 6px; }

.status { margin-top: 10px; font-size: 14px; min-height: 18px; }
.status.error { color: var(--danger); }
.status.ok { color: var(--accent-2); }

/* ---------- login ---------- */
.login { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: 100%; max-width: 380px;
  background: linear-gradient(180deg, rgba(33,40,56,.6), rgba(22,26,35,.85));
  border: 1px solid var(--line);
  border-radius: var(--radius); padding: 32px 28px;
  display: flex; flex-direction: column; gap: 16px;
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(12px);
  animation: rise .4s cubic-bezier(.2,.7,.2,1) both;
}
.login-card h1 {
  margin: 0; font-size: 26px; font-weight: 800; letter-spacing: -0.03em;
  background: linear-gradient(120deg, #fff, #bcd0ff);
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}
.login-card .muted { margin: -6px 0 4px; }

@keyframes rise {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: none; }
}

/* ---------- topbar + tabs ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  background: rgba(11,13,18,.72); backdrop-filter: blur(14px) saturate(1.2);
  border-bottom: 1px solid var(--line-soft);
}
.brand {
  font-weight: 800; font-size: 19px; letter-spacing: -0.02em;
  display: flex; align-items: center; gap: 9px;
}
.brand::before {
  content: ""; width: 22px; height: 22px; border-radius: 7px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 2px 10px rgba(91,140,255,.5);
}
.topbar-controls { display: flex; align-items: center; gap: 8px; }
.profile-pick select { width: auto; padding: 9px 11px; font-size: 14px; font-weight: 600; border-radius: 10px; }
.topbar-controls .ghost { padding: 9px 12px; font-size: 14px; }

.tabs {
  display: flex; gap: 4px; padding: 14px 16px 0; max-width: 980px; margin: 0 auto;
}
.tab {
  flex: 1; background: var(--surface); color: var(--muted);
  border-color: var(--line-soft); font-size: 14px; padding: 10px 12px;
}
.tab:hover { color: var(--text); }
.tab.active {
  background: linear-gradient(180deg, var(--accent), var(--accent-strong));
  color: #fff; border-color: transparent;
  box-shadow: 0 6px 16px rgba(91,140,255,.3);
}

.tabpane { padding: 18px 16px; max-width: 980px; margin: 0 auto; animation: fade .25s ease both; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.hint { font-size: 13px; margin: 6px 0 16px; line-height: 1.5; }

/* ---------- library ---------- */
.library-grid { display: grid; gap: 24px; }
.lib-day h3 {
  margin: 0 0 10px; font-size: 12px; color: var(--muted); font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.06em;
}
.lib-thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 10px; }
.thumb {
  position: relative; aspect-ratio: 3/4; border-radius: var(--radius-sm); overflow: hidden;
  background: var(--surface-2); border: 1px solid var(--line); cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform .16s cubic-bezier(.2,.7,.2,1), box-shadow .16s ease, border-color .16s ease;
}
.thumb:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); border-color: #3a4760; }
.thumb img, .thumb video { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .3s ease; }
.thumb:hover img, .thumb:hover video { transform: scale(1.05); }
.thumb .vbadge {
  position: absolute; bottom: 7px; right: 7px; font-size: 11px;
  background: rgba(0,0,0,.55); padding: 3px 7px; border-radius: 7px;
  backdrop-filter: blur(4px);
}
.empty {
  text-align: center; padding: 56px 20px; color: var(--muted);
  background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius);
  font-size: 15px;
}

/* ---------- add / review ---------- */
.add-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.filebtn { display: inline-flex; align-items: center; }
.review-list { display: flex; flex-direction: column; gap: 14px; margin-top: 8px; }
.review-row {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px; display: grid;
  grid-template-columns: 88px 1fr; gap: 14px;
  box-shadow: var(--shadow-sm);
}
.review-row .preview { width: 88px; height: 116px; border-radius: var(--radius-sm); overflow: hidden; background: var(--surface-2); }
.review-row .preview img, .review-row .preview video { width: 100%; height: 100%; object-fit: cover; }
.review-fields { display: grid; gap: 9px; min-width: 0; }
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 9px; min-width: 0; }
.stat-grid label, .review-fields label { min-width: 0; }
.stat-grid input { min-width: 0; }
.stat-grid .full { grid-column: 1 / -1; }
.review-actions { display: flex; gap: 10px; margin-top: 18px; position: sticky; bottom: 0; padding: 14px 0; background: linear-gradient(transparent, var(--bg) 35%); }
.review-actions .primary { flex: 1; }

/* ---------- compare ---------- */
.compare-pickers { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.compare-stage { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 16px; }
.compare-side {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden; min-height: 240px;
  display: grid; place-items: center;
  box-shadow: var(--shadow-sm);
}
.compare-side img, .compare-side video { width: 100%; display: block; }
.compare-side .cap { font-size: 12px; color: var(--muted); padding: 8px 10px; width: 100%; font-weight: 500; }
.delta-panel {
  margin-top: 18px; background: linear-gradient(180deg, var(--surface-2), var(--surface));
  border: 1px solid var(--line);
  border-radius: var(--radius); padding: 8px 16px;
  box-shadow: var(--shadow-md);
}
.delta-row { display: flex; justify-content: space-between; align-items: center; padding: 11px 0; border-bottom: 1px solid var(--line-soft); font-size: 14px; }
.delta-row:last-child { border-bottom: none; }
.delta-val { font-weight: 700; font-variant-numeric: tabular-nums; }
.delta-val.down { color: var(--accent-2); }
.delta-val.up { color: var(--danger); }

/* ---------- lightbox + toast ---------- */
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.92); display: grid; place-items: center; z-index: 50; padding: 16px; animation: fade .2s ease both; backdrop-filter: blur(6px); }
.lightbox-inner img, .lightbox-inner video { max-width: 100%; max-height: 90vh; border-radius: 12px; box-shadow: var(--shadow-lg); }
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%); background: var(--surface-3); color: var(--text);
  border: 1px solid var(--line); padding: 13px 20px; border-radius: 13px;
  z-index: 60; box-shadow: var(--shadow-lg); font-size: 14px; font-weight: 500;
  animation: rise .25s ease both;
  width: max-content; max-width: calc(100vw - 32px);
  box-sizing: border-box; text-align: center;
}
.toast.error { border-color: var(--danger); color: #ffd9d2; }

/* ---------- pane head + segmented control ---------- */
.pane-head { display: flex; justify-content: flex-end; margin-bottom: 14px; }
.seg-group {
  display: inline-flex; gap: 0; margin-top: 14px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 11px; padding: 3px;
}
.seg {
  border: none; background: none; color: var(--muted);
  padding: 8px 16px; border-radius: 8px; font-size: 14px;
}
.seg.active { background: var(--surface-3); color: var(--text); box-shadow: var(--shadow-sm); }

/* ---------- slider compare ---------- */
.compare-slider { margin-top: 14px; }
.cs-wrap {
  position: relative; width: 100%; aspect-ratio: 3/4; max-height: 70vh;
  border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line);
  background: var(--surface-2); touch-action: none; cursor: ew-resize; user-select: none;
  box-shadow: var(--shadow-md);
}
.cs-base, .cs-top { position: absolute; inset: 0; background-size: cover; background-position: center; }
.cs-top { clip-path: inset(0 50% 0 0); }
.cs-handle {
  position: absolute; top: 0; bottom: 0; left: 50%; width: 2px;
  background: rgba(255,255,255,.9); transform: translateX(-1px); pointer-events: none;
  box-shadow: 0 0 12px rgba(0,0,0,.5);
}
.cs-handle span {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: 38px; height: 38px; border-radius: 50%;
  background: rgba(255,255,255,.95); border: 2px solid var(--accent-strong);
  box-shadow: 0 4px 14px rgba(0,0,0,.5);
}
.cs-handle span::before, .cs-handle span::after {
  content: ""; position: absolute; top: 50%; width: 0; height: 0;
  border-top: 5px solid transparent; border-bottom: 5px solid transparent;
}
.cs-handle span::before { left: 7px; transform: translateY(-50%); border-right: 7px solid var(--accent-strong); }
.cs-handle span::after { right: 7px; transform: translateY(-50%); border-left: 7px solid var(--accent-strong); }
.cs-caps { display: flex; justify-content: space-between; margin-top: 8px; }
.cs-caps .cap { font-size: 12px; color: var(--muted); font-weight: 500; }

/* ---------- trends ---------- */
.trend-pick { max-width: 220px; }
.trend-chart {
  margin-top: 16px; background: linear-gradient(180deg, var(--surface-2), var(--surface));
  border: 1px solid var(--line); border-radius: var(--radius); padding: 12px;
  box-shadow: var(--shadow-md);
}
.chart-svg { width: 100%; height: auto; display: block; }
.chart-svg .ax { fill: var(--muted); font-size: 9px; font-family: Inter, sans-serif; }
.trend-summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-top: 14px; }
.trend-stat {
  background: var(--surface); border: 1px solid var(--line-soft); border-radius: var(--radius-sm);
  padding: 12px 10px; display: flex; flex-direction: column; gap: 5px; text-align: center;
}
.ts-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.ts-val { font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------- camera modal ---------- */
.cam, .tl {
  position: fixed; inset: 0; z-index: 70; background: #000;
  display: flex; flex-direction: column;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}
.cam-stage { position: relative; flex: 1; overflow: hidden; background: #000; }
.cam-stage #camVideo { width: 100%; height: 100%; object-fit: cover; display: block; }
.cam-ghost { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; pointer-events: none; }
.cam-controls {
  padding: 16px; display: flex; flex-direction: column; gap: 14px;
  background: rgba(11,13,18,.96); border-top: 1px solid var(--line);
}
.cam-opacity { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 13px; }
.cam-opacity input { flex: 1; }
.cam-buttons { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.cam-shutter {
  width: 68px; height: 68px; border-radius: 50%; padding: 0;
  background: #fff; border: 4px solid rgba(255,255,255,.4);
  box-shadow: 0 0 0 2px #000 inset;
}
.cam-shutter:active { transform: scale(.93); }

/* ---------- timelapse modal ---------- */
.tl-stage { flex: 1; display: grid; place-items: center; overflow: hidden; padding: 12px; }
.tl-stage #tlCanvas { max-width: 100%; max-height: 100%; border-radius: 12px; box-shadow: var(--shadow-lg); }
.tl-controls {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: center;
  padding: 14px 16px; background: rgba(11,13,18,.96); border-top: 1px solid var(--line);
}
.tl-speed { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.tl-speed select { width: auto; }
.tl .status, .cam .status { text-align: center; padding: 0 16px 10px; }

@media (max-width: 520px) {
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .trend-summary { grid-template-columns: repeat(2, 1fr); }
}
