:root {
  --paper: #f4efe7;
  --card: #fffaf3;
  --ink: #221e1a;
  --muted: #7b7166;
  --line: #e2d9cb;
  --accent: #c2562f;
  --gap: 4px;
  --radius: 7px;
  --cell-max: 172px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #14120f;
    --card: #1e1b17;
    --ink: #f1ebe2;
    --muted: #9b9186;
    --line: #2f2a24;
    --accent: #e3825a;
  }
}
@media (min-width: 700px) { :root { --gap: 6px; --radius: 9px; } }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 76px; }
html:has(dialog[open]) { overflow: hidden; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.45 var(--sans);
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
}
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.error { color: #c0392b; margin: 0.4rem 0 0; }
@media (prefers-color-scheme: dark) { .error { color: #ff8a7a; } }

.brand {
  font: italic 600 1.7rem/1 var(--serif);
  letter-spacing: -0.01em;
  margin: 0;
}

/* ---------- buttons ---------- */
.btn {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 999px;
  padding: 0.6rem 1.15rem;
  cursor: pointer;
  font-weight: 550;
  white-space: nowrap;
  transition: transform 0.1s, background 0.15s;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn.primary { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.btn.block { display: block; width: 100%; margin-top: 0.5rem; }
.icon-btn {
  border: 0; background: transparent; cursor: pointer;
  width: 42px; height: 42px; border-radius: 50%;
  display: inline-grid; place-items: center;
  font-size: 1.25rem; line-height: 1;
}
.icon-btn:hover { background: color-mix(in oklab, var(--ink) 8%, transparent); }

/* ---------- header ---------- */
.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 0.75rem;
  padding: calc(0.6rem + env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) 0.6rem max(1rem, env(safe-area-inset-left));
  background: color-mix(in oklab, var(--paper) 82%, transparent);
  backdrop-filter: saturate(1.4) blur(14px);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid color-mix(in oklab, var(--line) 60%, transparent);
}
.jump {
  flex: 1; min-width: 0;
  display: flex; gap: 0.35rem; overflow-x: auto; scrollbar-width: none;
  mask-image: linear-gradient(90deg, #000 85%, transparent);
}
.jump::-webkit-scrollbar { display: none; }
.chip {
  flex: none; text-decoration: none; color: var(--muted);
  font-size: 0.82rem; font-weight: 550;
  padding: 0.3rem 0.65rem; border-radius: 999px;
  border: 1px solid var(--line);
}
.chip:hover { color: var(--ink); border-color: var(--muted); }
.add-desktop { display: none; }
@media (min-width: 700px) {
  .add-desktop { display: inline-block; }
}

/* ---------- boards ---------- */
main {
  padding: 1.25rem max(0.75rem, env(safe-area-inset-right)) calc(6rem + env(safe-area-inset-bottom)) max(0.75rem, env(safe-area-inset-left));
}
@media (min-width: 700px) { main { padding-inline: 2rem; } }
.month { margin: 0 auto 3.5rem; }
@media (min-width: 700px) { .month { margin-bottom: 5rem; } }

.board-wrap {
  container-type: inline-size;
  width: 100%;
  max-width: calc(var(--c) * var(--cell-max));
  margin-inline: auto;
}
.board {
  --cell: calc((100cqw - (var(--c) - 1) * var(--gap)) / var(--c));
  display: grid;
  grid-template-columns: repeat(var(--c), minmax(0, 1fr));
  grid-auto-rows: var(--cell);
  gap: var(--gap);
}

.tile {
  position: relative;
  overflow: hidden;
  border: 0; padding: 0; margin: 0;
  border-radius: var(--radius);
  background: var(--tile, var(--line));
  cursor: pointer;
  display: block;
  min-width: 0;
}
.tile img {
  width: 100%; height: 100%; object-fit: cover; display: block;
  opacity: 0; transition: opacity 0.4s, transform 0.5s cubic-bezier(.2,.7,.2,1);
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.tile img.loaded { opacity: 1; }
.tile:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
@media (hover: hover) {
  .tile:hover img { transform: scale(1.04); }
}
.tile .cap {
  position: absolute; inset: auto 0 0 0;
  padding: 1.6rem 0.6rem 0.5rem;
  font-size: 0.8rem; line-height: 1.3; text-align: left;
  color: #fff;
  background: linear-gradient(transparent, rgb(0 0 0 / 0.62));
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
  opacity: 0; transition: opacity 0.25s;
  pointer-events: none;
}
@media (hover: hover) { .tile:hover .cap, .tile:focus-visible .cap { opacity: 1; } }
/* Touch screens: a small speech-bubble dot marks photos with a comment. */
@media (hover: none) {
  .tile.has-comment::after {
    content: ""; position: absolute; right: 6px; bottom: 6px;
    width: 9px; height: 9px; border-radius: 50% 50% 50% 2px;
    background: #fff; box-shadow: 0 0 0 1.5px rgb(0 0 0 / 0.25);
  }
}
.filler {
  cursor: default;
  background: color-mix(in oklab, var(--tile) var(--o, 16%), var(--paper));
}
.add-tile {
  background: transparent;
  border: 1.5px dashed var(--line);
  color: var(--muted);
  font-size: 1.4rem;
  display: grid; place-items: center;
}
.add-tile:hover { border-color: var(--muted); color: var(--ink); }

/* The month tile in the middle. Sizes scale with the board (cqw = 1% of the board width). */
.center {
  --cw: calc(var(--cell) * 2 + var(--gap));
  border: 0; margin: 0; cursor: pointer;
  border-radius: calc(var(--radius) * 1.6);
  padding: calc(var(--cw) * 0.08);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: calc(var(--cw) * 0.025);
  text-align: center;
  color: var(--ink);
  background:
    radial-gradient(120% 90% at 0% 0%, var(--g1), transparent 60%),
    radial-gradient(120% 90% at 100% 100%, var(--g3), transparent 60%),
    var(--g2);
  box-shadow: inset 0 0 0 1px color-mix(in oklab, var(--ink) 7%, transparent);
  min-width: 0; overflow: hidden;
}
.c-year {
  font: 600 calc(var(--cw) * 0.058)/1 var(--sans);
  letter-spacing: 0.32em; text-indent: 0.32em;
  color: color-mix(in oklab, var(--ink) 62%, transparent);
}
.c-month {
  font: italic 500 calc(var(--cw) * 0.165)/1.02 var(--serif);
  letter-spacing: -0.015em;
  max-width: 100%;
}
.c-caption {
  font: italic calc(var(--cw) * 0.06)/1.3 var(--serif);
  max-width: 92%;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
  color: color-mix(in oklab, var(--ink) 82%, transparent);
}
.c-caption.placeholder { opacity: 0.5; }
.c-count {
  margin-top: calc(var(--cw) * 0.02);
  font: 550 calc(var(--cw) * 0.047)/1 var(--sans);
  letter-spacing: 0.04em;
  color: color-mix(in oklab, var(--ink) 55%, transparent);
}
.center:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.empty { text-align: center; color: var(--muted); margin-top: 20vh; }
body.dropping main { outline: 3px dashed var(--accent); outline-offset: -12px; border-radius: 16px; }

/* ---------- floating add button (phones) ---------- */
.fab {
  position: fixed; z-index: 11;
  right: max(1.1rem, env(safe-area-inset-right));
  bottom: calc(1.1rem + env(safe-area-inset-bottom));
  width: 60px; height: 60px; border-radius: 50%;
  border: 0; cursor: pointer;
  background: var(--ink); color: var(--paper);
  font-size: 1.7rem; line-height: 1;
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.22), 0 2px 6px rgb(0 0 0 / 0.15);
  transition: transform 0.12s;
}
.fab:active { transform: scale(0.94); }
@media (min-width: 700px) { .fab { display: none; } }

/* ---------- login ---------- */
.login {
  min-height: 100dvh; display: grid; place-items: center; padding: 1.5rem;
}
.login-card {
  width: min(340px, 100%);
  display: flex; flex-direction: column; align-items: center; gap: 0.8rem;
  text-align: center;
}
.login-card .brand { font-size: 2.6rem; }
.login-card p { margin: 0 0 0.6rem; }
.login-card input, .sheet input[type=text], .sheet textarea {
  width: 100%;
  font: inherit; color: var(--ink);
  background: var(--card);
  border: 1px solid var(--line); border-radius: 12px;
  padding: 0.75rem 0.9rem;
}
.login-card input:focus, .sheet input:focus, .sheet textarea:focus, .lb-panel textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.login-card .btn { width: 100%; padding-block: 0.75rem; }
.login-mark {
  display: grid; grid-template-columns: repeat(4, 22px); grid-auto-rows: 22px; gap: 4px; margin-bottom: 0.6rem;
}
.login-mark i { border-radius: 5px; background: var(--line); }
.login-mark i:nth-child(1) { background: #d98b5f; }
.login-mark i:nth-child(3) { background: #7fa38a; }
.login-mark i:nth-child(7) { background: #6d8fb8; }
.login-mark i:nth-child(9) { background: #e0b75a; }
.login-mark b { grid-column: 2 / span 2; grid-row: 2 / span 2; border-radius: 8px; background: var(--ink); }

/* ---------- sheets (dialogs) ---------- */
dialog { color: var(--ink); }
dialog::backdrop { background: rgb(20 16 12 / 0.45); backdrop-filter: blur(3px); }
.sheet {
  border: 0; padding: 0;
  background: var(--paper);
  border-radius: 20px;
  width: min(600px, calc(100vw - 2rem));
  max-height: min(86dvh, 900px);
  box-shadow: 0 30px 80px rgb(0 0 0 / 0.3);
}
.small-sheet { width: min(420px, calc(100vw - 2rem)); }
@media (max-width: 600px) {
  .sheet:not(.small-sheet) {
    width: 100vw; max-width: 100vw; margin: auto 0 0;
    border-radius: 20px 20px 0 0;
    max-height: 92dvh;
  }
}
.sheet-inner { display: flex; flex-direction: column; padding: 1.1rem 1.2rem calc(1.1rem + env(safe-area-inset-bottom)); gap: 0.75rem; max-height: inherit; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-head h2 { margin: 0; font: italic 500 1.5rem/1.1 var(--serif); }
.sheet p { margin: 0; }
.sheet-actions { display: flex; justify-content: flex-end; gap: 0.6rem; }
.up-list {
  list-style: none; margin: 0; padding: 0;
  overflow-y: auto; min-height: 0; flex: 1;
  display: flex; flex-direction: column; gap: 0.6rem;
}
.up-item { display: grid; grid-template-columns: 76px 1fr; gap: 0.75rem; align-items: start; }
.up-item textarea { resize: none; min-height: 76px; }
.up-thumb {
  position: relative; width: 76px; height: 76px; border-radius: 10px; overflow: hidden;
  background: var(--line); display: grid; place-items: center;
}
.up-thumb img { width: 100%; height: 100%; object-fit: cover; }
.up-name { font-size: 0.65rem; padding: 0.3rem; word-break: break-all; color: var(--muted); }
.up-status {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-size: 1.6rem; font-weight: 700; color: #fff;
}
.up-item.busy .up-status { background: rgb(0 0 0 / 0.35); }
.up-item.busy .up-status::after {
  content: ""; width: 24px; height: 24px; border-radius: 50%;
  border: 3px solid rgb(255 255 255 / 0.35); border-top-color: #fff;
  animation: spin 0.8s linear infinite;
}
.up-item.done .up-status { background: rgb(40 120 70 / 0.55); }
.up-item.error .up-status { background: rgb(180 40 30 / 0.6); }
@keyframes spin { to { transform: rotate(360deg); } }
.progress { height: 4px; border-radius: 4px; background: var(--line); overflow: hidden; }
.progress i { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.3s; }

/* ---------- lightbox ---------- */
.lightbox {
  width: 100vw; height: 100dvh; max-width: none; max-height: none;
  margin: 0; padding: 0; border: 0;
  background: #0d0c0b; color: #f3eee7;
  overflow: hidden;
}
.lightbox[open] {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas: "top" "stage" "panel";
}
.lightbox::backdrop { background: #000; }
.lb-top {
  grid-area: top;
  display: flex; align-items: center; gap: 0.25rem;
  padding: calc(0.4rem + env(safe-area-inset-top)) 0.6rem 0.4rem;
}
.lb-count { flex: 1; text-align: center; font-size: 0.85rem; opacity: 0.7; font-variant-numeric: tabular-nums; }
.lightbox .icon-btn:hover { background: rgb(255 255 255 / 0.1); }
#lbStar.on { color: #f3c55c; }
.lb-stage {
  grid-area: stage; position: relative;
  display: grid; place-items: center;
  padding: 0 0.5rem;
  touch-action: pan-y pinch-zoom;
  min-height: 0;
}
.lb-stage img {
  max-width: 100%; max-height: 100%;
  width: auto; height: auto;
  object-fit: contain;
  border-radius: 6px;
  background-size: cover; background-position: center;
  user-select: none; -webkit-user-select: none;
}
.lb-nav {
  position: absolute; top: 50%; translate: 0 -50%;
  width: 48px; height: 72px; border: 0; border-radius: 12px;
  background: rgb(255 255 255 / 0.06); color: #fff;
  font-size: 2.2rem; cursor: pointer; display: none;
}
.lb-nav:hover:not(:disabled) { background: rgb(255 255 255 / 0.14); }
.lb-nav:disabled { opacity: 0.15; cursor: default; }
.lb-nav.prev { left: 0.75rem; }
.lb-nav.next { right: 0.75rem; }
@media (hover: hover) and (pointer: fine) { .lb-nav { display: block; } .lb-stage { padding: 0 4.5rem; } }
.lb-panel {
  grid-area: panel;
  padding: 0.7rem 1rem calc(0.9rem + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 0.45rem;
  max-width: 720px; width: 100%; justify-self: center;
}
.lb-date { position: relative; font-size: 0.85rem; opacity: 0.75; cursor: pointer; align-self: flex-start; }
.lb-date span { text-decoration: underline dotted; text-underline-offset: 3px; }
/* The native date picker sits invisibly on top of the text, so tapping the date opens it. */
.lb-date input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; }
.lb-panel textarea {
  width: 100%; resize: none;
  font: italic 1.05rem/1.4 var(--serif);
  color: #f3eee7; background: rgb(255 255 255 / 0.07);
  border: 1px solid rgb(255 255 255 / 0.1); border-radius: 12px;
  padding: 0.65rem 0.85rem;
  min-height: 2.9rem;
}
.lb-panel textarea::placeholder { color: rgb(255 255 255 / 0.4); }
.lb-saved { font-size: 0.75rem; min-height: 1em; color: rgb(255 255 255 / 0.45); }

/* Wide screens: comment panel to the right of the photo. */
@media (min-width: 1000px) {
  .lightbox[open] {
    grid-template-columns: minmax(0, 1fr) 340px;
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas: "top top" "stage panel";
  }
  .lb-panel { align-self: center; padding: 1rem 1.5rem 1rem 0.5rem; }
  .lb-panel textarea { min-height: 120px; }
}

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
