:root {
  --bg: #12041f;
  --bg2: #2a0a45;
  --purple: #8b2fc9;
  --violet: #b565f0;
  --orange: #ff8a1f;
  --amber: #ffb347;
  --text: #ffd9a8;
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; max-width: 100%; }
html { overflow-x: hidden; -webkit-text-size-adjust: 100%; }

body {
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg2) 60%, #4a0f5c 100%);
  color: var(--text);
  font-family: "Courier New", Courier, monospace;
  text-align: center;
  overflow-x: hidden;
  position: relative;
}

/* ретро-сетка снизу */
.grid-floor {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  width: 100%;
  height: 45vh;
  background:
    linear-gradient(var(--purple) 2px, transparent 2px) 0 0 / 60px 40px,
    linear-gradient(90deg, var(--purple) 2px, transparent 2px) 0 0 / 60px 40px;
  transform: perspective(300px) rotateX(60deg) scaleX(2);
  transform-origin: top center;
  opacity: .35;
  z-index: 0;
  pointer-events: none;
}

.hero, .game-wrap, .sign { position: relative; z-index: 1; }

.hero { padding: max(40px, env(safe-area-inset-top)) 16px 10px; }

.sun {
  width: 160px; height: 80px;
  margin: 0 auto 18px;
  border-radius: 160px 160px 0 0;
  background: repeating-linear-gradient(180deg, var(--orange) 0 10px, transparent 10px 14px),
              linear-gradient(180deg, var(--amber), var(--orange));
  background-blend-mode: normal;
  filter: drop-shadow(0 0 18px var(--orange));
}

.logo {
  margin: 0;
  font-size: clamp(2.6rem, 11vw, 6rem);
  font-weight: 900;
  font-style: italic;
  letter-spacing: .04em;
  color: var(--orange);
  text-shadow:
    3px 3px 0 var(--purple),
    6px 6px 0 #4a1470,
    0 0 24px rgba(255, 138, 31, .7);
}

.game-wrap { width: 100%; max-width: 100%; padding: 10px max(12px, env(safe-area-inset-left)) 20px max(12px, env(safe-area-inset-right)); }

.hud {
  display: flex; justify-content: center; gap: 30px;
  margin-bottom: 10px;
  color: var(--violet);
  font-size: 1.1rem;
}
.hud b { color: var(--orange); }

.screen {
  position: relative;
  display: block;
  box-sizing: border-box;
  width: 100%;
  max-width: 584px;
  margin: 0 auto;
  padding: 8px;
  background: #000;
  border: 4px solid var(--purple);
  border-radius: 14px;
  box-shadow: 0 0 0 4px #4a1470, 0 0 30px var(--purple), inset 0 0 20px rgba(139, 47, 201, .6);
}

canvas {
  display: block;
  width: 100%;
  max-width: 100%;
  touch-action: none;
  height: auto;
  aspect-ratio: 1;
  background: #0a0214;
  image-rendering: pixelated;
}

/* сканлайны ЭЛТ */
.screen::after {
  content: "";
  position: absolute; inset: 8px;
  background: repeating-linear-gradient(0deg, rgba(0,0,0,.25) 0 1px, transparent 1px 3px);
  pointer-events: none;
}

.overlay {
  position: absolute; inset: 8px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(10, 2, 20, .7);
  z-index: 2;
}
.overlay.hidden { display: none; }
.overlay p {
  margin: 0;
  font-size: 1.6rem; font-weight: bold;
  color: var(--orange);
  text-shadow: 2px 2px 0 var(--purple);
  animation: blink 1s steps(2) infinite;
}
@keyframes blink { 50% { opacity: .3; } }

.help { margin: 14px 0 10px; color: var(--violet); font-size: .9rem; }
.help-touch { display: none; }

/* экранные кнопки — крестом, только на сенсорных устройствах */
.pad {
  display: none;
  grid-template-columns: repeat(3, 72px);
  grid-template-rows: repeat(2, 64px);
  gap: 8px;
  justify-content: center;
  margin-top: 6px;
}
.b-up { grid-column: 2; grid-row: 1; }
.b-left { grid-column: 1; grid-row: 2; }
.b-down { grid-column: 2; grid-row: 2; }
.b-right { grid-column: 3; grid-row: 2; }
.pad button {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  background: var(--bg2);
  color: var(--orange);
  border: 2px solid var(--purple);
  border-radius: 6px;
  font-size: 1.2rem;
  cursor: pointer;
}
.pad button:hover { background: var(--purple); color: #fff; }
.pad button:focus-visible { outline: 3px solid var(--amber); outline-offset: 2px; }

.sign {
  max-width: 620px;
  margin: 10px auto 0;
  padding: 24px 20px 60px;
}
.sign p {
  margin: 0;
  padding: 18px 20px;
  line-height: 1.6;
  border: 2px dashed var(--orange);
  background: rgba(42, 10, 69, .8);
  color: var(--text);
  text-shadow: 0 0 8px rgba(255, 138, 31, .5);
}

@media (pointer: coarse), (hover: none), (max-width: 820px) {
  .pad { display: grid; }
  .help-pc { display: none; }
  .help-touch { display: block; }
  .pad button:active { background: var(--purple); color: #fff; }
}

/* планшеты и ПК: крупнее */
@media (min-width: 900px) {
  .hero { padding-top: 56px; }
  .hud { font-size: 1.3rem; gap: 50px; }
  .help { font-size: 1rem; }
  .sign { font-size: 1.1rem; max-width: 720px; }
}

/* маленькие телефоны */
@media (max-width: 380px) {
  .sun { width: 110px; height: 55px; margin-bottom: 14px; }
  .hud { gap: 16px; font-size: 1rem; }
  .pad { grid-template-columns: repeat(3, 64px); grid-template-rows: repeat(2, 56px); }
}

/* телефон в горизонтальном положении: поле слева, кнопки справа */
@media (orientation: landscape) and (max-height: 520px) and (pointer: coarse) {
  .hero { padding-top: 8px; }
  .sun { display: none; }
  .logo { font-size: 2.2rem; }
  .game-wrap {
    display: grid;
    grid-template-columns: auto auto;
    justify-content: center;
    align-items: center;
    column-gap: 28px;
  }
  .hud { grid-column: 1 / 3; margin-bottom: 6px; }
  .screen { grid-column: 1; grid-row: 2 / 4; }
  .screen { width: calc(60vh + 24px); }
  .help { grid-column: 2; grid-row: 2; margin: 0; align-self: end; }
  .pad { grid-column: 2; grid-row: 3; align-self: start; }
}

@media (prefers-reduced-motion: reduce) {
  .overlay p { animation: none; }
}

/* запасной вариант: JS пометил устройство как сенсорное */
.touch .pad { display: grid; }
.touch .help-pc { display: none; }
.touch .help-touch { display: block; }
