* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
  background: radial-gradient(1200px 700px at 50% -10%, #3a4358 0%, #232937 55%, #1b202c 100%);
  color: #eef1f6;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
#app {
  height: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 10px;
}
#topbar { display: flex; align-items: center; justify-content: space-between; }
#topbar h1 {
  margin: 0;
  font-size: clamp(15px, 3vw, 22px);
  font-weight: 800;
  letter-spacing: 0.5px;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
  white-space: nowrap;
}
#topbar-btns { display: flex; gap: 8px; }
.icon-btn {
  font-size: 16px; line-height: 1; padding: 7px 10px;
  background: rgba(15, 20, 32, 0.7); color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.16); border-radius: 10px; cursor: pointer;
}
.icon-btn:active { transform: scale(0.94); }

#hud { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.chip {
  background: rgba(15, 20, 32, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 10px;
  padding: 4px 12px;
  font-size: clamp(11px, 2.2vw, 15px);
  font-weight: 600; letter-spacing: 0.3px; white-space: nowrap;
}
.chip b { font-weight: 800; }
.heart-img { width: 20px; height: 18px; object-fit: contain; vertical-align: -4px; margin: 0 1px; }
.heart-img.empty { filter: grayscale(1) brightness(0.55); opacity: 0.5; }
#hud-progress {
  display: inline-block; width: 58px; height: 8px;
  background: rgba(0, 0, 0, 0.55); border-radius: 4px;
  margin-left: 7px; vertical-align: 2px; overflow: hidden;
}
#progress-fill {
  display: block; height: 100%; width: 0%; border-radius: 4px;
  background: linear-gradient(90deg, #3fae5a, #7ec8ff);
  transition: width 0.25s ease;
}
#hud-combo-chip.pulse { animation: pulse 0.45s ease; }
@keyframes pulse {
  0% { transform: scale(1); }
  35% { transform: scale(1.18); background: rgba(255, 180, 40, 0.85); color: #241a05; }
  100% { transform: scale(1); }
}
#progress { display: none; }

#stage-wrap { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; }
#stage { position: relative; font-size: 0; }
#game {
  display: block; border-radius: 14px;
  box-shadow: 0 16px 44px rgba(0, 0, 0, 0.5), 0 0 0 4px rgba(255, 255, 255, 0.06);
  background: #dcd6c8;
  touch-action: none;
}

.overlay {
  position: absolute; inset: 0; z-index: 5;
  display: flex; align-items: center; justify-content: center;
  background: rgba(13, 18, 29, 0.68);
  border-radius: 14px;
  font-size: 15px;
}
.overlay.hidden { display: none; }
.panel {
  background: linear-gradient(180deg, #fdf9ee, #f1e9d6);
  color: #2c3242;
  border-radius: 18px;
  border: 3px solid #ffffff;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.5);
  padding: clamp(14px, 3vw, 26px) clamp(18px, 4vw, 36px);
  text-align: center;
  max-width: 86%;
  font-size: clamp(12px, 2.4vw, 16px);
}
.panel-dark {
  background: linear-gradient(180deg, #24466e 0%, #16294a 60%, #101d38 100%);
  color: #eaf1fb;
  border: 3px solid #3e6ea8;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.6), inset 0 0 40px rgba(10, 20, 40, 0.6);
}
.panel h2 { margin: 0 0 8px; font-size: clamp(18px, 4.2vw, 32px); font-weight: 800; letter-spacing: 0.5px; }
.game-title {
  color: #ffd23e;
  -webkit-text-stroke: 1px #1d3a8f;
  text-shadow: 0 3px 0 #1d3a8f, 0 0 22px rgba(255, 210, 62, 0.35);
  letter-spacing: 1px;
}
.sub-light { margin: 2px 0 10px; font-weight: 700; color: #cfe0f5; }
.start-cards { display: flex; justify-content: center; gap: 4px; margin-bottom: 6px; }
.start-cards img { width: clamp(28px, 5vw, 42px); transform: rotate(-4deg); }
.start-cards img:nth-child(2n) { transform: rotate(5deg) translateY(3px); }
.start-row { display: flex; align-items: center; justify-content: center; gap: 14px; margin: 6px 0 4px; }
.start-boy { height: clamp(90px, 16vw, 132px); filter: drop-shadow(0 8px 12px rgba(0, 0, 0, 0.4)); }
.instr-box {
  background: rgba(10, 22, 42, 0.55);
  border: 1px solid rgba(140, 180, 230, 0.35);
  border-radius: 12px;
  padding: 10px 14px;
  max-width: 300px;
  color: #dce8f8;
  font-size: 0.92em;
  line-height: 1.45;
}
.instr-box .keys { display: block; margin-top: 6px; font-size: 0.85em; color: #9db8d8; }
.best-line-light { margin: 10px 0 12px; font-weight: 700; color: #ffe9a8; }
.panel .keys { margin: 8px 0 2px; font-size: 0.85em; color: #6b7488; }
.big-btn {
  font: inherit; font-weight: 800;
  font-size: clamp(14px, 3vw, 19px); letter-spacing: 0.5px;
  color: #5a3a00; background: linear-gradient(180deg, #ffd75e, #f0a03c);
  border: none; border-radius: 12px; padding: 12px 30px; cursor: pointer;
  box-shadow: 0 4px 0 #b8761c, 0 8px 18px rgba(0, 0, 0, 0.25);
  touch-action: manipulation;
}
.big-btn:active { transform: translateY(2px); box-shadow: 0 2px 0 #b8761c; }
.stats p { margin: 4px 0; font-size: 1.05em; }
.stats b { font-weight: 800; }
.record { margin: 6px 0 2px; font-weight: 800; color: #b8860b; }
.record.hidden { display: none; }
.over-ribbon { width: clamp(160px, 24vw, 230px); margin: -52px auto 2px; display: block; filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.25)); }
.over-boy { height: clamp(90px, 15vw, 128px); margin: 2px auto 0; display: block; }

#touch-controls {
  display: none;
  grid-template-areas: ". up ." "left . right" ". down .";
  grid-template-columns: repeat(3, 64px);
  grid-template-rows: repeat(3, 42px);
  gap: 2px;
  justify-content: center;
  align-items: center;
  background: linear-gradient(180deg, rgba(28, 44, 74, 0.75), rgba(14, 24, 44, 0.75));
  border: 1px solid rgba(120, 160, 210, 0.3);
  border-radius: 22px;
  padding: 6px 16px;
}
.tb {
  background: none; border: none; padding: 0; margin: 0;
  cursor: pointer; touch-action: manipulation;
  line-height: 0;
}
.tb img { width: 62px; height: 62px; display: block; pointer-events: none; }
.tb-up { grid-area: up; }
.tb-left { grid-area: left; }
.tb-right { grid-area: right; }
.tb-down { grid-area: down; }
.tb:active img, .tb.pressed img { transform: scale(0.88); filter: brightness(1.3); }

#key-hint { text-align: center; font-size: 12px; opacity: 0.55; }

@media (pointer: coarse) {
  #touch-controls { display: grid; }
  #key-hint { display: none; }
}
body.touch #touch-controls { display: grid; }
body.touch #key-hint { display: none; }

@media (max-height: 520px) {
  #hud { gap: 5px; }
  .chip { padding: 3px 8px; }
  #topbar h1 { font-size: 14px; }
}
