/* 都道府県つみつみタワー style.css — 構造とクラス名は docs/design.md を参照 */

:root {
  --c-ink: #3b2f2f;
  --c-ink-sub: #7a6a5e;
  --c-paper: #fffdf7;
  --c-bg: #fff6e4;
  --c-line: #eadcc0;
  --c-shu: #e8513b;
  --c-shu-deep: #b83a28;
  --c-ai: #2f4b7c;
  --c-ai-deep: #1e3256;
  --c-gold: #ffc83d;
  --c-gold-deep: #d99a00;
  --c-matcha: #7bc96f;
  --c-matcha-deep: #4fa443;
  --c-sky: #bfe6ff;
  --c-sky-deep: #7cc4f2;
  --c-cloud: #ffffff;

  --c-r1: #b39ddb; --c-r1-soft: #ece5f8;
  --c-r2: #f7a440; --c-r2-soft: #fdead3;
  --c-r3: #ff8fab; --c-r3-soft: #ffe3eb;
  --c-r4: #7bc96f; --c-r4-soft: #e3f5df;
  --c-r5: #ffd23f; --c-r5-soft: #fff4cc;
  --c-r6: #3fbfad; --c-r6-soft: #d9f3ef;
  --c-r7: #5b8fd9; --c-r7-soft: #dfe9f8;
  --c-r8: #e8513b; --c-r8-soft: #fbdcd6;

  --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;
  --ease-pop: cubic-bezier(0.34, 1.56, 0.64, 1);

  --stroke-ink:
    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);
  --stroke-ink-thin:
    1.5px 0 0 var(--c-ink), -1.5px 0 0 var(--c-ink),
    0 1.5px 0 var(--c-ink), 0 -1.5px 0 var(--c-ink),
    0 3px 0 var(--c-ink);
}

*,
*::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:
    linear-gradient(90deg, rgba(184, 155, 106, 0.1) 1px, transparent 1px),
    linear-gradient(rgba(184, 155, 106, 0.1) 1px, transparent 1px);
  background-size: 28px 28px;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  line-height: 1.5;
}

button {
  font: inherit;
  color: inherit;
}

.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;
}

.visually-hidden {
  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;
}

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

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

.logo__sub {
  display: inline-block;
  padding: 2px 14px;
  border: var(--border);
  border-radius: 999px;
  background: var(--c-paper);
  color: var(--c-ai);
  font-size: clamp(16px, 5vw, 22px);
  letter-spacing: 0.12em;
  box-shadow: var(--shadow-hard);
  transform: rotate(-3deg);
}

.logo__stack {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  margin: 14px 0 0;
  height: clamp(110px, 34vw, 150px);
}

.logo__block {
  --size: clamp(52px, 17vw, 72px);
  display: grid;
  place-items: center;
  width: var(--size);
  height: var(--size);
  border: var(--border);
  border-radius: 12px;
  background: var(--blk, var(--c-r3));
  color: #fff;
  font-size: calc(var(--size) * 0.62);
  text-shadow: var(--stroke-ink-thin);
  box-shadow: inset 0 -6px 0 rgba(0, 0, 0, 0.12), inset 0 4px 0 rgba(255, 255, 255, 0.35);
  transform-origin: 50% 100%;
}

.logo__block:nth-child(1) { --blk: var(--c-r3); transform: rotate(-6deg); animation: logo-wobble 2.6s ease-in-out infinite; }
.logo__block:nth-child(2) { --blk: var(--c-r5); margin-bottom: 18px; transform: rotate(4deg); animation: logo-wobble 2.6s ease-in-out 0.2s infinite; }
.logo__block:nth-child(3) { --blk: var(--c-r6); margin-bottom: 36px; transform: rotate(-3deg); animation: logo-wobble 2.6s ease-in-out 0.4s infinite; }
.logo__block:nth-child(4) { --blk: var(--c-r7); margin-bottom: 54px; transform: rotate(7deg); animation: logo-wobble 2.6s ease-in-out 0.6s infinite; }

.logo__base {
  position: relative;
  display: block;
  padding: 10px 40px 8px;
  min-width: min(84vw, 340px);
  color: #fff;
  font-size: clamp(30px, 10vw, 44px);
  letter-spacing: 0.2em;
  text-shadow: var(--stroke-ink);
  background: linear-gradient(var(--c-ai), var(--c-ai-deep));
  clip-path: polygon(14% 0, 86% 0, 100% 100%, 0 100%);
}

.logo__base::before {
  content: "";
  position: absolute;
  inset: 0 14% auto;
  height: 12px;
  background:
    linear-gradient(135deg, #fff 6px, transparent 6px) 0 0 / 12px 12px repeat-x,
    linear-gradient(225deg, #fff 6px, transparent 6px) 0 0 / 12px 12px repeat-x;
}

.logo__mount {
  display: block;
  margin-top: -2px;
  filter: drop-shadow(0 3px 0 var(--c-ink)) drop-shadow(0 -3px 0 var(--c-ink)) drop-shadow(3px 0 0 var(--c-ink)) drop-shadow(-3px 0 0 var(--c-ink));
}

.logo--small { flex-direction: row; gap: 6px; }
.logo--small .logo__sub { font-size: 11px; padding: 0 8px; box-shadow: none; border-width: 2px; }
.logo--small .logo__stack { height: auto; margin: 0; gap: 2px; }
.logo--small .logo__block { --size: 22px; border-width: 2px; border-radius: 5px; margin-bottom: 0; animation: none; box-shadow: none; }
.logo--small .logo__mount { display: none; }

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

.btn {
  --btn-bg: var(--c-shu);
  --btn-edge: var(--c-shu-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;
  touch-action: manipulation;
  box-shadow: 0 var(--btn-depth) 0 var(--btn-edge), 0 var(--btn-depth) 0 3px var(--c-ink);
  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,
.ctrl:focus-visible,
.icon-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--secondary { --btn-bg: var(--c-ai); --btn-edge: var(--c-ai-deep); }
.btn--gold { --btn-bg: var(--c-gold); --btn-edge: var(--c-gold-deep); --btn-fg: var(--c-ink); }
.btn--green { --btn-bg: var(--c-matcha); --btn-edge: var(--c-matcha-deep); }
.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--small::after { top: 4px; height: 4px; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  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;
}

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

.screen--title {
  justify-content: center;
  align-items: center;
  gap: 22px;
  text-align: center;
  background:
    radial-gradient(circle at 82% 14%, #fff2b3 0 28px, transparent 29px),
    radial-gradient(ellipse 60px 18px at 18% 22%, #fff 98%, transparent),
    radial-gradient(ellipse 44px 14px at 26% 19%, #fff 98%, transparent),
    radial-gradient(ellipse 70px 20px at 76% 34%, rgba(255, 255, 255, 0.85) 98%, transparent),
    linear-gradient(to bottom, var(--c-sky-deep) 0%, var(--c-sky) 55%, var(--c-bg) 100%);
}

.title__lead {
  margin: 0;
  padding: 6px 16px;
  border-radius: 999px;
  background: rgba(255, 253, 247, 0.85);
  font-size: 15px;
  font-weight: 700;
}

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

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

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

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

.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.08s; }
.rules__step:nth-child(3) { animation-delay: 0.16s; }
.rules__step:nth-child(4) { animation-delay: 0.24s; }

.rules__step::before {
  content: counter(step);
  flex: none;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: var(--border);
  border-radius: 10px;
  background: var(--step-c, var(--c-r5));
  font-family: var(--font-num);
  font-weight: 900;
  font-size: 20px;
  transform: rotate(-6deg);
}

.rules__step:nth-child(2) { --step-c: var(--c-r3); }
.rules__step:nth-child(3) { --step-c: var(--c-r6); }
.rules__step:nth-child(4) { --step-c: var(--c-r1); }

.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__keys {
  margin: 0;
  font-size: 13px;
  color: var(--c-ink-sub);
  text-align: center;
}

kbd {
  display: inline-block;
  min-width: 26px;
  margin: 0 2px;
  padding: 1px 6px;
  border: 2px solid var(--c-ink);
  border-radius: 6px;
  background: var(--c-paper);
  box-shadow: 0 2px 0 var(--c-ink);
  font-family: var(--font-num);
  font-size: 12px;
  font-weight: 800;
  color: var(--c-ink);
  text-align: center;
}

.rules__actions {
  display: flex;
  gap: 12px;
}

.rules__actions .btn { flex: 1; padding-inline: 12px; }

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

.screen--play {
  padding: 0;
  overflow: hidden;
  background: var(--c-sky);
}

.stage {
  position: absolute;
  inset: 0;
  touch-action: none;
}

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

.play-ui {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: calc(8px + var(--safe-top)) 10px calc(12px + var(--safe-bottom));
  pointer-events: none;
}

.play-ui button { pointer-events: auto; }

.hud {
  display: flex;
  align-items: stretch;
  gap: 6px;
}

.hud__item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 0;
  padding: 3px 6px 4px;
  border: var(--border);
  border-radius: 14px;
  background: var(--c-paper);
  box-shadow: 0 3px 0 var(--c-ink);
  line-height: 1.1;
}

.hud__label {
  font-size: 10px;
  font-weight: 800;
  color: var(--c-ink-sub);
  letter-spacing: 0.08em;
}

.hud__value { font-size: 22px; color: var(--c-ink); display: inline-block; }
.hud__unit { font-size: 11px; font-weight: 800; margin-left: 1px; }
.hud__item--height { flex: 1.4; background: var(--c-gold); }
.hud__item--height .hud__label { color: var(--c-ink); }
.hud__item--best .hud__value { color: var(--c-shu); font-size: 18px; }
.hud .icon-btn { align-self: center; flex: none; }

.hud__value.is-bump { animation: hud-bump 0.45s var(--ease-pop); }
.hud__item--height.is-record { background: var(--c-shu); }
.hud__item--height.is-record .hud__label,
.hud__item--height.is-record .hud__value,
.hud__item--height.is-record .hud__unit { color: #fff; }

.turn-badge {
  align-self: center;
  margin-top: 6px;
  padding: 2px 14px;
  border: 2px solid var(--c-ink);
  border-radius: 999px;
  background: var(--c-paper);
  font-size: 13px;
  font-weight: 800;
}

.turn-badge[data-player="1"] { background: var(--c-r3); }
.turn-badge[data-player="2"] { background: var(--c-r7); color: #fff; }

.spawn {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: start;
  gap: 8px;
  margin-top: 8px;
}

.spawn__zone {
  position: absolute;
  left: -10px;
  right: -10px;
  top: 64px;
  height: var(--spawn-h, 120px);
  border-block: 2px dashed rgba(59, 47, 47, 0.25);
  background: repeating-linear-gradient(-45deg, rgba(255, 255, 255, 0.14) 0 10px, transparent 10px 20px);
}

.pref-banner {
  position: relative;
  z-index: 1;
  justify-self: start;
  max-width: 100%;
  padding: 4px 14px 6px 12px;
  border: var(--border);
  border-left-width: 10px;
  border-left-color: var(--pref-c, var(--c-r3));
  border-radius: 6px 16px 16px 6px;
  background: var(--c-paper);
  box-shadow: 0 4px 0 var(--c-ink);
  transform-origin: 0 50%;
}

.pref-banner__name {
  display: block;
  font-size: clamp(30px, 10vw, 42px);
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.pref-banner__region {
  display: inline-block;
  margin-right: 6px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--pref-c, var(--c-r3));
  border: 2px solid var(--c-ink);
  font-size: 11px;
  font-weight: 800;
  vertical-align: 2px;
}

.pref-banner__catch {
  display: block;
  font-size: 13px;
  font-weight: 700;
  color: var(--c-ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pref-banner.is-pop { animation: pref-pop 0.55s var(--ease-pop) both; }
.pref-banner.is-pop .pref-banner__catch { animation: fade-up 0.4s ease 0.25s both; }

.next {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 76px;
  padding: 2px 4px 6px;
  border: var(--border);
  border-radius: 14px;
  background: rgba(255, 253, 247, 0.92);
  box-shadow: 0 3px 0 var(--c-ink);
}

.next__label {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.1em;
  color: var(--c-ink-sub);
}

.next__canvas {
  display: block;
  width: 56px;
  height: 56px;
}

.next__name {
  max-width: 100%;
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.next.is-swap { animation: next-swap 0.35s var(--ease-pop); }

.play-ui__spacer { flex: 1; }

.controls {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 10px;
}

.ctrl {
  --c-bg-ctrl: var(--c-paper);
  --c-edge-ctrl: var(--c-line);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
  width: 72px;
  height: 72px;
  padding: 0;
  border: var(--border);
  border-radius: 50%;
  background: var(--c-bg-ctrl);
  font-weight: 800;
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
  box-shadow: 0 5px 0 var(--c-edge-ctrl), 0 5px 0 3px var(--c-ink);
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}

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

.ctrl:disabled { filter: grayscale(0.8) opacity(0.55); }

.ctrl__icon { font-size: 28px; line-height: 1; }
.ctrl__label { font-size: 11px; letter-spacing: 0.06em; }

.ctrl--rotate { --c-bg-ctrl: var(--c-r6); --c-edge-ctrl: #2a9182; }
.ctrl--rotate.is-pressed .ctrl__icon { animation: spin-90 0.2s ease; }
.ctrl--move { width: 56px; height: 56px; }
.ctrl--move .ctrl__icon { font-size: 22px; }

.ctrl--drop {
  --c-bg-ctrl: var(--c-shu);
  --c-edge-ctrl: var(--c-shu-deep);
  flex: 1;
  max-width: 200px;
  height: 64px;
  border-radius: 999px;
  color: #fff;
  flex-direction: row;
  gap: 6px;
}

.ctrl--drop .ctrl__label { font-size: 20px; }
.ctrl--drop .ctrl__icon { font-size: 22px; }

.controls__hint {
  margin: 0 0 8px;
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--c-ink);
  text-shadow: 0 0 4px #fff, 0 0 2px #fff;
}

.screen--play.is-night .controls__hint { color: #fff; text-shadow: 0 1px 2px #000; }

.screen--play.is-waiting .ctrl--drop,
.screen--play.is-waiting .ctrl--rotate { filter: grayscale(0.7) opacity(0.6); pointer-events: none; }

.waiting-dots {
  display: none;
  align-self: center;
  margin-bottom: 8px;
  padding: 2px 12px;
  border-radius: 999px;
  background: rgba(255, 253, 247, 0.9);
  border: 2px solid var(--c-ink);
  font-size: 12px;
  font-weight: 800;
}

.screen--play.is-waiting .waiting-dots { display: inline-block; }
.waiting-dots::after { content: "…"; display: inline-block; animation: dots 1s steps(4) infinite; width: 1em; overflow: hidden; vertical-align: bottom; }

.alt-toast {
  position: absolute;
  left: 50%;
  top: 22%;
  z-index: 3;
  padding: 4px 16px;
  border: var(--border);
  border-radius: 999px;
  background: var(--c-gold);
  font-size: 18px;
  font-weight: 800;
  white-space: nowrap;
  box-shadow: 0 4px 0 var(--c-ink);
  transform: translate(-50%, 0);
  opacity: 0;
  pointer-events: none;
}

.alt-toast.is-show { animation: alt-toast 1.6s ease both; }

/* ---------- ゲームオーバー演出 ---------- */

.screen--play.is-shake { animation: shake 0.5s ease-in-out; }

.collapse-flash {
  position: absolute;
  inset: 0;
  z-index: 4;
  background: var(--c-shu);
  opacity: 0;
  pointer-events: none;
}

.screen--play.is-collapse .collapse-flash { animation: collapse-flash 0.6s ease-out; }

.collapse-stamp {
  position: absolute;
  left: 50%;
  top: 20%;
  z-index: 5;
  padding: 6px 22px 8px;
  border: 5px solid var(--c-shu);
  border-radius: 12px;
  background: rgba(255, 253, 247, 0.92);
  color: var(--c-shu);
  font-size: clamp(40px, 14vw, 60px);
  font-weight: 800;
  letter-spacing: 0.08em;
  white-space: nowrap;
  box-shadow: inset 0 0 0 3px var(--c-paper), inset 0 0 0 5px var(--c-shu);
  transform: translate(-50%, -50%) rotate(-10deg) scale(0);
  opacity: 0;
  pointer-events: none;
}

.screen--play.is-collapse .collapse-stamp { animation: stamp-center 0.5s var(--ease-pop) 0.2s forwards; }

/* ---------- 結果オーバーレイ ---------- */

.overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: calc(12px + var(--safe-top)) 12px calc(12px + var(--safe-bottom));
  background: rgba(30, 50, 86, 0.45);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--dur-mid) ease, visibility 0s linear var(--dur-mid);
}

.overlay.is-open {
  opacity: 1;
  visibility: visible;
  transition: opacity var(--dur-mid) ease, visibility 0s;
}

.result {
  position: relative;
  width: 100%;
  max-height: 100%;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 18px 16px 16px;
  border-radius: var(--radius-l);
}

.overlay.is-open .result { animation: sheet-up 0.5s var(--ease-pop) both; }

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

.result__stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.result__stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 6px 4px 8px;
  border: var(--border);
  border-radius: var(--radius-s);
  background: var(--c-bg);
}

.result__stat--height { background: var(--c-gold); }
.result__stat-label { font-size: 12px; font-weight: 800; color: var(--c-ink-sub); }
.result__stat--height .result__stat-label { color: var(--c-ink); }
.result__stat-value { font-size: 40px; line-height: 1.05; }
.result__stat-unit { font-size: 15px; font-weight: 800; margin-left: 2px; }
.result__stat-value.is-counting { animation: count-tick 0.12s ease; }

.result__title {
  position: relative;
  align-self: center;
  margin: 2px 0;
  padding: 6px 22px 8px;
  border: var(--border);
  border-radius: 8px;
  background: var(--c-ai);
  color: #fff;
  font-size: clamp(20px, 6.5vw, 26px);
  font-weight: 800;
  letter-spacing: 0.06em;
  text-align: center;
  box-shadow: 0 4px 0 var(--c-ink);
  animation: stamp 0.5s var(--ease-pop) 0.4s both;
}

.result__title::before {
  content: "称号";
  position: absolute;
  top: -12px;
  left: -10px;
  padding: 0 8px;
  border: 2px solid var(--c-ink);
  border-radius: 999px;
  background: var(--c-gold);
  color: var(--c-ink);
  font-size: 11px;
  letter-spacing: 0.1em;
  transform: rotate(-8deg);
}

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

.result__chips-label { margin: 0; font-size: 12px; font-weight: 800; color: var(--c-ink-sub); }

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  max-height: 132px;
  overflow-y: auto;
  margin: 0;
  padding: 8px;
  list-style: none;
  border: 2px dashed var(--c-line);
  border-radius: var(--radius-s);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 1px 9px 2px 4px;
  border: 2px solid var(--c-ink);
  border-radius: 999px;
  background: var(--chip-soft, var(--c-bg));
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
  animation: pop-in 0.3s var(--ease-pop) both;
  animation-delay: calc(var(--i, 0) * 30ms);
}

.chip::before {
  content: "";
  width: 12px;
  height: 12px;
  border: 2px solid var(--c-ink);
  border-radius: 4px;
  background: var(--chip-c, var(--c-r3));
}

.chip--fell { opacity: 0.55; text-decoration: line-through; }

.chip--r1 { --chip-c: var(--c-r1); --chip-soft: var(--c-r1-soft); }
.chip--r2 { --chip-c: var(--c-r2); --chip-soft: var(--c-r2-soft); }
.chip--r3 { --chip-c: var(--c-r3); --chip-soft: var(--c-r3-soft); }
.chip--r4 { --chip-c: var(--c-r4); --chip-soft: var(--c-r4-soft); }
.chip--r5 { --chip-c: var(--c-r5); --chip-soft: var(--c-r5-soft); }
.chip--r6 { --chip-c: var(--c-r6); --chip-soft: var(--c-r6-soft); }
.chip--r7 { --chip-c: var(--c-r7); --chip-soft: var(--c-r7-soft); }
.chip--r8 { --chip-c: var(--c-r8); --chip-soft: var(--c-r8-soft); }

.pref-banner.r1 { --pref-c: var(--c-r1); }
.pref-banner.r2 { --pref-c: var(--c-r2); }
.pref-banner.r3 { --pref-c: var(--c-r3); }
.pref-banner.r4 { --pref-c: var(--c-r4); }
.pref-banner.r5 { --pref-c: var(--c-r5); }
.pref-banner.r6 { --pref-c: var(--c-r6); }
.pref-banner.r7 { --pref-c: var(--c-r7); }
.pref-banner.r8 { --pref-c: var(--c-r8); }

.result__best {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  color: var(--c-ink-sub);
}

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

.record-badge {
  display: none;
  padding: 1px 10px;
  border: 2px solid var(--c-ink);
  border-radius: 999px;
  background: var(--c-shu);
  color: #fff;
  font-size: 13px;
  font-weight: 800;
}

.result.is-new-record .record-badge { display: inline-block; animation: record-pulse 1s ease-in-out infinite; }
.result.is-new-record .result__stat--height { background: var(--c-shu); }
.result.is-new-record .result__stat--height .result__stat-label,
.result.is-new-record .result__stat--height .result__stat-value { color: #fff; }

.result__actions {
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  gap: 10px;
  margin-top: 4px;
}

.result__actions .btn { padding-inline: 10px; }

.result__home {
  justify-self: center;
  background: none;
  border: 0;
  padding: 4px 8px;
  font-size: 13px;
  font-weight: 700;
  color: var(--c-ink-sub);
  text-decoration: underline;
  cursor: pointer;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--safe-bottom));
  z-index: 30;
  padding: 8px 18px;
  border: var(--border);
  border-radius: 999px;
  background: var(--c-ink);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  transform: translate(-50%, 20px);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-fast) ease, transform var(--dur-mid) var(--ease-pop);
}

.toast.is-show { opacity: 1; transform: translate(-50%, 0); }

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

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

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

.confetti__piece:nth-child(8n + 1) { background: var(--c-r1); }
.confetti__piece:nth-child(8n + 2) { background: var(--c-r2); border-radius: 50%; }
.confetti__piece:nth-child(8n + 3) { background: var(--c-r3); width: 6px; height: 14px; }
.confetti__piece:nth-child(8n + 4) { background: var(--c-r4); }
.confetti__piece:nth-child(8n + 5) { background: var(--c-r5); border-radius: 50%; }
.confetti__piece:nth-child(8n + 6) { background: var(--c-r6); width: 6px; height: 14px; }
.confetti__piece:nth-child(8n + 7) { background: var(--c-r7); }
.confetti__piece:nth-child(8n + 8) { background: var(--c-r8); width: 12px; height: 6px; }

/* ---------- キーフレーム ---------- */

@keyframes pop-in {
  from { opacity: 0; transform: scale(0.6); }
  to { opacity: 1; transform: none; }
}

@keyframes fade-up {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

@keyframes pref-pop {
  0% { opacity: 0; transform: scale(0.3) rotate(-8deg); }
  55% { opacity: 1; transform: scale(1.12) rotate(2deg); }
  75% { transform: scale(0.96) rotate(-1deg); }
  100% { opacity: 1; transform: none; }
}

@keyframes next-swap {
  0% { transform: scale(0.8); }
  100% { transform: none; }
}

@keyframes hud-bump {
  0% { transform: translateY(0) scale(1); }
  30% { transform: translateY(-8px) scale(1.25); }
  60% { transform: translateY(2px) scale(0.95); }
  100% { transform: none; }
}

@keyframes spin-90 {
  from { transform: rotate(-90deg); }
  to { transform: none; }
}

@keyframes dots {
  from { width: 0; }
  to { width: 1em; }
}

@keyframes alt-toast {
  0% { opacity: 0; transform: translate(-50%, 16px) scale(0.7); }
  15% { opacity: 1; transform: translate(-50%, 0) scale(1.08); }
  25% { transform: translate(-50%, 0) scale(1); }
  80% { opacity: 1; transform: translate(-50%, -10px); }
  100% { opacity: 0; transform: translate(-50%, -24px); }
}

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

@keyframes collapse-flash {
  0% { opacity: 0.35; }
  100% { opacity: 0; }
}

@keyframes stamp-center {
  0% { opacity: 0; transform: translate(-50%, -50%) rotate(-10deg) scale(2.4); }
  100% { opacity: 1; transform: translate(-50%, -50%) rotate(-10deg) scale(0.8); }
}

@keyframes stamp {
  0% { opacity: 0; transform: scale(2) rotate(-6deg); }
  100% { opacity: 1; transform: none; }
}

@keyframes sheet-up {
  from { opacity: 0; transform: translateY(60px); }
  to { opacity: 1; transform: none; }
}

@keyframes count-tick {
  50% { transform: scale(1.12); }
}

@keyframes record-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}

@keyframes confetti-fall {
  0% { transform: translate(0, 0) rotate(0); opacity: 1; }
  100% { transform: translate(var(--dx, 0px), 110dvh) rotate(var(--rot, 540deg)); opacity: 0.9; }
}

@keyframes logo-wobble {
  0%, 100% { translate: 0 0; rotate: 0deg; }
  50% { translate: 0 -4px; rotate: 3deg; }
}

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

@media (hover: hover) and (pointer: fine) {
  .controls__hint--touch { display: none; }
}

@media (hover: none) {
  .controls__hint--pc { display: none; }
}

@media (min-height: 760px) {
  .ctrl { width: 80px; height: 80px; }
  .ctrl--drop { height: 70px; }
}

/* ---------- 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;
  }

  .logo__block { animation: none !important; }
  .screen--play.is-shake { animation: none !important; }
  .screen--play.is-collapse .collapse-stamp { opacity: 1; transform: translate(-50%, -50%) rotate(-10deg) scale(0.8); }
  .confetti { display: none; }
}
