:root {
  color-scheme: dark;
  --bg: #030306;
  --panel: rgba(7, 8, 12, 0.74);
  --panel-strong: rgba(11, 12, 18, 0.92);
  --ink: #fff7ee;
  --muted: #a7a0aa;
  --line: rgba(255, 255, 255, 0.22);
  --grid-line: rgba(255, 255, 255, 0.095);
  --red: #ff3737;
  --red-soft: #ff5b50;
  --red-dark: #810909;
  --gold: #ffc400;
  --gold-soft: #ffe36a;
  --violet: #9b4cff;
  --focus: #75e7ff;
  --page-gutter: clamp(9px, 2vw, 18px);
  --board-limit: 760px;
  --rail-width: clamp(270px, 25vw, 350px);
  --pad-button: clamp(58px, 5.5vw, 74px);
  --pad-row: clamp(52px, 8vh, 66px);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  background: linear-gradient(
      115deg,
      rgba(41, 4, 49, 0.24) 0 22%,
      transparent 44%
    ),
    linear-gradient(295deg, transparent 0 58%, rgba(134, 12, 34, 0.22) 82%),
    #030306;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system,
    BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
  position: relative;
  isolation: isolate;
}

body::before,
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}

body::before {
  background-image: radial-gradient(
      circle at 22px 36px,
      rgba(255, 255, 255, 0.95) 0 1px,
      transparent 1.8px
    ),
    radial-gradient(
      circle at 124px 96px,
      rgba(255, 67, 78, 0.82) 0 1px,
      transparent 1.7px
    ),
    radial-gradient(
      circle at 76px 158px,
      rgba(255, 207, 74, 0.85) 0 1.4px,
      transparent 2.2px
    ),
    radial-gradient(
      circle at 170px 52px,
      rgba(181, 152, 255, 0.9) 0 1.3px,
      transparent 2px
    );
  background-size: 210px 210px, 310px 310px, 380px 380px, 460px 460px;
  opacity: 0.72;
  animation: starTwinkle 4.8s ease-in-out infinite alternate;
}

body::after {
  background-image: radial-gradient(
      circle at 9% 18%,
      rgba(255, 255, 255, 0.95) 0 1.5px,
      transparent 2.5px
    ),
    radial-gradient(
      circle at 78% 14%,
      rgba(255, 255, 255, 0.88) 0 1.4px,
      transparent 2.4px
    ),
    radial-gradient(
      circle at 86% 78%,
      rgba(255, 78, 90, 0.9) 0 1px,
      transparent 2px
    ),
    linear-gradient(
      145deg,
      transparent 0 38%,
      rgba(102, 26, 130, 0.18) 49%,
      transparent 63%
    );
  background-size: 100% 100%, 100% 100%, 100% 100%, 100% 100%;
  opacity: 0.78;
  animation: starDrift 12s linear infinite;
}

button {
  border: 0;
  color: inherit;
  font: inherit;
}

button:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 4px;
}

.app-shell {
  width: min(1360px, calc(100vw - var(--page-gutter) - var(--page-gutter)));
  margin: 0 auto;
  padding: clamp(14px, 2.5vh, 26px) 0 34px;
  position: relative;
  z-index: 1;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: clamp(72px, 12vh, 92px);
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--gold-soft);
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-shadow: 0 0 14px rgba(255, 196, 0, 0.52);
}

h1 {
  margin: 0;
  color: var(--red-soft);
  font-size: clamp(2.4rem, 6vw, 4.95rem);
  font-style: italic;
  font-weight: 950;
  line-height: 0.95;
  text-shadow: 0 0 4px rgba(255, 255, 255, 0.45), 0 0 13px rgb(0, 0, 0),
    0 0 28px rgba(0, 0, 0);
}

.title-spark {
  color: var(--red-soft);
  font-style: normal;
  font-size: 0.5em;
  vertical-align: 0.18em;
  animation: sparkBlink 1.8s ease-in-out infinite alternate;
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 14px;
}

.command-button,
.icon-button,
.direction-button,
.overlay-panel button {
  min-height: 48px;
  border: 2px solid var(--red);
  border-radius: 8px;
  background: linear-gradient(
    180deg,
    rgba(16, 17, 24, 0.92),
    rgba(5, 5, 8, 0.92)
  );
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08),
    0 0 12px rgba(255, 55, 55, 0.48), 0 0 26px rgba(255, 55, 55, 0.24);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-weight: 900;
  transition: border-color 150ms ease, box-shadow 150ms ease, color 150ms ease,
    transform 150ms ease;
}

.command-button {
  min-width: 138px;
  padding: 0 22px;
  color: var(--ink);
}

.icon-button {
  width: 52px;
  padding: 0;
}

#pauseButton,
#soundButton {
  border-color: var(--gold);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.1),
    0 0 12px rgba(255, 196, 0, 0.48), 0 0 26px rgba(255, 196, 0, 0.22);
}

.button-glyph {
  color: var(--red);
  font-size: 1.2em;
  line-height: 1;
  text-shadow: 0 0 13px currentColor;
}

#pauseButton .button-glyph,
#soundButton .button-glyph {
  color: var(--gold);
}

.command-button:hover,
.icon-button:hover,
.direction-button:hover,
.overlay-panel button:hover {
  transform: translateY(-1px);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12),
    0 0 16px rgba(255, 55, 55, 0.7), 0 0 34px rgba(255, 55, 55, 0.32);
}

#pauseButton:hover,
#soundButton:hover {
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12),
    0 0 16px rgba(255, 196, 0, 0.72), 0 0 34px rgba(255, 196, 0, 0.3);
}

.play-layout {
  --board-size: min(
    var(--board-limit),
    calc(100vh - 150px),
    calc(100vw - var(--rail-width) - 82px)
  );
  display: grid;
  grid-template-columns: minmax(320px, var(--board-size)) var(--rail-width);
  align-items: start;
  gap: clamp(18px, 3vw, 40px);
  justify-content: center;
  margin-top: 20px;
}

.game-frame {
  position: relative;
  width: 100%;
  max-width: var(--board-size);
  justify-self: center;
  overflow: hidden;
  border: 3px solid var(--red);
  border-radius: 8px;
  background: linear-gradient(
    180deg,
    rgba(12, 14, 16, 0.96),
    rgba(2, 2, 4, 0.98)
  );
  box-shadow: 0 0 0 1px rgba(255, 126, 109, 0.35),
    0 0 16px rgba(255, 55, 55, 0.92), 0 0 42px rgba(255, 55, 55, 0.42),
    0 28px 70px rgba(0, 0, 0, 0.62);
  animation: framePulse 2.8s ease-in-out infinite alternate;
}

.game-frame::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 5px;
  box-shadow: inset 0 0 28px rgba(255, 55, 55, 0.2);
  pointer-events: none;
  z-index: 2;
}

#gameCanvas {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
}

.game-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(0, 0, 0, 0.34);
  opacity: 1;
  transition: opacity 180ms ease;
  z-index: 3;
}

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

.overlay-panel {
  width: min(280px, 92%);
  padding: 20px;
  border: 1px solid rgba(255, 55, 55, 0.7);
  border-radius: 8px;
  background: rgba(6, 6, 10, 0.92);
  box-shadow: 0 0 18px rgba(255, 55, 55, 0.42), 0 20px 48px rgba(0, 0, 0, 0.48);
  text-align: center;
}

.overlay-panel p {
  margin: 0 0 6px;
  color: var(--gold);
  font-size: 1.15rem;
  font-weight: 950;
  text-shadow: 0 0 12px rgba(255, 196, 0, 0.62);
}

.overlay-panel strong {
  display: block;
  margin-bottom: 16px;
  color: var(--ink);
  font-size: 1.85rem;
  line-height: 1;
}

.overlay-panel button {
  width: 100%;
}

.control-panel {
  display: grid;
  gap: clamp(14px, 2.8vh, 28px);
  padding-top: clamp(0px, 4vh, 30px);
  min-width: 0;
}

.hud {
  display: grid;
  gap: 0;
}

.hud div,
.state-strip {
  min-height: clamp(56px, 8.5vh, 72px);
  padding: clamp(8px, 1.8vh, 15px) 0;
  border-bottom: 1px solid var(--line);
}

.hud div {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 18px;
}

.stat-label,
.state-strip span {
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: clamp(1rem, 1.7vw, 1.35rem);
  font-weight: 850;
  line-height: 1.1;
}

.state-strip span {
  color: var(--muted);
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.hud strong,
.state-strip strong {
  color: var(--ink);
  display: block;
  overflow-wrap: anywhere;
  font-size: clamp(1.45rem, 2.6vw, 2.1rem);
  font-weight: 950;
  line-height: 1;
  text-align: right;
}

.hud div:first-child strong {
  color: var(--gold);
  text-shadow: 0 0 12px rgba(255, 196, 0, 0.56);
}

.stat-icon {
  width: 34px;
  height: 34px;
  color: var(--red);
  display: inline-grid;
  flex: 0 0 34px;
  place-items: center;
  position: relative;
}

.stat-icon.trophy {
  color: var(--gold);
}

.stat-icon.trophy::before {
  content: "";
  width: 18px;
  height: 14px;
  border: 4px solid currentColor;
  border-top: 0;
  border-radius: 0 0 8px 8px;
  box-shadow: -8px -1px 0 -5px currentColor, 8px -1px 0 -5px currentColor,
    0 13px 0 -5px currentColor, 0 18px 0 -6px currentColor;
}

.stat-icon.star::before {
  content: "\2605";
  color: var(--gold);
  font-size: 2rem;
  line-height: 1;
  text-shadow: 0 0 12px rgba(255, 196, 0, 0.7);
}

.stat-icon.bars::before {
  content: "";
  width: 28px;
  height: 28px;
  background: linear-gradient(to top, var(--red) 0 40%, transparent 40%) 0 0 /
      7px 100% no-repeat,
    linear-gradient(to top, var(--red) 0 68%, transparent 68%) 10px 0 / 7px 100%
      no-repeat,
    linear-gradient(to top, var(--red) 0 94%, transparent 94%) 20px 0 / 7px 100%
      no-repeat;
  filter: drop-shadow(0 0 8px rgba(255, 55, 55, 0.65));
}

.stat-icon.dots::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--red);
  box-shadow: 13px 0 0 var(--red), 26px 0 0 var(--red),
    0 0 9px rgba(255, 55, 55, 0.86), 13px 0 9px rgba(255, 55, 55, 0.86),
    26px 0 9px rgba(255, 55, 55, 0.86);
}

.stat-icon.gauge::before {
  content: "";
  width: 26px;
  height: 26px;
  border: 5px solid var(--red);
  border-bottom-color: transparent;
  border-radius: 50%;
  transform: rotate(-42deg);
  filter: drop-shadow(0 0 8px rgba(255, 55, 55, 0.72));
}

.stat-icon.gauge::after {
  content: "";
  width: 10px;
  height: 4px;
  border-radius: 99px;
  background: var(--red);
  position: absolute;
  left: 17px;
  top: 18px;
  transform: rotate(-38deg);
  transform-origin: left center;
}

.direction-pad {
  display: grid;
  grid-template-columns: repeat(3, var(--pad-button));
  grid-template-rows: repeat(3, var(--pad-row));
  gap: 10px;
  justify-content: center;
  justify-self: center;
}

.direction-button {
  width: var(--pad-button);
  height: var(--pad-row);
  color: var(--red-soft);
  font-size: clamp(1.45rem, 3vw, 2.05rem);
  line-height: 1;
  text-shadow: 0 0 12px rgba(255, 55, 55, 0.72);
}

.direction-button.up {
  grid-column: 2;
}

.direction-button.left {
  grid-column: 1;
  grid-row: 2;
}

.direction-button.right {
  grid-column: 3;
  grid-row: 2;
}

.direction-button.down {
  grid-column: 2;
  grid-row: 3;
}

.state-strip {
  min-height: 64px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background: rgba(5, 5, 9, 0.68);
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 16px;
  padding: 14px 16px;
}

@keyframes starTwinkle {
  0% {
    opacity: 0.42;
    transform: translate3d(0, 0, 0);
  }

  100% {
    opacity: 0.92;
    transform: translate3d(-12px, 8px, 0);
  }
}

@keyframes starDrift {
  0% {
    opacity: 0.48;
    transform: translate3d(0, 0, 0);
  }

  50% {
    opacity: 0.88;
  }

  100% {
    opacity: 0.48;
    transform: translate3d(18px, -12px, 0);
  }
}

@keyframes sparkBlink {
  0% {
    opacity: 0.56;
    filter: drop-shadow(0 0 4px rgba(255, 55, 55, 0.55));
  }

  100% {
    opacity: 1;
    filter: drop-shadow(0 0 16px rgba(255, 55, 55, 0.95));
  }
}

@keyframes framePulse {
  0% {
    box-shadow: 0 0 0 1px rgba(255, 126, 109, 0.32),
      0 0 14px rgba(255, 55, 55, 0.74), 0 0 36px rgba(255, 55, 55, 0.36),
      0 28px 70px rgba(0, 0, 0, 0.62);
  }

  100% {
    box-shadow: 0 0 0 1px rgba(255, 126, 109, 0.55),
      0 0 20px rgba(255, 55, 55, 0.98), 0 0 54px rgba(255, 55, 55, 0.48),
      0 28px 70px rgba(0, 0, 0, 0.62);
  }
}

@media (min-width: 981px) and (max-height: 820px) {
  :root {
    --pad-button: 58px;
    --pad-row: 48px;
  }

  .control-panel {
    gap: 12px;
    padding-top: 0;
  }

  .hud div,
  .state-strip {
    min-height: 52px;
    padding: 6px 0;
  }

  .stat-label {
    gap: 10px;
    font-size: 0.95rem;
  }

  .hud strong,
  .state-strip strong {
    font-size: 1.35rem;
  }

  .stat-icon {
    width: 28px;
    height: 28px;
    flex-basis: 28px;
    transform: scale(0.82);
    transform-origin: left center;
  }

  .state-strip {
    padding: 8px 12px;
  }
}

@media (max-width: 980px) {
  :root {
    --board-limit: clamp(320px, calc(100vh - 220px), 760px);
  }

  .app-header {
    align-items: flex-start;
    flex-direction: column;
    gap: 14px;
  }

  .header-actions {
    justify-content: flex-start;
  }

  .play-layout {
    --board-size: min(
      var(--board-limit),
      calc(100vw - var(--page-gutter) - var(--page-gutter))
    );
    grid-template-columns: 1fr;
    justify-items: center;
    margin-top: 14px;
  }

  .control-panel {
    grid-template-columns: 1fr;
    align-items: start;
    width: min(100%, var(--board-size));
    padding-top: 4px;
  }

  .hud {
    grid-template-columns: repeat(auto-fit, minmax(112px, 1fr));
    gap: 8px;
    width: 100%;
  }

  .hud div {
    min-height: 68px;
    padding: 10px;
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 8px;
    background: rgba(5, 5, 9, 0.54);
  }

  .stat-label {
    gap: 8px;
    font-size: 0.8rem;
  }

  .stat-icon {
    width: 24px;
    height: 24px;
    flex-basis: 24px;
    transform: scale(0.72);
    transform-origin: left center;
  }

  .state-strip {
    width: 100%;
  }
}

@media (max-width: 680px) {
  :root {
    --board-limit: calc(100vw - 18px);
    --pad-button: clamp(52px, 18vw, 66px);
    --pad-row: clamp(48px, 16vw, 58px);
  }

  .app-shell {
    width: min(calc(100vw - 18px), 560px);
    padding-top: 16px;
  }

  h1 {
    font-size: clamp(2.2rem, 13vw, 4rem);
  }

  .header-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
    gap: 10px;
  }

  .command-button {
    min-width: 0;
    padding: 0 12px;
  }

  .icon-button {
    width: 100%;
  }

  .game-frame {
    border-width: 2px;
  }

  .control-panel {
    grid-template-columns: 1fr;
    gap: 18px;
  }

  .hud {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .hud div {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .hud strong {
    text-align: left;
  }

  .direction-pad {
    width: min(
      100%,
      calc(var(--pad-button) + var(--pad-button) + var(--pad-button) + 20px)
    );
  }

  .direction-button {
    width: var(--pad-button);
    height: var(--pad-row);
  }

  .hud div {
    min-height: 64px;
  }
}

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