:root {
  --bg: #f6f2ec;
  --paper: #fffdf9;
  --ink: #2b2622;
  --muted: #8a8079;
  --line: #e7dfd5;
  --accent: #b5435a;
  --accent-soft: #f6e3e7;
  --ok: #3f7d5a;
  --radius: 14px;
  --serif: 'Cormorant Garamond', 'Times New Roman', serif;
  --sans: 'Be Vietnam Pro', -apple-system, system-ui, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--sans); font-size: 15px; }
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }

.loading, .empty-page { min-height: 80vh; display: grid; place-content: center; text-align: center; gap: 12px; color: var(--muted); padding: 24px; }
.spinner { width: 28px; height: 28px; margin: 0 auto; border-radius: 50%; border: 2px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Header */
.hero { padding: 32px 16px 12px; text-align: center; max-width: 720px; margin: 0 auto; }
.brand { letter-spacing: .32em; font-size: 11px; color: var(--muted); text-transform: uppercase; }
.hero h1 { font-family: var(--serif); font-weight: 600; font-size: clamp(30px, 7vw, 44px); line-height: 1.1; margin: 10px 0 8px; }
.hero .note { color: var(--muted); margin: 0 auto; max-width: 520px; line-height: 1.55; white-space: pre-line; }
.hero .rule { margin: 14px auto 0; color: var(--ink); font-size: 14px; }
.hero .rule b { color: var(--accent); }

.bar { position: sticky; top: 0; z-index: 5; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.bar-in { max-width: 1400px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 10px; }
.tabs { display: flex; background: var(--paper); border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.tabs button { border: 0; background: none; padding: 7px 14px; border-radius: 999px; font-size: 14px; color: var(--muted); white-space: nowrap; }
.tabs button.on { background: var(--ink); color: #fff; }
.saved { margin-left: auto; font-size: 12px; color: var(--muted); white-space: nowrap; }

/* Grid */
.grid { max-width: 1400px; margin: 0 auto; padding: 12px 16px 120px; display: grid; gap: 6px; grid-template-columns: repeat(3, 1fr); }
@media (min-width: 640px) { .grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; } }
.tile { position: relative; aspect-ratio: 1; background: #ebe4da; border-radius: 6px; overflow: hidden; border: 0; padding: 0; }
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; opacity: 0; transition: opacity .25s; }
.tile img.ok { opacity: 1; }
.tile .heart { position: absolute; right: 4px; bottom: 4px; width: 36px; height: 36px; border-radius: 50%; border: 0; display: grid; place-items: center; font-size: 19px; line-height: 1; background: rgba(0,0,0,.28); color: #fff; }
.tile.picked { outline: 3px solid var(--accent); outline-offset: -3px; }
.tile.picked .heart { background: var(--accent); }
.tile .num { position: absolute; left: 6px; top: 5px; font-size: 10px; color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,.6); }
.tile .has-note { position: absolute; left: 4px; bottom: 4px; background: #fff; color: var(--ink); border-radius: 999px; font-size: 11px; padding: 2px 7px; }
.grid-empty { grid-column: 1 / -1; text-align: center; color: var(--muted); padding: 60px 0; }

/* Bottom action */
.dock { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); background: var(--paper); border-top: 1px solid var(--line); }
.dock-in { max-width: 720px; margin: 0 auto; display: flex; align-items: center; gap: 12px; }
.count { font-size: 14px; line-height: 1.3; }
.count b { font-size: 20px; color: var(--accent); }
.count.over b { color: #c26a00; }
.count small { display: block; color: var(--muted); font-size: 12px; }
.btn { border: 0; border-radius: 999px; padding: 13px 22px; font-weight: 600; background: var(--ink); color: #fff; }
.btn:disabled { opacity: .35; }
.btn.ghost { background: none; border: 1px solid var(--line); color: var(--ink); }
.btn.accent { background: var(--accent); }
.dock .btn { margin-left: auto; }

.done-box { max-width: 520px; margin: 8px auto 0; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; text-align: center; line-height: 1.55; }
.done-box b { color: var(--ok); }

/* Viewer */
.viewer { position: fixed; inset: 0; z-index: 20; background: #111; color: #fff; display: flex; flex-direction: column; touch-action: pan-y; }
.v-top, .v-bottom { display: flex; align-items: center; gap: 10px; padding: 10px 12px; }
.v-top { padding-top: calc(10px + env(safe-area-inset-top)); }
.v-bottom { padding-bottom: calc(14px + env(safe-area-inset-bottom)); justify-content: space-between; }
.v-pos { flex: 1; text-align: center; font-size: 13px; color: #bbb; }
.v-btn { width: 40px; height: 40px; border-radius: 50%; border: 0; background: rgba(255,255,255,.1); color: #fff; font-size: 17px; }
.v-stage { flex: 1; position: relative; display: grid; place-items: center; overflow: hidden; min-height: 0; }
.v-img { max-width: 100%; max-height: 100%; object-fit: contain; user-select: none; -webkit-user-drag: none; transition: opacity .15s; }
.v-nav { position: absolute; top: 50%; transform: translateY(-50%); width: 48px; height: 72px; border: 0; background: none; color: #fff; font-size: 40px; opacity: .6; }
.v-nav.prev { left: 0; } .v-nav.next { right: 0; }
@media (hover: none) { .v-nav { display: none; } }
.v-name, .v-count { font-size: 12px; color: #aaa; min-width: 70px; }
.v-count { text-align: right; }
.v-heart { border: 0; border-radius: 999px; padding: 12px 22px; background: #fff; color: var(--ink); font-weight: 600; display: flex; gap: 8px; align-items: center; }
.v-heart .h { font-size: 20px; line-height: 1; color: var(--accent); }
.v-heart.on { background: var(--accent); color: #fff; }
.v-heart.on .h { color: #fff; }
.v-note-text { position: absolute; left: 12px; right: 12px; bottom: calc(80px + env(safe-area-inset-bottom)); margin: 0; background: rgba(0,0,0,.6); padding: 8px 12px; border-radius: 10px; font-size: 13px; text-align: center; }

/* Sheet */
.sheet { position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.45); display: grid; align-items: end; justify-items: center; }
.sheet-box { background: var(--paper); width: 100%; max-width: 520px; border-radius: 20px 20px 0 0; padding: 22px 20px calc(20px + env(safe-area-inset-bottom)); line-height: 1.55; }
@media (min-width: 640px) { .sheet { align-items: center; } .sheet-box { border-radius: 20px; } }
.sheet-box h3 { font-family: var(--serif); font-size: 26px; margin: 0 0 8px; }
.sheet-box p { margin: 0 0 12px; color: var(--muted); }
.sheet-box .warn { color: #a65a00; background: #fff3e0; padding: 10px 12px; border-radius: 10px; }
.sheet-box textarea { width: 100%; min-height: 90px; border: 1px solid var(--line); border-radius: 10px; padding: 10px; font: inherit; resize: vertical; background: #fff; }
.sheet-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 14px; }

.toast { position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 40; background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 999px; font-size: 14px; max-width: calc(100% - 32px); text-align: center; }
