:root {
  --bg: #f4f1ea;
  --surface: #ffffff;
  --text: #1d1f23;
  --muted: #6b6e74;
  --line: #e2ddd2;
  --accent: #c2410c;
  --c1: #2f5d8a; /* 通販 */
  --c2: #8a3f5d; /* アパレル */
  --c3: #3d7a5a; /* 家電・インテリア */
  --c4: #a8621c; /* グルメ */
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181c;
    --surface: #22252b;
    --text: #eceae4;
    --muted: #9a9ca3;
    --line: #30343b;
    --accent: #fb923c;
    --c1: #6fa3d6;
    --c2: #d68aa8;
    --c3: #7fc3a0;
    --c4: #e0a463;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", sans-serif;
  padding: env(safe-area-inset-top) 16px calc(24px + env(safe-area-inset-bottom));
}

.top {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: center; gap: 12px;
  padding: 14px 0 10px;
  background: var(--bg);
}
.top h1 { font-size: 20px; margin: 0; letter-spacing: .02em; }
#q {
  flex: 1; min-width: 0;
  font-size: 16px; /* iOSのズーム防止 */
  padding: 9px 12px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); color: var(--text);
}

.group { margin-top: 18px; }
.group h2 {
  font-size: 13px; font-weight: 600; color: var(--muted);
  margin: 0 0 8px; letter-spacing: .04em;
}
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 10px;
}

.tile {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  min-height: 92px; padding: 10px 6px;
  background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius);
  color: var(--text); text-decoration: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform .08s ease;
}
.tile:active { transform: scale(.96); }
.tile .mark {
  width: 38px; height: 38px; border-radius: 11px;
  display: grid; place-items: center;
  font-weight: 700; font-size: 17px; color: #fff;
  background: var(--tc, var(--c1));
}
.tile .name {
  font-size: 12px; line-height: 1.25; text-align: center;
  overflow-wrap: anywhere;
}
.tile .badge {
  position: absolute; top: 4px; right: 4px;
  width: 30px; height: 30px; border: 0; border-radius: 8px;
  background: transparent; color: var(--muted);
  font-size: 15px; cursor: pointer;
}
.tile .badge.has { color: var(--accent); }

.card-tile .mark { background: var(--accent); }

/* 会員証ダイアログ */
dialog {
  width: min(520px, calc(100vw - 24px));
  border: 0; border-radius: 18px; padding: 16px;
  background: var(--surface); color: var(--text);
}
dialog::backdrop { background: rgba(0,0,0,.55); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; }
.dlg-head h3 { margin: 0; font-size: 17px; }
.icon-btn {
  border: 0; background: transparent; color: var(--muted);
  font-size: 18px; width: 36px; height: 36px; cursor: pointer;
}
#card-body {
  margin: 12px 0; min-height: 120px;
  display: grid; place-items: center;
  background: #fff; /* バーコードは明るい背景で読ませる */
  border-radius: 12px; padding: 12px;
}
#card-body img { max-width: 100%; max-height: 60vh; display: block; }
#card-body .empty { color: #6b6e74; font-size: 14px; text-align: center; }
.dlg-actions { display: flex; gap: 10px; }
.btn {
  flex: 1; text-align: center;
  padding: 11px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font-size: 15px; cursor: pointer;
}
.btn.danger { color: #c53030; flex: 0 0 auto; padding: 11px 18px; }
.note { font-size: 11px; color: var(--muted); margin: 10px 0 0; }
