:root {
  --board: #E9ECEF; --paper: #FFFFFF; --ink: #20242B; --muted: #5A6070; --line: #DCE3F0;
  --blue: #2446B8; --blue-dark: #1A338A; --sticky: #FFF3A8; --sticky-ink: #4F4A1E; --danger: #A3341F;
  --shadow: 0 2px 6px rgba(32, 36, 43, .13);
  --hand: Caveat, "Segoe Print", cursive;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--board); color: var(--ink);
  font: 15px/1.45 Rubik, system-ui, -apple-system, "Segoe UI", sans-serif; }
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--blue); }
.hand { font-family: var(--hand); font-weight: 700; }
[hidden] { display: none !important; }

/* ---------- buttons ---------- */
.btn { border: 0; border-radius: 999px; padding: 0 18px; height: 44px; cursor: pointer; background: var(--paper);
  font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn.primary { background: var(--blue); color: #fff; }
.btn.primary:hover { background: var(--blue-dark); }
.btn.big { height: 54px; font-size: 16px; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
.icon-btn { width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--paper); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; color: var(--ink); position: relative; flex-shrink: 0; }
.icon-btn .dot { position: absolute; right: 8px; top: 8px; width: 9px; height: 9px; border-radius: 50%; background: #E2552D; }
.fab { position: fixed; right: max(20px, env(safe-area-inset-right)); bottom: max(24px, env(safe-area-inset-bottom));
  width: 62px; height: 62px; border-radius: 50%; border: 0; background: var(--blue); color: #fff; cursor: pointer;
  display: flex; align-items: center; justify-content: center; transform: rotate(-6deg); box-shadow: 0 4px 14px rgba(36,70,184,.35); z-index: 5; }
.fab:hover { background: var(--blue-dark); }

/* ---------- layout ---------- */
.page { max-width: 1200px; margin: 0 auto; padding: max(14px, env(safe-area-inset-top)) 16px 110px; }
.top { display: flex; align-items: center; gap: 8px; padding: 4px 0 6px; }
.logo { font-family: var(--hand); font-weight: 700; font-size: 40px; line-height: 1; flex: 1; margin: 0; }
.search { display: flex; align-items: center; gap: 10px; height: 46px; padding: 0 16px; background: var(--paper);
  border-radius: 23px; margin: 8px 0 4px; color: var(--muted); }
.search input { border: 0; outline: 0; background: transparent; flex: 1; min-width: 0; font-size: 16px; color: var(--ink); }

/* tape: category labels */
.tapes { display: flex; gap: 10px; overflow-x: auto; padding: 10px 2px 16px; scrollbar-width: none; align-items: center; }
.tapes::-webkit-scrollbar { display: none; }
.tape { border: 0; height: 34px; padding: 0 14px; font-weight: 600; font-size: 14px; white-space: nowrap; cursor: pointer;
  background: var(--t-bg, #D5D9DF); color: var(--t-ink, #3A404A); display: inline-flex; align-items: center; gap: 6px; }
.tape .n { opacity: .65; font-weight: 500; }
.tape.on { background: var(--ink); color: #fff; }
.tape:nth-child(4n+1) { transform: rotate(-1.5deg); } .tape:nth-child(4n+2) { transform: rotate(1deg); }
.tape:nth-child(4n+3) { transform: rotate(-.8deg); } .tape:nth-child(4n) { transform: rotate(1.4deg); }

/* ---------- polaroid board ---------- */
.board { column-count: 2; column-gap: 18px; padding-top: 8px; }
@media (min-width: 700px) { .board { column-count: 3; column-gap: 28px; } }
@media (min-width: 1000px) { .board { column-count: 4; } }
.polaroid { break-inside: avoid; display: block; width: 100%; margin: 0 0 26px; background: var(--paper);
  padding: 8px 8px 0; box-shadow: var(--shadow); position: relative; cursor: pointer; border: 0; text-align: left;
  transform: rotate(var(--rot, 0deg)); transition: transform .15s; color: inherit; text-decoration: none; }
.polaroid:hover { transform: rotate(0deg) scale(1.02); z-index: 2; }
.polaroid .pic { display: block; width: 100%; max-height: 270px; object-fit: cover; background: #C9CDD3; min-height: 80px; }
@media (min-width: 700px) { .polaroid .pic { max-height: 360px; } }
.polaroid .caption { font-family: var(--hand); font-weight: 700; font-size: 22px; line-height: 1.05; padding: 8px 2px 10px; overflow-wrap: anywhere; }
/* In the feed: square pictures and at most 2 caption lines, so more cards fit on screen. */
.board .polaroid { margin-bottom: 20px; padding: 6px 6px 0; }
.board .polaroid .pic { aspect-ratio: 1 / 1; height: auto; max-height: none; min-height: 0; object-fit: cover; }
.board .polaroid .stub { aspect-ratio: 1 / 1; min-height: 0; -webkit-line-clamp: 6; }
.board .polaroid .caption { font-size: 19px; padding: 6px 2px 8px; display: -webkit-box; -webkit-line-clamp: 2;
  -webkit-box-orient: vertical; overflow: hidden; }
.board .polaroid .sub { padding-bottom: 8px; }
.polaroid .sub { font-size: 12px; color: var(--muted); padding: 0 2px 10px; margin-top: -6px; }
.polaroid .stub { min-height: 120px; padding: 10px 8px; background-image: repeating-linear-gradient(transparent 0 23px, var(--line) 23px 24px);
  line-height: 24px; font-size: 13px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 7; -webkit-box-orient: vertical; overflow: hidden; }
.strip { position: absolute; left: 50%; top: -10px; width: 64px; height: 20px; margin-left: -32px;
  background: var(--t-bg, #D5D9DF); opacity: .9; transform: rotate(var(--trot, 3deg)); }
.crop { position: relative; overflow: hidden; background: #C9CDD3; }
.crop img { position: absolute; left: 0; top: 0; width: 100%; max-width: none; max-height: none; opacity: 0; transition: opacity .2s; }
.crop.ready img { opacity: 1; }
.photos .main .crop { width: 100%; max-height: 460px; aspect-ratio: 3 / 4; }
.polaroid.pending .pic { animation: develop 1.6s ease-in-out infinite alternate; }
@keyframes develop { from { filter: brightness(.75); } to { filter: brightness(1.08); } }
.polaroid.error .caption { color: var(--danger); }

.empty { text-align: center; padding: 60px 20px; color: var(--muted); }
.empty .hand { font-size: 32px; color: var(--ink); display: block; margin-bottom: 6px; }

/* sticky notes */
.sticky { background: var(--sticky); color: var(--ink); padding: 12px 14px; box-shadow: var(--shadow); transform: rotate(-1deg);
  display: flex; flex-direction: column; gap: 8px; margin: 6px 0 16px; }
.sticky .hand { font-size: 22px; line-height: 1.15; }
.sticky .row { display: flex; gap: 6px; }

/* lined paper */
.lined { background: var(--paper); background-image: repeating-linear-gradient(transparent 0 29px, var(--line) 29px 30px);
  line-height: 30px; }

/* ---------- item page ---------- */
.item-page { max-width: 560px; margin: 0 auto; padding: max(14px, env(safe-area-inset-top)) 20px 40px; display: flex; flex-direction: column; gap: 18px; }
.bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.photos { position: relative; padding: 10px 0 0; min-height: 200px; }
.photos .main { width: min(78%, 330px); margin: 0 auto 0 4%; padding: 10px 10px 0; transform: rotate(-2.5deg); cursor: zoom-in; }
.photos .main .pic { max-height: 460px; }
.photos .main .caption { font-size: 30px; }
.photos .orig { position: absolute; right: 2%; top: 46px; width: 32%; max-width: 140px; padding: 6px 6px 0; transform: rotate(8deg); z-index: 0; }
.photos .orig .caption { font-size: 18px; padding: 4px 2px 6px; }
.photos .main { z-index: 1; }
.notes { padding: 0 16px; transform: rotate(-.5deg); box-shadow: var(--shadow); font-size: 15px; }
.notes p { margin: 0; }
.notes .k { color: var(--muted); }
.notes ul, .notes ol { margin: 0; padding-left: 20px; }
.notes h3 { margin: 0; font-family: var(--hand); font-size: 22px; font-weight: 700; }
.sibs { display: flex; flex-direction: column; gap: 8px; }
.sibs .hand { font-size: 22px; }
.sibs .list { display: flex; flex-wrap: wrap; gap: 8px; }
.sibs a { padding: 6px 10px; text-decoration: none; font-weight: 600; font-size: 13px; background: var(--t-bg); color: var(--t-ink); }
.actions { display: flex; gap: 10px; }
.actions .btn.primary { flex: 1; }
.edit { background: var(--paper); padding: 16px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 12px; }

/* ---------- forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 13px; color: var(--muted); }
.field input, .field select, .field textarea { border: 1.5px solid var(--line); background: #F6F7F9; padding: 10px 12px; outline: 0; border-radius: 0; }
.field textarea.lined { border: 0; padding: 0 12px; background-color: #F6F7F9; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--blue); }
.margin-note { font-family: var(--hand) !important; font-size: 22px !important; font-weight: 600; border: 0 !important;
  border-bottom: 2px solid var(--line) !important; background: transparent !important; }
.pick { border: 2px dashed #B8BEC8; min-height: 88px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px; cursor: pointer; color: #3A404A; transform: rotate(-.5deg); }
.pick.has { border-color: var(--blue); color: var(--blue); }
body.dragging .pick { border-color: var(--blue); }

/* ---------- categories page ---------- */
.cat-list { display: flex; flex-direction: column; gap: 10px; }
.cat-row { display: flex; align-items: center; gap: 10px; }
.cat-row .tape { flex: 1; height: 40px; font-size: 16px; justify-content: flex-start; }
.cat-row .count { width: 34px; text-align: right; font-family: var(--hand); font-size: 22px; font-weight: 700; }
.cat-edit { background: var(--paper); padding: 12px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 12px; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.swatch { width: 36px; height: 20px; border: 0; cursor: pointer; background: var(--t-bg); }
.swatch.on { outline: 2px solid var(--ink); outline-offset: 2px; }
.add-cat { border: 2px dashed #B8BEC8; background: transparent; height: 52px; font-weight: 600; cursor: pointer; width: 100%; margin-top: 8px; }

/* ---------- dialogs ---------- */
dialog.sheet { border: 0; padding: 0; margin: auto auto 0; width: min(560px, 100vw); max-width: 100vw; max-height: 92dvh;
  background: var(--paper); border-radius: 22px 22px 0 0; color: var(--ink); }
@media (min-width: 700px) { dialog.sheet { margin: auto; border-radius: 6px; } }
dialog::backdrop { background: rgba(32, 36, 43, .45); }
#addForm { display: flex; flex-direction: column; gap: 14px; padding: 12px 20px max(24px, env(safe-area-inset-bottom)); }
#addForm h2 { margin: 0; font-size: 32px; line-height: 1; }
.grip { align-self: center; width: 40px; height: 4px; border-radius: 2px; background: #D5D9DF; }
dialog.lightbox { border: 0; padding: 0; background: transparent; max-width: 100vw; max-height: 100dvh; }
dialog.lightbox::backdrop { background: rgba(10, 12, 16, .9); }
dialog.lightbox img { display: block; max-width: 100vw; max-height: 100dvh; object-fit: contain; cursor: zoom-out; }

.toast { position: fixed; left: 50%; bottom: 100px; transform: translate(-50%, 30px) rotate(-1deg); opacity: 0; pointer-events: none;
  background: var(--sticky); color: var(--ink); padding: 10px 16px; box-shadow: var(--shadow); font-family: var(--hand);
  font-size: 22px; font-weight: 700; transition: all .25s; z-index: 50; white-space: nowrap; }
.toast.show { opacity: 1; transform: translate(-50%, 0) rotate(-1deg); }
