/* 人口ぴったり100万人 style.css — 構造とクラス名は docs/design.md を参照 */

:root {
  --c-ink: #3b2f2f;
  --c-ink-sub: #7a6a5e;
  --c-paper: #fffdf7;
  --c-bg: #fff4e0;
  --c-line: #eadcc0;

  --c-felt: #2f8f6f;
  --c-felt-deep: #1f6a51;
  --c-felt-soft: #d7efe4;
  --c-felt-wave: rgba(255, 255, 255, 0.12);

  --c-beni: #e23b4e;
  --c-beni-deep: #a8243a;
  --c-beni-soft: #ffe1e4;

  --c-gunjo: #3450a8;
  --c-gunjo-deep: #22377a;
  --c-gunjo-soft: #e2e8f8;

  --c-gold: #ffc83d;
  --c-gold-deep: #d99a00;
  --c-gold-soft: #fff1c2;
  --c-gold-shine: #fff7d6;

  --c-burst: #ff3b2f;
  --c-burst-deep: #b3170f;

  --c-land: #fff4dc;
  --c-muni-line: #eadab8;
  --c-pref-line: #b89b6a;

  --c-t1: #ff5a6e;
  --c-t2: #ff9f43;
  --c-t3: #7bc96f;
  --c-t4: #3fbfad;
  --c-t5: #5b8fd9;
  --c-t6: #a77bd9;
  --c-t7: #ff8fc7;
  --c-t8: #c0844a;

  --c-band-s: #7bc96f;
  --c-band-m: #5b8fd9;
  --c-band-l: #e23b4e;

  --font-base: "Hiragino Maru Gothic ProN", "Hiragino Maru Gothic Pro", "BIZ UDPGothic",
    "Hiragino Sans", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  --font-num: "Arial Rounded MT Bold", "Hiragino Maru Gothic ProN", "SF Pro Rounded",
    ui-rounded, system-ui, sans-serif;

  --radius-s: 10px;
  --radius-m: 18px;
  --radius-l: 28px;
  --border: 3px solid var(--c-ink);
  --shadow-card: 0 4px 0 rgba(59, 47, 47, 0.14), 0 10px 24px rgba(59, 47, 47, 0.1);
  --shadow-hard: 0 4px 0 var(--c-ink);
  --btn-depth: 6px;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  --dur-fast: 0.15s;
  --dur-mid: 0.35s;
  --dur-flip: 0.6s;
  --ease-pop: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-drum: cubic-bezier(0.2, 0.9, 0.25, 1.06);

  --text-outline:
    0 3px 0 var(--c-ink),
    2px 0 0 var(--c-ink), -2px 0 0 var(--c-ink),
    0 2px 0 var(--c-ink), 0 -2px 0 var(--c-ink),
    2px 2px 0 var(--c-ink), -2px 2px 0 var(--c-ink),
    2px -2px 0 var(--c-ink), -2px -2px 0 var(--c-ink);

  --pattern-seigaiha: radial-gradient(circle at 50% 100%, transparent 0 6px, var(--c-felt-wave) 6px 8px, transparent 8px 11px, var(--c-felt-wave) 11px 13px, transparent 13px);
  --pattern-ichimatsu: conic-gradient(rgba(255, 255, 255, 0.1) 25%, transparent 0 50%, rgba(255, 255, 255, 0.1) 0 75%, transparent 0);
}

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

html,
body {
  margin: 0;
  height: 100%;
}

body {
  font-family: var(--font-base);
  color: var(--c-ink);
  background-color: var(--c-bg);
  background-image:
    radial-gradient(circle at 11px 11px, rgba(47, 143, 111, 0.08) 2px, transparent 2.5px),
    radial-gradient(circle at 0 0, rgba(226, 59, 78, 0.05) 2px, transparent 2.5px);
  background-size: 22px 22px;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  line-height: 1.5;
}

button {
  font: inherit;
  color: inherit;
}

[hidden] { display: none !important; }

.app {
  position: relative;
  max-width: 520px;
  height: 100dvh;
  margin: 0 auto;
  overflow: hidden;
}

.num {
  font-family: var(--font-num);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- 画面切替 ---------- */

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: calc(16px + var(--safe-top)) 16px calc(16px + var(--safe-bottom));
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(12px);
  transition: opacity var(--dur-mid) ease, transform var(--dur-mid) ease, visibility 0s linear var(--dur-mid);
  overflow-y: auto;
}

.screen.is-active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: none;
  transition: opacity var(--dur-mid) ease, transform var(--dur-mid) ease, visibility 0s;
}

.fade-in { animation: fade-in var(--dur-mid) ease both; }
.fade-out { animation: fade-out var(--dur-mid) ease both; }
.pop-in { animation: pop-in 0.45s var(--ease-pop) both; }
.bounce { animation: num-bounce 0.6s var(--ease-pop); }
.shake { animation: shake 0.4s ease; }

/* ---------- ロゴ ---------- */

.logo {
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  font-weight: 800;
  line-height: 1.1;
  text-align: center;
}

.logo__top {
  display: inline-block;
  padding: 4px 16px;
  border: var(--border);
  border-radius: 999px;
  background: var(--c-paper);
  color: var(--c-felt-deep);
  font-size: clamp(18px, 5.4vw, 24px);
  letter-spacing: 0.08em;
  box-shadow: var(--shadow-hard);
  transform: rotate(-3deg);
}

.logo__top em {
  font-style: normal;
  color: var(--c-beni);
}

.logo__main {
  position: relative;
  display: flex;
  align-items: flex-end;
  gap: 4px;
  margin: 14px 0 6px;
}

.logo__digit {
  display: grid;
  place-items: center;
  width: clamp(58px, 18vw, 84px);
  aspect-ratio: 5 / 7;
  border: var(--border);
  border-radius: 12px;
  background: var(--c-paper);
  color: var(--c-beni);
  font-family: var(--font-num);
  font-size: clamp(48px, 15vw, 70px);
  font-weight: 900;
  box-shadow: 0 5px 0 var(--c-ink);
  animation: logo-deal 2.8s ease-in-out infinite;
}

.logo__digit:nth-child(1) { transform: rotate(-9deg) translateY(6px); }
.logo__digit:nth-child(2) { transform: rotate(-2deg); animation-delay: 0.15s; }
.logo__digit:nth-child(3) { transform: rotate(6deg) translateY(4px); animation-delay: 0.3s; }

.logo__digit::before,
.logo__digit::after {
  content: "";
  position: absolute;
  width: 9px;
  height: 9px;
  background: var(--c-beni);
  transform: rotate(45deg);
}

.logo__digit { position: relative; }
.logo__digit::before { top: 7px; left: 7px; }
.logo__digit::after { bottom: 7px; right: 7px; }

.logo__man {
  display: grid;
  place-items: center;
  width: clamp(70px, 21vw, 96px);
  aspect-ratio: 1;
  margin-left: 2px;
  border: var(--border);
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, var(--c-gold-shine), var(--c-gold) 55%, var(--c-gold-deep));
  color: #fff;
  font-size: clamp(40px, 12vw, 56px);
  text-shadow: var(--text-outline);
  box-shadow: 0 5px 0 var(--c-ink);
  transform: rotate(8deg);
  animation: logo-coin 2.8s ease-in-out 0.45s infinite;
}

.logo__tail {
  font-size: clamp(28px, 9vw, 40px);
  color: #fff;
  text-shadow: var(--text-outline);
  letter-spacing: 0.1em;
}

.logo--small { flex-direction: row; gap: 4px; }
.logo--small .logo__top { display: none; }
.logo--small .logo__main { margin: 0; gap: 2px; }
.logo--small .logo__digit { width: 18px; font-size: 15px; border-width: 2px; border-radius: 4px; box-shadow: none; animation: none; }
.logo--small .logo__digit::before,
.logo--small .logo__digit::after { display: none; }
.logo--small .logo__man { width: 24px; font-size: 13px; border-width: 2px; box-shadow: none; animation: none; text-shadow: none; color: var(--c-ink); }
.logo--small .logo__tail { font-size: 13px; text-shadow: none; color: var(--c-ink); letter-spacing: 0; }

/* ---------- ボタン ---------- */

.btn {
  --btn-bg: var(--c-beni);
  --btn-edge: var(--c-beni-deep);
  --btn-fg: #fff;
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 56px;
  padding: 12px 28px;
  border: var(--border);
  border-radius: 999px;
  background: var(--btn-bg);
  color: var(--btn-fg);
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 0.04em;
  cursor: pointer;
  user-select: none;
  box-shadow: 0 var(--btn-depth) 0 var(--btn-edge), 0 var(--btn-depth) 0 3px var(--c-ink);
  transform: translateY(0);
  transition: transform 0.08s ease, box-shadow 0.08s ease, filter var(--dur-fast);
}

.btn::after {
  content: "";
  position: absolute;
  top: 5px;
  left: 18%;
  right: 18%;
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.35);
  pointer-events: none;
}

.btn:hover { filter: brightness(1.05); }

.btn:active,
.btn.is-pressed {
  transform: translateY(var(--btn-depth));
  box-shadow: 0 0 0 var(--btn-edge), 0 0 0 3px var(--c-ink);
}

.btn:focus-visible {
  outline: 4px solid var(--c-gold);
  outline-offset: 4px;
}

.btn:disabled {
  filter: grayscale(0.8) opacity(0.6);
  cursor: not-allowed;
  transform: translateY(var(--btn-depth));
  box-shadow: 0 0 0 var(--btn-edge), 0 0 0 3px var(--c-ink);
}

.btn--block { display: flex; width: 100%; }
.btn--felt { --btn-bg: var(--c-felt); --btn-edge: var(--c-felt-deep); }
.btn--gunjo { --btn-bg: var(--c-gunjo); --btn-edge: var(--c-gunjo-deep); }
.btn--gold { --btn-bg: var(--c-gold); --btn-edge: var(--c-gold-deep); --btn-fg: var(--c-ink); }
.btn--ghost { --btn-bg: var(--c-paper); --btn-edge: var(--c-line); --btn-fg: var(--c-ink); }
.btn--small { min-height: 40px; padding: 6px 16px; font-size: 15px; --btn-depth: 4px; }

.btn__sub {
  display: block;
  font-size: 12px;
  font-weight: 700;
  opacity: 0.85;
  letter-spacing: 0;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 2px solid var(--c-ink);
  border-radius: 50%;
  background: var(--c-paper);
  font-size: 18px;
  cursor: pointer;
  box-shadow: 0 3px 0 var(--c-ink);
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}

.icon-btn:active { transform: translateY(3px); box-shadow: 0 0 0 var(--c-ink); }

.card {
  background: var(--c-paper);
  border: var(--border);
  border-radius: var(--radius-m);
  box-shadow: var(--shadow-card);
  padding: 16px;
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 10px;
  border: 2px solid var(--c-ink);
  border-radius: 999px;
  background: var(--c-paper);
  font-size: 12px;
  font-weight: 800;
}

.tag--daily { background: var(--c-gunjo); color: #fff; }
.tag--gold { background: var(--c-gold); }

/* ---------- タイトル画面 ---------- */

.screen--title {
  justify-content: center;
  align-items: center;
  gap: 22px;
  text-align: center;
  background: radial-gradient(ellipse 140% 18% at 50% 100%, var(--c-felt) 0 98%, transparent 100%);
}

.title__lead {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  color: var(--c-ink-sub);
}

.title__lead strong { color: var(--c-beni); }

.title__actions {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: min(100%, 320px);
}

.title__daily {
  position: relative;
}

.title__daily .tag {
  position: absolute;
  top: -12px;
  right: -6px;
  transform: rotate(6deg);
  z-index: 1;
}

.title__daily.is-cleared .btn { --btn-bg: var(--c-gunjo-soft); --btn-fg: var(--c-gunjo-deep); --btn-edge: #b7c3e8; }

.title__best {
  margin: 0;
  font-size: 14px;
  color: var(--c-ink-sub);
}

.title__best .num { font-size: 20px; color: var(--c-beni); }

.title__source {
  margin: 0;
  font-size: 11px;
  color: var(--c-ink-sub);
}

/* ---------- ルール画面 ---------- */

.screen--rules {
  justify-content: center;
  gap: 18px;
}

.rules__title {
  margin: 0;
  text-align: center;
  font-size: 26px;
  font-weight: 800;
}

.rules__steps {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  counter-reset: step;
}

.rules__step {
  display: flex;
  align-items: center;
  gap: 14px;
  counter-increment: step;
  animation: pop-in 0.45s var(--ease-pop) both;
}

.rules__step:nth-child(2) { animation-delay: 0.1s; }
.rules__step:nth-child(3) { animation-delay: 0.2s; }
.rules__step:nth-child(4) { animation-delay: 0.3s; }

.rules__step::before {
  content: counter(step);
  flex: none;
  display: grid;
  place-items: center;
  width: 40px;
  height: 52px;
  border: var(--border);
  border-radius: 8px;
  background: var(--c-paper);
  color: var(--c-beni);
  font-family: var(--font-num);
  font-weight: 900;
  font-size: 22px;
  box-shadow: 0 3px 0 var(--c-ink);
  transform: rotate(-4deg);
}

.rules__text { font-size: 16px; font-weight: 700; }
.rules__text small { display: block; font-weight: 400; color: var(--c-ink-sub); font-size: 13px; }
.rules__text em { font-style: normal; color: var(--c-beni); }

.rules__demo {
  padding: 12px;
  border: var(--border);
  border-radius: var(--radius-m);
  background-color: var(--c-felt);
  background-image: var(--pattern-ichimatsu);
  background-size: 24px 24px;
}

.rules__demo .meter { margin: 0; }

.rules__source {
  margin: 0;
  font-size: 11px;
  color: var(--c-ink-sub);
  text-align: center;
}

/* ---------- プレイ画面 ---------- */

.screen--play {
  padding: calc(8px + var(--safe-top)) 12px calc(10px + var(--safe-bottom));
  gap: 8px;
  overflow: hidden;
}

.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 40px;
}

.hud__turn {
  font-size: 14px;
  font-weight: 800;
}

.hud__turn .num { font-size: 20px; color: var(--c-beni); }

/* スコアボード */

.scoreboard {
  position: relative;
  padding: 10px 14px 12px;
  border: var(--border);
  border-radius: var(--radius-m);
  background: var(--c-paper);
  box-shadow: var(--shadow-card);
  text-align: center;
  transition: background var(--dur-mid);
}

.scoreboard__label {
  margin: 0;
  font-size: 12px;
  font-weight: 800;
  color: var(--c-ink-sub);
  letter-spacing: 0.1em;
}

.scoreboard__total {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 4px;
  margin: 0;
  line-height: 1;
}

.scoreboard__num {
  display: inline-block;
  font-size: clamp(44px, 14vw, 64px);
  color: var(--c-ink);
}

.scoreboard__num.is-counting { animation: count-tick 0.12s ease; }
.scoreboard__num.is-done { animation: num-bounce 0.6s var(--ease-pop); }

.scoreboard__unit {
  font-size: 18px;
  font-weight: 800;
}

.scoreboard__added {
  position: absolute;
  top: 34px;
  right: 14px;
  padding: 2px 8px;
  border: 2px solid var(--c-ink);
  border-radius: 999px;
  background: var(--c-felt);
  color: #fff;
  font-size: 14px;
  animation: added-float 1.2s ease-out both;
}

.scoreboard__rest {
  margin: 4px 0 0;
  font-size: 13px;
  font-weight: 700;
  color: var(--c-ink-sub);
}

.scoreboard__rest .num { color: var(--c-felt-deep); font-size: 16px; }

.scoreboard.is-gold {
  background: linear-gradient(180deg, var(--c-gold-soft), var(--c-paper) 70%);
}

.scoreboard.is-gold .scoreboard__num { color: var(--c-gold-deep); }

.scoreboard.is-burst {
  background: var(--c-beni-soft);
}

.scoreboard.is-burst .scoreboard__num { color: var(--c-burst); }

/* プログレスバー: 目盛りは 0〜110万。--p = 合計 / 1,000,000（JS が設定） */

.meter {
  --p: 0;
  --max: 1.1;
  --line: calc(100% / var(--max));
  --gold-start: calc(90% / var(--max));
  position: relative;
  height: 26px;
  margin: 10px 0 24px;
  border: var(--border);
  border-radius: 999px;
  background: #f2e8d4;
  overflow: visible;
}

.meter__track {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  overflow: hidden;
}

.meter__gold {
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--gold-start);
  width: calc(var(--line) - var(--gold-start));
  background: repeating-linear-gradient(-45deg, var(--c-gold-soft) 0 6px, #ffe28a 6px 12px);
}

.meter__over {
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--line);
  right: 0;
  background: repeating-linear-gradient(-45deg, #f6d3d3 0 6px, #f0bcbc 6px 12px);
}

.meter__fill {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: calc(min(var(--p), var(--max)) / var(--max) * 100%);
  border-right: 3px solid var(--c-ink);
  background: linear-gradient(180deg, #5fc39a, var(--c-felt) 60%, var(--c-felt-deep));
  transition: width 0.7s var(--ease-drum), background var(--dur-mid);
}

.meter__fill::after {
  content: "";
  position: absolute;
  top: 4px;
  left: 6px;
  right: 6px;
  height: 5px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.4);
}

.meter__line {
  position: absolute;
  top: -8px;
  bottom: -8px;
  left: var(--line);
  width: 4px;
  margin-left: -2px;
  background: var(--c-beni);
  border-radius: 2px;
  box-shadow: 0 0 0 2px var(--c-ink);
  z-index: 2;
}

.meter__line-label {
  position: absolute;
  top: calc(100% + 8px);
  left: var(--line);
  transform: translateX(-50%);
  font-size: 11px;
  font-weight: 800;
  color: var(--c-beni);
  white-space: nowrap;
}

.meter__gold-label {
  position: absolute;
  top: calc(100% + 8px);
  left: var(--gold-start);
  transform: translateX(-100%);
  padding-right: 4px;
  font-size: 10px;
  font-weight: 800;
  color: var(--c-gold-deep);
  white-space: nowrap;
}

.meter.is-gold .meter__fill {
  background: linear-gradient(90deg, var(--c-gold-deep), var(--c-gold) 40%, var(--c-gold-shine) 50%, var(--c-gold) 60%, var(--c-gold-deep));
  background-size: 200% 100%;
  animation: shimmer 1.6s linear infinite;
}

.meter.is-gold-enter { animation: gold-pulse 0.8s ease-out; }

.meter.is-burst .meter__fill {
  background: var(--c-burst);
  animation: bar-burst 0.5s ease-out both;
}

.meter.is-burst .meter__line { animation: line-snap 0.5s ease-out both; }

/* キラキラ（ゴールドゾーン突入時に JS が i を数個生成） */

.sparkles {
  position: absolute;
  inset: -14px 0;
  pointer-events: none;
  z-index: 3;
}

.sparkles__piece {
  position: absolute;
  left: var(--x, 90%);
  top: var(--y, 50%);
  width: 14px;
  height: 14px;
  background: var(--c-gold);
  clip-path: polygon(50% 0, 62% 38%, 100% 50%, 62% 62%, 50% 100%, 38% 62%, 0 50%, 38% 38%);
  animation: sparkle 0.9s ease-out var(--delay, 0s) both;
}

.sparkles__piece:nth-child(3n) { width: 9px; height: 9px; background: #fff; }
.sparkles__piece:nth-child(3n + 1) { background: var(--c-gold-deep); }

/* バーストの破片 */

.burst-shards {
  position: absolute;
  left: var(--line, 90%);
  top: 50%;
  pointer-events: none;
  z-index: 4;
}

.burst-shards__piece {
  position: absolute;
  width: 10px;
  height: 10px;
  margin: -5px 0 0 -5px;
  background: var(--c-burst);
  border: 2px solid var(--c-ink);
  border-radius: 2px;
  animation: shard-fly 0.7s cubic-bezier(0.2, 0.7, 0.4, 1) both;
}

.burst-shards__piece:nth-child(2n) { background: var(--c-gold); }
.burst-shards__piece:nth-child(3n) { background: #fff; }

/* 地図 */

.map-wrap {
  position: relative;
  flex: 1;
  min-height: 140px;
  border: var(--border);
  border-radius: var(--radius-m);
  background-color: var(--c-felt);
  background-image: var(--pattern-seigaiha);
  background-size: 32px 16px;
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

.map-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.map-wrap.is-gold {
  border-color: var(--c-gold-deep);
  box-shadow: 0 0 0 3px var(--c-gold), var(--shadow-card);
}

.map-wrap.is-gold-enter { animation: gold-flash 0.8s ease-out; }

.map-pop {
  position: absolute;
  left: var(--x, 50%);
  top: var(--y, 50%);
  z-index: 2;
  padding: 3px 10px;
  border: 2px solid var(--c-ink);
  border-radius: 999px;
  background: var(--c-paper);
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
  transform: translate(-50%, calc(-100% - 12px));
  box-shadow: 0 3px 0 var(--c-ink);
  animation: map-pop 1.6s var(--ease-pop) both;
  pointer-events: none;
}

.map-pop::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -8px;
  width: 10px;
  height: 10px;
  margin-left: -5px;
  background: var(--c-paper);
  border-right: 2px solid var(--c-ink);
  border-bottom: 2px solid var(--c-ink);
  transform: rotate(45deg);
}

.map-legend {
  position: absolute;
  left: 8px;
  bottom: 8px;
  z-index: 1;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  max-width: 70%;
  margin: 0;
  padding: 0;
  list-style: none;
}

.map-legend__item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 1px 8px 1px 4px;
  border: 2px solid var(--c-ink);
  border-radius: 999px;
  background: var(--c-paper);
  font-size: 11px;
  font-weight: 800;
}

.map-legend__item::before {
  content: "";
  width: 10px;
  height: 10px;
  border: 2px solid var(--c-ink);
  border-radius: 50%;
  background: var(--turn, var(--c-t1));
}

/* 候補カード */

.hand {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  perspective: 900px;
}

.pcard {
  --turn: var(--c-t1);
  position: relative;
  aspect-ratio: 5 / 6.6;
  max-height: 25dvh;
  width: 100%;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  animation: deal 0.45s var(--ease-pop) both;
  transition: transform 0.25s var(--ease-pop), opacity 0.3s ease;
}

.pcard:nth-child(2) { animation-delay: 0.08s; }
.pcard:nth-child(3) { animation-delay: 0.16s; }

.pcard:focus-visible { outline: 4px solid var(--c-gold); outline-offset: 4px; border-radius: 14px; }

.pcard__inner {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transition: transform var(--dur-flip) var(--ease-pop);
}

.pcard__face {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 10px 6px;
  border: var(--border);
  border-radius: 14px;
  background: var(--c-paper);
  box-shadow: 0 5px 0 var(--c-ink);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  overflow: hidden;
}

.pcard__face--front::before,
.pcard__face--front::after {
  content: "";
  position: absolute;
  width: 8px;
  height: 8px;
  background: var(--c-beni);
  transform: rotate(45deg);
}

.pcard__face--front::before { top: 8px; left: 8px; }
.pcard__face--front::after { bottom: 8px; right: 8px; }

.pcard__pref {
  font-size: 12px;
  font-weight: 800;
  color: var(--c-ink-sub);
}

.pcard__name {
  font-size: clamp(16px, 5vw, 22px);
  font-weight: 800;
  line-height: 1.15;
  text-align: center;
  word-break: keep-all;
  overflow-wrap: anywhere;
}

.pcard__name.is-long { font-size: clamp(13px, 3.8vw, 17px); }

.pcard__q {
  font-family: var(--font-num);
  font-size: 22px;
  font-weight: 900;
  color: var(--c-line);
  letter-spacing: 0.1em;
}

.pcard__face--back {
  transform: rotateY(180deg);
  background-color: var(--turn);
  background-image: var(--pattern-ichimatsu);
  background-size: 16px 16px;
  color: #fff;
}

.pcard__face--back .pcard__name {
  font-size: 13px;
  color: #fff;
  text-shadow: 0 1px 0 rgba(59, 47, 47, 0.5);
}

.pcard__pop {
  display: flex;
  align-items: baseline;
  justify-content: center;
  padding: 4px 6px;
  border: 2px solid var(--c-ink);
  border-radius: 8px;
  background: var(--c-paper);
  color: var(--c-ink);
  font-size: clamp(16px, 4.8vw, 22px);
  line-height: 1;
}

.pcard__pop small { margin-left: 1px; font-size: 11px; font-weight: 800; }

.pcard:not(.is-flipped):not(:disabled):hover .pcard__inner { transform: translateY(-4px) rotate(-1deg); }
.pcard:not(.is-flipped):not(:disabled):active .pcard__inner { transform: translateY(4px); }
.pcard:not(.is-flipped):active .pcard__face { box-shadow: 0 1px 0 var(--c-ink); }

.pcard.is-picked { z-index: 2; transform: translateY(-10px) scale(1.06); }
.pcard.is-flipped .pcard__inner { transform: rotateY(180deg); }
.pcard.is-dropped { opacity: 0; transform: translateY(30px) rotate(var(--tilt, 6deg)) scale(0.9); pointer-events: none; }
.pcard.is-landed .pcard__pop { animation: num-bounce 0.6s var(--ease-pop); }
.pcard.is-gold .pcard__face--back { box-shadow: 0 5px 0 var(--c-ink), 0 0 0 4px var(--c-gold); }
.pcard.is-burst .pcard__face--back { background-color: var(--c-burst); animation: shake 0.4s ease; }

/* 人口帯のヒント（既定は無効。.hand.is-band-hint のときだけ角の小さな帯が出る） */

.pcard__band {
  position: absolute;
  top: 0;
  right: 0;
  width: 26px;
  height: 26px;
  display: none;
  background: linear-gradient(225deg, var(--band, transparent) 50%, transparent 50%);
}

.hand.is-band-hint .pcard__band { display: block; }
.pcard[data-band="s"] { --band: var(--c-band-s); }
.pcard[data-band="m"] { --band: var(--c-band-m); }
.pcard[data-band="l"] { --band: var(--c-band-l); }

/* ドラムロール: 1桁ごとに 0〜9 の縦帯を --d 分だけ送る */

.drum {
  display: inline-flex;
  height: 1em;
  line-height: 1;
  overflow: hidden;
}

.drum__digit {
  --d: 0;
  display: inline-block;
  width: 0.62em;
  height: 1em;
  overflow: hidden;
}

.drum__strip {
  display: flex;
  flex-direction: column;
  transform: translateY(calc(var(--d) * -1em - var(--spin-extra, 0em)));
  transition: transform 1.1s var(--ease-drum);
  transition-delay: calc(var(--i, 0) * 0.08s);
}

.drum__strip > span { height: 1em; text-align: center; }

.drum__comma { display: inline-block; width: 0.3em; text-align: center; }

.drum.is-rolling .drum__strip {
  animation: drum-spin 0.25s linear infinite;
  transition: none;
}

/* 操作 */

.actions {
  display: flex;
  gap: 10px;
  align-items: stretch;
}

.actions .btn { flex: 1; }

.btn--stop {
  --btn-bg: var(--c-gunjo);
  --btn-edge: var(--c-gunjo-deep);
  flex-direction: column;
  gap: 0;
  line-height: 1.15;
}

.btn--stop.is-gold {
  --btn-bg: var(--c-gold);
  --btn-edge: var(--c-gold-deep);
  --btn-fg: var(--c-ink);
  animation: stop-nudge 1.4s ease-in-out infinite;
}

.actions__hint {
  margin: 0;
  font-size: 12px;
  text-align: center;
  color: var(--c-ink-sub);
}

/* バースト演出 */

.screen--play.is-burst { animation: screen-shake 0.5s cubic-bezier(0.36, 0.07, 0.19, 0.97) both; }

.burst-flash {
  position: absolute;
  inset: 0;
  z-index: 20;
  background: radial-gradient(circle at 50% 30%, rgba(255, 255, 255, 0.9), rgba(255, 59, 47, 0.55) 40%, transparent 70%);
  pointer-events: none;
  animation: burst-flash 0.6s ease-out both;
}

.burst-stamp,
.gold-stamp,
.stop-stamp {
  position: absolute;
  top: 34%;
  left: 50%;
  z-index: 30;
  padding: 6px 22px;
  border: 5px solid var(--c-burst);
  border-radius: 14px;
  background: rgba(255, 253, 247, 0.92);
  color: var(--c-burst);
  font-size: clamp(36px, 12vw, 56px);
  font-weight: 900;
  letter-spacing: 0.08em;
  white-space: nowrap;
  box-shadow: 0 0 0 3px var(--c-ink);
  pointer-events: none;
  animation: stamp-center 0.45s var(--ease-pop) both;
}

.gold-stamp {
  border-color: var(--c-gold-deep);
  background: var(--c-gold);
  color: var(--c-ink);
  font-size: clamp(22px, 7vw, 32px);
}

.stop-stamp {
  border-color: var(--c-gunjo);
  color: var(--c-gunjo);
}

/* ---------- 結果画面 ---------- */

.screen--result {
  gap: 14px;
  align-items: stretch;
}

.result__head {
  margin: 0;
  text-align: center;
  font-size: 18px;
  font-weight: 800;
  color: var(--c-ink-sub);
}

.result__board {
  position: relative;
  text-align: center;
  background-color: var(--c-felt);
  background-image: var(--pattern-ichimatsu);
  background-size: 24px 24px;
  color: #fff;
}

.result__total {
  margin: 0;
  line-height: 1;
}

.result__total .num {
  display: inline-block;
  font-size: clamp(44px, 14vw, 64px);
  text-shadow: var(--text-outline);
}

.result__total.is-done .num { animation: num-bounce 0.6s var(--ease-pop); }
.result__total small { font-size: 18px; font-weight: 800; }

.result__diff {
  display: inline-block;
  margin: 8px 0 0;
  padding: 3px 12px;
  border: 2px solid var(--c-ink);
  border-radius: 999px;
  background: var(--c-paper);
  color: var(--c-ink);
  font-size: 15px;
  font-weight: 800;
}

.result__diff .num { color: var(--c-beni); font-size: 18px; }

.result__board .meter { margin: 14px 4px 18px; }
.result__board .meter__line-label,
.result__board .meter__gold-label { color: #fff; text-shadow: 0 1px 0 var(--c-ink); }

.result--gold .result__board {
  background-color: var(--c-gold-deep);
  color: var(--c-ink);
}

.result--burst .result__board {
  background-color: var(--c-burst-deep);
}

.result--burst .result__diff .num { color: var(--c-burst); }

.result__score {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 6px;
  margin: 0;
  font-weight: 800;
}

.result__score .num {
  display: inline-block;
  font-size: 44px;
  color: var(--c-beni);
}

.result__score.is-done .num { animation: num-bounce 0.6s var(--ease-pop); }

.new-record {
  align-self: center;
  padding: 4px 14px;
  border: 3px solid var(--c-beni);
  border-radius: 10px;
  background: var(--c-paper);
  color: var(--c-beni);
  font-weight: 900;
  animation: stamp 0.45s var(--ease-pop) both;
}

.result__best {
  margin: 0;
  text-align: center;
  font-size: 13px;
  color: var(--c-ink-sub);
}

.rank {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  animation: pop-in 0.45s var(--ease-pop) 0.2s both;
}

.rank__label { font-size: 12px; font-weight: 800; color: var(--c-ink-sub); }

.rank__name {
  padding: 6px 20px;
  border: var(--border);
  border-radius: 999px;
  background: var(--c-gold);
  font-size: 22px;
  font-weight: 900;
  box-shadow: var(--shadow-hard);
  transform: rotate(-2deg);
}

.result--burst .rank__name { background: var(--c-beni-soft); }

.result__map {
  position: relative;
  height: 220px;
  border: var(--border);
  border-radius: var(--radius-m);
  background-color: var(--c-felt);
  background-image: var(--pattern-seigaiha);
  background-size: 32px 16px;
  overflow: hidden;
}

.result__map canvas { width: 100%; height: 100%; display: block; }

.got-list {
  list-style: none;
  margin: 0;
  padding: 4px 12px;
}

.got-list__title {
  margin: 0 0 4px;
  font-size: 14px;
  font-weight: 800;
}

.got-list__item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 2px dashed var(--c-line);
  animation: pop-in 0.4s var(--ease-pop) both;
}

.got-list__item:last-child { border-bottom: 0; }
.got-list__item:nth-child(2) { animation-delay: 0.06s; }
.got-list__item:nth-child(3) { animation-delay: 0.12s; }
.got-list__item:nth-child(4) { animation-delay: 0.18s; }
.got-list__item:nth-child(n + 5) { animation-delay: 0.24s; }

.got-list__no {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border: 2px solid var(--c-ink);
  border-radius: 50%;
  background: var(--turn, var(--c-t1));
  color: #fff;
  font-family: var(--font-num);
  font-weight: 900;
  font-size: 13px;
  text-shadow: 0 1px 0 rgba(59, 47, 47, 0.6);
}

.got-list__name { font-weight: 800; line-height: 1.2; }
.got-list__name small { display: block; font-size: 11px; font-weight: 700; color: var(--c-ink-sub); }
.got-list__pop { font-size: 16px; }
.got-list__pop small { font-size: 11px; font-weight: 800; margin-left: 1px; }

.got-list__item.is-burst { background: var(--c-beni-soft); border-radius: 8px; padding-inline: 6px; }
.got-list__item.is-burst .got-list__pop { color: var(--c-burst); }

.result__actions {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-bottom: 8px;
}

.result__share-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.share-done {
  align-self: center;
  font-size: 13px;
  font-weight: 800;
  color: var(--c-felt-deep);
  animation: fade-in var(--dur-mid) ease both;
}

.share-preview {
  display: block;
  width: 100%;
  border: var(--border);
  border-radius: var(--radius-s);
}

.result__source {
  margin: 0;
  font-size: 11px;
  text-align: center;
  color: var(--c-ink-sub);
}

/* ---------- 紙吹雪 ---------- */

.confetti {
  position: fixed;
  inset: 0;
  z-index: 50;
  pointer-events: none;
  overflow: hidden;
}

.confetti__piece {
  position: absolute;
  top: -20px;
  left: var(--x, 50%);
  width: 10px;
  height: 14px;
  background: var(--c-gold);
  border-radius: 2px;
  opacity: 0;
  animation: confetti-fall var(--dur, 1.8s) cubic-bezier(0.25, 0.6, 0.5, 1) var(--delay, 0s) forwards;
}

.confetti__piece:nth-child(5n + 1) { background: var(--c-gold); }
.confetti__piece:nth-child(5n + 2) { background: var(--c-beni); width: 8px; height: 8px; border-radius: 50%; }
.confetti__piece:nth-child(5n + 3) { background: var(--c-felt); }
.confetti__piece:nth-child(5n + 4) { background: var(--c-gunjo); width: 6px; height: 16px; }
.confetti__piece:nth-child(5n + 5) { background: #fff; border: 1px solid var(--c-gold-deep); width: 12px; height: 8px; }

/* ---------- keyframes ---------- */

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes fade-out { from { opacity: 1; } to { opacity: 0; } }

@keyframes pop-in {
  0% { opacity: 0; transform: scale(0.85) translateY(8px); }
  100% { opacity: 1; transform: none; }
}

@keyframes deal {
  0% { opacity: 0; transform: translate(40px, -60px) rotate(18deg) scale(0.8); }
  70% { opacity: 1; transform: translate(0, 4px) rotate(-2deg); }
  100% { opacity: 1; transform: none; }
}

@keyframes logo-deal {
  0%, 100% { translate: 0 0; }
  50% { translate: 0 -5px; }
}

@keyframes logo-coin {
  0%, 100% { translate: 0 0; rotate: 0deg; }
  45% { translate: 0 -8px; rotate: y 0deg; }
  53% { translate: 0 -8px; rotate: y 360deg; }
  62% { translate: 0 0; rotate: y 360deg; }
}

@keyframes count-tick {
  0% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
  100% { transform: translateY(0); }
}

@keyframes num-bounce {
  0% { transform: scale(1); }
  30% { transform: scale(1.3) rotate(-3deg); }
  55% { transform: scale(0.92) rotate(1deg); }
  75% { transform: scale(1.06); }
  100% { transform: scale(1); }
}

@keyframes added-float {
  0% { opacity: 0; transform: translateY(8px) scale(0.8); }
  20% { opacity: 1; transform: translateY(0) scale(1.1); }
  70% { opacity: 1; transform: translateY(-6px) scale(1); }
  100% { opacity: 0; transform: translateY(-16px); }
}

@keyframes drum-spin {
  from { transform: translateY(0); }
  to { transform: translateY(-9em); }
}

@keyframes shimmer {
  from { background-position: 200% 0; }
  to { background-position: 0% 0; }
}

@keyframes gold-pulse {
  0% { box-shadow: 0 0 0 0 rgba(255, 200, 61, 0.9); }
  100% { box-shadow: 0 0 0 16px rgba(255, 200, 61, 0); }
}

@keyframes gold-flash {
  0% { box-shadow: inset 0 0 0 0 rgba(255, 200, 61, 0.9), 0 0 0 3px var(--c-gold); }
  40% { box-shadow: inset 0 0 0 14px rgba(255, 200, 61, 0.9), 0 0 0 3px var(--c-gold); }
  100% { box-shadow: inset 0 0 0 0 rgba(255, 200, 61, 0), 0 0 0 3px var(--c-gold); }
}

@keyframes sparkle {
  0% { opacity: 0; transform: scale(0) rotate(0); }
  40% { opacity: 1; transform: scale(1.3) rotate(45deg); }
  100% { opacity: 0; transform: translateY(-14px) scale(0.4) rotate(90deg); }
}

@keyframes bar-burst {
  0% { transform: scaleY(1); filter: brightness(1); }
  25% { transform: scaleY(1.5); filter: brightness(1.6); }
  50% { transform: scaleY(0.7); }
  100% { transform: scaleY(1); filter: brightness(1); }
}

@keyframes line-snap {
  0% { transform: rotate(0); }
  40% { transform: rotate(-18deg) translateY(-4px); }
  100% { transform: rotate(-10deg) translateY(2px); }
}

@keyframes shard-fly {
  0% { opacity: 1; transform: translate(0, 0) rotate(0) scale(1); }
  100% { opacity: 0; transform: translate(var(--dx, 40px), var(--dy, -40px)) rotate(var(--spin, 360deg)) scale(0.5); }
}

@keyframes burst-flash {
  0% { opacity: 0; }
  15% { opacity: 1; }
  100% { opacity: 0; }
}

@keyframes screen-shake {
  0%, 100% { transform: translate(0, 0); }
  10% { transform: translate(-8px, 2px) rotate(-1deg); }
  25% { transform: translate(8px, -3px) rotate(1deg); }
  40% { transform: translate(-6px, 3px); }
  55% { transform: translate(6px, -2px); }
  70% { transform: translate(-3px, 1px); }
  85% { transform: translate(2px, 0); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

@keyframes stamp {
  0% { opacity: 0; transform: scale(2.2) rotate(-12deg); }
  70% { opacity: 1; transform: scale(0.94) rotate(-4deg); }
  100% { opacity: 1; transform: scale(1) rotate(-4deg); }
}

@keyframes stamp-center {
  0% { opacity: 0; transform: translateX(-50%) scale(2.4) rotate(-14deg); }
  70% { opacity: 1; transform: translateX(-50%) scale(0.94) rotate(-8deg); }
  100% { opacity: 1; transform: translateX(-50%) scale(1) rotate(-8deg); }
}

@keyframes map-pop {
  0% { opacity: 0; transform: translate(-50%, calc(-100% - 2px)) scale(0.6); }
  20% { opacity: 1; transform: translate(-50%, calc(-100% - 12px)) scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, calc(-100% - 18px)); }
}

@keyframes stop-nudge {
  0%, 100% { scale: 1; }
  50% { scale: 1.04; }
}

@keyframes confetti-fall {
  0% { opacity: 1; transform: translate3d(0, 0, 0) rotate(0); }
  100% { opacity: 0.9; transform: translate3d(var(--drift, 30px), 110vh, 0) rotate(var(--spin, 720deg)); }
}

/* ---------- 画面の高さが足りないとき ---------- */

@media (max-height: 680px) {
  .scoreboard { padding: 6px 12px 8px; }
  .scoreboard__num { font-size: 40px; }
  .scoreboard__rest { display: none; }
  .meter { height: 20px; margin: 8px 0 16px; }
  .pcard { aspect-ratio: 5 / 5.4; }
  .pcard__q { display: none; }
  .btn--stop .btn__sub { display: none; }
  .btn--stop { min-height: 48px; }
}

/* ---------- PC ---------- */

@media (min-width: 768px) {
  .app {
    height: min(100dvh, 920px);
    margin-top: max(0px, calc((100dvh - 920px) / 2));
    border: var(--border);
    border-radius: var(--radius-l);
    background: var(--c-bg);
    box-shadow: 0 12px 40px rgba(59, 47, 47, 0.15);
  }
}

/* ---------- reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    animation-delay: 0s !important;
    transition-duration: 0.01ms !important;
    transition-delay: 0s !important;
    scroll-behavior: auto !important;
  }

  .screen { transform: none; }
  .confetti,
  .sparkles,
  .burst-shards,
  .burst-flash { display: none; }
  .meter.is-gold .meter__fill { animation: none; background-position: 50% 0; }
  .drum.is-rolling .drum__strip { animation: none; }
  .pcard__inner { transition: none; }
  .pcard.is-flipped .pcard__inner { transform: none; }
  .pcard.is-flipped .pcard__face--front { visibility: hidden; }
  .pcard.is-flipped .pcard__face--back { transform: none; }
  .screen--play.is-burst .scoreboard { outline: 4px solid var(--c-burst); }
}
