:root {
  color-scheme: dark;
  --bg: #03040a;
  --panel: rgba(11, 16, 29, 0.72);
  --panel-strong: rgba(22, 30, 50, 0.92);
  --ink: #f8fbff;
  --muted: #8f9dbd;
  --cyan: #39d9ff;
  --gold: #f4c95d;
  --red: #ff476f;
  --green: #68f5ad;
  --violet: #a979ff;
  --line: rgba(255, 255, 255, 0.18);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background:
    linear-gradient(135deg, rgba(57, 217, 255, 0.12), transparent 24rem),
    linear-gradient(225deg, rgba(255, 71, 111, 0.12), transparent 26rem),
    linear-gradient(180deg, #090b13 0%, var(--bg) 62%, #010208 100%);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.orientation-gate {
  position: fixed;
  z-index: 100;
  inset: 0;
  display: none;
  place-items: center;
  overflow: hidden;
  padding:
    max(1.25rem, env(safe-area-inset-top))
    max(1.25rem, env(safe-area-inset-right))
    max(1.25rem, env(safe-area-inset-bottom))
    max(1.25rem, env(safe-area-inset-left));
  background:
    radial-gradient(circle at 18% 18%, rgba(57, 217, 255, 0.2), transparent 36%),
    radial-gradient(circle at 82% 82%, rgba(255, 71, 111, 0.18), transparent 38%),
    #03040a;
  text-align: center;
}

body.smartphone-device.smartphone-portrait .orientation-gate {
  display: grid;
}

body.smartphone-device.smartphone-portrait .shell {
  visibility: hidden;
}

.orientation-card {
  display: grid;
  justify-items: center;
  gap: 0.7rem;
  width: min(28rem, 100%);
}

.orientation-card h1,
.orientation-card p {
  margin: 0;
}

.orientation-card h1 {
  font-size: clamp(2rem, 10vw, 3.5rem);
  line-height: 0.95;
  text-transform: uppercase;
  text-shadow: 0 0 30px rgba(57, 217, 255, 0.35);
}

.orientation-card p {
  max-width: 24rem;
  color: var(--muted);
  font-size: clamp(1rem, 4.5vw, 1.25rem);
  font-weight: 750;
  line-height: 1.45;
}

.orientation-kicker {
  color: var(--gold);
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

.phone-turn {
  position: relative;
  width: 9.5rem;
  height: 7.5rem;
  margin-bottom: 0.35rem;
}

.phone-outline {
  position: absolute;
  top: 0.45rem;
  left: 1.8rem;
  width: 4.25rem;
  height: 7rem;
  border: 0.28rem solid var(--cyan);
  border-radius: 0.85rem;
  background: linear-gradient(160deg, rgba(57, 217, 255, 0.16), rgba(169, 121, 255, 0.1));
  box-shadow: 0 0 30px rgba(57, 217, 255, 0.28);
  transform: rotate(-18deg);
  animation: turn-phone 1.8s ease-in-out infinite;
}

.phone-outline::before {
  position: absolute;
  top: 0.35rem;
  left: 50%;
  width: 1.4rem;
  height: 0.22rem;
  border-radius: 999px;
  background: var(--cyan);
  content: "";
  transform: translateX(-50%);
}

.phone-outline span {
  position: absolute;
  right: 0.35rem;
  bottom: 0.35rem;
  left: 0.35rem;
  height: 0.3rem;
  border-radius: 999px;
  background: rgba(248, 251, 255, 0.72);
}

.turn-arrow {
  position: absolute;
  right: 0.45rem;
  bottom: 0.55rem;
  color: var(--gold);
  font-size: 3.3rem;
  font-weight: 900;
  line-height: 1;
  text-shadow: 0 0 24px rgba(244, 201, 93, 0.36);
}

@keyframes turn-phone {
  0%, 18% { transform: rotate(-18deg); }
  58%, 82% { transform: translate(1.2rem, 1.1rem) rotate(72deg); }
  100% { transform: rotate(-18deg); }
}

button {
  min-width: 7.5rem;
  height: 2.85rem;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 6px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.14), transparent 48%),
    linear-gradient(180deg, #253551, #111827);
  color: var(--ink);
  font: inherit;
  font-weight: 800;
  letter-spacing: 0;
  cursor: pointer;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.2),
    inset 0 -10px 20px rgba(0, 0, 0, 0.28),
    0 10px 28px rgba(0, 0, 0, 0.34);
}

button:hover,
button:focus-visible {
  border-color: var(--cyan);
  transform: translateY(-1px);
  outline: none;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.2),
    0 0 0 3px rgba(57, 217, 255, 0.13),
    0 16px 32px rgba(0, 0, 0, 0.4);
}

kbd {
  display: inline-grid;
  min-width: 2.35rem;
  height: 2rem;
  padding: 0 0.6rem;
  place-items: center;
  border: 1px solid var(--line);
  border-bottom-color: rgba(255, 255, 255, 0.34);
  border-radius: 5px;
  background: rgba(15, 22, 38, 0.92);
  color: var(--ink);
  font-weight: 800;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.shell {
  display: grid;
  min-height: 100%;
  grid-template-rows: minmax(0, auto) auto;
  align-content: center;
  gap: clamp(0.55rem, 1.5vmin, 0.9rem);
  padding: clamp(0.5rem, 2vmin, 1.4rem);
  perspective: 1200px;
}

.game-frame {
  position: relative;
  display: grid;
  min-height: 0;
  overflow: hidden;
  width: min(100%, calc((100vh - 5rem) * 1.333));
  max-height: calc(100vh - 5rem);
  aspect-ratio: 4 / 3;
  margin: 0 auto;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.05), transparent 18%),
    #02030a;
  box-shadow:
    0 1.5rem 5rem rgba(0, 0, 0, 0.56),
    inset 0 1px 0 rgba(255, 255, 255, 0.14),
    inset 0 0 0 1px rgba(57, 217, 255, 0.04);
  transform: rotateX(1.2deg);
  transform-origin: center bottom;
}

.game-frame::before,
.game-frame::after {
  position: absolute;
  z-index: 2;
  inset: 0;
  pointer-events: none;
  content: "";
}

.game-frame::before {
  background:
    linear-gradient(90deg, rgba(57, 217, 255, 0.14), transparent 16%, transparent 84%, rgba(255, 71, 111, 0.12)),
    linear-gradient(180deg, rgba(255, 255, 255, 0.1), transparent 12%, transparent 74%, rgba(0, 0, 0, 0.34));
  mix-blend-mode: screen;
}

.game-frame::after {
  background: repeating-linear-gradient(180deg, rgba(255, 255, 255, 0.035) 0 1px, transparent 1px 4px);
  opacity: 0.35;
}

.hud {
  position: absolute;
  z-index: 3;
  top: 0.45rem;
  left: 0.55rem;
  right: 0.55rem;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  padding: 0.28rem 0.35rem;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 5px;
  background: rgba(5, 8, 17, 0.58);
  backdrop-filter: blur(10px) saturate(1.2);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
  pointer-events: none;
}

.settings-panel {
  position: absolute;
  z-index: 5;
  right: 0.85rem;
  bottom: 0.85rem;
  display: grid;
  gap: 0.75rem;
  width: min(24rem, calc(100% - 1.7rem));
  max-height: calc(100% - 1.7rem);
  overflow-y: auto;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.1), transparent 50%),
    rgba(5, 8, 17, 0.9);
  padding: 0.85rem;
  backdrop-filter: blur(18px);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.48);
}

.settings-heading {
  color: var(--gold);
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.settings-panel[hidden] {
  display: none;
}

.settings-row {
  display: grid;
  grid-template-columns: 6rem minmax(0, 1fr);
  gap: 0.75rem;
  align-items: center;
}

.settings-row label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.settings-row input,
.settings-row select {
  width: 100%;
  min-width: 0;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 6px;
  background: rgba(10, 15, 28, 0.9);
  color: var(--ink);
  font: inherit;
  font-weight: 700;
}

.settings-check input {
  justify-self: end;
  width: 1.25rem;
  height: 1.25rem;
  accent-color: var(--cyan);
}

.gamepad-line {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
}

.stats-block {
  display: grid;
  gap: 0.55rem;
  border-top: 1px solid var(--line);
  padding-top: 0.75rem;
}

.stats-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.4rem;
}

.stat-chip {
  border: 1px solid var(--line);
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.045);
  padding: 0.42rem;
  color: var(--muted);
  font-size: 0.67rem;
  font-weight: 800;
  text-align: center;
}

.stat-chip strong {
  display: block;
  color: var(--ink);
  font-size: 0.88rem;
}

.achievements-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.35rem;
}

.achievement {
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 5px;
  padding: 0.4rem 0.48rem;
  color: #5c667d;
  font-size: 0.67rem;
  font-weight: 800;
}

.achievement.unlocked {
  border-color: rgba(104, 245, 173, 0.38);
  background: rgba(104, 245, 173, 0.08);
  color: var(--green);
}

.touch-controls {
  position: absolute;
  z-index: 4;
  right: 0.65rem;
  bottom: 0.65rem;
  left: 0.65rem;
  display: none;
  justify-content: space-between;
  pointer-events: none;
}

.touch-controls > div {
  display: flex;
  gap: 0.4rem;
}

.touch-controls button {
  min-width: 3.4rem;
  height: 3.4rem;
  padding: 0 0.65rem;
  border-radius: 50%;
  pointer-events: auto;
  opacity: 0.82;
  user-select: none;
  -webkit-user-select: none;
}

.touch-controls .touch-fire {
  border-color: rgba(104, 245, 173, 0.65);
  color: var(--green);
}

.touch-controls .touch-bomb {
  border-color: rgba(255, 71, 111, 0.65);
  color: var(--red);
  font-size: 0.66rem;
}

body.high-contrast {
  --muted: #d8e1f8;
  --line: rgba(255, 255, 255, 0.46);
}

body.high-contrast #game {
  filter: saturate(1.3) contrast(1.22) brightness(1.08);
}

.settings-row select {
  height: 2.2rem;
  padding: 0 0.55rem;
}

.hud > div {
  display: flex;
  min-height: 1.5rem;
  min-width: 0;
  align-items: center;
  gap: 0.32rem;
  padding: 0 0.48rem;
  border-left: 1px solid rgba(255, 255, 255, 0.1);
}

.hud > div:first-child {
  border-left: 0;
}

.label {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: clamp(0.48rem, 1.15vmin, 0.62rem);
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.hud strong {
  display: inline-block;
  overflow: hidden;
  color: var(--gold);
  font-size: clamp(0.7rem, 1.8vmin, 0.98rem);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  line-height: 1;
  white-space: nowrap;
  text-overflow: ellipsis;
  text-shadow: 0 0 12px rgba(244, 201, 93, 0.28);
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
  touch-action: none;
  filter: saturate(1.08) contrast(1.04);
}

.overlay {
  position: absolute;
  z-index: 4;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 1.05rem;
  padding: 1rem;
  text-align: center;
  background:
    linear-gradient(180deg, rgba(2, 3, 10, 0.2), rgba(2, 3, 10, 0.78)),
    radial-gradient(ellipse at center, rgba(57, 217, 255, 0.1), transparent 60%);
  backdrop-filter: blur(1px);
}

.overlay.hidden {
  display: none;
}

.title {
  color: #f8fbff;
  font-size: clamp(2.2rem, 8vmin, 6rem);
  font-weight: 900;
  letter-spacing: 0;
  line-height: 0.9;
  text-shadow:
    0 2px 0 rgba(57, 217, 255, 0.8),
    0 8px 22px rgba(0, 0, 0, 0.75),
    0 0 42px rgba(57, 217, 255, 0.48);
  text-transform: uppercase;
}

.overlay p {
  max-width: min(38rem, 86vw);
  margin: 0 auto;
  color: var(--ink);
  font-size: clamp(0.88rem, 2.2vmin, 1.2rem);
  font-weight: 700;
  line-height: 1.45;
  text-shadow: 0 2px 14px rgba(0, 0, 0, 0.8);
}

.controls {
  display: flex;
  justify-content: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.control-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  min-height: 3rem;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.07), transparent),
    rgba(9, 13, 24, 0.9);
  padding: 0.55rem 0.75rem;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.key-group {
  display: flex;
  gap: 0.35rem;
}

.settings-toggle {
  min-width: 6.5rem;
  height: 2.25rem;
  font-size: 0.84rem;
}

.control-strip p {
  margin: 0;
  color: var(--muted);
  font-size: clamp(0.72rem, 2vmin, 0.95rem);
  font-weight: 700;
  text-align: right;
}

@media (max-width: 620px) {
  .shell {
    gap: 0.5rem;
    padding: 0.5rem;
  }

  .hud {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    padding: 0.2rem 0.3rem;
  }

  .game-frame {
    transform: none;
  }

  .hud > div {
    min-height: 1.25rem;
    padding: 0 0.28rem;
  }

  .hud > div:nth-child(4) {
    border-left: 0;
  }

  .control-strip {
    align-items: stretch;
  }

  .control-strip p {
    display: grid;
    align-items: center;
  }

  kbd {
    min-width: 2rem;
    padding: 0 0.45rem;
  }
}

@media (hover: none), (pointer: coarse) {
  .touch-controls {
    display: flex;
  }
}

body.smartphone-device:not(.smartphone-portrait) .shell {
  width: 100vw;
  height: 100dvh;
  min-height: 0;
  grid-template-rows: minmax(0, 1fr);
  place-items: center;
  gap: 0;
  padding:
    max(0.35rem, env(safe-area-inset-top))
    max(0.35rem, env(safe-area-inset-right))
    max(0.35rem, env(safe-area-inset-bottom))
    max(0.35rem, env(safe-area-inset-left));
}

body.smartphone-device:not(.smartphone-portrait) .game-frame {
  width: 100%;
  max-width: none;
  height: calc(100dvh - 0.7rem - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  max-height: none;
  aspect-ratio: auto;
  margin: 0;
  transform: none;
}

body.smartphone-device:not(.smartphone-portrait) .control-strip {
  display: none;
}

body.smartphone-device:not(.smartphone-portrait) .touch-controls {
  display: flex;
}

body.smartphone-device:not(.smartphone-portrait) .touch-controls button {
  min-width: clamp(3.2rem, 9vmin, 4.1rem);
  height: clamp(3.2rem, 9vmin, 4.1rem);
}

body.smartphone-device .shell,
body.smartphone-device .shell * {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

body.smartphone-device .touch-controls,
body.smartphone-device .touch-controls button {
  touch-action: none;
}

body.smartphone-device .shell ::selection {
  background: transparent;
}

@media (prefers-reduced-motion: reduce) {
  .phone-outline {
    animation: none;
    transform: translate(1.2rem, 1.1rem) rotate(72deg);
  }
}
