:root {
  color-scheme: dark;
  --bg: #050914;
  --panel: rgba(8, 18, 34, 0.84);
  --panel-strong: rgba(10, 23, 43, 0.96);
  --line: rgba(76, 226, 255, 0.18);
  --cyan: #56e8ff;
  --cyan-soft: rgba(86, 232, 255, 0.18);
  --violet: #9b7cff;
  --danger: #ff4d7d;
  --text: #eafaff;
  --muted: #7f9daf;
  --shadow: 0 0 40px rgba(27, 179, 255, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  min-height: 100vh;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 18% 20%, rgba(75, 91, 255, 0.16), transparent 26rem),
    radial-gradient(circle at 84% 74%, rgba(0, 221, 255, 0.12), transparent 30rem),
    linear-gradient(180deg, #07101d 0%, var(--bg) 60%, #03060d 100%);
  color: var(--text);
  font-family: "JetBrains Mono", "Cascadia Code", "SFMono-Regular", Consolas, monospace;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(86, 232, 255, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(86, 232, 255, 0.035) 1px, transparent 1px);
  background-size: 34px 34px;
  mask-image: linear-gradient(to bottom, black, rgba(0, 0, 0, 0.18));
}

button,
kbd {
  font: inherit;
}

.app-shell {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 36px 0 28px;
}

.hero-panel,
.hud,
.controls-panel {
  position: relative;
  z-index: 2;
}

.hero-panel {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 18px;
}

.eyebrow,
.metric-label,
.controls-title,
.danger-label {
  margin: 0;
  color: var(--cyan);
  font-size: 0.72rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

h1 {
  margin: 8px 0 6px;
  font-size: clamp(2rem, 6vw, 4.9rem);
  line-height: 0.94;
  letter-spacing: -0.07em;
  text-transform: uppercase;
  text-shadow:
    0 0 20px rgba(86, 232, 255, 0.28),
    0 0 58px rgba(155, 124, 255, 0.15);
}

.subtitle {
  margin: 0;
  max-width: 660px;
  color: var(--muted);
  line-height: 1.7;
}

.system-chip {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 10px 13px;
  border: 1px solid rgba(86, 232, 255, 0.24);
  background: rgba(9, 25, 38, 0.7);
  color: #a8f4ff;
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  box-shadow: inset 0 0 18px rgba(86, 232, 255, 0.06);
}

.pulse-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #60ffb2;
  box-shadow: 0 0 14px #60ffb2;
  animation: pulse 1.4s infinite;
}

.hud {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
  margin-bottom: 10px;
}

.metric-card {
  position: relative;
  overflow: hidden;
  padding: 14px 16px 12px;
  border: 1px solid var(--line);
  background: linear-gradient(135deg, rgba(11, 25, 45, 0.92), rgba(5, 14, 27, 0.66));
  box-shadow: var(--shadow);
}

.metric-card::after {
  content: "";
  position: absolute;
  right: 0;
  bottom: 0;
  width: 36%;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--cyan));
  opacity: 0.7;
}

.metric-card strong {
  display: block;
  margin-top: 5px;
  font-size: clamp(1.15rem, 3vw, 1.7rem);
  letter-spacing: 0.08em;
}

.status-card strong {
  color: #68ffc1;
}

.status-card.is-danger strong {
  color: var(--danger);
}

.game-frame {
  position: relative;
  min-height: 520px;
  height: min(64vh, 670px);
  overflow: hidden;
  border: 1px solid rgba(86, 232, 255, 0.28);
  background:
    linear-gradient(rgba(5, 14, 27, 0.28), rgba(3, 8, 17, 0.85)),
    radial-gradient(circle at 50% 118%, rgba(86, 232, 255, 0.13), transparent 48%);
  box-shadow:
    inset 0 0 80px rgba(19, 131, 176, 0.05),
    0 18px 70px rgba(0, 0, 0, 0.32);
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
}

.scanlines {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.12;
  background: repeating-linear-gradient(
    180deg,
    transparent 0,
    transparent 3px,
    rgba(112, 236, 255, 0.16) 4px
  );
  mix-blend-mode: screen;
}

.sound-toggle {
  position: absolute;
  z-index: 8;
  top: 10px;
  right: 12px;
  min-width: 86px;
  height: 30px;
  padding: 0 10px;
  cursor: pointer;
  border: 1px solid rgba(86, 232, 255, 0.28);
  border-radius: 4px;
  background: rgba(5, 18, 31, 0.72);
  color: #bff8ff;
  font-size: 0.62rem;
  letter-spacing: 0.08em;
  backdrop-filter: blur(5px);
  -webkit-tap-highlight-color: transparent;
}

.sound-toggle.is-muted {
  color: var(--muted);
  border-color: rgba(127, 157, 175, 0.2);
}

.frame-corner {
  position: absolute;
  z-index: 5;
  width: 34px;
  height: 34px;
  pointer-events: none;
}

.frame-corner::before,
.frame-corner::after {
  content: "";
  position: absolute;
  background: var(--cyan);
  box-shadow: 0 0 14px rgba(86, 232, 255, 0.55);
}

.frame-corner::before {
  width: 34px;
  height: 2px;
}

.frame-corner::after {
  width: 2px;
  height: 34px;
}

.frame-corner--tl {
  top: -1px;
  left: -1px;
}

.frame-corner--tr {
  top: -1px;
  right: -1px;
  transform: scaleX(-1);
}

.frame-corner--bl {
  bottom: -1px;
  left: -1px;
  transform: scaleY(-1);
}

.frame-corner--br {
  right: -1px;
  bottom: -1px;
  transform: scale(-1);
}

.game-over {
  position: absolute;
  z-index: 10;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(1, 5, 12, 0.68);
  backdrop-filter: blur(7px);
}

.game-over.hidden {
  display: none;
}

.game-over__panel {
  width: min(430px, 100%);
  padding: 28px;
  border: 1px solid rgba(255, 77, 125, 0.48);
  background:
    linear-gradient(135deg, rgba(46, 11, 29, 0.92), rgba(7, 15, 29, 0.96)),
    var(--panel-strong);
  box-shadow:
    0 0 0 1px rgba(255, 77, 125, 0.08) inset,
    0 0 54px rgba(255, 77, 125, 0.12);
  text-align: center;
}

.game-over__panel h2 {
  margin: 8px 0;
  color: #fff1f5;
  font-size: clamp(2.2rem, 8vw, 4.3rem);
  letter-spacing: -0.07em;
  text-transform: uppercase;
}

.game-over__panel p {
  margin: 0 0 22px;
  color: #b994a2;
}

.danger-label {
  color: var(--danger);
}

.final-score {
  margin: 0 auto 22px;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.025);
}

.final-score span {
  display: block;
  color: var(--muted);
  font-size: 0.68rem;
  letter-spacing: 0.16em;
}

.final-score strong {
  display: block;
  margin-top: 4px;
  color: var(--cyan);
  font-size: 2rem;
}

#restartButton {
  width: 100%;
  cursor: pointer;
  border: 1px solid rgba(86, 232, 255, 0.55);
  padding: 13px 18px;
  background: linear-gradient(90deg, rgba(86, 232, 255, 0.12), rgba(155, 124, 255, 0.14));
  color: var(--text);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  transition: transform 120ms ease, box-shadow 120ms ease, border-color 120ms ease;
}

#restartButton:hover,
#restartButton:focus-visible {
  transform: translateY(-1px);
  border-color: var(--cyan);
  box-shadow: 0 0 30px rgba(86, 232, 255, 0.13);
  outline: none;
}

.controls-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  margin-top: 10px;
  padding: 14px 16px;
  border: 1px solid rgba(86, 232, 255, 0.12);
  background: rgba(6, 15, 28, 0.76);
  color: var(--muted);
  font-size: 0.82rem;
}

.controls-panel p {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin: 8px 0 0;
}

kbd {
  display: inline-grid;
  min-width: 28px;
  height: 28px;
  place-items: center;
  border: 1px solid rgba(86, 232, 255, 0.25);
  border-bottom-color: rgba(86, 232, 255, 0.48);
  border-radius: 3px;
  background: rgba(86, 232, 255, 0.07);
  color: #c8f9ff;
  font-size: 0.72rem;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.28);
}

.or {
  margin: 0 6px;
  opacity: 0.56;
}

.tip {
  max-width: 560px;
  line-height: 1.65;
  text-align: right;
}

.tip__tag {
  margin-right: 8px;
  color: var(--violet);
}

@keyframes pulse {
  0%,
  100% {
    opacity: 0.35;
  }
  50% {
    opacity: 1;
  }
}

@media (max-width: 720px) {
  .app-shell {
    width: min(100% - 18px, 1120px);
    padding-top: 22px;
  }

  .hero-panel,
  .controls-panel {
    align-items: flex-start;
    flex-direction: column;
  }

  .hero-panel {
    gap: 14px;
  }

  .hud {
    grid-template-columns: 1fr 1fr;
  }

  .status-card {
    grid-column: 1 / -1;
  }

  .game-frame {
    min-height: 430px;
    height: 62vh;
  }

  .controls-panel {
    gap: 12px;
  }

  .tip {
    text-align: left;
  }
}

@media (max-width: 430px) and (orientation: portrait) {
  html,
  body {
    min-height: 100%;
  }

  body {
    min-height: 100dvh;
    overflow: hidden;
    overscroll-behavior: none;
  }

  .app-shell {
    width: 100%;
    height: 100dvh;
    min-height: 100dvh;
    margin: 0;
    padding:
      calc(env(safe-area-inset-top, 0px) + 10px)
      10px
      calc(env(safe-area-inset-bottom, 0px) + 10px);
    display: flex;
    flex-direction: column;
  }

  .hero-panel {
    position: relative;
    display: block;
    flex: 0 0 auto;
    min-height: 76px;
    margin-bottom: 7px;
    padding-right: 112px;
  }

  .eyebrow {
    font-size: 0.5rem;
    letter-spacing: 0.11em;
    white-space: nowrap;
  }

  h1 {
    margin: 5px 0 4px;
    font-size: 2rem;
    line-height: 0.95;
    letter-spacing: -0.06em;
  }

  .subtitle {
    max-width: 250px;
    font-size: 0.67rem;
    line-height: 1.35;
  }

  .system-chip {
    position: absolute;
    top: 0;
    right: 0;
    gap: 6px;
    padding: 7px 8px;
    font-size: 0.52rem;
    letter-spacing: 0.06em;
  }

  .pulse-dot {
    width: 6px;
    height: 6px;
  }

  .hud {
    flex: 0 0 auto;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 5px;
    margin-bottom: 6px;
  }

  .status-card {
    grid-column: auto;
  }

  .metric-card {
    min-width: 0;
    padding: 8px 8px 7px;
  }

  .metric-label {
    font-size: 0.5rem;
    letter-spacing: 0.12em;
  }

  .metric-card strong {
    overflow: hidden;
    margin-top: 3px;
    font-size: 0.93rem;
    letter-spacing: 0.03em;
    text-overflow: clip;
    white-space: nowrap;
  }

  .status-card strong {
    font-size: 0.73rem;
    letter-spacing: 0.01em;
  }

  .game-frame {
    flex: 1 1 auto;
    width: 100%;
    min-height: 0;
    height: auto;
    max-height: none;
  }

  #gameCanvas {
    touch-action: none;
  }

  .frame-corner {
    width: 24px;
    height: 24px;
  }

  .frame-corner::before {
    width: 24px;
  }

  .frame-corner::after {
    height: 24px;
  }

  .controls-panel {
    display: none;
  }

  .game-over {
    padding: 14px;
  }

  .game-over__panel {
    width: min(320px, 100%);
    padding: 22px 18px 18px;
  }

  .game-over__panel h2 {
    font-size: 2.45rem;
  }

  .game-over__panel p {
    margin-bottom: 16px;
    font-size: 0.78rem;
  }

  .final-score {
    margin-bottom: 16px;
    padding: 11px;
  }

  #restartButton {
    min-height: 46px;
  }
}
