:root {
  color: #fff;
  font-family: "Hiragino Maru Gothic ProN", "Yu Gothic", sans-serif;
  background: #172438;
}

* { box-sizing: border-box; }

body { margin: 0; overflow: hidden; }

#app, canvas { width: 100vw; height: 100vh; display: block; }

#hud, #overlay, .effects-layer { position: fixed; inset: 0; pointer-events: none; }

#camera-preview {
  position: fixed; right: 18px; bottom: 18px; width: min(26vw, 220px); aspect-ratio: 4 / 3;
  overflow: hidden; z-index: 2; border: 2px solid #ffcf4d; border-radius: 12px; background: #172438;
}

#camera-preview:empty { display: none; }

.camera-mini-video { width: 100%; height: 100%; object-fit: cover; }

.camera-mini-marker {
  position: absolute; width: 18px; height: 18px; border: 3px solid #ffcf4d; border-radius: 50%;
  transform: translate(-50%, -50%); pointer-events: none;
}

.camera-mini-marker.missing { border-color: #89909a; }

.camera-mini-message {
  position: absolute; right: 4px; bottom: 0; left: 4px; margin: 0; color: #fff; font-size: 12px;
  font-weight: 800; text-align: center; text-shadow: 0 1px 2px #172438;
}

#hud {
  display: flex;
  justify-content: space-between;
  padding: 18px 24px;
  font-weight: 800;
  font-size: clamp(18px, 3vw, 30px);
  text-shadow: 0 2px 3px #172438;
}

#hud .time { font-size: 1.25em; }

#hud .combo { display: inline-block; margin-left: 8px; color: #ffe45c; }

#hud .combo-4 { color: #ff9d3d; }

#hud .combo-5 { color: #ff5e9c; }

#hud .combo-6 { color: #a971ff; text-shadow: 2px 0 #5de2ff, -2px 0 #ffe45c; }

#hud .mute { pointer-events: auto; align-self: start; padding: 7px 10px; font-size: 1rem; }

.last-spurt-time { color: #ff7a3d; animation: time-pulse 0.5s ease-in-out infinite alternate; }

@keyframes time-pulse { to { transform: scale(1.11); color: #ff3f4f; } }

.effects-layer { z-index: 4; overflow: hidden; }

.burst-particle {
  position: absolute; left: var(--x); top: var(--y); width: 9px; height: 9px;
  border-radius: 50%; animation: burst 0.6s ease-out forwards;
}

.burst-particle.star { width: auto; height: auto; font-size: 25px; }

@keyframes burst { to { transform: translate(var(--dx), var(--dy)) rotate(180deg); opacity: 0; } }

.success-pop, .combo-pop, .last-spurt {
  position: absolute; left: 50%; top: 50%; font-weight: 900;
  text-shadow: 0 3px 3px #172438; animation: pop-away 0.8s ease-out forwards;
}

.success-pop { white-space: nowrap; translate: -50% -50%; font-size: clamp(26px, 6vw, 54px); }

.combo-pop, .last-spurt {
  white-space: nowrap; translate: -50% -50%; font-size: clamp(44px, 10vw, 100px);
}

.last-spurt { color: #ff713f; }

@keyframes pop-away {
  0% { opacity: 0; scale: 0.35; }
  35% { opacity: 1; scale: 1.15; }
  100% { opacity: 0; scale: var(--pop-end); }
}

.combo-border {
  position: absolute; inset: 8px; border: 8px solid var(--mode-color);
  border-radius: 24px; animation: border-glow 0.7s ease-out forwards;
}

@keyframes border-glow { to { opacity: 0; transform: scale(1.04); } }

.dispatch-car {
  position: absolute; top: 43%; font-size: clamp(80px, 20vw, 210px);
  animation: drive-by 0.9s ease-in forwards;
}

@keyframes drive-by { from { left: -25%; } to { left: 110%; } }

.confetti {
  position: absolute; top: -20px; left: var(--left); width: 9px; height: 16px;
  animation: confetti-fall 1.8s var(--delay) ease-in forwards;
}

@keyframes confetti-fall { to { transform: translateY(110vh) rotate(520deg); } }

.firework {
  position: absolute; width: 20px; height: 20px; border-radius: 50%; background: #fff3a3;
  box-shadow: 0 0 0 1px #ff7b57, 0 0 28px 12px #ff7b5788;
  opacity: var(--flash-max); animation: firework 0.8s ease-out forwards;
}

@keyframes firework { to { transform: scale(5); opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  .firework, .confetti, .burst-particle { display: none; }
  .success-pop, .combo-pop, .last-spurt, .result-star.show { animation: none; }
}

.result-stars { font-size: clamp(44px, 8vw, 72px); letter-spacing: 8px; color: #6b7180; }

.result-star { display: inline-block; }

.result-star.earned { color: #ffd452; opacity: 0.2; }

.result-star.show { animation: star-pop 0.45s ease-out forwards; }

@keyframes star-pop {
  from { opacity: 0; transform: scale(0.2) rotate(-120deg); }
  to { opacity: 1; transform: scale(1) rotate(0deg); }
}

.new-best {
  display: inline-block; padding: 7px 24px; color: #fff; background: #f05b73;
  font-size: 1.3rem; font-weight: 900; transform: rotate(-4deg);
}

#overlay {
  display: grid;
  place-items: center;
  background: linear-gradient(#17243899, #172438cc);
  pointer-events: auto;
}

/* 中身が無い時は幕を出さない（出したままだと画面が暗く、ポインタも遮る） */
#overlay:empty { display: none; }

.panel {
  max-width: 680px;
  padding: 30px;
  border: 3px solid #fff9;
  border-radius: 28px;
  background: #243654e8;
  text-align: center;
  box-shadow: 0 12px 45px #0008;
}

h1 { margin: 0 0 18px; font-size: clamp(34px, 7vw, 64px); }

.modes { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

.title-panel, .settings-panel, .result-panel { max-height: min(92vh, 760px); overflow: auto; }

.mode-card {
  display: grid; min-width: 140px; min-height: 120px; place-items: center; font-size: 1.08rem;
}

.mode-icon { font-size: 3rem; line-height: 1; }

.game-title span { display: block; white-space: nowrap; }

.title-panel h2 { margin: 16px 0 6px; font-size: 1.05rem; }

.title-choices { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }

.choice-button { min-width: 112px; }

.panel label { display: inline-flex; align-items: center; gap: 9px; margin: 12px 7px; font-weight: 800; }

select { border: 0; border-radius: 9px; padding: 7px; color: #172438; font: inherit; }

.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(230px, 1fr)); text-align: left; }
.settings-grid input[type="text"] { width: 100%; box-sizing: border-box; border: 0; border-radius: 9px; padding: 7px; color: #172438; font: inherit; }

.camera-sample {
  position: relative; width: min(72vw, 360px); margin: 12px auto; aspect-ratio: 4 / 3;
  overflow: hidden; border: 3px solid #ffcf4d; border-radius: 18px; background: #0d1726;
}

.camera-sample video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }

.sample-mask {
  position: absolute; inset: 0; width: 100%; height: 100%; opacity: 1; pointer-events: none;
}

.sample-marker {
  position: absolute; left: 50%; top: 50%; width: 42px; height: 42px; border: 3px solid #ffcf4d;
  border-radius: 50%; transform: translate(-50%, -50%); pointer-events: none;
}

.sample-marker.missing { border-color: #89909a; }

.camera-status { min-height: 1.4em; color: #ffdf86; }
.camera-status.good { color: #8ff7a0; }

.countdown h1 { font-size: clamp(70px, 15vw, 150px); }
.count-num { animation: count-in 0.3s ease-out both; }

@keyframes count-in {
  from { transform: scale(0.7); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

@media (prefers-reduced-motion: reduce) { .count-num { animation: none; } }

button {
  border: 0;
  border-radius: 14px;
  padding: 13px 16px;
  color: #172438;
  background: #fff;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

button.selected, button.primary { background: #ffcf4d; }

.primary { margin-top: 20px; font-size: 1.2rem; }

.error { color: #fff; background: #8f2540; }

[hidden] { display: none !important; }

/* くさはら: ゲットした なかま */
.caught-grid {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 8px;
  margin: 6px 0 12px; max-height: 280px; overflow: auto;
}

.caught-item {
  display: grid; justify-items: center; gap: 2px; margin: 0; padding: 6px 4px; width: 92px;
  border-radius: 14px; background: #ffffff1f;
}

.caught-thumb canvas { display: block; width: 76px; height: 76px; }

.caught-name { display: block; font-size: 0.78rem; }

.caught-count { font-weight: 800; color: #ffd23f; }

/* ゲットした なかま がある時は、上の飾りを詰めて一覧を画面内に収める */
.result-panel:has(.caught-grid) { padding: 18px 24px; }

.result-panel:has(.caught-grid) h1 { margin-bottom: 4px; font-size: clamp(28px, 5vw, 44px); }

.result-panel:has(.caught-grid) .result-stars { margin: 0; font-size: clamp(30px, 5vw, 44px); }

.result-panel:has(.caught-grid) p, .result-panel:has(.caught-grid) h2 { margin-top: 4px; margin-bottom: 4px; }

/* くさはら: とくべつ パック */
.pack-box { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 10px; margin: 14px 0 4px; }

.pack-status { font-weight: 800; }

.pack-form { display: inline-flex; gap: 8px; }

.pack-form input { width: 9em; border: 0; border-radius: 9px; padding: 7px; font: inherit; color: #172438; }

@media (max-width: 600px) {
  .panel { padding: 20px 13px; border-radius: 20px; }
  .settings-grid { grid-template-columns: 1fr; }
  #hud { padding: 12px; font-size: clamp(15px, 4vw, 24px); }
  #camera-preview { right: 10px; bottom: 10px; width: 35vw; }
}
