:root {
  --bg: #04050d;
  --ink: #eef3ff;
  --muted: #8f9bc4;
  --cyan: #5ff3ff;
  --gold: #ffc93c;
  --red: #ff5d73;
  --panel: rgba(9, 12, 28, 0.74);
  --line: rgba(150, 170, 255, 0.2);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation; /* no double-tap zoom on buttons; the canvas disables touch gestures itself */
}

#game {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  outline: none;
}

/* ---------- top bar ---------- */

.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: 1fr auto 1fr; /* equal side columns keep the score centred however many buttons are on the right */
  grid-template-areas: "left mid right";
  align-items: start;
  padding: max(12px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) 0 max(14px, env(safe-area-inset-left));
  pointer-events: none;
}

#pauseBtn { grid-area: left; justify-self: start; }
#scoreWrap { grid-area: mid; }
.top-right { grid-area: right; justify-self: end; display: flex; gap: 8px; }

.icon-btn {
  pointer-events: auto;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(9, 12, 28, 0.55);
  color: var(--ink);
  cursor: pointer;
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}
.icon-btn:hover { border-color: rgba(95, 243, 255, 0.5); }
.icon-btn svg { width: 22px; height: 22px; fill: currentColor; }
.icon-btn .wave,
.icon-btn .cross { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.icon-btn .cross { display: none; }
.icon-btn[aria-pressed="true"] .wave { display: none; }
.icon-btn[aria-pressed="true"] .cross { display: inline; }
#muteBtn[aria-pressed="true"] { color: var(--muted); } /* pressed means muted */

/* Vibration button: outline icon; pressed means vibration is ON, so it dims and gets a slash when off.
   On iPhone/iPad (data-unavailable) it is dimmed and slashed too, and tapping it explains why. */
.icon-btn .line-icon { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn .slash { display: none; }
#hapticBtn[aria-pressed="false"],
#hapticBtn[data-unavailable] { color: var(--muted); }
#hapticBtn[aria-pressed="false"] .slash,
#hapticBtn[data-unavailable] .slash { display: inline; }

/* A short note that appears under the top bar and fades away by itself. */
.toast {
  position: fixed;
  z-index: 6;
  left: 50%;
  top: calc(max(12px, env(safe-area-inset-top)) + 56px);
  transform: translateX(-50%);
  width: max-content;
  max-width: min(340px, calc(100vw - 32px));
  margin: 0;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(9, 12, 28, 0.92);
  color: var(--ink);
  font-size: 13px;
  line-height: 1.4;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  pointer-events: none;
}

.score-wrap { text-align: center; line-height: 1; padding-top: 2px; }
.score {
  font-size: clamp(32px, 6vw, 48px);
  font-weight: 800;
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 18px rgba(95, 243, 255, 0.35);
}
.combo {
  min-height: 1em;
  margin-top: 6px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold);
}
.combo.hot { color: #ffe9a8; text-shadow: 0 0 12px rgba(255, 201, 60, 0.65); }

/* ---------- overlay screens ---------- */

.screen {
  position: fixed;
  inset: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 72px max(16px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  overflow-y: auto; /* short screens (phones in landscape) can scroll instead of clipping */
  background: radial-gradient(ellipse at center, rgba(4, 5, 13, 0.2), rgba(4, 5, 13, 0.7) 75%);
}

.card {
  width: 100%;
  max-width: 380px;
  margin: auto; /* centres vertically but, unlike align-items, never clips the top when it overflows */
  padding: 28px 26px 22px;
  text-align: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.55);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}

h1 {
  text-wrap: balance; /* a long title breaks into two even lines instead of one long and one short */
  margin: 0 0 6px;
  font-size: clamp(34px, 9vw, 46px);
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  background: linear-gradient(180deg, #fff6dc 10%, #ffb347 60%, #ff6a3d);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

h2 { margin: 0 0 18px; font-size: 26px; letter-spacing: 0.06em; }
h2.eyebrow {
  margin-bottom: 4px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--red);
}

.tag { margin: 0 0 18px; color: var(--muted); font-size: 15px; }

.legend {
  margin: 0 0 22px;
  padding: 14px 16px;
  list-style: none;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.025);
}
.legend li { display: flex; align-items: center; gap: 12px; font-size: 14px; }
.legend li + li { margin-top: 10px; }
.legend svg { flex: none; width: 22px; height: 22px; }
.i-orb { fill: var(--gold); }
.i-rock { fill: #2a1824; stroke: var(--red); stroke-width: 2; stroke-linejoin: round; }

.final {
  font-size: 72px;
  font-weight: 800;
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 26px rgba(95, 243, 255, 0.35);
}

.badge {
  display: inline-block;
  margin: 6px 0 0;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: #2b1d00;
  background: linear-gradient(180deg, #ffe58a, var(--gold));
}

.best { margin: 14px 0 0; color: var(--muted); font-size: 14px; letter-spacing: 0.06em; }
.best strong { color: var(--ink); font-variant-numeric: tabular-nums; }
.stats { margin: 6px 0 20px; color: var(--muted); font-size: 13px; }
.hint { margin: 12px 0 0; color: var(--muted); font-size: 12px; opacity: 0.85; }
.hint-touch { display: none; }
@media (hover: none) and (pointer: coarse) {
  .hint-key { display: none; }
  .hint-touch { display: block; }
}

.row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

.install { margin-top: 16px; min-width: 0; padding: 10px 22px; font-size: 13px; }

.credit {
  margin: 18px 0 0;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.08em;
}

.steps {
  margin: 0 0 20px;
  padding: 14px 16px 14px 34px;
  text-align: left;
  font-size: 14px;
  line-height: 1.45;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.025);
}
.steps li + li { margin-top: 8px; }
.steps li::marker { color: var(--cyan); font-weight: 800; }

/* ---------- buttons ---------- */

.btn {
  appearance: none;
  min-width: 150px;
  padding: 14px 30px;
  border: 0;
  border-radius: 999px;
  font: inherit;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #03121a;
  background: linear-gradient(180deg, #9af9ff, #3fd0ff);
  box-shadow: 0 8px 26px rgba(63, 208, 255, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.6);
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease, opacity 0.2s ease;
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 12px 32px rgba(63, 208, 255, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.6); }
.btn:active { transform: translateY(1px) scale(0.98); }
.btn:disabled { opacity: 0.45; cursor: default; transform: none; }
.btn.ghost {
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--line);
  box-shadow: none;
}
.btn.ghost:hover { border-color: rgba(95, 243, 255, 0.5); }

.btn:focus-visible,
.icon-btn:focus-visible { outline: 2px solid var(--cyan); outline-offset: 3px; }

/* Short viewports, mainly phones held sideways: tighten everything so each screen fits. */
@media (max-height: 520px) {
  .screen { padding-top: 56px; padding-bottom: 12px; }
  .card { max-width: 440px; padding: 14px 22px 14px; }
  h1 { margin-bottom: 2px; font-size: 28px; }
  h2 { margin-bottom: 10px; font-size: 22px; }
  .tag { margin-bottom: 10px; font-size: 13px; }
  .legend { display: none; }
  .btn { padding: 10px 24px; font-size: 14px; }
  .best { margin-top: 8px; }
  .hint { margin-top: 6px; }
  .install { margin-top: 8px; padding: 8px 18px; }
  .credit { margin-top: 8px; padding-top: 8px; }
  .steps { margin-bottom: 10px; padding: 8px 12px 8px 30px; font-size: 13px; line-height: 1.35; }
  .steps li + li { margin-top: 4px; }
  .final { font-size: 44px; }
  .stats { margin-bottom: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .btn { transition: none; }
}
