:root {
  --paper: #FFFFFF;
  --surface: #F2F3F1;
  --ink: #15171C;
  --muted: #5A606B;
  --line: #D5D8DC;
  --flap: #1F2228;
  --flap-ink: #F4F1E6;
  --signal: #FFC527;
  --font-body: "Noto Sans JP", system-ui, sans-serif;
  --font-display: "Barlow Condensed", "Noto Sans JP", sans-serif;
  --font-code: "IBM Plex Mono", ui-monospace, monospace;
  --r-s: 8px;
  --r-m: 12px;
}
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; background: var(--paper); color: var(--ink); font-family: var(--font-body); font-size: 16px; line-height: 1.6; }
button, input { font: inherit; color: inherit; }
button { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
.lucide { width: 1.1em; height: 1.1em; stroke-width: 2; }
:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; box-shadow: 0 0 0 6px var(--signal); }
[hidden] { display: none !important; }

.app { max-width: 560px; margin: 0 auto; padding: max(16px, env(safe-area-inset-top)) 16px 120px; }
.top { display: flex; justify-content: flex-end; }
.back { font-size: 13px; color: var(--muted); }
.eyebrow { font-family: var(--font-display); font-weight: 500; font-size: 15px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); margin: 0; }
.hero { text-align: center; padding: 16px 0 8px; }
.hero h1 { font-size: 28px; line-height: 1.4; margin: 4px 0 8px; }
.lead { color: var(--muted); font-size: 14px; margin: 0; }

.field { display: grid; gap: 6px; margin: 24px 0 20px; font-size: 14px; font-weight: 700; }
.field input { padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--r-m); font-weight: 400; font-size: 16px; }
.field input:focus { outline: none; border-color: var(--ink); }

.group-label { margin: 28px 0 8px; font-size: 14px; font-weight: 700; }
.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
@media (min-width: 480px) { .grid { grid-template-columns: repeat(3, 1fr); } }
.item {
  position: relative; display: flex; align-items: center; gap: 10px;
  min-height: 52px; padding: 10px 12px; text-align: left;
  border: 1px solid var(--line); border-radius: var(--r-m); background: var(--paper);
  cursor: pointer; font-size: 15px; line-height: 1.3;
  transition: border-color .15s, background-color .15s;
}
.item:hover { border-color: var(--ink); }
.item:disabled { opacity: .4; cursor: default; border-color: var(--line); }
.rank {
  flex: none; width: 28px; height: 36px; border-radius: 4px;
  display: grid; place-items: center;
  font-family: var(--font-code); font-weight: 700; font-size: 18px;
  background: var(--surface); color: transparent;
}
.item.on { border-color: var(--ink); background: var(--surface); }
.item.on .rank { background: var(--flap); color: var(--flap-ink); }

.bar {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: flex; align-items: center; gap: 8px;
  padding: 12px max(16px, calc((100vw - 560px) / 2 + 16px)) max(12px, env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, .96); border-top: 1px solid var(--line);
}
#count { font-family: var(--font-code); font-weight: 700; margin-right: auto; }
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 12px 16px; border-radius: var(--r-m); border: 1px solid var(--ink); background: var(--paper); cursor: pointer; font-weight: 700; font-size: 15px; }
.btn.primary { background: var(--ink); color: var(--paper); }
.btn:disabled { opacity: .35; cursor: default; }
.btn.ghost { border-color: var(--line); }

#result { padding-top: 16px; }
#preview { display: block; width: 100%; margin-top: 12px; border: 1px solid var(--line); border-radius: var(--r-m); }
.hint { color: var(--muted); font-size: 13px; text-align: center; }
.actions { display: grid; gap: 8px; }
.actions .btn { justify-content: center; }
.item span:last-child, .btn, #count, .hero h1 { white-space: nowrap; }
.hero h1 { font-size: clamp(22px, 7vw, 28px); }
@media (max-width: 360px) { .item { padding: 10px 8px; gap: 8px; font-size: 14px; } .bar .btn { padding: 10px 12px; font-size: 14px; } }
@media (max-width: 360px) { #reset .lbl { display: none; } }
