:root {
  --night: #0a1020;
  --panel: #0e1830;
  --line: #26385a;
  --text: #d3ddf3;
  --faint: #93a2c6;
  --accent: #7fd6c0;
  --amber: #f0bd72;
  color-scheme: dark;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  /* iOS Safari double-tap-to-zoom would fire on quick repeated taps; the
     puzzle needs them. `manipulation` keeps pan + pinch, drops double-tap. */
  touch-action: manipulation;
}

body {
  background: radial-gradient(130% 120% at 50% -10%, #16233f 0%, var(--night) 62%);
  color: var(--text);
  font: 16px/1.4 ui-rounded, "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-text-size-adjust: 100%;
}

#bg {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  display: block;
}

.hud {
  position: relative;
  z-index: 1;
  height: 100dvh;
  max-width: 34rem;
  margin: 0 auto;
  padding: calc(10px + env(safe-area-inset-top)) 14px calc(10px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
}

.level { margin: 0; font-weight: 600; }
.sound {
  min-height: 44px;
  min-width: 44px;
  padding: 0 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}
.sound[aria-pressed="true"] {
  background: #17324a;
  border-color: #2f6f74;
  color: #dff6ee;
}
.goal { margin: 0; color: var(--faint); }
.hint {
  margin: 0;
  min-height: 2.9em;
  color: var(--faint);
  flex: 0 0 auto;
  text-shadow: 0 1px 3px rgba(6, 10, 22, 0.9);
}

@media (min-width: 900px) {
  .hud { max-width: 42rem; }
}

.stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  justify-content: center;
  align-items: center;
}

#board {
  display: block;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--night);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  cursor: pointer;
}

#board:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.banner {
  position: absolute;
  inset: auto 0 8%;
  margin: 0 auto;
  width: min(100%, 20rem);
  padding: 14px 16px;
  border-radius: 14px;
  background: rgba(9, 15, 29, 0.92);
  border: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
  text-align: center;
}

.banner-text { margin: 0; }

.controls {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.pad {
  display: grid;
  grid-template-columns: repeat(3, 46px);
  grid-template-rows: repeat(3, 46px);
  gap: 4px;
}

.pad-btn {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}

.pad-btn.up { grid-area: 1 / 2; }
.pad-btn.left { grid-area: 2 / 1; }
.pad-btn.right { grid-area: 2 / 3; }
.pad-btn.down { grid-area: 3 / 2; }

.acts { display: flex; flex-direction: column; gap: 6px; }

.acts button, .primary {
  min-height: 46px;
  min-width: 108px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

.primary {
  background: #17324a;
  border-color: #2f6f74;
  color: #dff6ee;
}

button {
  /* touch-action is not inherited, so every tappable control needs it. */
  touch-action: manipulation;
}

button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.note {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
  font-size: 16px;
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
