:root {
  --pink: #ff6fa5;
  --pink-dark: #e0417f;
  --blue: #4fc3e8;
  --cream: #fff8f0;
  --ink: #2b1e2a;
  color-scheme: light;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

html, body {
  height: 100%;
  margin: 0;
  background: linear-gradient(135deg, #ffd3e6 0%, #ffe3ee 50%, #ffd3e6 100%);
  font-family: "Hiragino Maru Gothic ProN", "Rounded Mplus 1c", "Yu Gothic", sans-serif;
  color: var(--ink);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

#app {
  position: relative;
  aspect-ratio: 16 / 10;
  width: min(94vw, 94vh * 1.6, 900px);
  height: auto;
  background: transparent;
  overflow: hidden;
  border-radius: 18px;
  box-shadow: 0 10px 50px rgba(150,60,110,0.35);
}

.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, #fff0f5 0%, #ffe3ee 60%, #ffd3e6 100%);
}
.screen.active { display: flex; }

/* ---------------- TITLE ---------------- */
#screen-title { gap: 10px; padding: 16px; position: relative; }

.title-bg-fx {
  position: absolute; inset: 0;
  background:
    radial-gradient(circle at 15% 20%, rgba(255,255,255,0.6) 0 40px, transparent 41px),
    radial-gradient(circle at 80% 15%, rgba(255,255,255,0.5) 0 25px, transparent 26px),
    radial-gradient(circle at 70% 80%, rgba(255,255,255,0.4) 0 30px, transparent 31px),
    radial-gradient(circle at 25% 85%, rgba(255,255,255,0.5) 0 20px, transparent 21px);
  pointer-events: none;
}

.title-logo {
  max-width: 70%;
  max-height: 32%;
  object-fit: contain;
  filter: drop-shadow(0 8px 14px rgba(150,60,90,0.35));
  animation: float 3s ease-in-out infinite;
}
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

.title-buttons {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(78%, 340px);
  z-index: 1;
}

.mode-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 20px;
}
.mode-btn .mode-name { font-size: clamp(13px, 2.2vw, 17px); }
.mode-btn .mode-hs {
  font-size: clamp(9px, 1.5vw, 12px);
  font-weight: 700;
  opacity: 0.85;
  letter-spacing: 0.03em;
}
.title-row2 {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}
.title-row2 .btn { flex: 1; padding: 10px 8px; }

.btn {
  border: none;
  border-radius: 999px;
  padding: 12px 20px;
  font-size: clamp(13px, 2.2vw, 17px);
  font-weight: 900;
  letter-spacing: 0.05em;
  cursor: pointer;
  box-shadow: 0 5px 0 rgba(0,0,0,0.2);
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}
.btn:active {
  transform: translateY(4px);
  box-shadow: 0 1px 0 rgba(0,0,0,0.2);
}
.btn-primary {
  background: linear-gradient(180deg, #ff8fb8, var(--pink-dark));
  color: white;
}
.btn-primary.mode-btn-expert { background: linear-gradient(180deg, #ff9f5a, #d85a1f); }
.btn-primary.mode-btn-ta { background: linear-gradient(180deg, #7fd4ff, #1f7fd8); }
.btn-secondary {
  background: linear-gradient(180deg, #ffffff, #ffd7e7);
  color: var(--pink-dark);
}
.btn-sound {
  background: linear-gradient(180deg, #9fe6ff, var(--blue));
  color: #123a4a;
}

/* ---------------- HOW TO PLAY ---------------- */
.howto-box {
  background: white;
  border-radius: 20px;
  padding: 24px 28px;
  width: min(85%, 420px);
  box-shadow: 0 10px 0 rgba(200,80,130,0.25);
  border: 4px solid var(--pink);
}
.howto-box h2 {
  margin: 0 0 12px;
  color: var(--pink-dark);
  text-align: center;
  font-size: clamp(18px, 3vw, 24px);
}
.howto-box ul {
  margin: 0 0 18px;
  padding-left: 1.2em;
  font-size: clamp(12px, 2vw, 15px);
  line-height: 1.9;
  color: #4a2a3a;
}
.howto-box .btn { display: block; margin: 0 auto; }

/* ---------------- GAME SCREEN ---------------- */
#screen-game { padding: 0; background: #000; }

.hud {
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 8px 10px;
  pointer-events: none;
}
.hud-left, .hud-center, .hud-right {
  display: flex;
  gap: 6px;
  pointer-events: auto;
}
.hud-left { flex-direction: column; }
#hud-lives-block span { font-size: clamp(11px, 1.9vw, 15px); letter-spacing: 1px; }
.hud-block {
  background: rgba(255,255,255,0.85);
  border: 2px solid var(--pink);
  border-radius: 10px;
  padding: 3px 10px;
  font-size: clamp(10px, 1.6vw, 13px);
  font-weight: bold;
  line-height: 1.2;
  color: #6a2c4a;
  text-align: center;
  min-width: 56px;
}
.hud-block span { font-size: clamp(14px, 2.4vw, 20px); color: var(--pink-dark); }
.hud-block.small span { font-size: clamp(12px, 2vw, 16px); }

.icon-btn {
  width: clamp(28px, 5vw, 38px);
  height: clamp(28px, 5vw, 38px);
  border-radius: 50%;
  border: 2px solid var(--pink);
  background: rgba(255,255,255,0.85);
  font-size: clamp(13px, 2.4vw, 17px);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}

.combo-display {
  position: absolute;
  top: 46px; left: 50%;
  transform: translateX(-50%);
  z-index: 21;
  background: linear-gradient(180deg,#ffe27a,#ffb400);
  border: 2px solid #b97400;
  color: #5a3900;
  font-weight: 900;
  padding: 3px 16px;
  border-radius: 999px;
  font-size: clamp(11px, 2vw, 15px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.combo-display.hidden { opacity: 0; pointer-events: none; }
.combo-display.pop { animation: combopop 0.25s ease; }
@keyframes combopop {
  0% { transform: translateX(-50%) scale(1.4); }
  100% { transform: translateX(-50%) scale(1); }
}

.stage {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #222;
  touch-action: none;
}

.room-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 30%;
  transition: filter 0.6s ease;
}

.danger-overlay {
  position: absolute; inset: 0;
  background: rgba(120, 0, 0, 0);
  pointer-events: none;
  transition: background 0.6s ease;
  z-index: 5;
}
.danger-overlay.warn { background: rgba(150, 10, 10, 0.18); animation: pulse-warn 1s infinite; }
@keyframes pulse-warn {
  0%, 100% { background: rgba(150,10,10,0.10); }
  50% { background: rgba(150,10,10,0.28); }
}

.character {
  position: absolute;
  left: 50%;
  top: 30%;
  height: 34%;
  transform: translate(-50%, 0);
  z-index: 6;
  filter: drop-shadow(0 6px 6px rgba(0,0,0,0.35));
}
.character img {
  height: 100%;
  width: auto;
  display: block;
}

.slots {
  position: absolute;
  inset: 0;
  z-index: 4;
}

.slot {
  position: absolute;
  width: 13%;
  aspect-ratio: 1/1;
  min-width: 44px;
  min-height: 44px;
  transform: translate(-50%, -50%);
  transition: left 0.4s ease, top 0.4s ease;
}

.slot-hole {
  position: absolute;
  left: 50%; bottom: 6%;
  width: 90%;
  height: 30%;
  transform: translateX(-50%);
  border-radius: 50%;
  background: radial-gradient(ellipse at center, rgba(0,0,0,0.28), transparent 70%);
}

.bottle {
  position: absolute;
  left: 50%;
  bottom: 8%;
  height: 92%;
  transform: translate(-50%, 0) scale(1);
  cursor: pointer;
  filter: drop-shadow(0 4px 4px rgba(0,0,0,0.3));
  animation: bottle-land 0.28s cubic-bezier(.34,1.56,.64,1);
  touch-action: none;
}
.bottle img { height: 100%; width: auto; display: block; pointer-events: none; }

@keyframes bottle-land {
  0% { transform: translate(-50%, -60px) scale(0.7) rotate(-10deg); opacity: 0.4; }
  60% { transform: translate(-50%, 4px) scale(1.08) rotate(4deg); opacity: 1; }
  100% { transform: translate(-50%, 0) scale(1) rotate(0deg); }
}

.bottle.collected {
  animation: bottle-collect 0.22s ease forwards;
  pointer-events: none;
}
@keyframes bottle-collect {
  to { transform: translate(-50%, -30px) scale(0.2); opacity: 0; }
}

.flying-bottle {
  position: absolute;
  height: 15%;
  z-index: 7;
  pointer-events: none;
}
.flying-bottle img { height: 100%; width: auto; }

.score-pop {
  position: absolute;
  z-index: 9;
  font-weight: 900;
  font-size: clamp(12px, 2.4vw, 18px);
  color: #fff;
  text-shadow: 0 0 4px #000, 0 2px 3px rgba(0,0,0,0.6);
  transform: translate(-50%, -50%);
  pointer-events: none;
  animation: score-float 0.8s ease forwards;
  white-space: nowrap;
  text-align: center;
}
.score-pop.perfect { color: #fff26b; }
.score-pop.great { color: #7bffb0; }
.score-pop.good { color: #9fdfff; }
@keyframes score-float {
  0% { opacity: 0; transform: translate(-50%, -50%) translateY(0) scale(0.7); }
  15% { opacity: 1; transform: translate(-50%, -50%) translateY(-6px) scale(1.1); }
  100% { opacity: 0; transform: translate(-50%, -50%) translateY(-46px) scale(1); }
}

.wander-toast {
  position: absolute;
  left: 50%; top: 38%;
  transform: translate(-50%, -50%);
  z-index: 15;
  background: linear-gradient(180deg, #ff8fb8, var(--pink-dark));
  color: white;
  font-weight: 900;
  font-size: clamp(14px, 3vw, 22px);
  padding: 10px 22px;
  border-radius: 999px;
  border: 3px solid white;
  box-shadow: 0 6px 0 rgba(150,20,70,0.35);
  white-space: nowrap;
  pointer-events: none;
  animation: wander-toast-anim 2.2s ease forwards;
}
@keyframes wander-toast-anim {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.6); }
  15% { opacity: 1; transform: translate(-50%, -50%) scale(1.08); }
  25% { transform: translate(-50%, -50%) scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1); }
}

/* ---------------- OVERLAYS ---------------- */
.overlay {
  position: absolute; inset: 0;
  background: rgba(20,10,20,0.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 30;
}
.overlay.hidden { display: none; }
.overlay-box {
  background: white;
  border-radius: 18px;
  padding: 26px 34px;
  text-align: center;
  border: 4px solid var(--pink);
}
.overlay-box h2 { margin: 0 0 16px; color: var(--pink-dark); }
.overlay-box .btn { display: block; width: 200px; margin: 8px auto 0; }

/* ---------------- GAME OVER ---------------- */
#screen-gameover { background: linear-gradient(180deg, #241018, #3a1a26); }
.gameover-box { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 10px; }
.gameover-illust { max-width: 90%; max-height: 46vh; object-fit: contain; }
.gameover-stats {
  color: #ffd7e5;
  font-weight: bold;
  font-size: clamp(12px, 2.2vw, 16px);
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  justify-content: center;
}
.gameover-stats span { color: #ffef9a; }
.gameover-stats-extra {
  font-size: clamp(10px, 1.9vw, 13px);
  color: #ffc9de;
  max-width: 90%;
}
.go-heading {
  font-weight: 900;
  font-size: clamp(16px, 3.2vw, 24px);
  color: #ffef9a;
  text-shadow: 0 2px 4px rgba(0,0,0,0.5);
}
.gameover-buttons { display: flex; gap: 12px; margin-top: 4px; }
.gameover-buttons .btn { width: 140px; }

.hidden { display: none !important; }

/* ---------------- responsive: tall/mobile portrait ---------------- */
@media (orientation: portrait) and (max-width: 600px) {
  #app { width: 100vw; height: 100dvh; max-width: none; max-height: none; aspect-ratio: auto; }
  .stage { }
}
