:root {
  color-scheme: light;
  --bg: #fbf6df;
  --card: #f5f3dc;              /* same cream as the game tiles */
  --card-edge: #e6dcb2;
  --ink: #4f3f23;
  --ink-soft: #8a7752;
  --accent: #2fb08f;
  --accent-ink: #ffffff;
  --accent-soft: #d8f3e8;
  --sun: #f7d36b;
  --sun-deep: #f0b93a;
  --danger: #d9534f;
  --radius: 16px;
  --font: ui-rounded, "SF Pro Rounded", "Hiragino Maru Gothic ProN", "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
  --top-h: 0px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  touch-action: manipulation;           /* no double-tap zoom delay */
  -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(84px + env(safe-area-inset-bottom));
}
button { font: inherit; color: inherit; }

/* ------------------------------------------------ header + category chips */
.top {
  position: sticky; top: 0; z-index: 20;
  background: linear-gradient(var(--sun), #f9dc85);
  padding: calc(env(safe-area-inset-top) + 10px) 0 10px;
  box-shadow: 0 2px 10px rgba(120, 90, 20, .15);
}
.title-row {
  display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
  padding: 0 max(16px, env(safe-area-inset-left)) 8px;
}
h1 { font-size: 19px; margin: 0; font-weight: 800; letter-spacing: .2px; }
.hint { font-size: 12.5px; color: #7a6230; white-space: nowrap; }
@media (max-width: 420px) { h1 { font-size: 17px; } .hint { font-size: 12px; } }

.chips {
  display: flex; gap: 8px; overflow-x: auto; overscroll-behavior-x: contain;
  padding: 2px max(16px, env(safe-area-inset-left)) 4px;
  scroll-snap-type: x proximity; scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; scroll-snap-align: start;
  display: flex; align-items: center; gap: 6px;
  min-height: 44px; padding: 4px 12px 4px 6px;
  border: 0; border-radius: 999px;
  background: rgba(255, 255, 255, .7);
  font-size: 15px; font-weight: 700; white-space: nowrap;
  box-shadow: inset 0 0 0 1px rgba(120, 90, 20, .12);
}
.chip img { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; background: var(--card); }
.chip .glyph { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: var(--card); font-size: 17px; }
.chip.active { background: var(--ink); color: #fff8e0; box-shadow: none; }
.chip .badge {
  min-width: 22px; height: 22px; padding: 0 6px; border-radius: 11px;
  display: inline-grid; place-items: center;
  background: var(--accent); color: #fff; font-size: 13px;
}
.chip .badge:empty { display: none; }

/* ------------------------------------------------ grid */
main { padding: 12px max(12px, env(safe-area-inset-left)) 24px; max-width: 1200px; margin: 0 auto; }
.loading, .empty { text-align: center; color: var(--ink-soft); margin: 48px 16px; font-size: 16px; }
.section-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
  margin: 14px 4px 8px; scroll-margin-top: calc(var(--top-h) + 8px);
}
.section-head h2 { margin: 0; font-size: 18px; }
.section-head span { color: var(--ink-soft); font-size: 14px; white-space: nowrap; }
.grid {
  display: grid; gap: 8px;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
}
@media (min-width: 700px) { .grid { grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 10px; } }

.tile {
  position: relative; display: block; width: 100%;
  aspect-ratio: 190 / 182; padding: 0;
  border: 0; border-radius: var(--radius);
  background: var(--card);
  box-shadow: inset 0 0 0 1px var(--card-edge);
  overflow: hidden; cursor: pointer;
  -webkit-touch-callout: none; user-select: none; -webkit-user-select: none;
  transition: transform .12s ease, box-shadow .12s ease, background-color .12s ease;
}
.tile img { width: 100%; height: 100%; object-fit: contain; display: block; pointer-events: none; }
.tile:active { transform: scale(.96); }
.tile .check {
  position: absolute; top: 6px; right: 6px; width: 28px; height: 28px; border-radius: 50%;
  display: grid; place-items: center;
  background: rgba(255, 255, 255, .85); box-shadow: inset 0 0 0 2px #cdbf92;
  color: transparent; font-size: 17px; font-weight: 900;
}
.tile.on { background: var(--accent-soft); box-shadow: inset 0 0 0 4px var(--accent); }
.tile.on .check { background: var(--accent); box-shadow: none; color: #fff; }

/* ------------------------------------------------ bottom bar */
.bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px max(16px, env(safe-area-inset-right)) calc(12px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  background: rgba(255, 251, 236, .96);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  box-shadow: 0 -2px 12px rgba(120, 90, 20, .15);
}
.bar-count { font-size: 17px; }
.bar-count strong { font-size: 22px; }

.btn {
  min-height: 48px; padding: 0 20px; border: 0; border-radius: 999px;
  font-size: 17px; font-weight: 800; cursor: pointer;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); box-shadow: 0 3px 0 #1f8a6f; }
.btn.primary:active { transform: translateY(2px); box-shadow: 0 1px 0 #1f8a6f; }
.btn.primary:disabled { background: #c9c0a0; box-shadow: none; }
.btn.ghost { background: rgba(0, 0, 0, .06); min-height: 40px; padding: 0 16px; font-size: 15px; }
.btn.link { background: none; color: var(--danger); padding: 0 8px; font-weight: 700; font-size: 15px; }
.btn.wide { width: 100%; }

/* ------------------------------------------------ review / result sheet */
.sheet {
  position: fixed; inset: 0; z-index: 50;
  background: var(--bg);
  display: flex; flex-direction: column;
}
.sheet[hidden] { display: none; }
.sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 10px) max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
  background: var(--sun);
}
.sheet-head h2 { margin: 0; font-size: 20px; }
.sheet-body {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 12px max(16px, env(safe-area-inset-right)) calc(24px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  max-width: 900px; width: 100%; margin: 0 auto;
}
.mini-grid { display: grid; gap: 6px; grid-template-columns: repeat(auto-fill, minmax(70px, 1fr)); }
.mini { position: relative; border: 0; padding: 0; border-radius: 12px; background: var(--card); aspect-ratio: 190/182; overflow: hidden; }
.mini img { width: 100%; height: 100%; object-fit: contain; }
.mini .x {
  position: absolute; top: 3px; right: 3px; width: 22px; height: 22px; border-radius: 50%;
  background: rgba(79, 63, 35, .75); color: #fff; font-size: 14px; line-height: 22px; text-align: center;
}
.group-title { margin: 16px 2px 6px; font-size: 16px; }
.group-title span { color: var(--ink-soft); font-weight: 600; }
.form { margin-top: 22px; display: grid; gap: 12px; }
.form label { display: grid; gap: 4px; font-weight: 700; font-size: 15px; }
.form small { font-weight: 500; color: var(--ink-soft); }
.form input, .form textarea {
  font: inherit; font-size: 16px;                       /* 16px stops iOS zooming in */
  padding: 12px 14px; border-radius: 12px; border: 1px solid var(--card-edge); background: #fff; color: var(--ink);
}
.form textarea { min-height: 80px; resize: vertical; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 4px; }
.error { color: var(--danger); font-weight: 700; }
.done-hero { text-align: center; margin: 16px 0 8px; }
.done-hero .big { font-size: 54px; line-height: 1; }
.done-hero h3 { font-size: 22px; margin: 8px 0 4px; }
.done-hero p { margin: 0; color: var(--ink-soft); }
.result-img { width: 100%; border-radius: 14px; margin: 10px 0; box-shadow: 0 2px 10px rgba(0, 0, 0, .1); display: block; }
.stack { display: grid; gap: 10px; margin-top: 12px; }

/* ------------------------------------------------ zoom peek + toast */
.peek {
  position: fixed; inset: 0; z-index: 60; display: grid; place-items: center;
  background: rgba(40, 30, 10, .55); pointer-events: none;
}
.peek[hidden] { display: none; }
.peek img { width: min(80vw, 420px); border-radius: 24px; background: var(--card); box-shadow: 0 10px 40px rgba(0, 0, 0, .35); }
.toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  z-index: 70; background: var(--ink); color: #fff8e0; padding: 10px 18px; border-radius: 999px; font-weight: 700;
  max-width: calc(100vw - 32px);
}
.toast[hidden] { display: none; }
