:root {
  --bg: #eeeeee;
  --card: #ffffff;
  --ink: #1d1d1f;
  --ink-soft: #3a3a3c;
  --muted: #8d7b6f;
  --tan: #b39a7e;
  --line: #ececec;
  --cell-out: #f8f8fa;
  --soft: #f6f5f3;
  --cream: #faf6ee;
  --accent-dot: #9fd49a;
  --radius-xl: 28px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 10px 30px rgba(0,0,0,.05);
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", "Segoe UI", Arial, sans-serif;
  --display: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Helvetica Neue", "Segoe UI", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Courier New", monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
button { font: inherit; color: inherit; cursor: pointer; }
svg { display: block; }
[hidden] { display: none !important; }

.app { max-width: 1180px; margin: 0 auto; padding: 24px 32px 40px; }

/* ---------- Top bar ---------- */
.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo { position: relative; width: 26px; height: 26px; flex: none; }
.logo i { position: absolute; width: 16px; height: 16px; border-radius: 50%; opacity: .9; }
.logo i:nth-child(1) { left: 0; top: 2px; background: #f5a3bd; }
.logo i:nth-child(2) { left: 9px; top: 3px; background: #f4d46b; }
.logo i:nth-child(3) { left: 4px; top: 10px; background: #8fb8f2; }
.brand-name { font-family: var(--display); font-weight: 700; font-size: 21px; letter-spacing: -.02em; }
.brand-tag { font-size: 11.5px; color: var(--muted); margin-top: 2px; }

.month-nav { display: flex; align-items: center; gap: 12px; }
.round-btn {
  width: 32px; height: 32px; border-radius: 50%;
  border: 0; background: #fff;
  display: grid; place-items: center;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
  transition: transform .15s ease, box-shadow .15s ease;
  flex: none;
}
.round-btn:hover { transform: translateY(-1px); box-shadow: 0 4px 10px rgba(0,0,0,.1); }
.round-btn svg { width: 16px; height: 16px; }
.round-btn.sm { width: 26px; height: 26px; }
.round-btn.sm svg { width: 13px; height: 13px; }
.month-pill {
  min-width: 136px; padding: 9px 26px; border-radius: 999px; background: #fff;
  text-align: center; font-weight: 600; font-size: 14px; letter-spacing: -.01em;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
}
.month-pill small { font-family: var(--mono); font-weight: 400; font-size: 10px; color: var(--muted); margin-left: 4px; }

.top-right { display: flex; justify-content: flex-end; align-items: center; gap: 10px; }
.tucked { display: inline-flex; align-items: center; gap: 6px; font-family: var(--mono); font-size: 10.5px; color: var(--muted); }
.tucked svg { width: 14px; height: 14px; color: #c9967a; }
.chip-btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 0; background: #fff; border-radius: 999px; padding: 7px 12px;
  font-size: 11.5px; font-weight: 500;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
}
.chip-btn svg { width: 14px; height: 14px; }
.picker-wrap { position: relative; }
.picker {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 20;
  width: 232px; background: #fff; border-radius: 18px; padding: 14px;
  box-shadow: 0 18px 40px rgba(0,0,0,.14);
  animation: pop .18s ease;
}
.picker-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; font-size: 14px; }
.picker-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.picker-grid button {
  border: 0; background: var(--soft); border-radius: 10px; padding: 8px 0; font-size: 12px;
}
.picker-grid button:hover { background: #ecebe8; }
.picker-grid button.on { background: var(--ink); color: #fff; }
.picker-grid button .has { display: block; width: 4px; height: 4px; border-radius: 50%; background: #e8a; margin: 2px auto 0; }
.link-btn { margin-top: 10px; width: 100%; border: 0; background: none; font-size: 12px; color: var(--muted); text-decoration: underline; text-underline-offset: 3px; }

/* ---------- Sheet ---------- */
.sheet {
  background: var(--card);
  border-radius: var(--radius-xl);
  padding: 30px 26px 24px;
  box-shadow: var(--shadow);
}
.sheet-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; padding: 0 2px 22px; }
.eyebrow { font-family: var(--mono); font-size: 9.5px; letter-spacing: .16em; text-transform: uppercase; color: var(--tan); }
h1 { font-family: var(--display); font-size: 33px; letter-spacing: -.035em; margin: 10px 0 6px; font-weight: 700; }
.sheet-sub { margin: 0; font-size: 12px; color: var(--muted); }
.status { display: flex; align-items: center; gap: 8px; font-size: 11.5px; color: var(--muted); padding-bottom: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent-dot); box-shadow: 0 0 0 3px rgba(159,212,154,.25); }

.weekdays { display: grid; grid-template-columns: repeat(7, 1fr); }
.weekdays span { text-align: center; font-family: var(--mono); font-size: 9.5px; letter-spacing: .12em; text-transform: uppercase; color: var(--tan); padding-bottom: 10px; }

.grid {
  display: grid; grid-template-columns: repeat(7, 1fr);
  border-top: 1px solid var(--line); border-left: 1px solid var(--line);
}
.cell {
  position: relative; height: 138px; padding: 0;
  border: 0; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line);
  background: #fff; text-align: left;
  transition: background .2s ease;
  overflow: visible;
}
.cell.out { background: var(--cell-out); }
.cell.out .num { color: #b9b4ae; }
.cell:hover { background: #fafafa; }
.cell:focus-visible { outline: 2px solid #9db8e8; outline-offset: -2px; z-index: 2; }
.num { position: absolute; top: 10px; left: 10px; font-family: var(--mono); font-size: 10.5px; color: var(--ink-soft); }
.cell.today .num {
  background: var(--ink); color: #fff; border-radius: 999px; padding: 2px 6px; left: 6px; top: 8px;
}
.cell .peg { position: absolute; top: 14px; left: 50%; width: 11px; height: 28px; transform: translateX(-50%); z-index: 3; filter: drop-shadow(0 1px 1px rgba(0,0,0,.08)); }
.cell .plus {
  position: absolute; left: 50%; top: 62%; transform: translate(-50%,-50%) scale(.92);
  width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  color: #b8b2ab; background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.06);
  opacity: .55; transition: opacity .2s, transform .2s, color .2s;
}
.cell .plus svg { width: 14px; height: 14px; }
.cell:hover .plus { opacity: 1; transform: translate(-50%,-50%) scale(1.05); color: var(--ink); box-shadow: 0 4px 12px rgba(0,0,0,.1); }

.cell { cursor: pointer; }
.cell .hang {
  position: absolute; left: 50%; top: 20px; width: min(78px, 54%);
  transform-origin: 50% 3px;
  transform: translateX(-50%) rotate(var(--swing, 0deg));
  transition: transform .6s cubic-bezier(.2,1.7,.4,1);
  z-index: 2;
}
.cell .hang .packet-svg { width: 100%; height: auto; filter: drop-shadow(0 6px 8px rgba(0,0,0,.13)); transition: filter .3s; }
.cell.filled:hover { background: #f6f6f7; }
.cell.filled:hover .hang .packet-svg { filter: drop-shadow(0 12px 14px rgba(0,0,0,.18)); }
.cell .hang.drop { animation: drop .9s cubic-bezier(.2,1.4,.4,1) both; }
.cell .more {
  position: absolute; top: 6px; right: 6px; z-index: 4;
  width: 24px; height: 18px; border: 0; border-radius: 999px; background: transparent;
  display: flex; align-items: center; justify-content: center; gap: 2px;
  opacity: 0; transition: opacity .2s, background .2s;
}
.cell .more i { width: 3px; height: 3px; border-radius: 50%; background: var(--ink-soft); }
.cell.filled:hover .more, .cell .more:focus-visible { opacity: 1; }
.cell .more:hover { background: rgba(0,0,0,.06); }
.cell-menu {
  position: absolute; z-index: 30; min-width: 160px; padding: 6px;
  background: #fff; border-radius: 14px; box-shadow: 0 14px 34px rgba(0,0,0,.14);
  display: flex; flex-direction: column; animation: pop .15s ease;
}
.cell-menu button { border: 0; background: none; text-align: left; font-size: 12px; padding: 9px 10px; border-radius: 9px; }
.cell-menu button:hover, .cell-menu button:focus-visible { background: var(--soft); outline: none; }
.cell-menu .danger { color: #b4614a; }
.cell .count {
  position: absolute; right: 8px; bottom: 8px; font-family: var(--mono); font-size: 9px; color: var(--tan);
}
/* Shared pocket: up to two packets per day (3.2, 3.3) */
.cell .hang { cursor: pointer; border-radius: 6px; }
.cell .hang:focus-visible { outline: 2px solid #9db8e8; outline-offset: 2px; z-index: 5; }
.cell .owner-dot {
  position: absolute; top: 6px; right: -3px; width: 9px; height: 9px; border-radius: 50%;
  border: 2px solid #fff; box-shadow: 0 1px 2px rgba(0,0,0,.15); pointer-events: none;
}
.cell.pair { --ov: 6px; }
.cell.pair .hang { width: min(50%, max(40%, 28px)); transform: rotate(var(--swing, 0deg)); }
.cell.pair .hang.p1 { left: auto; right: calc(50% - var(--ov) / 2); }
.cell.pair .hang.p2 { left: calc(50% - var(--ov) / 2); }
.cell.pair .hang:hover, .cell.pair .hang:focus-visible { z-index: 3; }
.cell.pair .hang.drop { animation-name: drop-pair; }
@keyframes drop-pair {
  0% { transform: translateY(-40px) scale(.6); opacity: 0; }
  60% { opacity: 1; }
  100% { transform: translateY(0) scale(1); }
}
button.plus { border: 0; padding: 0; z-index: 4; }
.cell .plus.corner {
  left: 6px; top: auto; bottom: 6px; width: 20px; height: 20px; transform: none;
}
.cell .plus.corner svg { width: 11px; height: 11px; }
.cell:hover .plus.corner, .cell .plus.corner:focus-visible { transform: scale(1.05); }
.cell .plus.corner:focus-visible { opacity: 1; outline: 2px solid #9db8e8; outline-offset: 1px; }
.cell-menu button[aria-disabled="true"] { opacity: .45; cursor: default; }

.hint { text-align: center; font-size: 11.5px; color: var(--muted); margin: 18px 0 0; }

.foot { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px; padding: 18px 8px 0; font-size: 10.5px; color: var(--muted); }
.foot a { color: inherit; }
.foot-mono { font-family: var(--mono); }

/* ---------- Packet SVG ---------- */
.packet-svg { overflow: visible; }

/* ---------- Editor modal ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(40,34,30,.38);
  backdrop-filter: blur(3px);
  display: grid; place-items: center; padding: 18px;
  animation: fade .2s ease;
}
.modal {
  width: min(1000px, 100%); height: min(720px, 100%);
  background: #efefef; border-radius: 24px;
  display: grid; grid-template-rows: auto 1fr auto;
  overflow: hidden;
  box-shadow: 0 30px 80px rgba(0,0,0,.25);
  animation: pop .25s cubic-bezier(.2,1.2,.4,1);
}
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; padding: 26px 30px 16px; border-bottom: 1px solid #e2e2e2; }
.modal-head h2 { font-family: var(--display); font-weight: 500; font-size: 26px; letter-spacing: -.03em; margin: 10px 0 4px; color: #4c3f38; }
.modal-date { margin: 0; font-size: 12px; color: var(--muted); }
.modal-body { display: grid; grid-template-columns: 1fr 1fr; min-height: 0; }
.ed-preview { position: relative; border-right: 1px solid #e2e2e2; display: grid; place-items: center; overflow: hidden; }
.ed-packet { width: min(220px, 52%); transform: translateX(-10%); }
.ed-packet .packet-svg { width: 100%; height: auto; filter: drop-shadow(0 18px 24px rgba(0,0,0,.18)); }
.ed-packet.wiggle { animation: wiggle .5s ease; }
.ed-border-preview { position: absolute; right: 9%; bottom: 13%; width: 32%; transform: rotate(-6deg); }
.mini-label { font-family: var(--mono); font-size: 8.5px; letter-spacing: .16em; text-transform: uppercase; color: #8b8178; margin: 0 0 6px 8px; transform: rotate(3deg); }
.ed-caption { position: absolute; left: 20px; bottom: 16px; font-family: var(--mono); font-size: 9.5px; letter-spacing: .14em; text-transform: uppercase; color: #9c8a76; }

.ed-steps { overflow-y: auto; padding: 10px 18px 20px; display: flex; flex-direction: column; gap: 10px; }
.step { background: #fff; border-radius: 16px; padding: 16px 12px 14px; }
.step-head { display: flex; gap: 10px; align-items: flex-start; margin-bottom: 14px; }
.step-no { width: 26px; height: 26px; border-radius: 50%; background: #f1f0ee; font-family: var(--mono); font-size: 9.5px; display: grid; place-items: center; flex: none; }
.step h3 { margin: 2px 0 2px; font-size: 13px; font-weight: 600; }
.step p { margin: 0; font-size: 10.5px; color: var(--muted); }

.swatches { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; padding: 0 2px; }
.swatch {
  position: relative; width: 30px; height: 30px; border-radius: 50%; border: 0; padding: 0;
  box-shadow: inset 0 -3px 6px rgba(0,0,0,.12), inset 0 3px 6px rgba(255,255,255,.4);
  transition: transform .15s;
}
.swatch:hover { transform: scale(1.08); }
.swatch.on { outline: 2px solid var(--ink); outline-offset: 3px; }
.swatches .swatch.on::after {
  content: ""; position: absolute; right: -6px; top: -6px; width: 13px; height: 13px; border-radius: 50%;
  background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M5 12.5l4.5 4.5L19 7.5' fill='none' stroke='%231d1d1f' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center/9px no-repeat;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.swatches.small .swatch { width: 24px; height: 24px; }
.custom-color { display: inline-flex; align-items: center; gap: 8px; font-size: 10.5px; color: var(--muted); }
.custom-color input { width: 24px; height: 24px; border: 1px solid #ddd; border-radius: 6px; padding: 0; background: none; cursor: pointer; }
.custom-color input::-webkit-color-swatch-wrapper { padding: 2px; }
.custom-color input::-webkit-color-swatch { border: 0; border-radius: 4px; }
.custom-color.on input { outline: 2px solid var(--ink); outline-offset: 2px; }

.stickers {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 7px;
  max-height: 108px; overflow-y: auto; padding: 2px 6px 2px 2px;
}
.sticker {
  aspect-ratio: 1; border: 0; border-radius: 9px; background: #faf5ec;
  font-size: 19px; display: grid; place-items: center; line-height: 1;
  transition: transform .15s, background .15s;
}
.sticker:hover { transform: scale(1.08); background: #f5ecdc; }
.sticker.on { background: #fff; box-shadow: 0 0 0 1.5px #e8a0a8, 0 3px 8px rgba(232,160,168,.3); }

.borders { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.border-opt {
  border: 0; background: #f5f5f6; border-radius: 12px; padding: 10px 6px 10px;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.border-opt.on { background: #f1f1f4; box-shadow: 0 0 0 2px var(--ink); }
.border-opt .demo { width: 48px; margin-bottom: 6px; }
.border-opt strong { font-size: 11px; font-weight: 600; }
.border-opt small { font-size: 9.5px; color: var(--muted); }
.sub-label { font-size: 10.5px; font-weight: 600; margin: 16px 0 10px; }

.file-btn {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 12px;
  border: 1px solid #e6e6e6; background: #fbfbfb; cursor: pointer; transition: background .15s;
}
.file-btn:hover { background: #f5f5f5; }
.file-btn svg { width: 18px; height: 18px; flex: none; }
.file-btn span { display: flex; flex-direction: column; gap: 3px; flex: 1; }
.file-btn strong { font-size: 11.5px; font-weight: 600; }
.file-btn small { font-size: 9.5px; color: var(--muted); }
.file-btn.drag { background: #f1f6ff; border-color: #a8c4f0; }
.thumbs { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.thumbs:empty { display: none; }
.thumb { position: relative; width: 52px; height: 52px; border-radius: 8px; overflow: visible; }
.thumb img { width: 100%; height: 100%; object-fit: cover; border-radius: 8px; }
.thumb .no { position: absolute; left: 4px; top: 4px; font-family: var(--mono); font-size: 8px; background: rgba(255,255,255,.88); padding: 1px 4px; border-radius: 4px; }
.thumb .rm {
  position: absolute; right: -5px; top: -5px; width: 16px; height: 16px; border-radius: 50%; border: 0; padding: 0;
  background: #f07a8a; color: #fff; display: grid; place-items: center;
}
.thumb .rm svg { width: 9px; height: 9px; }
.ed-error { background: #fff1ec; color: #b4614a; font-size: 11px; padding: 10px 12px; border-radius: 10px; }
.ed-error { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; line-height: 1.5; }
.ed-error[hidden] { display: none; }
.ed-error > span { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.ed-error.info { background: #f6f1e8; color: #7d6b5a; }
.ed-retry {
  flex: none; border: 0; border-radius: 999px; padding: 6px 12px; font-size: 11px; font-weight: 600;
  background: #b4614a; color: #fff; cursor: pointer;
}
.ed-retry:hover { background: #9c513c; }
.thumb .frame-loading { border-radius: 8px; }
/* Saving (4.3): editing and every exit are locked until the save settles */
#editor.saving .ed-steps, #editor.saving .file-btn { pointer-events: none; }
#editor.saving .ed-steps { opacity: .7; }
.ghost-btn:disabled, .round-btn:disabled { opacity: .45; cursor: not-allowed; }
.ghost-btn:disabled:hover { background: none; }
.round-btn:disabled:hover { transform: none; box-shadow: none; }

.modal-foot { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-top: 1px solid #e2e2e2; }
.spacer { flex: 1; }
.ghost-btn { display: inline-flex; align-items: center; gap: 6px; border: 0; background: none; font-size: 12px; padding: 10px 12px; border-radius: 999px; }
.ghost-btn:hover { background: rgba(0,0,0,.05); }
.ghost-btn.danger { color: #b4614a; }
.ghost-btn svg { width: 14px; height: 14px; }
.primary-btn {
  display: inline-flex; align-items: center; gap: 8px; border: 0; background: var(--ink); color: #fff;
  font-size: 12px; font-weight: 600; padding: 11px 18px; border-radius: 999px;
  transition: transform .15s;
}
.primary-btn:hover { transform: translateY(-1px); }
.primary-btn:disabled { opacity: .6; cursor: progress; }
.primary-btn svg { width: 15px; height: 15px; }

/* ---------- Photo frames (shared) ---------- */
.photo-frame { --bc: #fbf6e9; position: relative; background: var(--bc); box-shadow: 0 10px 24px rgba(0,0,0,.16); }
.photo-inner { position: relative; aspect-ratio: 1; background: #f1e7d8; overflow: hidden; display: grid; place-items: center; }
.photo-inner img { width: 100%; height: 100%; object-fit: cover; display: block; }
.frame-empty { padding: 14px; text-align: center; font-size: 11px; color: #a08f80; line-height: 1.4; }
/* Neutral slot while a photo loads, or when it's offline and not cached (7.5) */
.frame-loading {
  position: absolute; inset: 0;
  background: linear-gradient(110deg, #efe4d3 30%, #f7efe3 50%, #efe4d3 70%) 0 0 / 220% 100%;
  animation: frame-shimmer 1.6s linear infinite;
}
@keyframes frame-shimmer { to { background-position: -220% 0; } }
.frame-loading.idle { animation: none; background: #efe4d3; }
.lb-photo .frame-loading { position: static; display: block; aspect-ratio: 1; width: 100%; }
@media (prefers-reduced-motion: reduce) { .frame-loading { animation: none; } }
.photo-frame.polaroid { padding: 7% 7% 24%; border-radius: 2px; }
.photo-frame.postage {
  padding: 9%;
  --p: 5px;
  -webkit-mask: radial-gradient(circle var(--p) at var(--p) var(--p), #0000 98%, #000) calc(-1 * var(--p)) calc(-1 * var(--p)) / calc(var(--p) * 3) calc(var(--p) * 3) round;
  mask: radial-gradient(circle var(--p) at var(--p) var(--p), #0000 98%, #000) calc(-1 * var(--p)) calc(-1 * var(--p)) / calc(var(--p) * 3) calc(var(--p) * 3) round;
  filter: drop-shadow(0 8px 14px rgba(0,0,0,.18));
  box-shadow: none;
}
.photo-frame.postage .photo-inner { outline: 1px solid rgba(0,0,0,.08); }
.photo-frame.ticket {
  padding: 7% 11%;
  border-radius: 6px;
  -webkit-mask: radial-gradient(circle 9px at 0 50%, #0000 98%, #000) left / 51% 100% no-repeat, radial-gradient(circle 9px at 100% 50%, #0000 98%, #000) right / 51% 100% no-repeat;
  mask: radial-gradient(circle 9px at 0 50%, #0000 98%, #000) left / 51% 100% no-repeat, radial-gradient(circle 9px at 100% 50%, #0000 98%, #000) right / 51% 100% no-repeat;
  filter: drop-shadow(0 8px 14px rgba(0,0,0,.18));
  box-shadow: none;
}
.photo-frame.ticket .photo-inner { aspect-ratio: 4 / 3; outline: 1.5px dashed color-mix(in srgb, var(--bc) 60%, #fff); outline-offset: 4px; }

/* ---------- Viewer ---------- */
.viewer {
  position: fixed; inset: 0; z-index: 50; overflow-y: auto;
  background: rgba(246,246,246,.72);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  animation: fade .25s ease;
}
.viewer-close { position: fixed; right: 22px; top: 22px; background: var(--cream); z-index: 2; width: 30px; height: 30px; }
.viewer-inner { min-height: 100%; display: flex; flex-direction: column; align-items: center; padding: 40px 0 30px; overflow-x: hidden; }
.date-pill {
  position: relative; z-index: 6;
  display: flex; align-items: center; gap: 40px; padding: 18px 32px; border-radius: 999px;
  background: rgba(250,246,238,.92); box-shadow: 0 6px 24px rgba(160,130,90,.08);
}
.date-pill .round-btn { width: 30px; height: 30px; }
.date-pill-text { text-align: center; min-width: 190px; }
.date-big { font-family: var(--display); font-size: 21px; letter-spacing: -.02em; color: #5a4a40; margin-top: 6px; }
.date-year { font-family: var(--mono); font-size: 8px; color: var(--tan); margin-top: 4px; }

/* Shared pocket: who tucked it in + packet switcher (3.4, 3.5) */
.owner-line {
  position: relative; z-index: 6; display: inline-flex; align-items: center; gap: 6px; max-width: calc(100% - 32px);
  margin: 12px 0 0; font-size: 11.5px; color: #7a6a5e;
}
.owner-line strong { font-weight: 600; color: var(--ink-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pk-switch {
  position: relative; z-index: 6; display: inline-flex; gap: 4px; max-width: calc(100% - 32px); margin-top: 10px;
  padding: 3px; border-radius: 999px; background: rgba(250,246,238,.92); box-shadow: 0 6px 24px rgba(160,130,90,.08);
}
.pk-opt {
  display: inline-flex; align-items: center; gap: 6px; min-width: 0; max-width: 150px;
  border: 0; background: none; padding: 6px 12px 6px 9px; border-radius: 999px;
  font-size: 11.5px; color: var(--ink-soft); transition: background .2s, box-shadow .2s;
}
.pk-opt .pk-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pk-opt:hover { background: rgba(255,255,255,.6); }
.pk-opt[aria-pressed="true"] { background: #fff; font-weight: 600; color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.pk-opt:focus-visible { outline: 2px solid #9db8e8; outline-offset: 2px; }

/* Clothesline scene */
.scene { position: relative; width: 100%; display: flex; flex-direction: column; align-items: center; padding-top: 34px; margin-top: 8px; }
.rope {
  position: absolute; left: 0; right: 0; top: 18px; height: 2px; z-index: 1;
  background: linear-gradient(#dcc09a, #b58d5b); box-shadow: 0 1px 1px rgba(0,0,0,.08);
  transition: opacity .45s ease;
}
.line-track { position: absolute; left: 50%; top: 0; height: 0; z-index: 2; transition: transform .55s cubic-bezier(.3,.8,.3,1), opacity .45s ease; }
.line-item {
  position: absolute; top: 6px; width: 124px; transform: translateX(-50%);
  border: 0; background: none; padding: 0;
  display: flex; flex-direction: column; align-items: center;
  transition: opacity .3s, transform .3s;
}
.line-item:hover { transform: translateX(-50%) rotate(-2deg); }
.line-item .peg { position: relative; z-index: 2; width: 10px; height: 26px; }
.line-item .li-body { display: block; width: 124px; margin-top: -14px; }
.line-item .packet-svg { width: 100%; height: auto; filter: drop-shadow(0 10px 12px rgba(0,0,0,.12)); }
.line-item .li-pack { position: relative; display: block; }
.line-item .li-body.pair { display: flex; justify-content: center; gap: 4px; }
.line-item .li-body.pair .li-pack { width: calc(50% - 2px); }
.line-item .li-dot {
  position: absolute; top: 9%; right: 2%; width: 10px; height: 10px; border-radius: 50%;
  border: 2px solid #fff; box-shadow: 0 1px 2px rgba(0,0,0,.15);
}
.line-item .li-body.pair .li-dot { width: 8px; height: 8px; border-width: 1.5px; }
.li-empty {
  display: grid; place-items: center; height: 170px; border: 1.5px dashed #dcd4c8; border-radius: 4px;
  background: rgba(250,247,240,.75); font-family: var(--mono); font-size: 8.5px; letter-spacing: .16em;
  text-transform: uppercase; color: #b4a893;
}
.li-label { margin-top: 8px; font-family: var(--mono); font-size: 8.5px; letter-spacing: .14em; text-transform: uppercase; color: #9c8a76; }
.line-item.current { opacity: 0; pointer-events: none; }
.scene.focus .rope, .scene.focus .line-track { opacity: 0; pointer-events: none; }

/* Pendulum swing when moving between days (pivot = the peg) */
.line-item .li-body, .blank-ghost, .stage .pk-wrap { transform-origin: 50% 0; }
.scene.swinging .line-item .li-body { animation: pendulum 1.5s cubic-bezier(.35,.05,.4,1) both; --k: .7; }
.scene.swinging .line-item:nth-child(odd) .li-body { animation-duration: 1.65s; --k: .55; }
.scene.swinging .blank-ghost { animation: pendulum 1.8s cubic-bezier(.35,.05,.4,1) both; --k: 1; }
.scene.swinging .stage .pk-wrap { animation: pendulum 1.6s cubic-bezier(.35,.05,.4,1) both; --k: .5; }
@keyframes pendulum {
  0%   { rotate: 0deg; }
  14%  { rotate: calc(var(--amp, 12deg) * var(--k, 1)); }
  34%  { rotate: calc(var(--amp, 12deg) * var(--k, 1) * -.55); }
  52%  { rotate: calc(var(--amp, 12deg) * var(--k, 1) * .3); }
  68%  { rotate: calc(var(--amp, 12deg) * var(--k, 1) * -.15); }
  84%  { rotate: calc(var(--amp, 12deg) * var(--k, 1) * .06); }
  100% { rotate: 0deg; }
}

.blank { position: relative; z-index: 3; display: flex; flex-direction: column; align-items: center; text-align: center; padding: 0 16px; animation: fade .3s ease; }
.blank-peg { position: absolute; top: -28px; width: 10px; height: 26px; z-index: 2; }
.blank-ghost { width: 120px; margin-top: -12px; opacity: .55; transform: rotate(4deg); filter: saturate(.7); }
.blank-ghost .packet-svg { width: 100%; height: auto; }
.blank h3 { font-family: var(--display); font-weight: 400; font-size: 21px; letter-spacing: -.02em; color: #5a4a40; margin: 6px 0 6px; }
.blank p { margin: 0 0 18px; font-size: 11.5px; color: var(--muted); }

/* Packet stage */
.stage {
  position: relative; z-index: 3; width: min(240px, 62vw); aspect-ratio: 200 / 280;
  margin: 0 0 34px; touch-action: none; user-select: none; -webkit-user-select: none;
}
.stage .pk-wrap { position: absolute; inset: 0; transition: transform .25s ease-out; transform-style: preserve-3d; }
.stage .packet-svg { position: absolute; inset: 0; width: 100%; height: 100%; filter: drop-shadow(0 22px 26px rgba(40,80,160,.18)); }
.stage.squish .pk-wrap { animation: squish .35s ease; }
.stage.pull { cursor: crosshair; }
.stage .peg-top { position: absolute; left: 50%; top: -9%; width: 4.5%; height: 14%; transform: translateX(-50%); z-index: 6; }
.stage .dent {
  position: absolute; z-index: 5; width: 70px; height: 70px; margin: -35px 0 0 -35px; border-radius: 50%; pointer-events: none;
  background: radial-gradient(circle at 46% 44%, rgba(0,0,0,.24), rgba(0,0,0,.1) 36%, rgba(255,255,255,.35) 54%, rgba(255,255,255,0) 70%);
  mix-blend-mode: multiply;
  animation: dent 2.6s ease-out forwards;
}
.stage .shine {
  position: absolute; z-index: 5; pointer-events: none; width: 90px; height: 90px; margin: -45px 0 0 -45px; border-radius: 50%;
  background: radial-gradient(circle, rgba(255,255,255,.55), rgba(255,255,255,0) 65%);
  mix-blend-mode: screen; animation: dent 1.6s ease-out forwards;
}

/* Torn pieces + photos */
.stage .piece { pointer-events: none; transform-origin: 50% 50%; transition: transform .75s cubic-bezier(.2,1.25,.35,1); }
.stage .piece .piece-hit { pointer-events: visiblePainted; cursor: grab; }
.stage .piece.dragging { transition: none; }
.stage .piece.dragging .piece-hit { cursor: grabbing; }
.stage .piece.upper { z-index: 3; }
.stage .piece.lower { z-index: 1; }
.stage .spill { position: absolute; inset: 0; z-index: 2; pointer-events: none; }
.stage .pf {
  position: absolute; width: 50%; pointer-events: auto; cursor: grab; touch-action: none;
  transform: translate(-50%, -12%);
  transition: transform .7s cubic-bezier(.2,1.2,.35,1) .12s, opacity .35s ease .12s, box-shadow .2s;
}
.stage .pf.dragging { transition: none; cursor: grabbing; box-shadow: 0 18px 34px rgba(0,0,0,.22); }
.stage.joining .pf { transition-delay: 0s; }

.viewer-hint { font-size: 11.5px; font-weight: 500; color: #7a6a5e; margin: 0 0 14px; text-align: center; min-height: 1em; }
.viewer-actions {
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  padding: 12px 18px 14px; border-radius: 22px; background: rgba(250,246,238,.7);
}
.viewer-actions .row { display: flex; gap: 22px; flex-wrap: wrap; justify-content: center; }
.text-btn {
  display: inline-flex; align-items: center; gap: 5px; border: 0; background: none; font-size: 11px; color: var(--ink-soft);
  text-decoration: underline; text-underline-offset: 3px; text-decoration-color: rgba(0,0,0,.35); padding: 4px 2px;
}
.text-btn:disabled { opacity: .4; cursor: default; }
.text-btn svg { width: 12px; height: 12px; }
.pull-btn {
  display: inline-flex; align-items: center; gap: 8px; border: 1px solid #e3ddd4; background: #fff;
  font-size: 11.5px; padding: 9px 16px; border-radius: 999px; transition: background .2s, color .2s;
}
.pull-btn svg { width: 15px; height: 15px; }
.pull-btn.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.pull-btn:disabled { opacity: .45; cursor: default; }

/* ---------- Lightbox ---------- */
.lightbox {
  position: fixed; inset: 0; z-index: 60; background: rgba(28,24,22,.82);
  display: grid; place-items: center; animation: fade .2s ease;
}
.lb-photo { width: min(78vw, 560px); }
.lb-photo .photo-frame { width: 100%; animation: pop .25s ease; }
.lb-photo .photo-inner { aspect-ratio: auto; max-height: 72vh; }
.lb-photo .photo-inner img { max-height: 72vh; object-fit: contain; background: #111; }
.lb-photo .photo-frame.ticket .photo-inner { aspect-ratio: auto; }
.lb-close { position: fixed; right: 22px; top: 22px; }
.lb-nav { position: fixed; top: 50%; transform: translateY(-50%); }
.lb-nav:hover { transform: translateY(calc(-50% - 1px)); }
.lb-prev { left: 22px; }
.lb-next { right: 22px; }
.lb-count { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); color: #eee; font-family: var(--mono); font-size: 11px; }

/* ---------- Confirm dialog ---------- */
.confirm-overlay {
  position: fixed; inset: 0; z-index: 80;
  display: grid; place-items: center; padding: 16px;
  background: rgba(40,34,30,.32);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  animation: fade .18s ease;
}
.confirm-card {
  position: relative; width: min(360px, 100%);
  padding: 74px 26px 20px; margin-top: 50px;
  background: var(--cream); border-radius: 26px; text-align: center;
  box-shadow: 0 30px 70px rgba(60,40,20,.22), 0 2px 6px rgba(0,0,0,.05);
  animation: pop .26s cubic-bezier(.2,1.3,.4,1);
}
.cf-packet {
  position: absolute; left: 50%; top: -58px; width: 92px;
  transform: translateX(-50%) rotate(-6deg); transform-origin: 50% 0;
  animation: cfSwing 2.4s ease-in-out infinite;
}
.cf-packet .packet-svg { width: 100%; height: auto; filter: drop-shadow(0 14px 16px rgba(0,0,0,.18)); }
.confirm-card .eyebrow { color: #c08a72; }
.confirm-card h2 { font-family: var(--display); font-weight: 500; font-size: 22px; letter-spacing: -.025em; color: #4c3f38; margin: 10px 0 8px; }
.confirm-card p { margin: 0 auto 22px; max-width: 280px; font-size: 12.5px; line-height: 1.55; color: var(--muted); }
.cf-actions { display: flex; gap: 8px; justify-content: center; }
.cf-actions .ghost-btn { padding: 11px 18px; font-weight: 500; background: rgba(0,0,0,.04); }
.cf-actions .ghost-btn:hover { background: rgba(0,0,0,.08); }
.primary-btn.danger { background: #c4654c; }
.primary-btn.danger:hover { background: #b2563e; }
.confirm-overlay.leaving { animation: fade .2s ease reverse forwards; }
.confirm-overlay.removing .cf-packet { animation: cfDrop .45s cubic-bezier(.5,0,.8,.4) forwards; }
@keyframes cfSwing { 0%,100% { transform: translateX(-50%) rotate(-6deg); } 50% { transform: translateX(-50%) rotate(3deg); } }
@keyframes cfDrop { to { transform: translateX(-50%) translateY(60px) rotate(18deg) scale(.6); opacity: 0; } }

.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%); z-index: 70;
  background: var(--ink); color: #fff; font-size: 12px; padding: 10px 16px; border-radius: 999px;
  box-shadow: 0 10px 30px rgba(0,0,0,.2); animation: rise .3s ease;
}

/* ---------- Animations ---------- */
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: scale(.96); } }
@keyframes rise { from { opacity: 0; transform: translate(-50%, 10px); } }
@keyframes sway { 0%,100% { transform: translateX(-50%) rotate(0); } 25% { transform: translateX(-50%) rotate(3deg); } 75% { transform: translateX(-50%) rotate(-3deg); } }
@keyframes drop {
  0% { transform: translateX(-50%) translateY(-40px) scale(.6); opacity: 0; }
  60% { opacity: 1; }
  100% { transform: translateX(-50%) translateY(0) scale(1); }
}
@keyframes wiggle { 0%,100% { transform: translateX(-10%) rotate(0); } 30% { transform: translateX(-10%) rotate(-4deg) scale(1.03); } 65% { transform: translateX(-10%) rotate(3deg); } }
@keyframes squish { 40% { transform: scale(.985, .97); } }
@keyframes dent { 0% { opacity: 0; transform: scale(.4); } 12% { opacity: 1; transform: scale(1); } 100% { opacity: 0; transform: scale(1.1); } }
@keyframes flyoff {
  0% { transform: translate(0,0) rotate(0); opacity: 1; }
  100% { transform: translate(-60px,-150px) rotate(-28deg); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  .app { padding: 16px 16px 30px; }
  .topbar { grid-template-columns: 1fr auto; }
  .month-nav { grid-column: 1 / -1; grid-row: 2; justify-content: center; }
  .brand-tag { display: none; }
  .tucked span { display: none; }
  .sheet { padding: 22px 12px 18px; border-radius: 22px; }
  .sheet-head { flex-direction: column; align-items: flex-start; }
  h1 { font-size: 27px; }
  .cell { height: 92px; }
  .cell .hang { width: 44px; top: 18px; }
  .cell .peg { width: 8px; height: 20px; top: 11px; }
  .num { top: 6px; left: 6px; font-size: 9.5px; }
  .cell .plus { width: 22px; height: 22px; }
  .cell .count { display: none; }

  .modal { height: 100%; }
  .modal-head { padding: 18px 18px 12px; }
  .modal-head h2 { font-size: 22px; }
  .modal-body { grid-template-columns: 1fr; overflow-y: auto; }
  .ed-preview { border-right: 0; border-bottom: 1px solid #e2e2e2; min-height: 300px; }
  .ed-packet { width: 150px; }
  .ed-border-preview { width: 120px; right: 8%; bottom: 10%; }
  .ed-steps { overflow: visible; padding: 10px 12px 16px; }
  .stickers { grid-template-columns: repeat(6, 1fr); }
  .line-item, .line-item .li-body { width: 96px; }
  .li-empty { height: 132px; }
  .cell .more { opacity: 1; top: 3px; right: 2px; }
  .date-pill { gap: 14px; padding: 14px 16px; }
  .date-pill-text { min-width: 150px; }
  .date-big { font-size: 18px; }
}
@media (max-width: 420px) {
  .weekdays span { font-size: 8px; letter-spacing: .04em; }
  .cell { height: 78px; }
  .cell .hang { width: 36px; }
  /* Two packets stay separately tappable: no overlap, each takes half the cell. */
  .cell.pair { --ov: 0px; }
  .cell.pair .hang { width: 50%; }
  .cell .owner-dot { width: 8px; height: 8px; top: 4px; right: -2px; border-width: 1.5px; }
  .cell .plus.corner { left: 2px; bottom: 2px; width: 18px; height: 18px; }
  .cell.today .num { padding: 1px 4px; left: 3px; top: 4px; }
}

/* ---------- Shared pocket: sign-in, profile, user chip, offline ---------- */
body.auth-pending .app { visibility: hidden; }
/* Read-only (offline): write entry points stay clickable so guardWrite() can explain (7.3) */
body.read-only [data-write], body.read-only .cell:hover .plus[data-write] { opacity: .45; }
.status .status-retry { margin: 0; width: auto; padding: 0 2px; font-size: inherit; color: var(--ink); cursor: pointer; }

/* Above the app, viewer and lightbox; below the toast (70) and #confirm (80). */
.auth-overlay { z-index: 65; overflow-y: auto; }
.auth-card { margin: 50px auto 0; text-align: center; }
.auth-card:focus { outline: none; }
.auth-card :focus-visible { outline: 2px solid #9db8e8; outline-offset: 2px; }
.auth-brand { display: inline-flex; align-items: center; gap: 8px; }
.auth-brand .logo { width: 20px; height: 20px; }
.auth-brand .logo i { width: 12px; height: 12px; }
.auth-brand .logo i:nth-child(2) { left: 7px; top: 2px; }
.auth-brand .logo i:nth-child(3) { left: 3px; top: 8px; }
.confirm-card .auth-lead { margin: 0 auto 16px; }
.confirm-card .auth-notice {
  margin: 0 0 14px; max-width: none; padding: 10px 12px; border-radius: 12px;
  background: rgba(192,138,114,.12); color: #8a5f4c; font-size: 11.5px; line-height: 1.5;
}
.auth-field { display: flex; flex-direction: column; gap: 6px; margin: 0 0 12px; text-align: left; }
.auth-field > span {
  font-family: var(--mono); font-size: 9.5px; letter-spacing: .14em; text-transform: uppercase; color: var(--tan);
  padding-left: 4px;
}
.auth-field input {
  width: 100%; font: inherit; font-size: 13px; color: var(--ink);
  padding: 11px 14px; border-radius: 14px; border: 1px solid #e8dfd2; background: #fff;
  transition: border-color .15s, box-shadow .15s;
}
.auth-field input:focus { outline: none; border-color: #c9b59c; box-shadow: 0 0 0 3px rgba(179,154,126,.18); }
.auth-card .auth-field input:focus-visible { outline: none; }
.auth-field input:disabled { background: #f4f0e9; color: var(--muted); cursor: not-allowed; }
.auth-field input[aria-invalid="true"] { border-color: #d99a86; }
.confirm-card .auth-error {
  margin: 0 0 12px; max-width: none; min-height: 0; padding: 10px 12px; border-radius: 10px;
  background: #fff1ec; color: #b4614a; font-size: 11.5px; line-height: 1.5; text-align: left;
}
.confirm-card .auth-error:empty { padding: 0; margin: 0; background: none; }
.auth-submit { width: 100%; justify-content: center; margin-top: 6px; padding: 12px 18px; }
.auth-submit:disabled { cursor: not-allowed; }
.auth-submit[aria-busy="true"] { cursor: progress; }

/* Profile dialog */
.profile-card { padding-top: 28px; margin-top: 0; }
.pf-tag {
  display: inline-flex; align-items: center; gap: 8px; max-width: 100%;
  margin: 2px 0 18px; padding: 7px 14px 7px 10px; border-radius: 999px;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.08); font-size: 12px; font-weight: 500;
}
.pf-tag span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pf-tag .empty { color: var(--muted); font-weight: 400; }
.uc-dot.empty { background: #e6ddd0; }
.id-swatches { justify-content: center; gap: 14px; padding: 6px 2px 4px; }
.id-swatch { cursor: pointer; }
.id-swatch.taken { cursor: not-allowed; opacity: .55; }
.id-swatch.taken:hover { transform: none; }
.sw-lock {
  position: absolute; right: -5px; bottom: -5px; width: 16px; height: 16px; border-radius: 50%;
  display: grid; place-items: center; background: #fff; color: var(--ink-soft);
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.sw-lock svg { width: 9px; height: 9px; }
.profile-card .cf-actions { margin-top: 6px; }

/* User chip + menu */
.user-chip-wrap { position: relative; }
.user-chip-wrap:empty { display: none; }
.user-chip { max-width: 180px; }
.uc-dot {
  width: 10px; height: 10px; border-radius: 50%; flex: none;
  box-shadow: inset 0 -1px 2px rgba(0,0,0,.15);
}
.uc-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.uc-initial { display: none; font-weight: 600; }
.user-chip:focus-visible { outline: 2px solid #9db8e8; outline-offset: 2px; }
.user-menu { right: 0; top: calc(100% + 8px); }

/* Offline badge */
.offline-badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 999px;
  background: #fff1ec; color: #b4614a; font-family: var(--mono); font-size: 9.5px;
  letter-spacing: .12em; text-transform: uppercase;
}
.offline-badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: #d98a72; }

@media (max-width: 860px) {
  .auth-field input { font-size: 16px; }
  .uc-name { display: none; }
  .uc-initial { display: inline; }
  .user-chip { padding: 7px 10px; }
  body.is-offline .tucked { display: none; }
}
@media (max-width: 420px) {
  .auth-card { padding-left: 20px; padding-right: 20px; }
  .id-swatches { gap: 12px; }
  .top-right { gap: 6px; }
}
