/* Stampbook: a stockbook album page for your photo stamps. */
:root {
  --chrome: #e8ece9;
  --ink: #171c1f;
  --muted: #5d6968;
  --card: #f8faf8;
  --line: #cdd5d2;
  --accent: #2757d6;
  --on-accent: #ffffff;
  --danger: #b3261e;
  --page: #161c1f;
  --page-ink: #e9eeeb;
  --page-muted: #8d9997;
  --strip: rgba(255, 255, 255, 0.13);
  --didone: "Bodoni 72", "Bodoni MT", Didot, "Playfair Display", "Times New Roman", serif;
  --sans: system-ui, -apple-system, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --chrome: #0d1113; --ink: #e8ece9; --muted: #93a09e; --card: #171d20; --line: #283134;
    --accent: #7399ff; --on-accent: #08101f; --danger: #ff8f86; --page: #1a2226;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --chrome: #0d1113; --ink: #e8ece9; --muted: #93a09e; --card: #171d20; --line: #283134;
  --accent: #7399ff; --on-accent: #08101f; --danger: #ff8f86; --page: #1a2226;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--chrome); color: var(--ink);
  font: 16px/1.45 var(--sans);
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
  min-height: 100vh; min-height: 100dvh;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
h1, h2, h3, p { margin: 0; }
.muted { color: var(--muted); }
.grow { flex: 1; }

/* Airmail edge: the one loud moment */
.airmail {
  height: 8px;
  background: repeating-linear-gradient(135deg, #d6402f 0 14px, #fff 14px 22px, #2757d6 22px 36px, #fff 36px 44px);
}

.wrap { max-width: 980px; margin: 0 auto; padding-bottom: calc(120px + env(safe-area-inset-bottom)); }

/* Header */
.top { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; padding: 18px 18px 12px; }
.top h1 {
  font: 600 34px/1 var(--didone); letter-spacing: 0.01em;
}
.top .count { font: 400 15px var(--sans); color: var(--muted); margin-left: 10px; }
.top-actions { display: flex; gap: 4px; }
.icon-btn {
  appearance: none; border: 0; background: transparent; width: 44px; height: 44px; border-radius: 12px;
  display: inline-flex; align-items: center; justify-content: center; color: var(--ink);
}
.icon-btn:hover { background: color-mix(in srgb, var(--ink) 8%, transparent); }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* Banners */
.banner {
  margin: 4px 14px 12px; padding: 14px 16px; border-radius: 14px; background: var(--card);
  border: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px;
}
.banner strong { display: block; font-weight: 650; }
.banner span { color: var(--muted); font-size: 14.5px; }
.banner svg { width: 17px; height: 17px; vertical-align: -3px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.b-actions { display: flex; gap: 8px; }

/* Folder tabs */
.chips { display: flex; gap: 8px; padding: 2px 14px 12px; overflow-x: auto; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  appearance: none; flex: none; border: 1px solid var(--line); background: transparent; border-radius: 999px;
  padding: 8px 14px; min-height: 40px; font-size: 14.5px; font-weight: 550; white-space: nowrap;
}
.chip small { font: 400 13px var(--sans); color: var(--muted); margin-left: 6px; }
.chip[aria-pressed="true"] { background: var(--ink); color: var(--chrome); border-color: var(--ink); }
.chip[aria-pressed="true"] small { color: inherit; opacity: 0.7; }
.chip.ghost { border-style: dashed; color: var(--muted); }

/* The album page */
.album {
  margin: 0 12px; background: var(--page); color: var(--page-ink); border-radius: 10px; overflow: hidden;
  box-shadow: inset 16px 0 14px -14px rgba(0, 0, 0, 0.55), 0 10px 30px rgba(10, 20, 20, 0.22);
}
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); }
@media (min-width: 720px) { .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); } }
.cell {
  appearance: none; border: 0; background: none; position: relative; text-align: center;
  padding: 18px 10px 12px; display: flex; flex-direction: column; align-items: center; gap: 8px; color: inherit;
}
.cell::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 1px; background: var(--strip); }
.cell .img { width: 100%; aspect-ratio: 1 / 1.12; display: flex; align-items: center; justify-content: center; position: relative; }
.cell img {
  max-width: 100%; max-height: 100%; display: block;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.5)) drop-shadow(0 6px 8px rgba(0, 0, 0, 0.35));
}
.cap { font-size: 12.5px; color: var(--page-muted); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-height: 1.45em; }
.cell:active img { transform: scale(0.98); }
.selecting .cell { opacity: 0.45; }
.selecting .cell.sel { opacity: 1; }
.cell .tick {
  position: absolute; right: 2px; top: 2px; width: 24px; height: 24px; border-radius: 50%;
  background: var(--accent); color: var(--on-accent); display: none; align-items: center; justify-content: center;
}
.cell.sel .tick { display: flex; }
.tick svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }

/* Empty album */
.empty { padding: 44px 24px 40px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.empty svg { width: 120px; height: auto; margin-bottom: 4px; }
.empty h2 { font: 600 24px/1.2 var(--didone); }
.empty p { color: var(--page-muted); max-width: 30ch; }
.empty .btn { margin-top: 8px; }

/* Buttons */
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--card); color: var(--ink);
  min-height: 46px; padding: 0 18px; border-radius: 12px; font-weight: 600; font-size: 15.5px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; }
.btn.small { min-height: 38px; padding: 0 14px; font-size: 14px; }
.btn[disabled] { opacity: 0.5; pointer-events: none; }

.fab {
  position: fixed; right: calc(18px + env(safe-area-inset-right)); bottom: calc(20px + env(safe-area-inset-bottom));
  width: 62px; height: 62px; border-radius: 50%; border: 0; background: var(--accent); color: var(--on-accent);
  display: flex; align-items: center; justify-content: center; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.3);
}
.fab svg { width: 28px; height: 28px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; }

.selectbar {
  position: fixed; left: 0; right: 0; bottom: 0; padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: var(--card); border-top: 1px solid var(--line); display: flex; align-items: center; gap: 10px;
}
.selectbar .n { flex: 1; font-weight: 600; }

/* Sheets (dialogs) */
dialog.sheet {
  border: 0; padding: 0; background: var(--card); color: var(--ink); width: min(560px, 100%); max-width: none;
  max-height: 92vh; max-height: 92dvh; border-radius: 22px; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4); overflow: hidden;
}
dialog.sheet::backdrop { background: rgba(8, 14, 16, 0.55); }
@media (max-width: 600px) {
  dialog.sheet { margin: auto 0 0; border-radius: 22px 22px 0 0; }
}
dialog.sheet[open] { animation: rise 0.22s ease-out; }
@keyframes rise { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { dialog.sheet[open] { animation: none; } }

.sheet-body {
  display: flex; flex-direction: column; gap: 16px; max-height: 92vh; max-height: 92dvh; overflow: auto;
  padding: 0 18px calc(20px + env(safe-area-inset-bottom)); -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
}
.sheet-head {
  position: sticky; top: 0; z-index: 2; background: var(--card); display: flex; align-items: center; gap: 10px;
  padding: 12px 0 8px; min-height: 60px;
}
.sheet-head h2 { font: 600 21px/1.1 var(--didone); flex: 1; text-align: center; }
.sheet-head > h2:first-child { text-align: left; }
.sheet-head h2 small { display: block; font: 400 13px var(--sans); color: var(--muted); margin-top: 2px; }
.sheet-head .btn { min-height: 40px; }
.sheet h3 { font-size: 15px; font-weight: 650; margin-bottom: 8px; }
.sheet section { display: flex; flex-direction: column; gap: 8px; }

.stage {
  background: var(--chrome); border-radius: 16px; padding: 18px; display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.stage canvas {
  max-width: 100%; max-height: 44vh; max-height: 44dvh; width: auto; height: auto; touch-action: none; cursor: grab;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.35)) drop-shadow(0 8px 14px rgba(0, 0, 0, 0.22));
}
.stage canvas.view { cursor: default; touch-action: auto; max-height: 40vh; max-height: 40dvh; }
.stage.sticky { position: sticky; top: 60px; z-index: 1; padding: 12px 18px 8px; box-shadow: 0 0 0 18px var(--card); }
.stage.sticky canvas { max-height: 36vh; max-height: 36dvh; }
.hint { font-size: 13px; color: var(--muted); text-align: center; }

.shapes, .papers { display: flex; gap: 8px; overflow-x: auto; padding: 2px; scrollbar-width: none; }
.shapes::-webkit-scrollbar, .papers::-webkit-scrollbar { display: none; }
.shape {
  appearance: none; flex: none; width: 74px; padding: 8px 4px 6px; border-radius: 12px; border: 1.5px solid var(--line);
  background: transparent; display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 12px;
}
.shape svg { width: 28px; height: 28px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-dasharray: 2.2 1.8; }
.shape[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); }
.swatch {
  appearance: none; flex: none; width: 38px; height: 38px; border-radius: 50%; border: 1.5px solid var(--line);
  box-shadow: inset 0 0 0 3px var(--card);
}
.swatch[aria-pressed="true"] { border-color: var(--accent); border-width: 3px; }

.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }
.field input[type="text"], .field select {
  min-height: 46px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--chrome);
  font-size: 16px; color: var(--ink); width: 100%;
}
.field textarea {
  min-height: 84px; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--chrome);
  font-size: 16px; color: var(--ink); width: 100%; resize: vertical; font-family: inherit;
}
.field input[type="date"] {
  min-height: 46px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--chrome);
  font-size: 16px; color: var(--ink); width: 100%;
}
.swatch.custom { position: relative; background: conic-gradient(#e5484d, #f5d90a, #46a758, #00a2c7, #3e63dd, #d6409f, #e5484d); overflow: hidden; }
.swatch.custom input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; border: 0; padding: 0; }
.note { white-space: pre-wrap; overflow-wrap: anywhere; color: var(--ink) !important; font-size: 15px !important; margin-top: 10px !important; text-align: left; }
.note:empty { display: none; }
.field input[type="range"] { width: 100%; accent-color: var(--accent); height: 32px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row > .btn { flex: 1; }

.seg { display: flex; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.seg button { flex: 1; appearance: none; border: 0; background: transparent; min-height: 42px; font-weight: 600; font-size: 14.5px; }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--chrome); }

.list { display: flex; flex-direction: column; }
.list-item { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.list-item .name { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item .muted { font-size: 13px; }

.detail-title { text-align: center; }
.detail-title h2 { font: 600 24px/1.2 var(--didone); overflow-wrap: anywhere; }
.detail-title p { color: var(--muted); font-size: 14px; margin-top: 4px; }
.nav-arrow[disabled] { opacity: 0.25; pointer-events: none; }

.pages { display: flex; flex-direction: column; gap: 12px; background: var(--chrome); border-radius: 14px; padding: 12px; min-height: 120px; }
.pages img { width: 100%; height: auto; display: block; background: #fff; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25); }
.progress { font-size: 14px; color: var(--muted); text-align: center; padding: 20px 0; }

.toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--chrome); padding: 11px 18px; border-radius: 999px; font-size: 14.5px; font-weight: 550;
  max-width: calc(100vw - 32px); text-align: center; z-index: 100; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

#printRoot { display: none; }
@media print {
  body > *:not(#printRoot) { display: none !important; }
  html, body { background: #fff !important; padding: 0 !important; }
  #printRoot { display: block; }
  #printRoot img { display: block; break-after: page; page-break-after: always; }
  #printRoot img:last-child { break-after: auto; page-break-after: auto; }
}

/* Views, calendar, map, create menu */
.seg.views { margin: 0 14px 12px; }
.seg.views button { display: inline-flex; align-items: center; justify-content: center; gap: 7px; }
.seg.views svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
:root[data-grid="small"] .grid { grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); }
:root[data-grid="large"] .grid { grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); }
:root[data-grid="large"] .cell { padding: 22px 14px 14px; }

.cal { padding: 8px 8px 14px; }
.cal-head { display: flex; align-items: center; justify-content: space-between; padding: 4px 4px 8px; }
.cal-head h2 { font: 600 24px/1 var(--didone); }
.cal .icon-btn { color: var(--page-ink); }
.cal-week { display: grid; grid-template-columns: repeat(7, 1fr); text-align: center; font-size: 12.5px; color: var(--page-muted); padding-bottom: 4px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.day {
  appearance: none; border: 0; background: rgba(255, 255, 255, 0.04); border-radius: 6px; position: relative; padding: 0;
  aspect-ratio: 1 / 1.18; display: flex; align-items: center; justify-content: center; color: var(--page-ink); overflow: hidden; cursor: default;
}
.day.out { opacity: 0.35; }
.day.today { box-shadow: inset 0 0 0 2px var(--accent); }
.day.has { cursor: pointer; background: rgba(255, 255, 255, 0.07); }
.day img { max-width: 88%; max-height: 88%; filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.55)); }
.day .num { position: absolute; left: 4px; top: 2px; font-size: 11px; color: var(--page-muted); text-shadow: 0 0 3px #000; }
.day.has .num { color: #fff; }
.day .n { position: absolute; right: 3px; bottom: 3px; min-width: 18px; height: 18px; border-radius: 9px; background: var(--accent); color: var(--on-accent); font-size: 11px; font-weight: 700; display: flex; align-items: center; justify-content: center; padding: 0 4px; }
.cal-foot { display: flex; justify-content: center; padding-top: 10px; }
.cal-foot .btn { color: var(--page-ink); border-color: rgba(255, 255, 255, 0.25); }

.mapwrap { background: var(--page); }
.mapbox { height: 62vh; height: 62dvh; min-height: 320px; width: 100%; background: #cfd8d6; }
.map-note { padding: 10px 14px; font-size: 13.5px; color: var(--page-muted); }
.leaflet-container .leaflet-marker-pane .stamp-pin img { width: 46px; height: auto; display: block; filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.55)); }
.leaflet-container { font: inherit; }

.menu { display: flex; flex-direction: column; gap: 8px; }
.menu-item { appearance: none; text-align: left; border: 1px solid var(--line); background: transparent; border-radius: 14px; padding: 12px 14px; display: flex; align-items: center; gap: 14px; min-height: 64px; }
.menu-item strong { display: block; font-size: 16px; }
.menu-item small { color: var(--muted); font-size: 13.5px; }
.menu-item .mi { width: 40px; height: 40px; border-radius: 12px; background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); display: flex; align-items: center; justify-content: center; flex: none; }
.menu-item .mi svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.sheet-head h2 small { font-weight: 400; }
.chip svg { width: 15px; height: 15px; vertical-align: -2px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
dialog .album { margin: 0; }

.synccode { font: 600 1.35rem/1.4 ui-monospace, 'SF Mono', Menlo, monospace; letter-spacing: .06em; text-align: center; padding: 14px 10px; margin: 10px 0 14px; background: var(--page); border: 1px dashed var(--line); border-radius: 10px; word-break: break-all; user-select: all; -webkit-user-select: all; }
