:root {
  --ink: #102033;
  --muted: #5e6b7e;
  --panel: rgba(255, 255, 255, 0.9);
  --line: rgba(16, 32, 51, 0.14);
  --green: #10b981;
  --yellow: #facc15;
  --pink: #fb7185;
  --blue: #38bdf8;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    linear-gradient(180deg, #8bdcf7 0%, #d8f7ff 54%, #a7f3d0 54%, #46c88b 100%);
  overflow: hidden;
  overscroll-behavior: none;
}

button {
  font: inherit;
  border: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.game-shell {
  width: min(430px, 100%);
  height: 100dvh;
  min-height: 100svh;
  margin: 0 auto;
  padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 8px;
}

.topbar {
  min-height: 54px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr)) 48px;
  gap: 7px;
  align-items: center;
}

.topbar > div,
.icon-btn,
.primary-btn,
.control-btn {
  border: 2px solid rgba(255, 255, 255, 0.74);
  box-shadow: 0 10px 22px rgba(16, 32, 51, 0.14);
}

.topbar > div {
  min-width: 0;
  height: 54px;
  padding: 7px 9px;
  background: var(--panel);
  border-radius: 8px;
}

.label {
  margin: 0 0 2px;
  color: var(--muted);
  font-size: 0.66rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
}

.topbar strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: clamp(1.18rem, 6vw, 1.56rem);
  line-height: 1;
}

.icon-btn {
  width: 48px;
  height: 54px;
  border-radius: 8px;
  color: #fff;
  background: #ec4899;
  font-size: 1.4rem;
  font-weight: 900;
}

.stage-wrap {
  position: relative;
  min-height: 0;
  border: 3px solid rgba(255, 255, 255, 0.72);
  border-radius: 8px;
  overflow: hidden;
  background: #70d6ff;
  box-shadow: 0 20px 48px rgba(16, 32, 51, 0.2);
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  background: #8bdcf7;
  touch-action: none;
  user-select: none;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 18px;
  padding: 18px;
  text-align: center;
  background: rgba(255, 255, 255, 0.48);
  backdrop-filter: blur(4px);
}

.overlay.hidden {
  display: none;
}

.overlay img {
  width: clamp(88px, 30vw, 126px);
  height: auto;
  filter: drop-shadow(0 14px 16px rgba(16, 32, 51, 0.22));
}

h1 {
  margin: 0;
  max-width: 100%;
  color: #0f766e;
  font-size: clamp(2.2rem, 13vw, 3.7rem);
  line-height: 0.95;
  letter-spacing: 0;
  text-wrap: balance;
  text-shadow: 0 3px 0 #fff, 0 12px 22px rgba(16, 32, 51, 0.14);
}

.primary-btn {
  min-width: 132px;
  min-height: 52px;
  padding: 0 22px;
  border-radius: 8px;
  color: #102033;
  background: var(--yellow);
  font-weight: 900;
}

.primary-btn:active,
.control-btn:active,
.icon-btn:active {
  transform: translateY(2px);
}

.primary-btn.small {
  min-width: 96px;
  background: #ffffff;
}

.controls {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 8px;
  align-items: center;
  min-height: 78px;
}

.control-btn {
  min-height: 78px;
  border-radius: 8px;
  color: #fff;
  background: var(--green);
  font-size: clamp(2.8rem, 17vw, 4rem);
  font-weight: 900;
  line-height: 1;
}

#rightBtn {
  background: var(--blue);
}

@media (max-width: 380px), (max-height: 690px) {
  .game-shell {
    gap: 6px;
  }

  .topbar {
    grid-template-columns: repeat(3, minmax(0, 1fr)) 42px;
    min-height: 48px;
    gap: 6px;
  }

  .topbar > div {
    height: 48px;
    padding: 6px 7px;
  }

  .icon-btn {
    width: 42px;
    height: 48px;
  }

  .label {
    font-size: 0.6rem;
  }

  .topbar strong {
    font-size: 1.16rem;
  }

  .controls {
    min-height: 66px;
  }

  .control-btn {
    min-height: 66px;
  }

  .primary-btn.small {
    min-height: 44px;
    min-width: 86px;
    padding: 0 14px;
  }
}
