:root {
  --bg: #04060d;
  --ink: #eaf8ff;
  --muted: #7f95ad;
  --cyan: #38f2ff;
  --magenta: #ff4fd8;
  --yellow: #ffe14d;
  --coral: #ff6a5f;
  --line: rgba(126, 190, 222, 0.18);
  --panel: rgba(7, 14, 27, 0.78);
  --display: "Arial Black", "Avenir Next Heavy", "Helvetica Neue", sans-serif;
  --body: "Avenir Next", "Trebuchet MS", "Segoe UI", sans-serif;
  --mono: "SFMono-Regular", "Cascadia Code", "Roboto Mono", Menlo, Consolas, monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  min-height: 100svh;
  display: grid;
  place-items: center;
  overflow: hidden;
  color: var(--ink);
  background:
    radial-gradient(circle at 18% 12%, rgba(56, 242, 255, 0.12), transparent 32%),
    radial-gradient(circle at 84% 86%, rgba(255, 79, 216, 0.1), transparent 34%),
    radial-gradient(circle at 50% 50%, #0a1222 0%, #04060d 62%, #020308 100%);
  font-family: var(--body);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body::before {
  content: "";
  position: fixed;
  inset: -20%;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(120, 190, 220, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(120, 190, 220, 0.035) 1px, transparent 1px);
  background-size: 72px 72px;
  transform: perspective(600px) rotateX(58deg) translateY(12%);
  mask-image: radial-gradient(circle at 50% 55%, #000 0%, transparent 72%);
}

.app {
  width: min(96vw, 160vh, 1440px);
  position: relative;
  z-index: 1;
}

.game-shell {
  position: relative;
  width: 100%;
  aspect-ratio: 5 / 3;
  overflow: hidden;
  border-radius: clamp(14px, 1.8vw, 26px);
  background: #05070f;
  border: 1px solid rgba(126, 220, 255, 0.22);
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.7),
    0 20px 80px rgba(0, 0, 0, 0.65),
    0 0 90px rgba(56, 242, 255, 0.11),
    inset 0 0 80px rgba(0, 0, 0, 0.55);
  isolation: isolate;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: none;
}

.fx {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
}

.scanlines {
  opacity: 0.28;
  background: repeating-linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0.03) 0,
    rgba(255, 255, 255, 0.03) 1px,
    transparent 1px,
    transparent 4px
  );
  mix-blend-mode: overlay;
}

.vignette {
  box-shadow:
    inset 0 0 90px rgba(0, 0, 0, 0.62),
    inset 0 0 24px rgba(0, 0, 0, 0.5);
  border-radius: inherit;
}

.top-actions {
  position: absolute;
  top: clamp(10px, 1.5vw, 18px);
  right: clamp(10px, 1.5vw, 18px);
  z-index: 8;
  display: flex;
  gap: 8px;
}

.icon-btn {
  width: clamp(30px, 3vw, 40px);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid rgba(137, 216, 244, 0.2);
  border-radius: 12px;
  color: rgba(214, 243, 255, 0.8);
  background: rgba(6, 14, 26, 0.68);
  backdrop-filter: blur(8px);
  cursor: pointer;
  transition: color 160ms ease, border-color 160ms ease, background 160ms ease, transform 160ms ease;
}

.icon-btn:hover {
  color: #fff;
  border-color: rgba(56, 242, 255, 0.65);
  background: rgba(12, 30, 48, 0.85);
  transform: translateY(-1px);
}

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

.icon-btn svg {
  width: 52%;
  height: 52%;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-btn .icon-on {
  display: block;
}

.icon-btn .icon-off {
  display: none;
}

.icon-btn.muted .icon-on {
  display: none;
}

.icon-btn.muted .icon-off {
  display: block;
}

.icon-btn .icon-play {
  display: none;
}

.icon-btn.is-paused .icon-pause {
  display: none;
}

.icon-btn.is-paused .icon-play {
  display: block;
  fill: currentColor;
  stroke: none;
}

.overdrive-btn {
  position: absolute;
  left: 50%;
  bottom: clamp(10px, 1.8vw, 22px);
  z-index: 9;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: 0.55em;
  padding: 0.6em 1.1em;
  border: 1px solid rgba(255, 225, 77, 0.8);
  border-radius: 999px;
  color: #241a00;
  background: linear-gradient(110deg, #fff3a8, var(--yellow) 45%, #ffb13b);
  box-shadow:
    0 0 0 4px rgba(255, 225, 77, 0.09),
    0 0 30px rgba(255, 225, 77, 0.45);
  font-family: var(--display);
  font-size: clamp(9px, 0.9vw, 13px);
  letter-spacing: 0.14em;
  cursor: pointer;
  animation: overdrive-pulse 1.25s ease-in-out infinite;
}

.overdrive-btn:hover {
  filter: brightness(1.08);
  transform: translateX(-50%) translateY(-1px);
}

.overdrive-btn .bolt {
  font-size: 1.15em;
  filter: drop-shadow(0 0 4px rgba(255, 255, 255, 0.8));
}

.overdrive-btn .key {
  padding: 0.15em 0.45em;
  border-radius: 5px;
  color: rgba(36, 26, 0, 0.72);
  background: rgba(255, 255, 255, 0.35);
  font-family: var(--mono);
  font-size: 0.8em;
  letter-spacing: 0.06em;
}

@keyframes overdrive-pulse {
  0%,
  100% {
    box-shadow: 0 0 0 4px rgba(255, 225, 77, 0.08), 0 0 26px rgba(255, 225, 77, 0.35);
  }
  50% {
    box-shadow: 0 0 0 7px rgba(255, 225, 77, 0.11), 0 0 44px rgba(255, 225, 77, 0.62);
  }
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 7;
  display: grid;
  place-items: center;
  padding: clamp(16px, 3vw, 42px);
  overflow: auto;
  background:
    radial-gradient(circle at 50% 44%, rgba(8, 18, 34, 0.72), rgba(3, 6, 14, 0.93) 70%),
    rgba(3, 6, 14, 0.82);
  backdrop-filter: blur(10px) saturate(0.8);
  transition: opacity 240ms ease, visibility 240ms ease;
}

.overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.menu-card,
.modal-card {
  width: min(780px, 100%);
  text-align: center;
  animation: card-in 420ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

@keyframes card-in {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 0.65em;
  color: rgba(163, 216, 238, 0.72);
  font-family: var(--mono);
  font-size: clamp(8px, 0.9vw, 11px);
  letter-spacing: 0.22em;
  text-transform: uppercase;
}

.eyebrow-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--cyan);
  box-shadow: 0 0 10px var(--cyan);
}

h1,
h2 {
  margin: 0;
  font-family: var(--display);
  text-transform: uppercase;
  line-height: 0.84;
  letter-spacing: -0.045em;
}

h1 {
  margin: clamp(10px, 1.8vw, 22px) 0 clamp(10px, 1.4vw, 16px);
  font-size: clamp(58px, 10vw, 132px);
  color: #f4fdff;
  text-shadow:
    0 0 24px rgba(56, 242, 255, 0.2),
    0 8px 0 rgba(0, 0, 0, 0.3);
}

h1 span {
  display: inline-block;
  margin-left: 0.06em;
  color: transparent;
  background: linear-gradient(100deg, var(--cyan) 0%, #b7a6ff 48%, var(--magenta) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  filter: drop-shadow(0 0 18px rgba(255, 79, 216, 0.26));
}

.tagline {
  margin: 0 auto clamp(18px, 2.4vw, 30px);
  max-width: 34em;
  color: #a9bfd2;
  font-size: clamp(12px, 1.3vw, 17px);
  line-height: 1.5;
  letter-spacing: 0.02em;
}

.rule-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 0 auto clamp(20px, 2.6vw, 32px);
  text-align: left;
}

.rule {
  position: relative;
  display: flex;
  gap: 0.8em;
  min-height: 100%;
  padding: clamp(11px, 1.35vw, 17px);
  border: 1px solid rgba(130, 198, 225, 0.14);
  border-radius: 13px;
  background: linear-gradient(145deg, rgba(16, 30, 50, 0.6), rgba(6, 12, 24, 0.52));
  overflow: hidden;
}

.rule::after {
  content: "";
  position: absolute;
  inset: auto 0 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(56, 242, 255, 0.35), transparent);
}

.rule-num {
  flex: none;
  color: var(--cyan);
  font-family: var(--mono);
  font-size: clamp(9px, 0.95vw, 11px);
  letter-spacing: 0.08em;
  opacity: 0.8;
}

.rule strong {
  display: block;
  margin-bottom: 0.38em;
  color: #e9f8ff;
  font-family: var(--mono);
  font-size: clamp(9px, 0.95vw, 11px);
  letter-spacing: 0.1em;
}

.rule p {
  margin: 0;
  color: #829ab0;
  font-size: clamp(10px, 0.95vw, 12.5px);
  line-height: 1.45;
}

.menu-actions,
.modal-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(14px, 2.2vw, 28px);
  flex-wrap: wrap;
}

.primary-btn,
.ghost-btn {
  min-width: clamp(170px, 18vw, 230px);
  padding: 0.95em 1.45em;
  border-radius: 10px;
  font-family: var(--display);
  font-size: clamp(11px, 1.1vw, 15px);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  transition: transform 160ms ease, filter 160ms ease, background 160ms ease, border-color 160ms ease;
}

.primary-btn {
  border: 1px solid rgba(113, 250, 255, 0.8);
  color: #031016;
  background: linear-gradient(105deg, #8dfaff, var(--cyan) 52%, #65c9ff);
  box-shadow:
    0 0 0 5px rgba(56, 242, 255, 0.06),
    0 0 32px rgba(56, 242, 255, 0.28);
}

.primary-btn span {
  display: inline-block;
  margin-left: 0.35em;
  transition: transform 160ms ease;
}

.primary-btn:hover {
  filter: brightness(1.08);
  transform: translateY(-2px);
}

.primary-btn:hover span {
  transform: translateX(3px);
}

.ghost-btn {
  border: 1px solid rgba(138, 198, 221, 0.24);
  color: #b7cbd9;
  background: rgba(10, 20, 34, 0.55);
}

.ghost-btn:hover {
  color: #fff;
  border-color: rgba(138, 198, 221, 0.6);
  background: rgba(18, 34, 54, 0.75);
  transform: translateY(-2px);
}

.best {
  color: rgba(150, 180, 199, 0.72);
  font-family: var(--mono);
  font-size: clamp(9px, 0.9vw, 11px);
  letter-spacing: 0.16em;
}

.best strong {
  margin-left: 0.55em;
  color: var(--yellow);
  font-weight: 600;
  text-shadow: 0 0 12px rgba(255, 225, 77, 0.25);
}

.controls-line {
  display: flex;
  justify-content: center;
  gap: clamp(9px, 1.6vw, 20px);
  flex-wrap: wrap;
  margin-top: clamp(16px, 2.2vw, 28px);
  color: #61788c;
  font-family: var(--mono);
  font-size: clamp(8px, 0.8vw, 10px);
  letter-spacing: 0.05em;
}

.controls-line span {
  white-space: nowrap;
}

.touch-only {
  display: none;
}

@media (hover: none) and (pointer: coarse) {
  .desktop-only {
    display: none;
  }

  .touch-only {
    display: inline-flex;
    align-items: center;
    gap: 0.35em;
  }

  .overdrive-btn .key {
    display: none;
  }
}

kbd {
  padding: 0.18em 0.45em;
  border: 1px solid rgba(135, 195, 218, 0.2);
  border-bottom-color: rgba(135, 195, 218, 0.35);
  border-radius: 4px;
  color: #9db7c9;
  background: rgba(19, 37, 58, 0.65);
  font-family: var(--mono);
  font-size: 0.9em;
}

.modal-card {
  width: min(560px, 100%);
  padding: clamp(24px, 4vw, 46px);
  border: 1px solid rgba(132, 205, 230, 0.17);
  border-radius: 20px;
  background:
    linear-gradient(145deg, rgba(15, 31, 52, 0.78), rgba(5, 11, 22, 0.86));
  box-shadow:
    0 30px 80px rgba(0, 0, 0, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.modal-card h2 {
  margin: 0.35em 0 0.4em;
  font-size: clamp(44px, 6vw, 78px);
  color: #f2fdff;
  text-shadow: 0 0 26px rgba(56, 242, 255, 0.18);
}

.modal-sub {
  margin: 0 0 clamp(20px, 3vw, 32px);
  color: #8da6b9;
  font-size: clamp(12px, 1.2vw, 15px);
  line-height: 1.5;
}

.result-card h2.win {
  color: transparent;
  background: linear-gradient(100deg, var(--cyan), #9df8c8 48%, var(--yellow));
  -webkit-background-clip: text;
  background-clip: text;
  filter: drop-shadow(0 0 18px rgba(56, 242, 255, 0.22));
}

.result-card h2.lose {
  color: transparent;
  background: linear-gradient(100deg, #ff8b7c, var(--magenta));
  -webkit-background-clip: text;
  background-clip: text;
  filter: drop-shadow(0 0 18px rgba(255, 79, 216, 0.22));
}

.result-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: clamp(20px, 3vw, 32px);
}

.result-stats div {
  padding: 0.85em 0.5em;
  border: 1px solid rgba(128, 188, 214, 0.13);
  border-radius: 9px;
  background: rgba(4, 10, 20, 0.45);
}

.result-stats span {
  display: block;
  margin-bottom: 0.55em;
  color: #678094;
  font-family: var(--mono);
  font-size: clamp(7px, 0.72vw, 9px);
  letter-spacing: 0.1em;
}

.result-stats strong {
  color: #e9f9ff;
  font-family: var(--mono);
  font-size: clamp(14px, 1.6vw, 21px);
  font-weight: 600;
}

.rotate-hint {
  position: absolute;
  left: 50%;
  bottom: 8px;
  z-index: 6;
  transform: translateX(-50%);
  display: none;
  padding: 0.45em 0.9em;
  border: 1px solid rgba(130, 200, 225, 0.16);
  border-radius: 999px;
  color: rgba(171, 205, 221, 0.72);
  background: rgba(5, 12, 22, 0.72);
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.06em;
  pointer-events: none;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.hidden {
  display: none !important;
}

@media (max-width: 820px) {
  .app {
    width: min(98vw, 170vh, 1440px);
  }

  .rule-grid {
    grid-template-columns: 1fr;
    gap: 6px;
    max-width: 520px;
  }

  .rule {
    padding: 8px 11px;
  }

  .rule p {
    display: none;
  }

  .rule strong {
    margin-bottom: 0;
  }

  .tagline {
    margin-bottom: 14px;
  }

  .controls-line {
    margin-top: 14px;
  }

  .result-stats {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (orientation: portrait) and (max-width: 760px) {
  .app {
    width: 98vw;
  }

  .overlay {
    position: fixed;
    inset: 0;
    z-index: 50;
    padding: clamp(18px, 5vw, 32px);
    background:
      radial-gradient(circle at 50% 28%, rgba(8, 18, 34, 0.75), rgba(3, 6, 14, 0.97) 72%),
      rgba(3, 6, 14, 0.94);
    backdrop-filter: blur(12px) saturate(0.75);
  }

  .top-actions {
    position: fixed;
    top: 12px;
    right: 12px;
    z-index: 60;
  }

  .overdrive-btn {
    z-index: 60;
    bottom: 6px;
  }

  .rotate-hint {
    position: fixed;
    left: 50%;
    bottom: 14px;
    display: block;
    z-index: 60;
  }

  .game-shell:has(.overlay:not(.hidden)) .rotate-hint {
    display: none;
  }

  .menu-card h1 {
    font-size: clamp(48px, 15vw, 90px);
  }

  .rule-grid {
    max-width: none;
  }

  .controls-line {
    margin-top: 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
  }
}
