:root {
  --paper: #FBF8F1;
  --card: #FFFFFF;
  --ink: #1F2A24;
  --ink-2: #56625B;
  --line: #E7E1D3;
  --sage: #7FA38A;
  --sage-deep: #3E6B52;
  --sage-wash: #E6EFE7;
  --terra: #C2603F;
  --c-n: #C2603F;
  --c-s: #3E6B52;
  --c-k: #B8862F;
  --c-l: #5F7282;
  --c-h: #8A5E45;
  --pad: clamp(12px, 2.6vw, 28px);
  --gap: clamp(8px, 1.4vw, 14px);
  font-family: "Instrument Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
}
* { box-sizing: border-box; margin: 0; }
html, body { height: 100%; }
body { overflow: hidden; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
button:focus-visible, a:focus-visible { outline: 3px solid var(--sage); outline-offset: 2px; }
img { display: block; }

.app {
  height: 100svh;
  padding: calc(var(--pad) + env(safe-area-inset-top)) calc(var(--pad) + env(safe-area-inset-right))
           calc(var(--pad) + env(safe-area-inset-bottom)) calc(var(--pad) + env(safe-area-inset-left));
  display: flex; flex-direction: column; gap: var(--gap);
  max-width: 1400px; margin: 0 auto;
}
.view { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: var(--gap); animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } }

/* boot skeleton */
.boot { flex: 1; display: flex; flex-direction: column; gap: 14px; }
.boot-bar { height: 70px; border-radius: 8px; background: linear-gradient(90deg, #EFEADF, #F6F2EA, #EFEADF); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
.boot-grid { flex: 1; display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.boot-grid i { border-radius: 8px; background: linear-gradient(90deg, #EFEADF, #F6F2EA, #EFEADF); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* top bar */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.mark { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: clamp(18px, 2.4vw, 24px); letter-spacing: -0.01em; }
.mark svg { width: 28px; height: 28px; }
.actions { display: flex; gap: 6px; }
.btn-quiet { padding: 9px 12px; border-radius: 6px; font-weight: 600; font-size: 14px; color: var(--ink-2); }
.btn-quiet:hover { background: #F1ECE1; color: var(--ink); }
.btn-main { padding: 14px 22px; border-radius: 8px; background: var(--ink); color: var(--paper); font-weight: 600; font-size: 16px; transition: transform .1s; }
.btn-main:active { transform: scale(.98); }

/* home hero */
.hero { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.6fr); gap: var(--gap); align-items: stretch; }
.score { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: clamp(12px, 2vw, 20px); display: flex; flex-direction: column; justify-content: center; gap: 8px; }
.score-num { font-size: clamp(34px, 6vw, 64px); font-weight: 700; line-height: 1; letter-spacing: -0.03em; }
.score-sub { color: var(--ink-2); font-size: clamp(13px, 1.4vw, 15px); }
.bar { height: 8px; border-radius: 4px; background: #EEE8DB; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--sage-deep); border-radius: 4px; transition: width .4s ease; }
.next { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: clamp(10px, 1.6vw, 16px); display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.next h2 { font-size: 15px; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.next h2 svg { width: 16px; height: 16px; color: var(--terra); }
.next-list { display: flex; flex-direction: column; gap: 4px; }
.next-empty { color: var(--ink-2); font-size: 14px; }

/* category grid */
.cats { flex: 1; min-height: 0; display: grid; gap: var(--gap);
  grid-template-columns: repeat(var(--cols, 3), minmax(0, 1fr)); grid-template-rows: repeat(var(--rows, 5), minmax(0, 1fr)); }
.cat { position: relative; background: var(--card); border: 1px solid var(--line); border-radius: 10px; overflow: hidden;
  display: flex; flex-direction: column; text-align: left; transition: transform .15s ease, box-shadow .15s ease; min-height: 0; }
.cat:hover { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(60, 50, 30, .08); }
.cat-img { flex: 1; min-height: 0; background: #FAF6EC; }
.cat-img img { width: 100%; height: 100%; object-fit: cover; object-position: center; }
.cat-body { padding: 8px 10px 10px; display: flex; flex-direction: column; gap: 5px; }
.cat-name { font-weight: 600; font-size: clamp(12px, 1.35vw, 15px); line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cat-count { font-size: 12px; color: var(--ink-2); }
.cat .bar { height: 4px; }
.cat.done .cat-img::after { content: ""; position: absolute; inset: 0; background: rgba(230, 239, 231, .55); }
.cat .stamp { position: absolute; top: 8px; right: 8px; width: 30px; height: 30px; border-radius: 50%; background: var(--sage-deep); color: #fff; display: none; place-items: center; }
.cat.done .stamp { display: grid; }
.cat.legend { background: var(--sage-wash); border-color: #D3E2D5; padding: 12px; justify-content: center; gap: 6px; }
.legend-row { display: flex; align-items: center; gap: 7px; font-size: clamp(11px, 1.2vw, 13px); font-weight: 500; }

/* when dots */
.when, .star { white-space: nowrap; flex: none; }
.when { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--ink-2); }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; background: var(--c); }
.w-n { --c: var(--c-n); } .w-s { --c: var(--c-s); } .w-k { --c: var(--c-k); } .w-l { --c: var(--c-l); } .w-h { --c: var(--c-h); }
.star { display: inline-flex; align-items: center; gap: 4px; color: var(--terra); font-size: 12.5px; font-weight: 600; }
.star svg { width: 12px; height: 12px; }

/* item rows */
.item { display: flex; align-items: stretch; border-radius: 8px; background: var(--card); border: 1px solid var(--line); transition: background .2s, border-color .2s; min-height: 0; overflow: hidden; }
.item:hover { border-color: #D8D0BE; }
.item-toggle { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; text-align: left; padding: 10px 12px; }
.check { width: 26px; height: 26px; flex: none; border-radius: 50%; border: 2px solid #C9C0AD; display: grid; place-items: center; transition: all .2s; }
.check svg { width: 15px; height: 15px; color: #fff; opacity: 0; transform: scale(.5); transition: all .2s cubic-bezier(.3, 1.6, .5, 1); }
.item.on { background: var(--sage-wash); border-color: #CFE0D2; }
.item.on .check { background: var(--sage-deep); border-color: var(--sage-deep); }
.item.on .check svg { opacity: 1; transform: scale(1); }
.item.on .item-text { color: var(--ink-2); }
.item-main { min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.item-text { font-size: clamp(14px, 1.5vw, 16px); font-weight: 500; line-height: 1.3; }
.item-meta { display: flex; gap: 12px; align-items: center; min-width: 0; }
.note-prev { font-size: 12.5px; color: var(--ink); min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.note-prev::before { content: "Note: "; color: var(--ink-2); }
.item-note { flex: none; width: 48px; display: grid; place-items: center; color: #A89F8C; border-left: 1px solid transparent; }
.item-note:hover { color: var(--ink); background: rgba(0, 0, 0, .03); }
.item-note.has { color: var(--sage-deep); }
.item-note svg { width: 20px; height: 20px; }
.next .item-toggle { padding: 7px 10px; }
.next .item-text { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* category view */
.cat-head { display: grid; grid-template-columns: auto auto minmax(0, 1fr); gap: 12px; align-items: center; }
.back { width: 44px; height: 44px; border-radius: 8px; display: grid; place-items: center; background: var(--card); border: 1px solid var(--line); }
.back svg { width: 20px; height: 20px; }
.cat-thumb { width: clamp(52px, 8vw, 76px); aspect-ratio: 1; border-radius: 8px; overflow: hidden; background: #FAF6EC; border: 1px solid var(--line); }
.cat-thumb img { width: 100%; height: 100%; object-fit: cover; }
.cat-title { min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.cat-title h1 { font-size: clamp(20px, 3vw, 30px); font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; }
.cat-title .row { display: flex; align-items: center; gap: 10px; color: var(--ink-2); font-size: 14px; }
.cat-title .bar { flex: 1; max-width: 260px; }
.page { flex: 1; min-height: 0; display: grid; gap: 8px; grid-template-columns: repeat(var(--icols, 1), minmax(0, 1fr));
  grid-template-rows: repeat(var(--irows, 6), minmax(0, 1fr)); touch-action: pan-y; }
.page.slide-l { animation: slideL .22s ease; } .page.slide-r { animation: slideR .22s ease; }
@keyframes slideL { from { opacity: 0; transform: translateX(24px); } }
@keyframes slideR { from { opacity: 0; transform: translateX(-24px); } }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.pager button[disabled] { opacity: .3; cursor: default; }
.pager .pbtn { padding: 12px 16px; border-radius: 8px; background: var(--card); border: 1px solid var(--line); font-weight: 600; font-size: 14px; display: flex; align-items: center; gap: 6px; }
.pager .pbtn svg { width: 16px; height: 16px; }
.dots { display: flex; gap: 6px; }
.dots i { width: 8px; height: 8px; border-radius: 50%; background: #DDD5C4; transition: all .2s; }
.dots i.on { background: var(--ink); width: 22px; border-radius: 4px; }
.empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 12px; color: var(--ink-2); padding: 20px; }
.empty strong { color: var(--ink); font-size: 18px; }

/* setup */
.setup-head h1 { font-size: clamp(26px, 4.4vw, 46px); font-weight: 700; letter-spacing: -0.025em; line-height: 1.05; }
.setup-head p { color: var(--ink-2); margin-top: 6px; font-size: clamp(14px, 1.6vw, 17px); }
.picks { flex: 1; min-height: 0; display: grid; gap: 8px; grid-template-columns: repeat(var(--pcols, 2), minmax(0, 1fr)); grid-template-rows: repeat(var(--prows, 7), minmax(0, 1fr)); }
.pick { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 8px; background: var(--card); border: 1px solid var(--line); text-align: left; font-weight: 500; font-size: clamp(13px, 1.5vw, 16px); min-height: 0; }
.pick .box { width: 22px; height: 22px; border-radius: 5px; border: 2px solid #C9C0AD; flex: none; display: grid; place-items: center; transition: all .15s; }
.pick .box svg { width: 13px; height: 13px; color: #fff; opacity: 0; }
.pick[aria-pressed="true"] { background: var(--sage-wash); border-color: #CFE0D2; }
.pick[aria-pressed="true"] .box { background: var(--sage-deep); border-color: var(--sage-deep); }
.pick[aria-pressed="true"] .box svg { opacity: 1; }
.setup-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.setup-foot span { color: var(--ink-2); font-size: 14px; }

/* modal */
.modal { position: fixed; inset: 0; background: rgba(31, 42, 36, .35); display: grid; place-items: center; padding: 20px; z-index: 20; animation: fade .2s; }
.modal-card { background: var(--paper); border-radius: 12px; padding: 22px; max-width: 460px; width: 100%; display: flex; flex-direction: column; gap: 14px; max-height: calc(100svh - 40px); }
.modal-card h2 { font-size: 20px; }
.modal-row { display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; align-items: start; }
.modal-row .dot { margin-top: 5px; }
.modal-row b { font-weight: 600; }
.modal-row p { grid-column: 2; color: var(--ink-2); font-size: 14px; }
.modal-actions { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.btn-danger { color: var(--terra); }
.btn-line { padding: 11px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); font-weight: 600; font-size: 14px; }
.btn-line:hover { border-color: #CFC6B2; }
.modal-tools { display: flex; flex-wrap: wrap; gap: 8px; }
.modal-card { overflow-y: auto; }
.modal-card h2 + .modal-row { margin-top: -4px; }
.fine { color: var(--ink-2); font-size: 14px; }
.fine.warn { color: #8A4A2E; }
.form-err { color: #9A3A1E; background: #FFF1E8; border-radius: 6px; padding: 8px 10px; font-size: 14px; }
textarea { font: inherit; font-size: 16px; width: 100%; resize: none; border: 1px solid #D6CEBC; border-radius: 8px; padding: 10px 12px; background: #fff; color: var(--ink); }
textarea:focus { outline: 3px solid var(--sage-wash); border-color: var(--sage); }
.note-row { display: flex; justify-content: space-between; gap: 8px; }
.modal-actions > span { display: flex; gap: 6px; }

.toast { position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--ink); color: var(--paper);
  padding: 11px 16px; border-radius: 8px; font-weight: 500; font-size: 14px; z-index: 30; animation: fade .2s; max-width: calc(100vw - 32px); }
.banner { position: fixed; top: 0; left: 0; right: 0; z-index: 40; background: #FFF3E8; color: #7A3A1F; border-bottom: 1px solid #F0D3BC; padding: 10px 16px; font-size: 14px; display: flex; gap: 12px; justify-content: center; align-items: center; }
.banner button { text-decoration: underline; font-weight: 600; }
.banner[hidden], .toast[hidden] { display: none; }
body.has-banner { display: flex; flex-direction: column; height: 100svh; }
body.has-banner .banner { position: static; flex: none; }
body.has-banner .app { height: auto; flex: 1; min-height: 0; width: 100%; }
.noscript { padding: 24px; font-size: 16px; }
.print { display: none; }

/* phones */
@media (max-width: 700px) {
  .hero { grid-template-columns: 1fr; }
  .score { flex-direction: row; align-items: center; gap: 14px; padding: 12px 14px; }
  .score .bar { flex: 1; }
  .score-txt { display: flex; flex-direction: column; gap: 4px; }
  .actions .lbl { display: none; }
  .item-meta .when span.long { display: none; }
  .pager .pbtn .lbl { display: none; }
  .mark { font-size: 17px; white-space: nowrap; }
  .mark svg { width: 24px; height: 24px; }
  .btn-quiet { padding: 8px 8px; font-size: 13px; }
  .cat { flex-direction: row; align-items: stretch; }
  .cat-img { flex: none; height: 100%; aspect-ratio: 1; }
  .cat-body { flex: 1; min-width: 0; justify-content: center; padding: 6px 10px; }
  .cat-name { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
  .btn-quiet { white-space: nowrap; }
  .cat .stamp { top: 50%; transform: translateY(-50%); left: 8px; right: auto; }
}
@media (max-height: 640px) { .next { display: none; } }

@media print {
  body { overflow: visible; background: #fff; }
  .app, .toast, .banner, .modal { display: none !important; }
  .print { display: block; font-size: 10.5pt; color: #000; }
  .print h1 { font-size: 18pt; margin-bottom: 4pt; }
  .print .sub { color: #444; margin-bottom: 10pt; }
  .print h2 { font-size: 12pt; margin: 12pt 0 4pt; break-after: avoid; }
  .print ul { list-style: none; padding: 0; columns: 2; column-gap: 18pt; }
  .print li { break-inside: avoid; padding: 2pt 0 2pt 16pt; position: relative; }
  .print li::before { content: ""; position: absolute; left: 0; top: 4pt; width: 9pt; height: 9pt; border: 1pt solid #000; border-radius: 2pt; }
  .print li.done::before { background: #000; }
  .print li em { font-style: normal; color: #555; font-size: 9pt; }
}
