:root {
  --ink: #17324d;
  --cream: #fff8df;
  --paper: #fffdf5;
  --orange: #ff8057;
  --yellow: #ffd85a;
  --blue: #55bfe5;
  --green: #69c98c;
  --purple: #9b83dc;
  --red: #ef5c62;
  --shadow: 0 10px 0 rgba(23, 50, 77, .13), 0 18px 35px rgba(69, 49, 27, .12);
  font-family: "Hiragino Maru Gothic ProN", "Yu Gothic", "Meiryo", sans-serif;
  color: var(--ink);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 10% 15%, rgba(255, 216, 90, .35) 0 4px, transparent 5px),
    radial-gradient(circle at 85% 18%, rgba(85, 191, 229, .22) 0 5px, transparent 6px),
    radial-gradient(circle at 75% 82%, rgba(105, 201, 140, .24) 0 5px, transparent 6px),
    var(--cream);
  background-size: 54px 54px, 68px 68px, 76px 76px, auto;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

button, a { font: inherit; }
button { color: inherit; }

.home-shell {
  width: min(980px, calc(100% - 28px));
  margin: 0 auto;
  padding: 30px 0 26px;
}

.hero { text-align: center; position: relative; }
.hero-mascot { font-size: 56px; line-height: 1; filter: drop-shadow(0 5px 0 rgba(255, 128, 87, .25)); }
.eyebrow { margin: 8px 0 5px; font-size: clamp(14px, 2vw, 20px); font-weight: 800; letter-spacing: .12em; }
.hero h1 { margin: 0; font-size: clamp(36px, 7vw, 66px); line-height: .98; letter-spacing: .04em; }
.hero h1 span { color: var(--orange); }
.hero-copy { margin: 15px 0 22px; font-size: clamp(19px, 3vw, 27px); font-weight: 800; }

.game-picker {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 24px;
}

.game-card {
  position: relative;
  display: grid;
  grid-template-columns: .92fr 1.08fr;
  min-height: 318px;
  overflow: hidden;
  border: 4px solid var(--ink);
  border-radius: 32px;
  box-shadow: var(--shadow);
  color: var(--ink);
  text-decoration: none;
  transform: translateY(0);
  transition: transform .15s ease, box-shadow .15s ease;
}

.game-card:hover { transform: translateY(-4px); box-shadow: 0 14px 0 rgba(23,50,77,.13), 0 22px 40px rgba(69,49,27,.15); }
.game-card:active { transform: translateY(5px); box-shadow: 0 4px 0 rgba(23,50,77,.13); }
.game-card:focus-visible, button:focus-visible, a:focus-visible { outline: 5px solid #1d84d6; outline-offset: 4px; }
.game-card--find { background: #dff4fb; }
.game-card--memory { background: #efe8ff; }
.game-card--classify { grid-column: 1 / -1; background: #e4f7e8; min-height: 270px; }

.game-card__number {
  position: absolute;
  top: 14px;
  left: 14px;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border: 3px solid var(--ink);
  border-radius: 50%;
  background: white;
  font-size: 24px;
  font-weight: 900;
}

.game-card__art { position: relative; min-height: 100%; }
.game-card__body { align-self: center; padding: 30px 24px 30px 4px; }
.game-card__title { display: block; font-size: clamp(31px, 4vw, 45px); font-weight: 900; line-height: 1.07; }
.game-card__desc { display: block; margin: 16px 0 20px; font-size: clamp(14px, 1.7vw, 18px); font-weight: 700; line-height: 1.7; }
.play-pill { display: inline-flex; align-items: center; gap: 14px; padding: 10px 18px 10px 22px; border: 3px solid var(--ink); border-radius: 999px; background: white; box-shadow: 0 5px 0 rgba(23,50,77,.16); font-size: 20px; font-weight: 900; }
.play-pill b { color: var(--orange); }

.mini-shape { position: absolute; filter: drop-shadow(0 6px 0 rgba(23,50,77,.12)); }
.mini-shape.circle { width: 76px; height: 76px; left: 40px; top: 65px; border: 4px solid var(--ink); border-radius: 50%; }
.mini-shape.triangle { left: 62px; top: 163px; width: 0; height: 0; border-left: 48px solid transparent; border-right: 48px solid transparent; border-bottom: 82px solid var(--yellow); filter: drop-shadow(0 0 2px var(--ink)) drop-shadow(0 6px 0 rgba(23,50,77,.12)); }
.mini-shape.red { background: var(--red); }
.mini-animal { position: absolute; left: 125px; top: 90px; font-size: 72px; transform: rotate(7deg); }
.magnifier { position: absolute; left: 90px; bottom: 25px; font-size: 70px; transform: rotate(-12deg); }

.memory-preview { display: grid; grid-template-columns: repeat(2, 74px); align-content: center; justify-content: center; gap: 10px; }
.memory-preview span { display: grid; place-items: center; width: 74px; aspect-ratio: 1; border: 3px solid var(--ink); border-radius: 17px; background: white; box-shadow: 0 5px 0 rgba(23,50,77,.14); font-size: 36px; font-weight: 900; }
.memory-preview span:nth-child(even) { background: #d9cdf9; color: #7258bc; }
.classify-preview { display: grid; grid-template-columns: 72px 34px 132px; align-content: center; justify-content: center; gap: 9px 7px; padding-left: 30px; }
.classify-preview > span { display: grid; place-items: center; }
.classify-item { width: 68px; aspect-ratio: 1; border: 3px solid var(--ink); border-radius: 17px; background: white; box-shadow: 0 4px 0 rgba(23,50,77,.14); font-size: 36px; }
.classify-arrow { font-size: 27px; font-weight: 900; }
.classify-basket { grid-template-columns: auto 1fr; gap: 7px; width: 132px; min-height: 58px; padding: 5px 8px; border: 3px solid var(--ink); border-radius: 16px; background: #c6edcf; font-size: 28px; }
.classify-basket small { font-size: 12px; font-weight: 900; }
.home-note { margin: 24px 0 0; text-align: center; font-size: 14px; font-weight: 700; opacity: .72; }

/* Game pages */
.game-page { min-height: 100dvh; }
.topbar { display: flex; align-items: center; justify-content: space-between; width: min(900px, calc(100% - 24px)); margin: 0 auto; padding: 14px 0 8px; }
.icon-button { display: inline-grid; place-items: center; width: 52px; height: 52px; padding: 0; border: 3px solid var(--ink); border-radius: 50%; background: white; box-shadow: 0 4px 0 rgba(23,50,77,.16); cursor: pointer; text-decoration: none; font-size: 23px; }
.top-title { font-weight: 900; font-size: clamp(19px, 3vw, 27px); }
.game-shell { width: min(900px, calc(100% - 24px)); margin: 0 auto; padding-bottom: 28px; }
.panel { background: rgba(255,255,255,.92); border: 4px solid var(--ink); border-radius: 30px; box-shadow: var(--shadow); overflow: hidden; }
.setup-panel { max-width: 680px; margin: 6vh auto 0; padding: clamp(24px, 5vw, 48px); text-align: center; }
.setup-icon { display: block; margin-bottom: 8px; font-size: 64px; }
.setup-panel h1 { margin: 0 0 10px; font-size: clamp(34px, 6vw, 52px); line-height: 1.1; }
.setup-panel p { margin: 0; font-size: clamp(17px, 2.5vw, 22px); font-weight: 700; line-height: 1.7; }
.level-label { display: block; margin: 28px 0 12px; font-size: 17px; font-weight: 900; }
.level-picker { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.level-picker--memory { grid-template-columns: repeat(3, 1fr); }
.level-button { min-height: 80px; padding: 10px 4px; border: 3px solid var(--ink); border-radius: 18px; background: white; box-shadow: 0 5px 0 rgba(23,50,77,.16); cursor: pointer; font-size: 18px; font-weight: 900; }
.level-button--expert { font-size: 16px; line-height: 1.15; }
.level-button--oni { color: #8c2530; background: #fff0e8; }
.level-button small { display: block; margin-top: 3px; font-size: 12px; }
.best-time { display: block; margin-top: 7px; padding-top: 6px; border-top: 2px dashed rgba(23,50,77,.22); font-size: 11px; font-weight: 900; white-space: nowrap; }
.level-button.selected { background: var(--yellow); transform: translateY(4px); box-shadow: 0 1px 0 rgba(23,50,77,.16); }
.start-button, .next-button, .again-button { min-width: 220px; min-height: 68px; margin-top: 26px; padding: 12px 28px; border: 3px solid var(--ink); border-radius: 999px; background: var(--orange); box-shadow: 0 7px 0 #c54f31; color: white; cursor: pointer; font-size: 25px; font-weight: 900; }
.start-button:active, .next-button:active, .again-button:active { transform: translateY(6px); box-shadow: 0 1px 0 #c54f31; }
.hidden { display: none !important; }

.game-hud { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px; margin: 5px 0 12px; }
.progress-track { height: 18px; overflow: hidden; border: 3px solid var(--ink); border-radius: 999px; background: white; }
.progress-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--green), #a8df6b); transition: width .35s ease; }
.round-count { font-size: 17px; font-weight: 900; white-space: nowrap; }
.star-count { justify-self: end; min-width: 74px; padding: 5px 11px; border: 3px solid var(--ink); border-radius: 999px; background: white; text-align: center; font-size: 18px; font-weight: 900; }

.instruction { min-height: 80px; display: flex; align-items: center; justify-content: center; gap: 10px; margin: 0 0 12px; padding: 12px 18px; border: 4px solid var(--ink); border-radius: 25px; background: white; box-shadow: 0 6px 0 rgba(23,50,77,.12); text-align: center; font-size: clamp(23px, 4.6vw, 38px); font-weight: 900; }
.instruction strong { color: #d9474e; }
.board { display: grid; gap: clamp(8px, 1.6vw, 14px); padding: clamp(12px, 2.6vw, 24px); border: 4px solid var(--ink); border-radius: 30px; background: rgba(255,255,255,.65); box-shadow: var(--shadow); }
.find-board.cols-3 { grid-template-columns: repeat(3, 1fr); }
.find-board.cols-4 { grid-template-columns: repeat(4, 1fr); }
.find-board.cols-5 { grid-template-columns: repeat(5, 1fr); }
.tile { position: relative; display: grid; place-items: center; min-width: 0; aspect-ratio: 1; padding: 5px; border: 3px solid var(--ink); border-radius: clamp(14px, 2.2vw, 22px); background: white; box-shadow: 0 6px 0 rgba(23,50,77,.14); cursor: pointer; transition: transform .12s ease, background .12s ease; }
.tile:hover { transform: translateY(-2px); }
.tile:active { transform: translateY(5px); box-shadow: 0 1px 0 rgba(23,50,77,.14); }
.tile.wrong { animation: wiggle .35s ease; background: #fff1e9; }
.tile.correct { animation: pop .4s ease; background: #e1f8df; }
.tile-emoji { font-size: clamp(34px, 7.5vw, 64px); line-height: 1; }
.shape-svg { width: 72%; height: 72%; overflow: visible; filter: drop-shadow(0 4px 0 rgba(23,50,77,.12)); }
.shape-svg > * { fill: currentColor; stroke: var(--ink); stroke-width: 5; stroke-linejoin: round; }
.shape-svg.red { color: #ef4b52; }
.shape-svg.blue { color: #42b9e6; }
.shape-svg.yellow { color: #ffd24a; }
.shape-svg.green { color: #59c77c; }
.shape-svg.purple { color: #9478d7; }
.shape-svg.orange { color: #ff943d; }
.shape-svg.pink { color: #f47fb7; }
.feedback { min-height: 55px; margin-top: 9px; text-align: center; font-size: clamp(19px, 3vw, 25px); font-weight: 900; }
.feedback.good { color: #22804c; }
.feedback.try { color: #c05a28; }

.memory-board.cols-3 { grid-template-columns: repeat(3, 1fr); max-width: 590px; margin-inline: auto; }
.memory-board.cols-4 { grid-template-columns: repeat(4, 1fr); max-width: 680px; margin-inline: auto; }
.memory-board.cols-5 { grid-template-columns: repeat(5, 1fr); max-width: 720px; margin-inline: auto; }
.memory-tile { background: #faf7ff; }
.memory-tile.covered { background: linear-gradient(145deg, #b7a5e9, #8b71d0); }
.memory-tile.covered::after { content: "？"; color: white; font-size: clamp(30px, 6vw, 58px); font-weight: 900; text-shadow: 0 3px 0 rgba(23,50,77,.18); }
.memory-tile.revealed-answer { background: #e1f8df; }
.memory-tile.missed { background: #fff1c9; animation: pulse 1s infinite alternate; }
.countdown { color: #7b61c3; }

/* Classifying game */
.sort-instruction { min-height: 72px; display: grid; place-items: center; margin-bottom: 13px; padding: 10px 18px; border: 4px solid var(--ink); border-radius: 24px; background: white; box-shadow: 0 6px 0 rgba(23,50,77,.12); text-align: center; font-size: clamp(19px, 3vw, 26px); font-weight: 900; }
.sorting-workspace { display: grid; gap: 15px; }
.sorting-workspace > section { padding: 14px; border: 4px solid var(--ink); border-radius: 27px; background: rgba(255,255,255,.78); box-shadow: 0 7px 0 rgba(23,50,77,.12); }
.sorting-heading { margin: 0 0 11px; text-align: center; font-size: clamp(17px, 2.5vw, 22px); }
.card-pool { display: grid; grid-template-columns: repeat(8, 1fr); gap: 9px; min-height: 112px; }
.sort-card { position: relative; display: grid; place-items: center; min-width: 0; min-height: 100px; padding: 11px 4px 6px; border: 3px solid var(--ink); border-radius: 18px; background: white; box-shadow: 0 5px 0 rgba(23,50,77,.15); cursor: pointer; overflow: hidden; transition: transform .12s ease, opacity .2s ease; }
.sort-card:hover { transform: translateY(-2px); }
.sort-card:active { transform: translateY(4px); box-shadow: 0 1px 0 rgba(23,50,77,.15); }
.sort-card > span { font-size: clamp(34px, 5vw, 48px); line-height: 1; }
.sort-card small { margin-top: 5px; font-size: clamp(10px, 1.45vw, 14px); font-weight: 900; white-space: nowrap; }
.sort-card--colored { box-shadow: inset 0 11px 0 var(--card-color), 0 5px 0 rgba(23,50,77,.15); }
.sort-card.selected { outline: 6px solid #ff9b3e; outline-offset: 2px; transform: translateY(-4px) scale(1.04); background: #fff8d8; }
.sort-card.selected::after { content: "✓"; position: absolute; top: 4px; right: 6px; display: grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--orange); color: white; font-size: 14px; font-weight: 900; }
.sort-card.placed { opacity: .08; pointer-events: none; }
.sort-bins { display: grid; gap: 11px; }
.sort-bins--3 { grid-template-columns: repeat(3, 1fr); }
.sort-bins--4 { grid-template-columns: repeat(2, 1fr); }
.sort-bin { position: relative; display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; align-items: center; min-height: 115px; padding: 12px 17px; border: 4px solid var(--ink); border-radius: 22px 22px 32px 32px; box-shadow: inset 0 -9px 0 rgba(23,50,77,.08), 0 6px 0 rgba(23,50,77,.15); cursor: pointer; text-align: left; overflow: hidden; }
.sort-bin::before { content: ""; position: absolute; top: 0; left: 7%; right: 7%; height: 8px; border-radius: 0 0 8px 8px; background: rgba(23,50,77,.13); }
.sort-bin--food { background: #fff0c7; }
.sort-bin--animal { background: #dff5e3; }
.sort-bin--vehicle { background: #dff2fb; }
.sort-bin--clothes { background: #f0e8ff; }
.bin-example { grid-row: 1 / 3; margin-right: 12px; font-size: clamp(38px, 6vw, 54px); }
.bin-example--large { font-size: clamp(48px, 7vw, 64px); }
.bin-title { font-size: clamp(18px, 2.6vw, 25px); font-weight: 900; }
.bin-dropped { min-height: 29px; font-size: 22px; letter-spacing: 3px; }
.bin-color { grid-row: 1 / 3; width: 44px; height: 44px; margin-right: 12px; border: 3px solid var(--ink); border-radius: 50%; background: var(--bin-color); }
.sort-bin.correct { animation: pop .4s ease; filter: saturate(1.2); }
.sort-bin.wrong { animation: wiggle .35s ease; filter: saturate(.55); }

.result-panel { max-width: 650px; margin: 5vh auto 0; padding: 32px; text-align: center; }
.result-stars { min-height: 80px; font-size: clamp(44px, 8vw, 72px); letter-spacing: .08em; }
.result-panel h2 { margin: 8px 0; font-size: clamp(34px, 6vw, 50px); }
.result-panel p { font-size: 20px; font-weight: 700; line-height: 1.7; }
.result-time-card { position: relative; display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; max-width: 500px; margin: 20px auto 0; padding: 13px; border: 3px solid var(--ink); border-radius: 22px; background: #fff8df; }
.result-time-card > div { display: grid; gap: 4px; padding: 8px; border-radius: 14px; background: white; }
.result-time-card span { font-size: 14px; font-weight: 900; }
.result-time-card strong { font-size: clamp(22px, 4vw, 31px); }
.result-time-card .new-record { grid-column: 1 / -1; margin: 0; padding: 5px; color: #d9474e; font-size: 23px; font-weight: 900; animation: pop .5s ease; }
.result-actions { display: flex; justify-content: center; align-items: center; flex-wrap: wrap; gap: 15px; }
.home-button { min-height: 56px; display: inline-flex; align-items: center; margin-top: 26px; padding: 10px 22px; border: 3px solid var(--ink); border-radius: 999px; background: white; box-shadow: 0 5px 0 rgba(23,50,77,.16); color: var(--ink); text-decoration: none; font-size: 18px; font-weight: 900; }

@keyframes wiggle { 25% { transform: translateX(-7px) rotate(-2deg); } 50% { transform: translateX(7px) rotate(2deg); } 75% { transform: translateX(-4px); } }
@keyframes pop { 45% { transform: scale(1.12) rotate(2deg); } }
@keyframes pulse { from { transform: scale(.97); } to { transform: scale(1.03); } }

@media (max-width: 720px) {
  .game-picker { grid-template-columns: 1fr; }
  .game-card--classify { grid-column: auto; }
  .game-card { min-height: 270px; }
  .game-card__art { min-height: 270px; }
  .game-card__body { padding-right: 18px; }
  .home-shell { padding-top: 20px; }
  .find-board.cols-5 { grid-template-columns: repeat(4, 1fr); }
}

@media (max-width: 430px) {
  .hero-mascot { font-size: 44px; }
  .game-card { grid-template-columns: .85fr 1.15fr; min-height: 245px; border-radius: 25px; }
  .game-card__art { min-height: 245px; transform: scale(.8); transform-origin: center; }
  .game-card__body { padding: 20px 14px 20px 0; }
  .game-card__desc { line-height: 1.5; }
  .mini-shape.circle { left: 15px; }
  .mini-shape.triangle { left: 28px; }
  .mini-animal { left: 87px; }
  .magnifier { left: 54px; }
  .memory-preview { grid-template-columns: repeat(2, 64px); }
  .memory-preview span { width: 64px; }
  .classify-preview { grid-template-columns: 60px 26px 116px; padding-left: 0; }
  .classify-item { width: 60px; }
  .classify-basket { width: 116px; }
  .setup-panel { margin-top: 2vh; }
  .level-picker { gap: 6px; }
  .level-picker--memory { grid-template-columns: repeat(2, 1fr); }
  .level-button { min-height: 72px; font-size: 16px; }
  .game-hud { grid-template-columns: 1fr auto; }
  .progress-track { grid-column: 1 / -1; grid-row: 2; }
  .round-count { grid-column: 1; grid-row: 1; }
  .star-count { grid-column: 2; grid-row: 1; }
  .board { gap: 7px; padding: 9px; border-radius: 23px; }
  .tile { border-width: 2px; border-radius: 13px; box-shadow: 0 4px 0 rgba(23,50,77,.14); }
  .find-board.cols-5 { grid-template-columns: repeat(4, 1fr); }
  .instruction { min-height: 70px; border-radius: 20px; }
  .sorting-workspace > section { padding: 10px; border-radius: 21px; }
  .card-pool { grid-template-columns: repeat(4, 1fr); gap: 7px; }
  .sort-card { min-height: 88px; border-radius: 14px; }
  .sort-bins--3 { grid-template-columns: 1fr; }
  .sort-bin { min-height: 86px; padding: 8px 12px; border-radius: 17px 17px 23px 23px; }
  .bin-example { margin-right: 8px; }
  .bin-dropped { font-size: 18px; }
  .bin-color { width: 34px; height: 34px; margin-right: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
