:root {
  --bg: #12324a;
  --panel: #1a4a66;
  --line: #7ec8e3;
  --text: #f4fbff;
  --muted: #c5e8f5;
  --head: #f7fbff;
  --body: #e6f4fb;
  --food: #f08a3a;
  --wall: #8fd4ef;
  --btn: #2b6d8a;
  --btn-press: #3e8aaa;
  --danger: #8a3a4a;
}

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

html,
body {
  margin: 0;
  min-height: 100%;
  min-height: 100dvh;
  background: linear-gradient(180deg, #7ec8e8 0%, #3d8fb8 42%, #1b4d68 100%);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, sans-serif;
  touch-action: manipulation;
  user-select: none;
  overflow: hidden;
}

.sky {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1;
}

.flake {
  position: absolute;
  top: -8px;
  width: 6px;
  height: 6px;
  background: #fff;
  border-radius: 50%;
  opacity: 0.7;
  animation: fall 9s linear infinite;
}

.flake:nth-child(1) { left: 8%; animation-duration: 8s; animation-delay: -1s; }
.flake:nth-child(2) { left: 22%; width: 4px; height: 4px; animation-duration: 11s; animation-delay: -3s; }
.flake:nth-child(3) { left: 36%; animation-duration: 9.5s; animation-delay: -2s; }
.flake:nth-child(4) { left: 51%; width: 5px; height: 5px; animation-duration: 10s; animation-delay: -5s; }
.flake:nth-child(5) { left: 64%; animation-duration: 7.5s; animation-delay: -1.5s; }
.flake:nth-child(6) { left: 73%; width: 3px; height: 3px; animation-duration: 12s; animation-delay: -4s; }
.flake:nth-child(7) { left: 81%; animation-duration: 8.8s; animation-delay: -6s; }
.flake:nth-child(8) { left: 90%; width: 4px; height: 4px; animation-duration: 9.2s; animation-delay: -2.8s; }
.flake:nth-child(9) { left: 15%; width: 3px; height: 3px; animation-duration: 13s; animation-delay: -7s; }

@keyframes fall {
  from { transform: translateY(-10px); }
  to { transform: translateY(110dvh); }
}

.app {
  position: relative;
  z-index: 2;
  max-width: 520px;
  margin: 0 auto;
  padding: 12px 12px calc(12px + env(safe-area-inset-bottom));
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.hud {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 10px;
  font-size: 13px;
  color: var(--muted);
}

.hud strong {
  color: var(--text);
}

#board {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1 / 1;
  background: #d7f1fb;
  border: 8px solid #9fe0f4;
  border-radius: 12px;
  box-shadow: inset 0 0 0 3px #ffffffaa, 0 8px 24px #06203366;
  image-rendering: auto;
  flex: 0 0 auto;
}

.banner {
  margin: 8px 0 0;
  text-align: center;
  font-size: 14px;
  min-height: 20px;
}

.controls {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.dpad {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: 64px 64px 64px;
  gap: 8px;
  max-width: 280px;
  margin: 0 auto;
  width: 100%;
}

.dpad .dir[data-dir="up"] { grid-column: 2; grid-row: 1; }
.dpad .dir[data-dir="left"] { grid-column: 1; grid-row: 2; }
.dpad .dir[data-dir="right"] { grid-column: 3; grid-row: 2; }
.dpad .dir[data-dir="down"] { grid-column: 2; grid-row: 3; }

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}

.btn {
  appearance: none;
  border: 1px solid #b7e7f6;
  background: var(--btn);
  color: var(--text);
  border-radius: 14px;
  font-size: 16px;
  font-weight: 700;
  min-height: 52px;
  cursor: pointer;
  box-shadow: 0 3px 0 #164258;
}

.btn:active,
.btn.pressed {
  background: var(--btn-press);
  transform: translateY(2px);
  box-shadow: 0 1px 0 #164258;
}

.btn.danger {
  background: var(--danger);
}

.btn.primary {
  background: #2f8eb0;
  min-height: 56px;
  width: 100%;
}

.btn.ghost {
  background: transparent;
  box-shadow: none;
  width: 100%;
  margin-top: 8px;
}

.overlay {
  position: fixed;
  inset: 0;
  background: linear-gradient(180deg, #8fd4ef 0%, #4aa7c9 38%, #1b4d68 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 10;
}

#home-snow {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
}

.overlay.hidden {
  display: none;
}

.sheet {
  width: min(360px, 100%);
  text-align: center;
  position: relative;
  z-index: 1;
}

.home-sheet {
  padding-bottom: 8px;
}

.sheet h1 {
  margin: 0 0 8px;
  font-size: 28px;
  letter-spacing: 1px;
}

.sheet h2 {
  margin: 0 0 12px;
  font-size: 24px;
}

.sheet p {
  margin: 0 0 8px;
  color: var(--muted);
}

.hero {
  display: block;
  width: 200px;
  height: auto;
  margin: 8px auto 12px;
}

.high-line {
  margin: 0 0 18px !important;
  color: var(--text) !important;
  font-size: 18px;
  font-weight: 700;
}

.hint {
  margin-top: 16px !important;
  font-size: 13px;
}

.rules {
  text-align: left;
  margin: 0 0 20px;
  padding-left: 20px;
  color: var(--muted);
  line-height: 1.7;
}

@media (max-height: 720px) {
  .hero {
    width: 160px;
  }
  .dpad {
    grid-template-rows: 52px 52px 52px;
    gap: 6px;
  }
  .btn {
    min-height: 46px;
    font-size: 15px;
  }
}
