/* マストバイ2026 — 感熱レシート（実用性優先）
 * 方針: 読みやすさ・押しやすさを最優先。レシートらしさは「紙・破線・部門表記・数字」で足す。
 * 外部フォント不使用（端末標準フォントのみ）。 */

:root {
  --color-bg: #262626;
  --color-paper: #f7f4ec;
  --color-paper-2: #ece7da;
  --color-ink: #1c1b19;
  --color-ink-2: #3d3a35;
  --color-muted: #5f5a50;
  --color-rule: #b9b3a4;
  --color-stamp: #b3261e;
  --color-stamp-soft: rgba(179, 38, 30, 0.09);

  --font-body: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "BIZ UDPGothic",
    "Yu Gothic", "Noto Sans JP", Meiryo, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, "Courier New",
    "BIZ UDGothic", monospace;

  --paper-max: 30rem; /* 480px。PCでも広げない */
  --gutter: 1rem;
  --tap: 2.75rem; /* 44px */
  --toolbar-h: 6.75rem; /* JSが実測値で上書き */
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  overflow-x: clip;
}

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--color-bg);
  color: var(--color-ink);
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.5;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 100;
  padding: 0.5rem 0.75rem;
  background: var(--color-paper);
  color: var(--color-ink);
}

.skip-link:focus {
  left: 0.5rem;
  top: 0.5rem;
}

/* ───────── 紙 ───────── */
.receipt {
  width: 100%;
  max-width: var(--paper-max);
  margin: 0 auto;
  background: var(--color-paper);
}

.tear {
  width: 100%;
  max-width: var(--paper-max);
  height: 0.75rem;
  margin: 0 auto 3rem;
  /* 紙の下端のギザギザ */
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='12' viewBox='0 0 16 12'%3E%3Cpolygon points='0,0 16,0 8,12' fill='%23f7f4ec'/%3E%3C/svg%3E")
    repeat-x left top / 1rem 0.75rem;
}

.dash {
  border: 0;
  border-top: 2px dashed var(--color-rule);
  margin: 0;
}

/* ───────── ヘッダー（レシートの頭） ───────── */
.masthead {
  padding: 1.75rem var(--gutter) 1.25rem;
  text-align: center;
}

.store {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  font-weight: 700;
  letter-spacing: 0.3em;
  text-indent: 0.3em;
}

.title {
  margin: 0.375rem 0 0.75rem;
  font-size: clamp(1.75rem, 9vw, 2.375rem);
  font-weight: 800;
  line-height: 1.25;
  letter-spacing: 0.02em;
  word-break: keep-all;
  overflow-wrap: anywhere;
}

.title span {
  display: block;
}

.issue {
  margin: 0 0 0.75rem;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--color-muted);
  font-variant-numeric: tabular-nums;
}

.count-block {
  position: relative;
  margin: 0.25rem 0 0.5rem;
  padding: 1.25rem 0 1rem;
  border-top: 2px dashed var(--color-rule);
  border-bottom: 2px dashed var(--color-rule);
}

.count-label {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 0.875rem;
  letter-spacing: 0.4em;
  text-indent: 0.4em;
  color: var(--color-ink-2);
}

.count-big {
  margin: 0;
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 0.25rem;
  font-family: var(--font-mono);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.04em;
}

.count-num {
  font-size: clamp(4.25rem, 24vw, 6.75rem);
  font-variant-numeric: tabular-nums;
}

.count-unit {
  font-size: clamp(1.5rem, 8vw, 2.25rem);
  letter-spacing: 0;
}

.stamp {
  position: absolute;
  right: 0.25rem;
  top: 0.5rem;
  transform: rotate(-9deg);
  padding: 0.15rem 0.5rem;
  border: 3px solid var(--color-stamp);
  border-radius: 0.25rem;
  color: var(--color-stamp);
  font-size: 0.9375rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  opacity: 0.88;
  pointer-events: none;
}

.count-note {
  margin: 0;
  font-size: 0.75rem;
  line-height: 1.5;
  color: var(--color-muted);
  text-align: center;
}

.lede {
  margin: 1rem 0;
  font-size: 0.9375rem;
  color: var(--color-ink-2);
  text-align: left;
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  padding: 0.5rem 0.75rem;
  border: 2px solid var(--color-ink);
  border-radius: 0.25rem;
  background: var(--color-paper);
  color: var(--color-ink);
  font: inherit;
  font-size: 0.9375rem;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}

.btn-primary {
  background: var(--color-ink);
  color: var(--color-paper);
}

.btn:hover {
  background: var(--color-paper-2);
}

.btn-primary:hover {
  background: var(--color-ink-2);
}

.action-note {
  margin: 0.5rem 0 0;
  font-size: 0.75rem;
  line-height: 1.5;
  color: var(--color-muted);
  text-align: left;
}

.disclosure {
  margin: 0.875rem 0 0;
  font-size: 0.75rem;
  line-height: 1.5;
  color: var(--color-muted);
  text-align: left;
}

/* ───────── 操作バー（固定） ───────── */
.toolbar {
  position: sticky;
  top: 0;
  z-index: 20;
  padding: 0.5rem var(--gutter) 0.5rem;
  background: var(--color-paper);
  border-top: 2px dashed var(--color-rule);
  border-bottom: 2px solid var(--color-ink);
}

.search-box {
  position: relative;
}

.search-label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.search-input {
  display: block;
  width: 100%;
  height: 3rem;
  padding: 0 3rem 0 0.875rem;
  border: 2px solid var(--color-ink);
  border-radius: 0.25rem;
  background: #fff;
  color: var(--color-ink);
  font: inherit;
  font-size: 1rem; /* 16px未満だとiPhoneで拡大される */
  -webkit-appearance: none;
  appearance: none;
}

.search-input::-webkit-search-cancel-button {
  display: none;
}

.search-input::placeholder {
  color: var(--color-muted);
}

.search-clear {
  position: absolute;
  top: 0;
  right: 0;
  width: 3rem;
  height: 3rem;
  border: 0;
  background: none;
  color: var(--color-ink);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}

.search-status {
  margin: 0.375rem 0 0;
  font-size: 0.8125rem;
  color: var(--color-ink-2);
}

.search-status:empty {
  display: none;
}

.chips {
  display: flex;
  gap: 0.375rem;
  margin: 0.5rem calc(var(--gutter) * -1) 0;
  padding: 0 var(--gutter) 0.125rem;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.chips::-webkit-scrollbar {
  display: none;
}

.chip {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  height: 2.5rem;
  padding: 0 0.875rem;
  border: 1.5px solid var(--color-ink);
  border-radius: 999px;
  color: var(--color-ink);
  font-size: 0.875rem;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}

.chip.is-active {
  background: var(--color-ink);
  color: var(--color-paper);
}

/* ───────── 本文 ───────── */
main {
  padding: 0 var(--gutter);
}

#catalogBody {
  scroll-margin-top: calc(var(--toolbar-h) + 0.5rem);
}

.picks {
  margin: 1.5rem 0 0.5rem;
  padding: 0.75rem 0.875rem 0.25rem;
  border: 2px solid var(--color-stamp);
  border-radius: 0.25rem;
  background: var(--color-stamp-soft);
}

.section-label {
  margin: 0;
  color: var(--color-stamp);
  font-size: 1.0625rem;
  font-weight: 800;
}

.section-note {
  margin: 0 0 0.25rem;
  font-size: 0.8125rem;
  color: var(--color-ink-2);
}

.item-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.item-row {
  border-top: 1px dotted var(--color-rule);
}

.picks .item-row:first-child {
  border-top: 0;
}

.item-link {
  display: grid;
  grid-template-columns: 2.75rem minmax(0, 1fr) auto;
  align-items: start;
  column-gap: 0.5rem;
  min-height: 3.5rem;
  padding: 0.75rem 0;
  color: inherit;
  text-decoration: none;
}

.pick-link {
  grid-template-columns: minmax(0, 1fr) auto;
}

.item-no {
  padding-top: 0.2rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--color-muted);
  font-variant-numeric: tabular-nums;
}

.item-main {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
  min-width: 0;
}

.item-name {
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.item-point {
  font-size: 0.8125rem;
  line-height: 1.4;
  color: var(--color-muted);
}

.item-go {
  padding-top: 0.2rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--color-muted);
  white-space: nowrap;
}

.item-go::after {
  content: " \203A";
  font-weight: 700;
}

.item-go.accent {
  color: var(--color-stamp);
  font-weight: 700;
}

.item-link:hover .item-name {
  text-decoration: underline;
  text-underline-offset: 0.2em;
}

.item-row.is-highlight {
  margin: 0 -0.5rem;
  padding: 0 0.5rem;
  background: var(--color-stamp-soft);
  box-shadow: inset 4px 0 0 var(--color-stamp);
}

/* 大分類（レシートの「部門」） */
.group {
  margin: 2rem 0 0;
  scroll-margin-top: calc(var(--toolbar-h) + 0.5rem);
}

.group-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  margin: 0;
  padding-bottom: 0.5rem;
  border-bottom: 2px dashed var(--color-rule);
  font-size: 1.1875rem;
  font-weight: 800;
  line-height: 1.3;
}

.group-name {
  min-width: 0;
  overflow-wrap: anywhere;
}

.group-count {
  flex: 0 0 auto;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  font-weight: 400;
  color: var(--color-muted);
}

.genre-block {
  scroll-margin-top: calc(var(--toolbar-h) + 0.5rem);
}

.genre-block summary {
  display: grid;
  grid-template-columns: 1.5rem minmax(0, 1fr) auto;
  align-items: center;
  min-height: 3.25rem;
  padding: 0.5rem 0;
  border-bottom: 1px dotted var(--color-rule);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
}

.genre-block summary::-webkit-details-marker {
  display: none;
}

.genre-mark {
  font-family: var(--font-mono);
  font-weight: 700;
}

.genre-block details:not([open]) .genre-mark::before {
  content: "+";
}

.genre-block details[open] .genre-mark::before {
  content: "\2212";
}

.genre-block details[open] summary {
  border-bottom: 2px solid var(--color-ink);
}

.genre-name {
  overflow-wrap: anywhere;
}

.genre-count {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  font-weight: 400;
  color: var(--color-muted);
  font-variant-numeric: tabular-nums;
}

.genre-block .item-list {
  padding-bottom: 0.5rem;
}

.loading,
.error,
.empty {
  padding: 2rem 0;
  font-size: 0.9375rem;
  color: var(--color-muted);
}

.error {
  color: var(--color-stamp);
}

/* ───────── フッター（合計・バーコード） ───────── */
.foot {
  margin-top: 2.5rem;
  padding: 0 var(--gutter) 2rem;
  font-family: var(--font-mono);
  font-size: 0.9375rem;
}

.foot .dash-heavy {
  border: 0;
  border-top: 3px double var(--color-ink);
  margin: 0 0 1rem;
}

.foot-row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin: 0 0 0.25rem;
  font-variant-numeric: tabular-nums;
}

.foot-row.total {
  font-size: 1.125rem;
  font-weight: 800;
}

.foot-thanks {
  margin: 1.25rem 0 0;
  font-family: var(--font-body);
  font-weight: 700;
  text-align: center;
}

.barcode {
  height: 3.5rem;
  margin: 1rem auto 0.5rem;
  max-width: 18rem;
  background: repeating-linear-gradient(
    90deg,
    var(--color-ink) 0 2px,
    transparent 2px 5px,
    var(--color-ink) 5px 6px,
    transparent 6px 8px,
    var(--color-ink) 8px 11px,
    transparent 11px 13px,
    var(--color-ink) 13px 14px,
    transparent 14px 18px
  );
}

.foot-note {
  margin: 0.75rem 0 0;
  font-family: var(--font-body);
  font-size: 0.75rem;
  line-height: 1.6;
  color: var(--color-muted);
  text-align: center;
}

.to-top {
  position: fixed;
  right: max(0.75rem, calc((100vw - var(--paper-max)) / 2 + 0.75rem));
  bottom: max(1rem, env(safe-area-inset-bottom));
  z-index: 40;
  width: 3rem;
  height: 3rem;
  border: 2px solid var(--color-ink);
  border-radius: 50%;
  background: var(--color-paper);
  color: var(--color-ink);
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

:focus-visible {
  outline: 3px solid var(--color-stamp);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}
