:root {
  --bg: #111113;
  --surface: #18181b;
  --surface-2: #202024;
  --surface-3: #2a2a2f;
  --line: #2c2c31;
  --text: #ececee;
  --muted: #9b9ba3;
  --faint: #6c6c74;
  --accent: #ff8a3d;
  --accent-ink: #1a1007;
  --danger: #ff6b6b;
  --radius: 10px;
  --roll-w: 248px;
  --panel-w: 300px;
  --top-h: 42px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 13px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button, select, input { font: inherit; color: inherit; }
[hidden] { display: none !important; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- top bar ---------- */
.topbar {
  height: var(--top-h);
  flex: none;
  display: grid;
  grid-template-columns: var(--roll-w) minmax(0, 1fr) minmax(var(--panel-w), auto);
  align-items: center;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.brand { grid-column: 1; padding-left: 16px; display: flex; align-items: center; gap: 9px; font-weight: 650; font-size: 14px; letter-spacing: .01em; }
.logo { width: 20px; height: 14px; border-radius: 4px; background: var(--accent); position: relative; }
.logo::after { content: ""; position: absolute; inset: 3.5px 4.5px; border-radius: 1.5px; background: var(--surface); }
.top-actions { grid-column: 3; justify-self: end; display: flex; gap: 6px; padding: 0 10px 0 12px; }
.top-actions .btn { height: 28px; padding: 0 10px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 32px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface-2); cursor: pointer;
  transition: background .12s, border-color .12s, opacity .12s;
}
.btn svg { width: 16px; height: 16px; }
.btn:hover:not(:disabled) { background: var(--surface-3); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover:not(:disabled) { background: #ff9b57; }
.btn.ghost { background: transparent; }
.btn.full { width: 100%; margin-top: 8px; }
.btn.google { justify-content: center; margin-top: 4px; }
.or { display: flex; align-items: center; gap: 10px; margin: 16px 0 4px; color: var(--muted); font-size: 12px; }
.or::before, .or::after { content: ""; flex: 1; border-top: 1px solid var(--line); }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.link { background: none; border: 0; padding: 0; color: var(--muted); cursor: pointer; font-size: 12px; }
.link:hover { color: var(--text); }
.icon {
  width: 34px; height: 34px; display: inline-grid; place-items: center;
  border: 0; border-radius: 8px; background: transparent; color: var(--muted); cursor: pointer;
}
.icon:hover { background: var(--surface-3); color: var(--text); }
.icon.on { background: var(--accent); color: var(--accent-ink); }
.icon.small { width: 28px; height: 28px; }
.icon.small svg { width: 16px; height: 16px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- layout ---------- */
.layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: var(--roll-w) 1fr var(--panel-w);
}

/* ---------- roll (left) ---------- */
.roll {
  border-right: 1px solid var(--line);
  background: var(--surface);
  display: flex; flex-direction: column; min-height: 0;
}
.roll-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; color: var(--muted); font-size: 12px;
}
.roll-tools { display: flex; gap: 12px; }
.thumbs {
  list-style: none; margin: 0; padding: 0 10px 14px;
  overflow-y: auto; flex: 1;
  display: grid; grid-template-columns: 1fr 1fr; grid-auto-rows: max-content; gap: 8px; align-content: start;
}
.thumbs:empty { display: none; }
.thumb {
  position: relative; border-radius: 8px; overflow: hidden; cursor: pointer;
  background: var(--surface-2); aspect-ratio: 3 / 2;
  outline: 2px solid transparent; outline-offset: -2px;
  display: grid; place-items: center;
}
.thumb canvas { display: block; max-width: 100%; max-height: 100%; }
.thumb.selected { outline-color: rgba(255,138,61,.45); }
.thumb.current { outline-color: var(--accent); }
.thumb .num {
  position: absolute; left: 5px; bottom: 4px; font-size: 10px; font-variant-numeric: tabular-nums;
  padding: 1px 5px; border-radius: 4px; background: rgba(0,0,0,.55); color: #ddd;
}
.thumb .state { font-size: 11px; color: var(--faint); text-align: center; padding: 6px; }
.thumb .state.err { color: var(--danger); }
.thumb .remove {
  position: absolute; top: 4px; right: 4px; width: 20px; height: 20px; border-radius: 50%;
  border: 0; background: rgba(0,0,0,.6); color: #ddd; cursor: pointer; display: none; place-items: center; padding: 0;
}
.thumb .remove svg { width: 12px; height: 12px; stroke-width: 2.4; }
.thumb:hover .remove { display: grid; }
.roll-empty {
  margin: 4px 14px 14px; flex: 1; border: 1.5px dashed var(--line); border-radius: var(--radius);
  background: transparent; color: var(--muted); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; text-align: center;
}
.roll-empty svg { width: 30px; height: 30px; stroke-width: 1.4; }
.roll-empty small { color: var(--faint); }
.roll-empty:hover { border-color: var(--faint); color: var(--text); }

/* ---------- viewer (center) ---------- */
.viewer { position: relative; min-width: 0; min-height: 0; background: var(--bg); overflow: hidden; }
#view { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.viewer.picking #view { cursor: crosshair; }
.viewer-empty {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 40px; color: var(--muted);
}
.viewer-empty .big { color: var(--text); font-size: 20px; font-weight: 600; margin: 0 0 8px; }
.viewer-empty p { margin: 0; }
.viewer-empty-text { position: relative; max-width: 380px; }
/* dashed 3:2 frame outline behind the welcome text */
.frame-ph {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(calc(100% - 64px), 720px, (100vh - var(--top-h) - 64px) * 1.5); aspect-ratio: 3 / 2;
  border: 1.5px dashed var(--line); border-radius: 14px; pointer-events: none;
}
.frame-ph i { position: absolute; width: 22px; height: 22px; border: 2px solid var(--surface-3); }
.frame-ph i:nth-child(1) { left: 14px; top: 14px; border-width: 2px 0 0 2px; }
.frame-ph i:nth-child(2) { right: 14px; top: 14px; border-width: 2px 2px 0 0; }
.frame-ph i:nth-child(3) { right: 14px; bottom: 14px; border-width: 0 2px 2px 0; }
.frame-ph i:nth-child(4) { left: 14px; bottom: 14px; border-width: 0 0 2px 2px; }
/* Placed under the photo by render(); until then it sits at the bottom. */
.viewer-tools {
  position: absolute; left: 50%; top: calc(100% - 52px); transform: translateX(-50%);
  display: flex; align-items: center; gap: 2px; padding: 3px;
  background: rgba(24,24,27,.88); border: 1px solid var(--line); border-radius: 11px;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.viewer-tools .icon { width: 30px; height: 30px; }
.viewer-tools .sep { width: 1px; height: 20px; background: var(--line); margin: 0 4px; }
.tool-check { display: flex; align-items: center; gap: 6px; padding: 0 10px 0 6px; color: var(--text); font-size: 12px; white-space: nowrap; cursor: pointer; }
.tool-check input { accent-color: var(--accent); width: 14px; height: 14px; margin: 0; }
.tool-check[hidden] { display: none; }
.spinner {
  position: absolute; top: 50%; left: 50%; width: 34px; height: 34px; margin: -17px 0 0 -17px;
  border: 3px solid rgba(255,255,255,.12); border-top-color: var(--accent); border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.toast {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%); max-width: 80%;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; color: var(--text);
  box-shadow: 0 6px 24px rgba(0,0,0,.4);
}

/* crop editor */
.crop-layer { position: absolute; inset: 0; }
.crop-box {
  position: absolute; border: 1.5px solid #fff; box-shadow: 0 0 0 9999px rgba(0,0,0,.55); cursor: move;
}
.crop-box span { position: absolute; width: 14px; height: 14px; background: #fff; border-radius: 3px; }
.crop-box [data-h="nw"] { left: -7px; top: -7px; cursor: nwse-resize; }
.crop-box [data-h="ne"] { right: -7px; top: -7px; cursor: nesw-resize; }
.crop-box [data-h="se"] { right: -7px; bottom: -7px; cursor: nwse-resize; }
.crop-box [data-h="sw"] { left: -7px; bottom: -7px; cursor: nesw-resize; }
.crop-box [data-h="n"] { left: 50%; top: -4px; width: 28px; height: 8px; margin-left: -14px; cursor: ns-resize; }
.crop-box [data-h="s"] { left: 50%; bottom: -4px; width: 28px; height: 8px; margin-left: -14px; cursor: ns-resize; }
.crop-box [data-h="w"] { top: 50%; left: -4px; width: 8px; height: 28px; margin-top: -14px; cursor: ew-resize; }
.crop-box [data-h="e"] { top: 50%; right: -4px; width: 8px; height: 28px; margin-top: -14px; cursor: ew-resize; }

/* ---------- panel (right) ---------- */
.panel { border-left: 1px solid var(--line); background: var(--surface); overflow-y: auto; min-height: 0; }
.panel-empty-note { color: var(--muted); margin: 0; padding: 14px 16px; border-bottom: 1px solid var(--line); }
/* greyed-out outline of the adjustments, shown before a photo is open */
.ph { opacity: .75; pointer-events: none; user-select: none; }
.ph h2 { color: var(--faint); }
.ph-box { height: 32px; border: 1px dashed var(--line); border-radius: 8px; margin-top: 8px; }
.ph-box:first-of-type { margin-top: 0; }
.ph-slider { color: var(--faint); font-size: 12px; margin-top: 8px; }
.ph-slider::after { content: ""; display: block; height: 3px; border-radius: 3px; background: var(--surface-3); margin: 8px 0 6px; }
.ph-curve {
  aspect-ratio: 1; border: 1px dashed var(--line); border-radius: 8px;
  background: linear-gradient(to bottom right, transparent calc(50% - 1px), var(--surface-3) calc(50% - 1px), var(--surface-3) calc(50% + 1px), transparent calc(50% + 1px));
}
.group { padding: 14px 16px 16px; border-bottom: 1px solid var(--line); }
.group h2 { font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0 0 10px; }
.group-head { display: flex; align-items: center; justify-content: space-between; margin: -4px 0 6px; }
.group-head h2 { margin: 0; }
.hint { color: var(--faint); font-size: 11.5px; margin: 8px 0 0; }
.hint.warn { color: var(--accent); }
.hint.lead { margin: -4px 0 0; }
.clip-state { color: var(--muted); font-size: 12px; margin: 8px 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.film-row { display: flex; gap: 6px; align-items: center; }
select {
  width: 100%; height: 32px; padding: 0 28px 0 10px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface-2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%239b9ba3' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='m7 10 5 5 5-5'/%3E%3C/svg%3E") no-repeat right 8px center / 14px;
  -webkit-appearance: none; appearance: none; cursor: pointer;
}
.segmented { display: grid; grid-template-columns: 1fr 1fr; margin-top: 8px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 2px; }
.segmented button { height: 26px; border: 0; border-radius: 6px; background: transparent; color: var(--muted); cursor: pointer; }
.segmented button.on { background: var(--surface-3); color: var(--text); }
.check { display: flex; align-items: center; gap: 8px; margin-top: 10px; color: var(--muted); cursor: pointer; }
.check input { accent-color: var(--accent); width: 15px; height: 15px; margin: 0; }

/* sliders */
.slider { margin-top: 8px; }
.slider .row { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; margin-bottom: 2px; }
.slider .val { color: var(--text); font-variant-numeric: tabular-nums; }
.slider input[type="range"] { width: 100%; margin: 0; height: 20px; background: transparent; -webkit-appearance: none; appearance: none; cursor: pointer; }
.slider input[type="range"]::-webkit-slider-runnable-track { height: 3px; border-radius: 3px; background: var(--surface-3); }
.slider input[type="range"]::-moz-range-track { height: 3px; border-radius: 3px; background: var(--surface-3); }
.slider input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px; margin-top: -5.5px; border-radius: 50%; background: var(--text); border: 0; box-shadow: 0 1px 3px rgba(0,0,0,.5); }
.slider input[type="range"]::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: var(--text); border: 0; }
.slider input[type="range"]:hover::-webkit-slider-thumb { background: #fff; }

/* curves */
.tabs { display: flex; gap: 4px; margin-bottom: 8px; }
.tabs button { flex: 1; height: 24px; border: 1px solid var(--line); border-radius: 6px; background: transparent; color: var(--muted); cursor: pointer; font-size: 12px; font-weight: 600; }
.tabs button.on { background: var(--surface-3); color: var(--text); }
.tabs .c-r.on { color: #ff8a8a; } .tabs .c-g.on { color: #79e0a3; } .tabs .c-b.on { color: #82bfff; }
.curve { width: 100%; aspect-ratio: 1; display: block; border-radius: 8px; border: 1px solid var(--line); touch-action: none; }

/* ---------- overlays ---------- */
.drop-overlay {
  position: fixed; inset: 0; z-index: 20; display: grid; place-items: center;
  background: rgba(17,17,19,.78); pointer-events: none;
}
.drop-overlay div { border: 2px dashed var(--accent); border-radius: 16px; padding: 40px 56px; font-size: 16px; color: var(--text); }
dialog {
  border: 1px solid var(--line); border-radius: 14px; background: var(--surface); color: var(--text);
  padding: 20px; width: min(380px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
dialog::backdrop { background: rgba(0,0,0,.55); }
dialog h3 { margin: 0 0 4px; font-size: 16px; }
.field { display: flex; flex-direction: column; gap: 5px; margin-top: 14px; color: var(--muted); font-size: 12px; }
.field input { height: 34px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface-2); padding: 0 10px; color: var(--text); font-size: 13px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.dialog-foot { display: flex; justify-content: space-between; margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--line); }
.progress {
  position: fixed; right: 16px; bottom: 16px; z-index: 30; width: 300px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px;
  box-shadow: 0 10px 30px rgba(0,0,0,.45);
}
.progress-text { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.bar { height: 4px; border-radius: 4px; background: var(--surface-3); overflow: hidden; }
.bar div { height: 100%; width: 0; background: var(--accent); transition: width .2s; }

@media (max-width: 900px) {
  :root { --roll-w: 180px; --panel-w: 260px; }
  .thumbs { grid-template-columns: 1fr; }
}

/* ---------- account ---------- */
#accountBtn { max-width: 180px; }
#accountBtn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#accountBtn.pro::after { content: "PRO"; font-size: 9.5px; font-weight: 700; letter-spacing: .06em; padding: 1px 5px; border-radius: 4px; background: var(--accent); color: var(--accent-ink); }
dialog.account { width: min(440px, calc(100vw - 32px)); }
dialog.account form { position: relative; }
dialog.account .close { position: absolute; top: -8px; right: -8px; }
.notice { margin: 0 28px 14px 0; padding: 8px 10px; border-radius: 8px; background: rgba(255,138,61,.12); color: #ffb685; font-size: 12.5px; }
.plans { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }
.plan { position: relative; border: 1px solid var(--line); border-radius: 12px; padding: 16px 14px 14px; background: var(--surface-2); display: flex; flex-direction: column; gap: 4px; }
.plan.best { border-color: var(--accent); }
.plan .tag { position: absolute; top: -9px; left: 12px; font-size: 10px; font-weight: 700; padding: 1px 7px; border-radius: 6px; background: var(--accent); color: var(--accent-ink); }
.plan .name { color: var(--muted); font-size: 12px; }
.plan .price { font-size: 22px; font-weight: 650; }
.plan .price small { font-size: 12px; font-weight: 400; color: var(--muted); }
.plan .btn { margin-top: 10px; }
.sub-line { margin: 10px 0 0; }
