:root {
  --bg-0: #05090d;
  --bg-1: #09141a;
  --bg-2: #10262b;
  --text: #f3f7f4;
  --muted: #88a0a6;
  --glass-line: #d8f9fc;
  --plus: #ff744a;
  --minus: #35cfff;
  --flux: #edffd7;
  --danger: #ff526b;
}

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

/* WebKit may let an authored display value override the native hidden rule. */
[hidden] {
  display: none !important;
  pointer-events: none !important;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  background: #020507;
  color: var(--text);
  font-family: ui-rounded, "SF Pro Rounded", "Segoe UI", system-ui, sans-serif;
  overscroll-behavior: none;
}

body {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  background:
    radial-gradient(ellipse at 50% 90%, #10262b 0%, transparent 48%),
    #020507;
}

button {
  color: inherit;
  font: inherit;
}

.game-shell {
  position: relative;
  width: min(100vw, calc(100dvh * 0.4621), 460px);
  height: min(100dvh, calc(100vw * 2.1641), 996px);
  aspect-ratio: 390 / 844;
  overflow: hidden;
  isolation: isolate;
  background:
    radial-gradient(ellipse at 50% 82%, #10262b 0%, transparent 58%),
    radial-gradient(circle at 72% 18%, #112129 0%, transparent 42%),
    var(--bg-0);
  box-shadow: 0 0 80px rgba(17, 50, 57, 0.22);
}

.game-shell::after {
  position: absolute;
  inset: 0;
  z-index: 8;
  border: 1px solid rgba(216, 249, 252, 0.055);
  pointer-events: none;
  content: "";
}

#game {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
  touch-action: none;
  user-select: none;
}

.hud {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 4;
  display: grid;
  width: 100%;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  padding: calc(18px + env(safe-area-inset-top)) 18px 0;
  pointer-events: none;
}

.identity {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-top: 4px;
}

.wordmark,
.edition,
.score-label,
.build-mark,
.prompt,
.rules-kicker,
.failure-kicker,
.failure-reason,
.failure-best,
.failure-action {
  font-weight: 720;
  line-height: 1;
  letter-spacing: 0.18em;
}

.wordmark {
  font-size: 10px;
  letter-spacing: 0.26em;
}

.edition,
.score-label {
  color: var(--muted);
  font-size: 7px;
  letter-spacing: 0.2em;
}

.score-block {
  display: flex;
  min-width: 146px;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.score {
  display: block;
  font-size: 34px;
  font-variant-numeric: tabular-nums;
  font-weight: 650;
  letter-spacing: -0.055em;
  line-height: 0.95;
  text-shadow: 0 0 24px rgba(237, 255, 215, 0.12);
  transform-origin: 50% 50%;
}

.score.bump {
  animation: score-bump 180ms cubic-bezier(0.2, 0.9, 0.2, 1);
}

@keyframes score-bump {
  45% { transform: scale(1.08); color: var(--flux); }
}

.hud-actions {
  z-index: 6;
  justify-self: end;
  display: flex;
  align-items: center;
  margin-top: -7px;
  pointer-events: auto;
}

.hud-button {
  width: 44px;
  height: 44px;
  padding: 10px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  opacity: 0.72;
  pointer-events: auto;
  cursor: pointer;
}

.hud-button:focus-visible {
  outline: 1px solid rgba(216, 249, 252, 0.7);
  outline-offset: -5px;
}

.help-toggle {
  color: rgba(243, 247, 244, 0.86);
  font-size: 15px;
  font-weight: 650;
}

.sound-toggle svg {
  width: 100%;
  fill: rgba(243, 247, 244, 0.92);
  stroke: rgba(243, 247, 244, 0.92);
  stroke-width: 1.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sound-toggle[aria-pressed="true"] .sound-wave {
  opacity: 0.15;
}

.prompt {
  position: absolute;
  top: 169px;
  left: 50%;
  z-index: 4;
  display: flex;
  width: min(318px, 84%);
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 11px 16px 12px;
  border: 1px solid rgba(216, 249, 252, 0.14);
  border-radius: 15px;
  background: rgba(5, 9, 13, 0.68);
  text-align: center;
  transform: translateX(-50%);
  transition: opacity 180ms ease, transform 180ms ease;
  pointer-events: none;
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.18);
  backdrop-filter: blur(12px);
}

.prompt[hidden] {
  display: none;
}

.prompt-step {
  color: rgba(154, 244, 255, 0.74);
  font-size: 8px;
  font-weight: 740;
  letter-spacing: 0.22em;
  line-height: 1;
}

.prompt-title {
  color: rgba(243, 247, 244, 0.96);
  font-size: 12px;
  font-weight: 760;
  letter-spacing: 0.12em;
  line-height: 1.15;
}

.prompt-detail {
  color: rgba(174, 194, 199, 0.88);
  font-size: 11px;
  font-weight: 520;
  letter-spacing: 0.01em;
  line-height: 1.3;
}

.rules-overlay {
  position: absolute;
  inset: 0;
  z-index: 7;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(2, 7, 10, 0.72);
  backdrop-filter: blur(13px);
}

.rules-card {
  width: min(340px, 100%);
  padding: 24px 22px 20px;
  border: 1px solid rgba(216, 249, 252, 0.17);
  border-radius: 24px;
  background:
    radial-gradient(circle at 82% 4%, rgba(53, 207, 255, 0.11), transparent 32%),
    linear-gradient(155deg, rgba(16, 38, 43, 0.98), rgba(5, 12, 16, 0.98));
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.46);
}

.rules-kicker {
  color: rgba(154, 244, 255, 0.7);
  font-size: 8px;
  letter-spacing: 0.24em;
}

.rules-card h1 {
  margin: 7px 0 22px;
  font-size: 25px;
  font-weight: 640;
  letter-spacing: -0.025em;
}

.rule-row {
  display: grid;
  grid-template-columns: 30px 1fr;
  gap: 10px;
  padding: 12px 0;
  border-top: 1px solid rgba(216, 249, 252, 0.08);
}

.rule-number {
  padding-top: 2px;
  color: rgba(136, 160, 166, 0.52);
  font-size: 9px;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  letter-spacing: 0.12em;
}

.rule-row strong,
.rule-row small {
  display: block;
}

.rule-row strong {
  margin-bottom: 4px;
  color: rgba(243, 247, 244, 0.92);
  font-size: 10px;
  letter-spacing: 0.11em;
}

.rule-row small {
  color: rgba(174, 194, 199, 0.76);
  font-size: 11px;
  line-height: 1.38;
}

.danger-rule strong {
  color: rgba(255, 143, 157, 0.92);
}

.rules-dismiss {
  width: 100%;
  margin-top: 18px;
  padding: 14px 16px;
  border: 1px solid rgba(237, 255, 215, 0.21);
  border-radius: 999px;
  background: rgba(237, 255, 215, 0.09);
  color: var(--flux);
  font-size: 10px;
  font-weight: 740;
  letter-spacing: 0.14em;
  cursor: pointer;
}

.rules-dismiss:focus-visible {
  outline: 1px solid var(--flux);
  outline-offset: 3px;
}

.failure {
  position: absolute;
  inset: 0;
  z-index: 7;
  display: flex;
  width: 100%;
  height: 100%;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: 0;
  background:
    radial-gradient(circle at 50% 54%, rgba(13, 30, 35, 0.74), rgba(5, 9, 13, 0.91) 48%, rgba(5, 9, 13, 0.76));
  cursor: pointer;
  opacity: 0;
  transition: opacity 240ms ease;
  backdrop-filter: blur(7px);
}

.failure:not([hidden]) {
  opacity: 1;
}

.failure-kicker {
  margin-bottom: 9px;
  color: rgba(243, 247, 244, 0.74);
  font-size: 11px;
}

.failure-reason {
  width: 72%;
  margin-bottom: 18px;
  color: rgba(255, 143, 157, 0.84);
  font-size: 8px;
  line-height: 1.45;
  text-align: center;
}

.failure-score {
  font-size: 54px;
  font-variant-numeric: tabular-nums;
  font-weight: 620;
  letter-spacing: -0.055em;
  line-height: 1;
}

.failure-best {
  margin-top: 13px;
  color: var(--muted);
  font-size: 9px;
}

.failure-action {
  position: absolute;
  bottom: calc(48px + env(safe-area-inset-bottom));
  color: var(--flux);
  font-size: 10px;
}

.build-mark {
  position: absolute;
  right: 18px;
  bottom: calc(12px + env(safe-area-inset-bottom));
  z-index: 4;
  color: rgba(136, 160, 166, 0.28);
  font-size: 7px;
  pointer-events: none;
}

@media (prefers-reduced-motion: reduce) {
  .score.bump { animation: none; }
  .prompt,
  .rules-overlay,
  .failure { transition-duration: 0.01ms; }
}
