:root {
  color-scheme: dark;
  --ink: #f7f7ff;
  --muted: #b8bbd8;
  --panel: rgba(26, 25, 55, .94);
  --panel-2: rgba(45, 42, 88, .82);
  --line: rgba(255,255,255,.16);
  --pink: #ff5fa2;
  --yellow: #ffd84d;
  --cyan: #43e8ff;
  --mint: #64f3b6;
  --purple: #9d7cff;
  font-family: "Hiragino Sans", "Yu Gothic", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background:
    radial-gradient(circle at 15% 12%, rgba(255,95,162,.24), transparent 28rem),
    radial-gradient(circle at 90% 20%, rgba(67,232,255,.2), transparent 24rem),
    linear-gradient(155deg, #111128 0%, #1c1740 55%, #0e2035 100%);
  font-size: clamp(16px, 3.9vw, 18px);
  overscroll-behavior: none;
}

button { font: inherit; }
button:focus-visible { outline: 3px solid var(--yellow); outline-offset: 3px; }

.game-shell {
  width: min(100%, 720px);
  min-height: 100svh;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 12px max(18px, env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.topbar h1 { margin: 1px 0 0; font-size: clamp(20px, 5vw, 29px); line-height: 1.1; }
.eyebrow, .kicker { margin: 0; color: var(--cyan); font-size: 12px; font-weight: 900; letter-spacing: .14em; }
.icon-btn { width: 48px; height: 48px; border: 1px solid var(--line); border-radius: 16px; color: white; background: var(--panel-2); cursor: pointer; }

.screen {
  border: 1px solid var(--line);
  border-radius: 26px;
  background: linear-gradient(150deg, rgba(37,34,77,.97), rgba(20,28,54,.97));
  box-shadow: 0 22px 60px rgba(0,0,0,.3);
  overflow: hidden;
}

.start-screen, .quiz-screen, .result-screen { padding: clamp(20px, 6vw, 38px); text-align: center; }
.start-screen h2 { margin: 10px 0; font-size: clamp(31px, 9vw, 52px); line-height: 1.12; }
.lead { margin: 0 auto 20px; max-width: 32em; line-height: 1.75; color: var(--muted); }

.hero-art { position: relative; height: 108px; margin: -4px auto 8px; max-width: 350px; }
.hero-shape { position: absolute; filter: drop-shadow(0 10px 16px rgba(0,0,0,.25)); animation: bob 2.6s ease-in-out infinite; }
.hero-shape.circle { width: 72px; height: 72px; border-radius: 50%; background: var(--pink); left: 5%; top: 18px; }
.hero-shape.triangle { width: 84px; height: 76px; background: var(--yellow); clip-path: polygon(50% 0, 100% 100%, 0 100%); left: 29%; top: 3px; animation-delay: -.5s; }
.hero-shape.square { width: 68px; height: 68px; border-radius: 12px; background: var(--cyan); right: 27%; top: 28px; transform: rotate(12deg); animation-delay: -1s; }
.hero-shape.rect { width: 88px; height: 48px; border-radius: 12px; background: var(--mint); right: 2%; top: 14px; transform: rotate(-11deg); animation-delay: -1.5s; }
@keyframes bob { 50% { translate: 0 -9px; } }

.rule-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 18px 0; }
.rule-grid div { padding: 12px 6px; min-width: 0; border: 1px solid var(--line); border-radius: 16px; background: rgba(255,255,255,.055); }
.rule-grid strong, .rule-grid span { display: block; }
.rule-grid strong { font-size: clamp(15px, 4vw, 18px); }
.rule-grid span { margin-top: 4px; color: var(--muted); font-size: 12px; }
.collection-card { display: flex; justify-content: space-between; align-items: center; margin: 0 0 18px; padding: 13px 16px; border-radius: 16px; color: var(--muted); background: rgba(0,0,0,.2); }
.collection-card strong { color: var(--yellow); }

.primary-btn {
  min-height: 52px;
  width: min(100%, 360px);
  border: 0;
  border-radius: 17px;
  padding: 13px 22px;
  color: #151329;
  background: linear-gradient(135deg, var(--yellow), #ff9f5d);
  box-shadow: 0 10px 26px rgba(255,184,74,.22);
  font-size: clamp(16px, 4.5vw, 20px);
  font-weight: 900;
  cursor: pointer;
  touch-action: manipulation;
}
.primary-btn:active { transform: translateY(2px); }
.tiny-note { margin: 12px 0 0; color: var(--muted); font-size: 12px; }

.play-screen { padding: 12px; touch-action: none; }
.hud { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.hud > div { min-width: 0; padding: 8px 4px; text-align: center; border: 1px solid var(--line); border-radius: 14px; background: rgba(0,0,0,.18); }
.hud span, .hud strong { display: block; }
.hud span { color: var(--muted); font-size: 11px; }
.hud strong { margin-top: 2px; font-size: clamp(17px, 5vw, 25px); font-variant-numeric: tabular-nums; }
.timer-box strong { color: var(--yellow); }
.mission-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin: 12px 2px 9px; }
.mission-row h2 { margin: 1px 0 0; font-size: clamp(22px, 6vw, 31px); }
.round-label { color: var(--cyan); font-size: 12px; font-weight: 900; }
.shape-hint { max-width: 48%; padding: 7px 10px; border-radius: 999px; color: var(--mint); background: rgba(100,243,182,.09); font-size: 12px; font-weight: 800; text-align: center; }

.board {
  position: relative;
  width: min(100%, 420px);
  aspect-ratio: 1;
  margin: 0 auto;
  border: 2px dashed rgba(255,255,255,.2);
  border-radius: 24px;
  background:
    linear-gradient(rgba(255,255,255,.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.04) 1px, transparent 1px),
    radial-gradient(circle at 50% 45%, rgba(157,124,255,.11), transparent 62%);
  background-size: 20% 20%, 20% 20%, auto;
  overflow: hidden;
}

.slot {
  position: absolute;
  left: var(--x); top: var(--y); width: var(--w); height: var(--h);
  transform: rotate(var(--r, 0deg));
  border: 3px dashed rgba(255,255,255,.42);
  background: rgba(255,255,255,.065);
  cursor: pointer;
  transition: filter .15s, scale .15s, opacity .2s;
}
.slot[data-shape="circle"] { border-radius: 50%; }
.slot[data-shape="triangle"] { border: 0; background: rgba(255,255,255,.11); clip-path: polygon(50% 0, 100% 100%, 0 100%); }
.slot[data-shape="triangle"]::after { content: ""; position: absolute; inset: 8px; background: #22244d; clip-path: inherit; }
.slot[data-shape="square"], .slot[data-shape^="rect"] { border-radius: 10px; }
.slot.is-target { filter: drop-shadow(0 0 9px var(--yellow)); scale: 1.06; }
.slot.is-filled { border-style: solid; border-color: rgba(255,255,255,.25); }
.slot .placed-piece { width: 100%; height: 100%; }

.feedback { min-height: 25px; margin: 9px 4px; color: var(--yellow); font-weight: 900; text-align: center; }
.tray-wrap { padding: 10px; border-radius: 18px; background: rgba(0,0,0,.18); }
.tray-wrap > p { margin: 0 0 8px; color: var(--muted); font-size: 12px; font-weight: 800; }
.tray { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 10px; min-height: 74px; }
.piece {
  display: grid;
  place-items: center;
  width: 60px;
  height: 60px;
  min-width: 52px;
  min-height: 52px;
  padding: 8px;
  border: 2px solid transparent;
  border-radius: 15px;
  background: rgba(255,255,255,.09);
  cursor: grab;
  touch-action: none;
}
.piece:active { cursor: grabbing; }
.piece.is-selected { border-color: var(--yellow); box-shadow: 0 0 0 4px rgba(255,216,77,.12); }
.piece-shape, .placed-piece, .drag-ghost { display: block; background: var(--piece-color, var(--pink)); }
.piece-shape { width: 42px; height: 42px; }
[data-shape="circle"] .piece-shape, .placed-piece[data-shape="circle"], .drag-ghost[data-shape="circle"] { border-radius: 50%; }
[data-shape="triangle"] .piece-shape, .placed-piece[data-shape="triangle"], .drag-ghost[data-shape="triangle"] { clip-path: polygon(50% 0, 100% 100%, 0 100%); }
[data-shape="square"] .piece-shape, .placed-piece[data-shape="square"], .drag-ghost[data-shape="square"] { border-radius: 8px; }
[data-shape="rect-h"] .piece-shape { width: 48px; height: 30px; border-radius: 7px; }
[data-shape="rect-v"] .piece-shape { width: 30px; height: 48px; border-radius: 7px; }
.placed-piece[data-shape^="rect"] { border-radius: 8px; }
.drag-ghost { position: fixed; z-index: 50; width: 54px; height: 54px; pointer-events: none; translate: -50% -50%; filter: drop-shadow(0 10px 12px rgba(0,0,0,.35)); opacity: .95; }
.drag-ghost[data-shape="rect-h"] { height: 34px; }
.drag-ghost[data-shape="rect-v"] { width: 34px; }
.piece[disabled] { opacity: .2; pointer-events: none; }

.quiz-screen h2 { margin: 20px 0; font-size: clamp(21px, 5.6vw, 30px); line-height: 1.55; }
.quiz-progress { display: flex; align-items: center; gap: 12px; margin-top: 10px; color: var(--muted); font-weight: 900; }
.quiz-progress > div { flex: 1; height: 8px; border-radius: 999px; background: rgba(255,255,255,.1); overflow: hidden; }
.quiz-progress i { display: block; width: 33%; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--cyan), var(--mint)); transition: width .25s; }
.quiz-choices { display: grid; gap: 10px; }
.choice-btn { min-height: 52px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 16px; color: var(--ink); background: rgba(255,255,255,.07); font-size: clamp(16px, 4.3vw, 19px); font-weight: 800; cursor: pointer; }
.choice-btn.correct { border-color: var(--mint); background: rgba(100,243,182,.16); }
.choice-btn.wrong { border-color: var(--pink); background: rgba(255,95,162,.15); }
.choice-btn:disabled { color: var(--ink); opacity: .72; }
.quiz-explanation { margin-top: 16px; padding: 16px; border-radius: 18px; background: rgba(0,0,0,.2); text-align: left; }
.quiz-explanation strong { color: var(--yellow); font-size: 20px; }
.quiz-explanation p { color: var(--muted); line-height: 1.7; }
.quiz-explanation .primary-btn { display: block; margin: 12px auto 0; }

.rank-badge { display: grid; place-items: center; width: 96px; height: 96px; margin: 14px auto 8px; border-radius: 28px; color: #17142b; background: linear-gradient(135deg, var(--yellow), var(--pink)); font-size: 54px; font-weight: 1000; transform: rotate(-4deg); box-shadow: 0 16px 30px rgba(255,95,162,.22); }
.result-screen h2 { margin: 10px 0; font-size: clamp(26px, 7vw, 38px); }
.final-score span, .final-score strong, .final-score small { display: inline-block; }
.final-score span { display: block; color: var(--muted); }
.final-score strong { color: var(--yellow); font-size: clamp(42px, 13vw, 72px); font-variant-numeric: tabular-nums; }
.final-score small { margin-left: 4px; }
.result-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin: 18px 0; }
.result-grid div { padding: 12px; border: 1px solid var(--line); border-radius: 16px; background: rgba(255,255,255,.055); }
.result-grid span, .result-grid strong { display: block; }
.result-grid span { color: var(--muted); font-size: 12px; }
.result-grid strong { margin-top: 4px; font-size: 22px; }
.result-message { min-height: 3.2em; color: var(--muted); line-height: 1.6; }
.ranking-panel { margin-top: 22px; padding: 16px; border-radius: 18px; background: rgba(0,0,0,.2); text-align: left; }
.ranking-panel h3 { margin: 0 0 10px; font-size: 18px; }

.pop { animation: pop .28s ease-out; }
.shake { animation: shake .28s linear; }
@keyframes pop { 50% { scale: 1.13; } }
@keyframes shake { 25% { translate: -7px 0; } 75% { translate: 7px 0; } }

@media (min-width: 620px) {
  .game-shell { padding-inline: 22px; }
  .play-screen { padding: 18px; }
  .tray { min-height: 84px; }
  .piece { width: 70px; height: 70px; }
}

@media (max-width: 370px) {
  .game-shell { padding-inline: 7px; }
  .screen { border-radius: 21px; }
  .start-screen, .quiz-screen, .result-screen { padding: 18px 13px; }
  .rule-grid { gap: 5px; }
  .rule-grid div { padding-inline: 3px; }
  .piece { width: 52px; height: 52px; padding: 6px; }
  .piece-shape { width: 36px; height: 36px; }
  [data-shape="rect-h"] .piece-shape { width: 40px; height: 26px; }
  [data-shape="rect-v"] .piece-shape { width: 26px; height: 40px; }
}

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