:root {
  --paper: #f5f2ea;
  --surface: #fffdf8;
  --ink: #1f1d18;
  --muted: #6b665c;
  --line: #e4ded1;
  --accent: #12706b;
  --accent-ink: #0b4f4b;
  --accent-soft: #e2efec;
  --caution: #8a5a0b;
  --caution-soft: #f6ead2;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(31 29 24 / .06), 0 6px 18px rgb(31 29 24 / .06);
  font-family: system-ui, -apple-system, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", sans-serif;
  color: var(--ink);
  background: var(--paper);
  -webkit-text-size-adjust: 100%;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; display: flex; flex-direction: column; }
main { flex: 1; width: min(1080px, 100%); margin: 0 auto; padding: 8px 20px 40px; }
h1, h2, p { margin: 0; }
[hidden] { display: none !important; }

/* header */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  width: min(1080px, 100%); margin: 0 auto; padding: 18px 20px 10px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand h1 { font-size: 22px; letter-spacing: .08em; font-weight: 800; }
.brand .sub { font-size: 11px; color: var(--muted); letter-spacing: .06em; }
.mark { display: inline-flex; align-items: flex-end; gap: 3px; height: 30px; padding: 0 2px; border-bottom: 3px solid var(--ink); }
.mark i { display: block; width: 6px; border-radius: 2px 2px 0 0; background: var(--ink); }
.mark i:nth-child(1) { height: 22px; }
.mark i:nth-child(2) { height: 26px; background: var(--accent); }
.mark i:nth-child(3) { height: 18px; }
.mark i:nth-child(4) { height: 24px; transform: rotate(12deg); transform-origin: bottom left; margin-left: 2px; }
.tag { font-size: 11px; color: var(--muted); border: 1px solid var(--line); background: var(--surface); padding: 4px 10px; border-radius: 999px; white-space: nowrap; }

/* intro */
.intro { padding: 18px 0 22px; }
.lead { font-size: clamp(20px, 3.4vw, 28px); font-weight: 700; line-height: 1.5; letter-spacing: .02em; }
.how { margin-top: 8px; color: var(--muted); font-size: 14px; line-height: 1.7; }
.sp { display: none; }

h2 { font-size: 15px; font-weight: 700; display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.step { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--ink); color: var(--paper); font-size: 12px; }

/* choices */
.choices { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.choice {
  position: relative; display: flex; flex-direction: column; gap: 8px; padding: 8px; margin: 0;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  font: inherit; color: inherit; text-align: left; cursor: pointer; box-shadow: var(--shadow);
  transition: transform .15s ease, border-color .15s ease, box-shadow .15s ease;
}
.choice:hover { transform: translateY(-2px); border-color: #cfc7b6; }
.choice:focus-visible, .choice:focus-within { outline: 3px solid var(--accent-soft); outline-offset: 2px; border-color: var(--accent); }
.choice[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent) inset, var(--shadow); }
.choice img { width: 100%; aspect-ratio: 3 / 4; object-fit: cover; border-radius: 9px; background: var(--line); }
.choice-label { display: flex; flex-direction: column; padding: 0 4px 4px; }
.choice-label .eyebrow { font-size: 10px; color: var(--muted); letter-spacing: .06em; }
.choice-label .name { font-size: 13px; font-weight: 600; }
.choice:disabled, .choices.busy .choice { opacity: .5; pointer-events: none; }
.upload { justify-content: center; border-style: dashed; border-width: 1.5px; background: transparent; box-shadow: none; }
.upload input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.upload-inner { display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; padding: 18px 6px; }
.upload svg { width: 34px; height: 34px; fill: none; stroke: var(--accent); stroke-width: 1.6; }
.upload strong { font-size: 13px; }
.upload small { font-size: 12px; color: var(--muted); }

/* stage */
.stage { margin-top: 30px; }
.stage-grid { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: 24px; align-items: start; }
.photo { position: sticky; top: 16px; margin: 0; border-radius: var(--radius); overflow: hidden; background: var(--ink); box-shadow: var(--shadow); }
.photo img { display: block; width: 100%; height: auto; }
.photo figcaption { position: absolute; left: 10px; bottom: 10px; font-size: 11px; color: #fff; background: rgb(0 0 0 / .45); padding: 3px 8px; border-radius: 999px; }
.scanline { position: absolute; inset: 0; pointer-events: none; opacity: 0; transition: opacity .3s ease; }
.scanline::after {
  content: ""; position: absolute; left: 0; right: 0; height: 22%;
  background: linear-gradient(180deg, transparent, rgb(18 112 107 / .35) 70%, rgb(255 255 255 / .8) 72%, transparent 74%);
  animation: sweep 1.8s cubic-bezier(.4,0,.6,1) infinite;
}
.photo.scanning .scanline { opacity: 1; }
@keyframes sweep { from { top: -22%; } to { top: 100%; } }

.tiles { list-style: none; margin: 0 0 12px; padding: 0; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.tile { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.glyph { display: grid; grid-template-columns: repeat(var(--cols), 7px); gap: 2px; flex: none; }
.glyph i { width: 7px; height: 7px; border-radius: 1.5px; background: var(--line); }
.glyph i.on { background: var(--muted); }
.tile-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.tile-text b { font-size: 12px; }
.tile-state { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.tile:not(.done):not(.err) .tile-state { animation: pulse 1.2s ease-in-out infinite; }
.tile.done { border-color: #bcd9d4; background: var(--accent-soft); }
.tile.done .glyph i.on { background: var(--accent); }
.tile.done .tile-state { color: var(--accent-ink); }
.tile.err { border-color: #e7cf9f; background: var(--caution-soft); }
@keyframes pulse { 50% { opacity: .45; } }

.results { min-width: 0; }
.summary { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi-label { display: block; font-size: 12px; color: var(--muted); }
.kpi-value { display: block; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi-value b { font-size: 34px; font-weight: 800; letter-spacing: .01em; }
.kpi-value small { font-size: 14px; color: var(--muted); margin: 0 3px; }

.metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0; margin: 12px 0 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.metrics div { padding: 10px 14px; }
.metrics div + div { border-left: 1px solid var(--line); }
.metrics dt { font-size: 11px; color: var(--muted); }
.metrics dd { margin: 2px 0 0; font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; }
.metrics dd.live { color: var(--accent); }

.status { min-height: 1.6em; margin: 14px 2px 6px; font-size: 13px; color: var(--muted); }
.status.err { color: var(--caution); }

/* books */
.books { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.book {
  display: grid; grid-template-columns: 2.2em minmax(0, 1fr) 4.6em 4.2em; align-items: center; gap: 10px;
  padding: 11px 4px; border-bottom: 1px solid var(--line);
  animation: enter .35s cubic-bezier(.2,.7,.2,1) both;
}
.book .num { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; text-align: right; }
.book .meta { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.book .title { font-weight: 600; font-size: 15px; line-height: 1.45; overflow-wrap: anywhere; }
.book .author { font-size: 12px; color: var(--muted); }
.book .author:empty { display: none; }
.book .price { font-size: 14px; font-weight: 700; font-variant-numeric: tabular-nums; min-width: 4.2em; text-align: right; }
.book.flash { animation: flash .9s ease; }
.pill { justify-self: end; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.pill:empty { visibility: hidden; padding: 0; }
.pill.caution { color: var(--caution); background: var(--caution-soft); }
@keyframes enter { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes flash { 0% { background: var(--accent-soft); } 100% { background: transparent; } }
.note-low { margin-top: 12px; font-size: 12px; color: var(--muted); }

/* footer */
.foot { width: min(1080px, 100%); margin: 0 auto; padding: 18px 20px 32px; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); line-height: 1.8; }

/* auth dialog */
dialog { border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; width: min(360px, 90vw); background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
dialog::backdrop { background: rgb(31 29 24 / .45); }
dialog h2 { font-size: 16px; margin-bottom: 6px; }
dialog p { font-size: 13px; color: var(--muted); }
dialog input { width: 100%; margin: 14px 0 8px; padding: 10px 12px; font: inherit; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.auth-err { color: var(--caution) !important; margin-bottom: 8px; }
.btn { width: 100%; padding: 11px; font: inherit; font-weight: 700; color: #fff; background: var(--accent); border: 0; border-radius: 10px; cursor: pointer; }
.btn:hover { background: var(--accent-ink); }

@media (max-width: 760px) {
  main { padding: 0 16px 32px; }
  .top { padding: 14px 16px 6px; }
  .sp { display: inline; }
  .choices { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stage-grid { grid-template-columns: 1fr; gap: 16px; }
  .photo { position: relative; top: 0; justify-self: center; width: fit-content; max-width: 100%; }
  .photo img { width: auto; max-width: 100%; max-height: 24vh; }
  .photo figcaption { display: none; }
  .stage-grid { gap: 12px; }
  .tiles { gap: 6px; margin-bottom: 10px; }
  .tile { padding: 6px; gap: 6px; }
  .tile-text b { display: none; }
  .tile-state { font-size: 10px; }
  .summary { gap: 8px; }
  .kpi { padding: 10px 12px; }
  .kpi-value b { font-size: 24px; }
  .metrics { margin-top: 8px; }
  .metrics div { padding: 8px 10px; }
  .metrics dd { font-size: 14px; }
  .status { margin: 10px 2px 4px; }
  .book { grid-template-columns: 1.6em minmax(0, 1fr) auto 3.4em; gap: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  .tile::after { animation: none; }
  .book, .book.flash { animation: none; }
  .choice { transition: none; }
}
