:root {
  --cream: #fff6ea;
  --ink: #3a2a22;
  --accent: #e8895a;
  --sky: #7ec8e8;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  background: #0e1620;
  color: var(--ink);
  font-family: "Zen Maru Gothic", "Hiragino Maru Gothic ProN", sans-serif;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  overscroll-behavior: none;
  position: fixed;
  inset: 0;
}

#frame {
  position: relative;
  width: 100%;
  height: 100%;
  height: 100dvh;
  display: grid;
  place-items: center;
  background: #081018;
  container-type: size;
}

#game {
  display: block;
  width: min(100cqw, calc(100cqh * 16 / 9));
  height: min(100cqh, calc(100cqw * 9 / 16));
  background: #7ec8e8;
  border-radius: 12px;
  box-shadow: 0 20px 80px rgba(0, 0, 0, 0.45);
  position: relative;
  z-index: 0;
  pointer-events: none;
}

#game.is-play {
  pointer-events: auto;
}

.hud {
  z-index: 3;
  position: absolute;
  inset: auto 0 auto 0;
  top: max(8px, env(safe-area-inset-top));
  width: min(100cqw, calc(100cqh * 16 / 9));
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 10px max(28px, env(safe-area-inset-right)) 10px max(28px, env(safe-area-inset-left));
  pointer-events: none;
  text-shadow: 0 2px 0 rgba(255, 255, 255, 0.35), 0 8px 18px rgba(40, 20, 10, 0.25);
  color: #fffdf8;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.hud-left,
.hud-right {
  display: flex;
  align-items: baseline;
  gap: 10px;
  font-size: 28px;
}

.hud-label {
  font-size: 12px;
  letter-spacing: 0.18em;
  opacity: 0.85;
}

.hud-center {
  font-size: 13px;
  letter-spacing: 0.12em;
  min-height: 1em;
}

.sound-dock {
  position: absolute;
  z-index: 8;
  left: max(12px, env(safe-area-inset-left));
  bottom: max(12px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
}

.sound-panel {
  width: 220px;
  padding: 12px 14px 10px;
  border-radius: 16px;
  background: rgba(255, 250, 242, 0.96);
  color: var(--ink);
  box-shadow: 0 10px 24px rgba(20, 12, 8, 0.28);
}

.sound-panel label {
  display: grid;
  grid-template-columns: 36px 1fr;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  font-size: 13px;
  font-weight: 700;
}

.sound-panel input[type="range"] {
  width: 100%;
  accent-color: #e8895a;
}

.sound-mute {
  appearance: none;
  border: 0;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  font-size: 13px;
  padding: 6px 12px;
  border-radius: 999px;
  color: var(--ink);
  background: #fff;
}

.sound-toggle {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  font: inherit;
  font-weight: 900;
  font-size: 15px;
  letter-spacing: 0.04em;
  color: var(--ink);
  background: rgba(255, 250, 242, 0.94);
  box-shadow: 0 8px 18px rgba(20, 12, 8, 0.28);
}

.sound-toggle.is-muted {
  color: rgba(58, 42, 34, 0.45);
}

.coin-icon {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffe9a0, #e2b13a 55%, #b8861f);
  box-shadow: 0 0 0 2px rgba(255, 240, 180, 0.5);
  display: inline-block;
}

.panel {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 4;
  pointer-events: auto;
  width: min(560px, calc(100cqw - 32px));
  padding: 28px 28px 24px;
  border-radius: 28px;
  background: linear-gradient(180deg, rgba(255, 250, 242, 0.92), rgba(255, 236, 214, 0.9));
  box-shadow: 0 24px 60px rgba(20, 12, 8, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.8);
  text-align: center;
  backdrop-filter: blur(8px);
}

.panel h1,
.panel h2 {
  font-weight: 900;
  letter-spacing: 0.04em;
  line-height: 1.2;
}

.panel h1 {
  font-size: clamp(36px, 7vw, 56px);
  margin: 4px 0 8px;
}

.panel h2 {
  font-size: 28px;
  margin-bottom: 10px;
}

.kicker {
  font-size: 11px;
  letter-spacing: 0.28em;
  color: #c56a3c;
  font-weight: 700;
}

.lead,
.hint,
.bank {
  color: #6b5348;
  font-size: 14px;
  margin: 6px 0 14px;
}

.hero-stat {
  display: grid;
  gap: 6px;
  margin: 4px 0 0;
  color: #6b5348;
  font-size: 13px;
}

.hero-meta {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  font-size: 14px;
}

.hero-stat small {
  font-size: 11px;
  letter-spacing: 0.04em;
}

.xp-bar {
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: rgba(90, 60, 40, 0.12);
  overflow: hidden;
}

.xp-fill {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, #f0c060, #e8895a);
}

.boost {
  color: #c56a3c;
  font-size: 13px;
  font-weight: 700;
  margin: -4px 0 14px;
}

.hint {
  font-size: 12px;
  opacity: 0.85;
}

.btn {
  appearance: none;
  border: 0;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 12px 22px;
  border-radius: 999px;
  color: #fffdf8;
  background: linear-gradient(180deg, #f0a06a, #d56a3a);
  box-shadow: 0 8px 0 #a24a28, 0 12px 20px rgba(160, 70, 30, 0.28);
  transition: transform 0.12s ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(4px);
  box-shadow: 0 4px 0 #a24a28;
}

.btn-ghost {
  background: #fff;
  color: #6b5348;
  box-shadow: 0 8px 0 #e6d3c2, 0 12px 20px rgba(80, 50, 30, 0.08);
}

.row {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 8px;
}

.stage-grid {
  display: grid;
  gap: 10px;
  margin: 10px 0 12px;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding-right: 6px;
  scrollbar-width: thin;
  scrollbar-color: rgba(213, 106, 58, 0.45) rgba(90, 60, 40, 0.08);
}

.stage-grid::-webkit-scrollbar {
  width: 8px;
}

.stage-grid::-webkit-scrollbar-track {
  margin: 6px 0;
  background: rgba(90, 60, 40, 0.08);
  border-radius: 999px;
}

.stage-grid::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, rgba(240, 160, 106, 0.85), rgba(213, 106, 58, 0.75));
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}

.stage-grid::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(180deg, #f0a06a, #d56a3a);
  border: 2px solid transparent;
  background-clip: padding-box;
}

.stage-card {
  position: relative;
  overflow: visible;
  text-align: left;
  border: 0;
  cursor: pointer;
  font: inherit;
  border-radius: 18px;
  padding: 14px 16px;
  color: #fffdf8;
  display: grid;
  grid-template-columns: 1fr;
  align-items: center;
  gap: 8px;
  box-shadow: 0 8px 18px rgba(20, 12, 8, 0.18);
}

.stage-card-body {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.stage-card strong {
  font-size: 18px;
  padding-right: 64px;
}

.stage-card small {
  opacity: 0.86;
  font-size: 12px;
}

.stage-card:disabled,
.stage-card.is-locked {
  cursor: default;
  grid-template-columns: 36px 1fr;
  filter: grayscale(0.45) brightness(0.72);
}

.stage-card.is-locked.can-buy {
  filter: grayscale(0.12) brightness(0.92);
}

.stage-lock {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  color: rgba(255, 246, 232, 0.92);
  filter: drop-shadow(0 2px 4px rgba(20, 12, 8, 0.35));
}

.stage-card.can-buy .stage-lock {
  color: #ffe08a;
  animation: lock-ready 1.4s ease-in-out infinite;
}

.stage-clear-badge {
  position: absolute;
  top: 6px;
  right: 10px;
  z-index: 2;
  pointer-events: none;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.14em;
  color: #5a3010;
  background: linear-gradient(180deg, #ffe9a8, #e8b43a);
  border: 2px solid #fff8e8;
  border-radius: 8px;
  padding: 4px 7px 3px;
  box-shadow: 0 2px 0 #b88620, 0 4px 10px rgba(80, 40, 8, 0.28);
  transform: rotate(-12deg);
}

.stage-card.is-cleared .stage-clear-badge {
  animation: stamp-in 0.45s cubic-bezier(0.2, 1.4, 0.4, 1);
}

.stage-unlock-burst {
  pointer-events: none;
  position: absolute;
  inset: 0;
}

.stage-card.is-unlocking {
  filter: none;
  animation: card-unlock 0.7s ease;
}

.stage-card.is-unlocking .stage-lock {
  animation: lock-pop 0.55s ease forwards;
  color: #ffe08a;
}

.stage-card.is-unlocking .stage-unlock-burst::before,
.stage-card.is-unlocking .stage-unlock-burst::after {
  content: "";
  position: absolute;
  left: 22px;
  top: 50%;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid rgba(255, 224, 140, 0.9);
  transform: translate(-50%, -50%) scale(0.3);
  animation: burst-ring 0.65s ease-out forwards;
}

.stage-card.is-unlocking .stage-unlock-burst::after {
  animation-delay: 0.08s;
  border-color: rgba(255, 255, 255, 0.7);
}

@keyframes lock-ready {
  0%,
  100% {
    transform: translateY(0) scale(1);
  }
  50% {
    transform: translateY(-2px) scale(1.08);
  }
}

@keyframes lock-pop {
  0% {
    transform: rotate(0) scale(1);
    opacity: 1;
  }
  25% {
    transform: rotate(-14deg) scale(1.15);
  }
  50% {
    transform: rotate(10deg) scale(1.35);
  }
  100% {
    transform: rotate(18deg) scale(0.15);
    opacity: 0;
  }
}

@keyframes card-unlock {
  0% {
    box-shadow: 0 8px 18px rgba(20, 12, 8, 0.18);
  }
  40% {
    box-shadow: 0 0 0 4px rgba(255, 224, 140, 0.85), 0 12px 28px rgba(255, 180, 60, 0.45);
  }
  100% {
    box-shadow: 0 8px 18px rgba(20, 12, 8, 0.18);
  }
}

@keyframes burst-ring {
  to {
    transform: translate(-50%, -50%) scale(2.4);
    opacity: 0;
  }
}

@keyframes stamp-in {
  0% {
    transform: rotate(-18deg) scale(1.55);
    opacity: 0;
  }
  70% {
    transform: rotate(-12deg) scale(0.92);
    opacity: 1;
  }
  100% {
    transform: rotate(-14deg) scale(1);
  }
}

.btn-unlock {
  margin-top: 8px;
  width: 100%;
  border: 0;
  border-radius: 999px;
  padding: 8px 14px;
  font: inherit;
  font-weight: 800;
  font-size: 13px;
  cursor: pointer;
  color: #5a3018;
  background: #fff6e8;
  box-shadow: 0 4px 10px rgba(20, 12, 8, 0.2);
}

.btn-unlock:disabled {
  opacity: 0.85;
}

#screen-stages,
#screen-chars {
  max-height: min(88vh, 720px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

#screen-stages .stages-head,
#screen-chars .stages-head {
  flex: 0 0 auto;
}

#screen-stages .stages-foot,
#screen-chars #btn-chars-back {
  flex: 0 0 auto;
}

.stages-foot {
  margin-top: 4px;
}

.s1 {
  background: linear-gradient(120deg, #7ec8e8, #8fbf5a);
}

.s2 {
  background: linear-gradient(120deg, #355c4a, #7aa35a);
}

.s3 {
  background: linear-gradient(120deg, #4a2030, #e07038);
}

.s4 {
  background: linear-gradient(120deg, #4a6a78, #8ab0c0);
}

.s5 {
  background: linear-gradient(120deg, #8aa4c0, #e8f0f8);
  color: #243044;
}

.s6 {
  background: linear-gradient(120deg, #121c28, #2a8890);
}

.s7 {
  background: linear-gradient(120deg, #e07040, #ffd080);
}

.s8 {
  background: linear-gradient(120deg, #a88858, #e8d0a0);
  color: #3a2810;
}

.s9 {
  background: linear-gradient(120deg, #5aa8e8, #dff4ff);
  color: #1a4068;
}

.s10 {
  background: linear-gradient(120deg, #3a1848, #e07050);
}

.s-endless {
  background: linear-gradient(120deg, #1a1028, #5a3878);
}

.c-pometa {
  background: linear-gradient(120deg, #f4ece0, #e8c8a0);
  color: #4a3020;
}

.c-cocoa {
  background: linear-gradient(120deg, #d4924a, #f0d090);
  color: #3a2410;
}

.c-cookie {
  background: linear-gradient(120deg, #e8f0f8, #b8d0e8);
  color: #2a4060;
}

.stage-card.is-picked {
  outline: 3px solid #fff6e8;
  box-shadow: 0 0 0 3px rgba(232, 137, 90, 0.85), 0 10px 24px rgba(20, 12, 8, 0.28);
}

.char-note {
  margin: 4px 0 0;
  text-align: left;
}

.stats {
  list-style: none;
  display: grid;
  gap: 6px;
  margin: 12px 0;
  font-size: 15px;
  color: #6b5348;
}

.banner {
  color: #c56a3c;
  font-weight: 700;
  margin-bottom: 10px;
}

.hidden {
  display: none !important;
}

@media (max-width: 640px) {
  .panel {
    padding: 22px 18px 18px;
  }
  .hud-left,
  .hud-right {
    font-size: 20px;
  }
}

@media (pointer: coarse) {
  #game {
    border-radius: 0;
    box-shadow: none;
  }
}

@media (pointer: coarse) and (orientation: portrait) {
  #frame {
    width: 100dvh;
    height: 100dvw;
    top: 0;
    left: 100dvw;
    transform: rotate(90deg);
    transform-origin: top left;
    position: fixed;
  }
}

@media (pointer: coarse), (orientation: landscape) and (max-height: 520px) {
  .panel {
    width: min(760px, calc(100cqw - 28px));
    max-height: calc(100cqh - 12px);
    padding: 12px 18px 12px;
    border-radius: 20px;
  }
  .panel h1 {
    font-size: clamp(22px, 8cqh, 36px);
    margin: 0 0 4px;
  }
  .panel h2 {
    font-size: 20px;
    margin-bottom: 6px;
  }
  .lead,
  .hint,
  .char-note {
    margin: 4px 0 8px;
    font-size: 12px;
  }
  .btn {
    padding: 8px 16px;
    font-size: 14px;
  }
  #screen-stages,
  #screen-chars {
    max-height: calc(100cqh - 12px);
  }
  .stage-grid {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin: 8px 0 8px;
  }
  .stage-card {
    padding: 10px 12px;
  }
  .hud-left,
  .hud-right {
    font-size: 18px;
  }
}
