* {
  box-sizing: border-box;
}

:root {
  color-scheme: dark;
  --bg: #050806;
  --panel: rgba(9, 22, 12, 0.82);
  --panel-strong: #102619;
  --ink: #f7fff1;
  --muted: #c5d8c3;
  --quiet: #8ba48e;
  --line: rgba(126, 241, 172, 0.2);
  --pocket: #7ef1ac;
  --crate: #ffc65f;
  --gate: #ff667c;
  --water: #70dcff;
  --wall: #223226;
  --floor: #102116;
  --shadow: rgba(0, 0, 0, 0.48);
}

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

body {
  margin: 0;
  overflow-x: hidden;
  background:
    linear-gradient(135deg, rgba(255, 198, 95, 0.1) 0 12%, transparent 12% 100%),
    linear-gradient(225deg, rgba(255, 102, 124, 0.08) 0 14%, transparent 14% 100%),
    linear-gradient(180deg, #102317 0%, #071109 55%, var(--bg) 100%);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans CJK JP", "Microsoft YaHei", sans-serif;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

.play-shell {
  width: min(1180px, calc(100% - 32px));
  min-height: 100svh;
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 0 max(24px, env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 0 22px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-size: 24px;
  font-weight: 900;
  text-decoration: none;
}

.brand::before {
  width: 18px;
  height: 18px;
  border: 2px solid var(--pocket);
  border-radius: 5px;
  background: linear-gradient(135deg, transparent 0 45%, var(--crate) 45% 63%, transparent 63% 100%), rgba(117, 234, 167, 0.12);
  box-shadow: 0 0 24px rgba(117, 234, 167, 0.32);
  content: "";
}

.status-pills {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.status-pills span,
.progress-dot {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(8, 23, 13, 0.72);
}

.status-pills span {
  min-height: 38px;
  padding: 8px 12px;
  color: #fff1bf;
  font-size: 13px;
  font-weight: 900;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 390px);
  align-items: stretch;
  gap: clamp(18px, 4vw, 42px);
}

.stage-panel,
.hud {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 28px 90px var(--shadow);
}

.stage-panel {
  position: relative;
  display: grid;
  min-height: min(74svh, 760px);
  place-items: center;
  overflow: hidden;
  padding: clamp(14px, 3vw, 28px);
}

.stage-panel::before {
  position: absolute;
  inset: -15%;
  background:
    linear-gradient(rgba(126, 241, 172, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(126, 241, 172, 0.07) 1px, transparent 1px);
  background-size: 64px 64px;
  content: "";
  opacity: 0.62;
  transform: rotate(-1deg);
}

#gameCanvas {
  position: relative;
  z-index: 1;
  display: block;
  width: min(100%, 74svh);
  max-width: 720px;
  aspect-ratio: 1;
  border: 1px solid rgba(126, 241, 172, 0.26);
  border-radius: 8px;
  background: #071108;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.36);
  touch-action: none;
}

.message {
  position: absolute;
  z-index: 2;
  left: 50%;
  bottom: 20px;
  max-width: calc(100% - 32px);
  border: 1px solid rgba(245, 182, 82, 0.5);
  border-radius: 8px;
  padding: 10px 14px;
  color: #fff6d6;
  background: rgba(10, 16, 11, 0.88);
  box-shadow: 0 18px 44px var(--shadow);
  font-size: 14px;
  font-weight: 900;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 8px);
  transition: opacity 180ms ease, transform 180ms ease;
}

.message.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.hud {
  display: flex;
  min-height: 100%;
  flex-direction: column;
  justify-content: space-between;
  gap: 22px;
  padding: clamp(18px, 3vw, 28px);
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--crate);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.hud h1 {
  margin: 0;
  color: var(--ink);
  font-size: clamp(34px, 5vw, 56px);
  line-height: 0.95;
}

.hud p {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.5;
}

.progress-track {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.progress-dot {
  width: 34px;
  height: 34px;
  color: var(--quiet);
  cursor: pointer;
  font-weight: 900;
}

.progress-dot.unlocked {
  color: #1c1204;
  background: var(--crate);
}

.progress-dot.current {
  outline: 2px solid var(--pocket);
  outline-offset: 2px;
}

.button-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

button {
  min-height: 46px;
  border: 1px solid rgba(117, 234, 167, 0.36);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(8, 23, 13, 0.76);
  font: inherit;
  font-weight: 900;
  cursor: pointer;
  transition: transform 150ms ease, border-color 150ms ease, background-color 150ms ease, color 150ms ease;
}

button:hover:not(:disabled),
button:focus-visible {
  border-color: #fff1bf;
  color: #fff1bf;
  background: rgba(25, 50, 28, 0.9);
  transform: translateY(-1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

#nextButton.ready {
  border-color: rgba(245, 182, 82, 0.86);
  color: #1c1204;
  background: var(--crate);
}

.touch-pad {
  display: grid;
  grid-template-areas:
    ". up ."
    "left down right";
  grid-template-columns: repeat(3, 64px);
  justify-content: center;
  gap: 10px;
}

.pad-btn {
  width: 64px;
  height: 58px;
  color: #1c1204;
  background: var(--pocket);
  font-size: 24px;
}

.pad-btn.up {
  grid-area: up;
}

.pad-btn.left {
  grid-area: left;
}

.pad-btn.down {
  grid-area: down;
}

.pad-btn.right {
  grid-area: right;
}

.control-note {
  color: var(--quiet) !important;
  font-size: 13px !important;
}

@media (max-width: 900px) {
  .play-shell {
    width: min(100% - 24px, 680px);
  }

  .game-layout {
    grid-template-columns: 1fr;
  }

  .stage-panel {
    min-height: auto;
  }

  #gameCanvas {
    width: min(100%, 62svh);
  }
}

@media (max-width: 560px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .status-pills {
    justify-content: flex-start;
  }

  #gameCanvas {
    width: 100%;
  }

  .button-row {
    grid-template-columns: 1fr;
  }

  .touch-pad {
    grid-template-columns: repeat(3, minmax(54px, 1fr));
  }

  .pad-btn {
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 1ms !important;
  }
}
