/* Пиксель-8 — общий визуальный язык. 8-bit картриджный экран. */
:root {
  --bg: #0b0714;
  --gold: #f8d878;
  --red: #e83830;
  --blue: #3090f8;
  --green: #40c040;
  --cream: #f8f0d8;
  --steel: #a0a8b8;
  --purple: #2a1848;
  --magenta: #d040a0;
  --slot: #1a1028;
  --ink: #140c20;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  background: var(--bg);
  color: var(--cream);
  font-family: "Press Start 2P", ui-monospace, monospace;
  height: auto;
  min-height: 100%;
  min-height: 100dvh;
  overflow-x: hidden;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

html:has(body.game) {
  height: 100dvh;
  overflow: hidden;
}

body.game {
  height: 100dvh;
  overflow: hidden;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

body {
  background-color: var(--bg);
  background-image:
    linear-gradient(rgba(248, 216, 120, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(248, 216, 120, 0.035) 1px, transparent 1px);
  background-size: 8px 8px;
}

/* CRT scanlines + vignette — no blur */
.crt::before {
  content: "";
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 9998;
  opacity: 0;
  background: repeating-linear-gradient(
    to bottom,
    rgba(8, 4, 16, 0.22) 0px,
    rgba(8, 4, 16, 0.22) 1px,
    transparent 1px,
    transparent 3px
  );
}

.crt.crt-on::before,
.crt.game::before {
  opacity: 1;
}

.crt.crt-on::before {
  animation: scanFade 520ms steps(6) forwards;
}

@keyframes scanFade {
  from { opacity: 0; }
  to { opacity: 1; }
}

.crt::after {
  content: "";
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 9999;
  background:
    radial-gradient(ellipse at center, transparent 42%, rgba(0, 0, 0, 0.62) 100%),
    linear-gradient(180deg, rgba(248, 216, 120, 0.03), transparent 18%, transparent 82%, rgba(48, 144, 248, 0.04));
}

a { color: var(--gold); text-decoration: none; }
a:hover, a:focus-visible { color: var(--cream); }

.pixel-title {
  color: var(--gold);
  text-shadow:
    4px 0 0 #7a5010,
    0 4px 0 #7a5010,
    4px 4px 0 #3a2010,
    -2px 0 0 #e83830;
  letter-spacing: 0.08em;
  line-height: 1.25;
}

.back {
  display: inline-flex;
  align-items: center;
  font-size: 10px;
  line-height: 1;
  color: var(--gold);
  padding: 10px 6px;
  min-height: 44px;
  min-width: 44px;
  flex-shrink: 0;
  white-space: nowrap;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: 640px;
  flex-shrink: 0;
  gap: 4px 10px;
  padding: 0 2px;
}

.hud {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  justify-content: flex-end;
  align-items: center;
  font-size: 10px;
  color: var(--cream);
  padding: 2px 4px;
  text-shadow: 2px 2px 0 #000;
  flex: 1 1 auto;
}

.hud b { color: var(--gold); }

.mute-btn {
  font-family: inherit;
  font-size: 9px;
  line-height: 1;
  min-width: 44px;
  min-height: 36px;
  padding: 6px 8px;
  border: 3px solid var(--steel);
  background:
    linear-gradient(180deg, #3a2460, #1a1028);
  color: var(--gold);
  cursor: pointer;
  box-shadow:
    2px 2px 0 #050308,
    inset 0 2px 0 rgba(248, 240, 216, 0.14);
}

.mute-btn:hover, .mute-btn:focus-visible {
  border-color: var(--gold);
  color: var(--cream);
}

.mute-btn.off {
  color: var(--steel);
  border-color: #4a4058;
}

.mute-btn.off .mute-wave { opacity: 0.25; }

.stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 100vw;
  padding: 8px 8px 16px;
}

.game .stage {
  height: 100%;
  max-height: 100%;
  justify-content: space-between;
  padding: 2px 8px 6px;
}

.field {
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

/* Deeper CRT bezel with inner highlight + corner screws */
.bezel {
  position: relative;
  display: inline-block;
  padding: 18px;
  background:
    radial-gradient(circle at 12px 12px, #e8d8a8 0 2px, #8a7848 2px 4px, #3a2a14 4px 6px, transparent 7px),
    radial-gradient(circle at calc(100% - 12px) 12px, #e8d8a8 0 2px, #8a7848 2px 4px, #3a2a14 4px 6px, transparent 7px),
    radial-gradient(circle at 12px calc(100% - 12px), #e8d8a8 0 2px, #8a7848 2px 4px, #3a2a14 4px 6px, transparent 7px),
    radial-gradient(circle at calc(100% - 12px) calc(100% - 12px), #e8d8a8 0 2px, #8a7848 2px 4px, #3a2a14 4px 6px, transparent 7px),
    linear-gradient(180deg, #6a5a44 0%, #4a3a28 28%, #2a1c12 72%, #1a1008 100%);
  border: 5px solid #0a0610;
  box-shadow:
    inset 0 4px 0 rgba(248, 240, 216, 0.28),
    inset 0 -6px 0 #0c0804,
    inset 4px 0 0 #5a4a34,
    inset -4px 0 0 #181008,
    0 16px 0 #050308;
}

.bezel::before {
  content: "";
  pointer-events: none;
  position: absolute;
  inset: 10px;
  border: 3px solid #08060c;
  box-shadow:
    inset 0 2px 0 rgba(248, 240, 216, 0.1),
    0 0 0 2px #3a2a18;
}

canvas {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #140c22;
  position: relative;
  z-index: 1;
  touch-action: none;
  max-width: 100%;
  height: auto;
}

.bezel canvas {
  box-shadow: none;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(11, 7, 20, 0.72);
  padding: 16px;
}

.overlay[hidden] { display: none !important; }

.panel {
  width: min(420px, 100%);
  background:
    linear-gradient(180deg, rgba(248,240,216,0.08), transparent 18%),
    var(--slot);
  border: 4px solid var(--gold);
  box-shadow:
    6px 6px 0 #050308,
    inset 0 0 0 4px #3a2060,
    inset 0 3px 0 rgba(248,240,216,0.16);
  padding: 22px 18px 20px;
  text-align: center;
}

.panel h2 {
  color: var(--gold);
  font-size: 16px;
  margin-bottom: 14px;
  text-shadow: 3px 3px 0 #000;
}

.panel p {
  font-size: 10px;
  line-height: 1.8;
  color: var(--cream);
  margin-bottom: 16px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  min-width: 140px;
  padding: 12px 18px;
  border: 4px solid var(--cream);
  background: var(--red);
  color: var(--cream);
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  box-shadow: 4px 4px 0 #050308, inset 0 3px 0 rgba(248,240,216,0.18);
  text-shadow: 2px 2px 0 #000;
}

.btn:hover, .btn:focus-visible {
  background: #ff5048;
  transform: translate(-1px, -1px);
}

.btn:active {
  transform: translate(2px, 2px);
  box-shadow: 2px 2px 0 #050308;
}

.btn.gold {
  background: #c09020;
  border-color: var(--gold);
  color: var(--ink);
  text-shadow: none;
}

.hint {
  font-size: 8px;
  line-height: 1.7;
  color: var(--steel);
  text-align: center;
  padding: 8px 10px 4px;
  max-width: 520px;
}

.touch-bar {
  display: none;
  width: min(440px, 100%);
  margin: 6px auto 0;
  padding: 4px 10px 2px;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  touch-action: none;
}

.touch-bar.solo { justify-content: center; }

.dpad {
  display: grid;
  grid-template-columns: 56px 56px 56px;
  grid-template-rows: 56px 56px 56px;
  gap: 4px;
}

.dpad button {
  font-family: inherit;
  font-size: 16px;
  color: var(--cream);
  background:
    linear-gradient(180deg, #3a2460, #2a1848);
  border: 3px solid var(--steel);
  box-shadow: 3px 3px 0 #050308, inset 0 2px 0 rgba(248,240,216,0.12);
  min-width: 56px;
  min-height: 56px;
  cursor: pointer;
}

.dpad .u { grid-column: 2; grid-row: 1; }
.dpad .l { grid-column: 1; grid-row: 2; }
.dpad .r { grid-column: 3; grid-row: 2; }
.dpad .d { grid-column: 2; grid-row: 3; }
.dpad button:active, .dpad button.held {
  background: var(--blue);
  border-color: var(--cream);
}

.fire-btn {
  width: 88px;
  height: 88px;
  border-radius: 8px;
  border: 4px solid var(--cream);
  background:
    linear-gradient(180deg, #ff6058, var(--red) 40%, #a01820);
  color: var(--cream);
  font-family: inherit;
  font-size: 11px;
  box-shadow: 4px 4px 0 #050308, inset 0 3px 0 rgba(248,240,216,0.2);
  cursor: pointer;
}

.fire-btn:active, .fire-btn.held {
  background: #ff6058;
  transform: translate(2px, 2px);
}

@media (any-pointer: coarse), (max-width: 900px) {
  .touch-bar { display: flex !important; }
  .hint { display: none; }
}

@media (pointer: fine) and (min-width: 901px) {
  .touch-bar { display: none !important; }
}

@media (max-width: 900px) {
  .pixel-title { font-size: 22px; }
  .topbar {
    flex-wrap: nowrap;
    gap: 4px 8px;
  }
  .hud {
    flex-wrap: nowrap;
    justify-content: flex-end;
    font-size: 8px;
    gap: 6px 8px;
    padding: 0;
  }
  .back {
    font-size: 8px;
    padding: 10px 4px;
    min-height: 44px;
  }
  .mute-btn {
    min-width: 36px;
    min-height: 36px;
    font-size: 8px;
    padding: 4px 6px;
  }
  .bezel {
    padding: 7px;
    border-width: 3px;
    box-shadow:
      inset 0 3px 0 rgba(248, 240, 216, 0.28),
      inset 0 -4px 0 #0c0804,
      inset 3px 0 0 #5a4a34,
      inset -3px 0 0 #181008,
      0 8px 0 #050308;
    background:
      radial-gradient(circle at 7px 7px, #e8d8a8 0 1px, #8a7848 1px 2px, #3a2a14 2px 3px, transparent 4px),
      radial-gradient(circle at calc(100% - 7px) 7px, #e8d8a8 0 1px, #8a7848 1px 2px, #3a2a14 2px 3px, transparent 4px),
      radial-gradient(circle at 7px calc(100% - 7px), #e8d8a8 0 1px, #8a7848 1px 2px, #3a2a14 2px 3px, transparent 4px),
      radial-gradient(circle at calc(100% - 7px) calc(100% - 7px), #e8d8a8 0 1px, #8a7848 1px 2px, #3a2a14 2px 3px, transparent 4px),
      linear-gradient(180deg, #6a5a44 0%, #4a3a28 28%, #2a1c12 72%, #1a1008 100%);
  }
  .bezel::before {
    inset: 4px;
    border-width: 2px;
  }
  canvas { max-width: 100%; }
}

@media (max-height: 500px) {
  .dpad {
    grid-template-columns: 48px 48px 48px;
    grid-template-rows: 48px 48px 48px;
    gap: 3px;
  }
  .dpad button {
    min-width: 48px;
    min-height: 48px;
    font-size: 14px;
  }
  .fire-btn {
    width: 72px;
    height: 72px;
  }
}
