:root {
  --bg: #1b1b1d;
  --panel: #252528;
  --line: #3a3a3f;
  --text: #ececec;
  --muted: #9a9aa2;
  --accent: #e0b04b;
  --danger: #e5484d;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
button, select, input { font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 6px 10px; }
button { cursor: pointer; }
button:disabled { opacity: 0.4; cursor: default; }
button.primary { background: var(--accent); color: #1b1b1d; border-color: var(--accent); font-weight: 600; }
.row { display: flex; gap: 8px; align-items: center; }

.home { max-width: 720px; margin: 10vh auto; padding: 0 16px; }
.home .recent { display: block; width: 100%; text-align: left; margin: 4px 0; }
.home .status { color: var(--muted); }

.toolbar { display: flex; gap: 8px; align-items: center; padding: 8px 12px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.toolbar strong { margin-right: auto; }

.select .grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 8px; padding: 12px; }
.tile { position: relative; margin: 0; border: 3px solid transparent; border-radius: 6px; cursor: pointer; opacity: 0.55; }
.tile.on { border-color: var(--accent); opacity: 1; }
.tile img { width: 100%; aspect-ratio: 1; object-fit: contain; background: #000; display: block; }
.tile figcaption { font-size: 11px; color: var(--muted); padding: 2px 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile .star { position: absolute; top: 4px; right: 4px; padding: 0 6px; }
.tile.fav .star { color: var(--accent); }

.editor { display: grid; grid-template-columns: 180px 1fr; grid-template-rows: auto 1fr auto; height: 100vh; }
.editor .toolbar { grid-column: 1 / -1; }
.spread-list { overflow-y: auto; padding: 8px; border-right: 1px solid var(--line); }
.spread-item { margin-bottom: 8px; padding: 4px; border: 2px solid transparent; border-radius: 4px; cursor: pointer; }
.spread-item.current { border-color: var(--accent); }
.spread-item .num { font-size: 11px; color: var(--muted); }
.stage { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 12px; min-height: 0; }
.stage .spread { width: min(100%, calc((100vh - 280px) * var(--ratio))); }
.stage-controls { display: flex; gap: 8px; align-items: center; }

.spread { position: relative; width: 100%; background: #fff; overflow: hidden; }
.cell { position: absolute; overflow: hidden; background: #d8d8d8; }
.cell img { position: absolute; pointer-events: none; }
.cell.selected { outline: 3px solid var(--accent); outline-offset: -3px; z-index: 1; }
.cell .badge { position: absolute; left: 4px; bottom: 4px; font-size: 11px; padding: 2px 6px; border-radius: 4px; background: rgba(0, 0, 0, 0.7); color: #fff; }
.cell.low-dpi { outline: 2px dashed var(--accent); outline-offset: -2px; }
.cell.missing { outline: 2px dashed var(--danger); outline-offset: -2px; }
.guide-bleed { position: absolute; border: 1px dashed rgba(229, 72, 77, 0.8); pointer-events: none; }
.guide-fold { position: absolute; top: 0; bottom: 0; left: 50%; border-left: 1px dashed rgba(0, 120, 255, 0.8); pointer-events: none; }

.strip { grid-column: 1 / -1; border-top: 1px solid var(--line); background: var(--panel); padding: 6px 12px; }
.strip label { font-size: 12px; color: var(--muted); }
.strip-photos { display: flex; gap: 6px; overflow-x: auto; padding-top: 6px; height: 104px; }
.strip-photos img { height: 90px; border: 3px solid transparent; border-radius: 4px; cursor: grab; }
.strip-photos img.used { opacity: 0.4; }
.strip-photos img.fav { border-color: var(--accent); }

.modal { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.75); display: flex; align-items: center; justify-content: center; z-index: 10; }
.dialog, .crop-dialog { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px; display: flex; flex-direction: column; gap: 12px; max-width: 90vw; }
.dialog { min-width: 420px; }
.dialog label { display: flex; gap: 8px; align-items: center; }
.warnings { max-height: 40vh; overflow-y: auto; margin: 0; padding-left: 18px; color: var(--accent); }
.crop-frame { position: relative; overflow: hidden; width: min(80vw, calc(70vh * var(--ratio))); cursor: grab; touch-action: none; background: #000; }
.crop-frame img { position: absolute; pointer-events: none; }

.toast { position: fixed; bottom: 130px; left: 50%; transform: translateX(-50%); background: var(--panel); border: 1px solid var(--accent); padding: 10px 16px; border-radius: 8px; z-index: 20; }
.home .big { font-size: 18px; padding: 14px 22px; margin: 8px 0 20px; }
.save-banner { position: fixed; top: 12px; left: 50%; transform: translateX(-50%); display: flex; gap: 12px; align-items: center; max-width: min(900px, 94vw); background: #3a1d1f; border: 1px solid var(--danger); color: var(--text); padding: 10px 14px; border-radius: 8px; z-index: 30; }
