:root {
  --ink: #111010;
  --cream: #FFF6E3;
  --gold: #FFD45C;
  --green: #08A752;
  --pink: #FF7EB6;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; }
body {
  font: 800 18px/1.6 "M PLUS Rounded 1c", "Hiragino Maru Gothic ProN", "Yu Gothic", "Meiryo", sans-serif;
  color: #fff;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  background:
    radial-gradient(2px 2px at 8% 12%, rgba(255,255,255,.8) 50%, transparent 52%),
    radial-gradient(1.5px 1.5px at 22% 30%, rgba(255,255,255,.6) 50%, transparent 52%),
    radial-gradient(2px 2px at 41% 8%, rgba(255,255,255,.7) 50%, transparent 52%),
    radial-gradient(1.5px 1.5px at 63% 22%, rgba(255,255,255,.8) 50%, transparent 52%),
    radial-gradient(2px 2px at 82% 10%, rgba(255,255,255,.7) 50%, transparent 52%),
    radial-gradient(1.5px 1.5px at 93% 34%, rgba(255,255,255,.6) 50%, transparent 52%),
    radial-gradient(1.5px 1.5px at 72% 48%, rgba(255,255,255,.5) 50%, transparent 52%),
    radial-gradient(1.5px 1.5px at 14% 56%, rgba(255,255,255,.5) 50%, transparent 52%),
    radial-gradient(130% 55% at 50% 112%, rgba(255,138,61,.38), transparent 65%),
    linear-gradient(#2a1658, #43267c 62%, #55318f);
  background-attachment: fixed;
  background-color: #2a1658;
}
button { font: inherit; color: inherit; }
/* 日本語の折り返しを、文節のまとまりで */
.lead, .bubble, .res-msg, .note { text-wrap: balance; word-break: auto-phrase; }

.screen { max-width: 760px; margin: 0 auto; padding: 14px 16px calc(28px + env(safe-area-inset-bottom)); }

/* ---------- ボタン共通 ---------- */
.btn {
  appearance: none; cursor: pointer;
  min-height: 46px; padding: 6px 16px;
  border: 3px solid var(--ink); border-radius: 999px;
  background: var(--cream); color: var(--ink);
  font-size: 16px; font-weight: 800; white-space: nowrap;
  box-shadow: 0 4px 0 var(--ink);
  transition: transform .08s, box-shadow .08s;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.btn.icon { min-width: 52px; padding: 6px 10px; font-size: 20px; }
.btn.big { font-size: 20px; min-height: 56px; background: var(--gold); }
.btn:focus-visible, .level:focus-visible, .card:focus-visible { outline: 4px solid var(--gold); outline-offset: 3px; }

/* ---------- タイトル ---------- */
#title { text-align: center; padding-top: 8px; }
.to-center { display: inline-block; margin: 0 0 4px; padding: 6px 14px; border-radius: 999px; font-size: 15px; color: #fff; text-decoration: none; background: rgba(255,255,255,.14); border: 2px solid rgba(255,255,255,.35); }
.to-center:focus-visible { outline: 4px solid var(--gold); outline-offset: 3px; }
#titleGhost { display: block; margin: 0 auto; width: 240px; height: 210px; }
#title h1 {
  margin: 0 0 10px; font-size: clamp(28px, 7.4vw, 44px); line-height: 1.25; font-weight: 800;
  text-shadow: 0 3px 0 var(--ink), 0 0 12px rgba(0,0,0,.35);
}
#title h1 span { color: var(--gold); font-size: 1.25em; }
.lead { margin: 0 0 18px; font-size: 18px; }
.lead span { display: block; text-wrap: balance; word-break: auto-phrase; }
.levels { display: grid; gap: 14px; max-width: 420px; margin: 0 auto; }
.level {
  appearance: none; cursor: pointer; display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
  padding: 14px 22px; min-height: 66px;
  border: 4px solid var(--ink); border-radius: 26px; color: var(--ink);
  box-shadow: 0 6px 0 var(--ink); transition: transform .08s, box-shadow .08s;
}
.level b { font-size: 26px; white-space: nowrap; }
.level small { font-size: 18px; font-weight: 700; white-space: nowrap; }
.level.easy   { background: #BDF0CF; }
.level.normal { background: #FFE8A3; }
.level.hard   { background: #FFC4DD; }
.level:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--ink); }
.note { margin: 20px 0 0; font-size: 16px; opacity: .92; }

/* ---------- ゲーム ---------- */
.topbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.topbar .icon { margin-left: auto; }

.stage { margin-top: 2px; }
#mascot { width: 100%; height: clamp(180px, 50vw, 240px); display: block; }
.bubble {
  position: relative; min-height: 66px; display: flex; align-items: center; justify-content: center; text-align: center;
  margin-top: 10px; padding: 10px 18px; background: #fff; color: var(--ink);
  border: 3px solid var(--ink); border-radius: 24px;
  font-size: 20px; line-height: 1.45; box-shadow: 0 4px 0 var(--ink);
}
.bubble::before {
  content: ""; position: absolute; left: 50%; top: -13px; width: 22px; height: 22px; margin-left: -11px;
  background: #fff; border-left: 3px solid var(--ink); border-top: 3px solid var(--ink); transform: rotate(45deg);
}
.bubble.pop { animation: pop .28s ease-out; }
@keyframes pop { 0% { transform: scale(.9); } 60% { transform: scale(1.04); } 100% { transform: scale(1); } }

.status { display: flex; flex-wrap: wrap; gap: 10px; margin: 12px 0 4px; }
.pill {
  padding: 4px 16px; border-radius: 999px; font-size: 17px;
  background: rgba(255,255,255,.14); border: 2px solid rgba(255,255,255,.35);
}
.pill b { font-size: 22px; color: var(--gold); }

.board {
  --cols: 3; --aspect: 1.5;
  display: grid; grid-template-columns: repeat(var(--cols), 1fr);
  gap: clamp(8px, 2.4vw, 16px); margin: 12px auto 0;
  width: min(100%, max(320px, calc((100svh - 420px) * var(--aspect))));
}
.card {
  appearance: none; cursor: pointer; padding: 0; position: relative; aspect-ratio: 1;
  border: 3px solid var(--ink); border-radius: 22px; background: var(--cream);
  box-shadow: 0 5px 0 var(--ink); overflow: hidden;
  transition: transform .08s, box-shadow .08s, background .3s;
}
.card canvas { display: block; width: 100%; height: 100%; pointer-events: none; }
.card:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--ink); }
.card.matched { background: #FFF0A8; cursor: default; }
.card.matched:active { transform: none; box-shadow: 0 5px 0 var(--ink); }

/* ---------- 結果 ---------- */
.modal {
  position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 16px;
  background: rgba(15,6,40,.72); overflow-y: auto;
}
.sheet {
  width: 100%; max-width: 440px; padding: 20px 20px 22px; text-align: center; color: var(--ink);
  background: var(--cream); border: 4px solid var(--ink); border-radius: 30px; box-shadow: 0 8px 0 var(--ink);
  animation: sheet-in .45s cubic-bezier(.2,1.4,.4,1);
}
@keyframes sheet-in { from { transform: translateY(30px) scale(.9); opacity: 0; } to { transform: none; opacity: 1; } }
.res-lead { margin: 0; font-size: 20px; }
#resCandy { display: block; width: 130px; height: 130px; margin: 2px auto 0; }
#resTitle { margin: 4px 0 8px; font-size: clamp(30px, 9vw, 42px); line-height: 1.2; color: #E0431F; }
.lead + .btn.small.first { font-size: 20px; min-height: 54px; padding: 8px 24px; background: var(--gold); animation: nudge 1.4s ease-in-out infinite; }
@keyframes nudge { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.08); } }
.btn.small { margin: 0 0 16px; }
.btn.small { min-height: 40px; padding: 4px 16px; font-size: 15px; margin: 0 0 12px; }
.credit { margin: 14px 0 0; font-size: 13px; opacity: .8; }
.credit + .credit { margin-top: 4px; }
.parents-link { color: #fff; text-decoration: underline; }
.parents-link:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }
.res-fact { margin: 0 0 12px; font-size: 20px; line-height: 1.6; text-wrap: balance; word-break: auto-phrase; }
.res-stats { margin: 0 0 16px; font-size: 16px; opacity: .8; }
.res-btns { display: grid; gap: 12px; }

/* ---------- 効果（紙ふぶき） ---------- */
#fx { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 30; }

@media (min-width: 600px) {
  .bubble { font-size: 24px; min-height: 76px; }
  #titleGhost { width: 300px; height: 260px; }
}
@media (max-width: 340px) {
  .level { padding: 12px 16px; }
  .level b { font-size: 22px; }
  .level small { font-size: 15px; }
}
@media (prefers-reduced-motion: reduce) {
  .bubble.pop, .sheet, .btn.small.first { animation: none; }
}
