:root {
  --night: #07111f;
  --panel: #0d1a2e;
  --panel-strong: #111f38;
  --ink: #f7f9ff;
  --muted: #96a7c2;
  --line: rgba(151, 177, 214, 0.18);
  --accent: #52f0b4;
  --accent-rgb: 82, 240, 180;
  --violet: #8b72ff;
  --coral: #ff7077;
  --safe-top: max(8px, env(safe-area-inset-top));
  --safe-right: max(8px, env(safe-area-inset-right));
  --safe-bottom: max(8px, env(safe-area-inset-bottom));
  --safe-left: max(8px, env(safe-area-inset-left));
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--night);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body {
  padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
  background:
    radial-gradient(circle at 10% -20%, rgba(var(--accent-rgb), 0.12), transparent 42%),
    radial-gradient(circle at 90% -30%, rgba(139, 114, 255, 0.15), transparent 38%),
    var(--night);
}

button {
  color: inherit;
  font: inherit;
}

.arcade-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 9px;
  width: min(1180px, 100%);
  height: 100%;
  margin: 0 auto;
}

.game-bar {
  position: relative;
  z-index: 10;
  display: flex;
  align-items: center;
  min-height: 62px;
  gap: 14px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(10, 21, 39, 0.9);
  box-shadow: 0 16px 56px rgba(0, 0, 0, 0.24);
  backdrop-filter: blur(18px);
}

.game-identity {
  display: flex;
  align-items: center;
  min-width: 238px;
  gap: 11px;
}

.game-mark {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 13px;
  background: linear-gradient(145deg, var(--accent), color-mix(in srgb, var(--accent) 58%, var(--violet)));
  box-shadow: 0 0 28px rgba(var(--accent-rgb), 0.24), inset 0 1px rgba(255, 255, 255, 0.48);
  color: #061d1b;
  font-size: 17px;
  font-weight: 1000;
  letter-spacing: -0.06em;
}

.game-copy {
  min-width: 0;
}

.game-copy h1 {
  overflow: hidden;
  margin: 0;
  font-size: 15px;
  font-weight: 900;
  letter-spacing: -0.025em;
  line-height: 1.15;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.game-copy p {
  overflow: hidden;
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 9px;
  font-weight: 850;
  letter-spacing: 0.09em;
  line-height: 1.2;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.game-stats {
  display: flex;
  align-items: stretch;
  min-width: 0;
  margin-left: auto;
}

.game-stat {
  display: flex;
  min-width: 84px;
  flex-direction: column;
  justify-content: center;
  padding: 3px 12px;
  border-left: 1px solid var(--line);
}

.game-stat span {
  color: var(--muted);
  font-size: 8px;
  font-weight: 850;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.game-stat strong {
  overflow: hidden;
  margin-top: 3px;
  font-size: 16px;
  font-variant-numeric: tabular-nums;
  font-weight: 900;
  letter-spacing: -0.035em;
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.goal-stat {
  width: 160px;
}

.goal-stat strong {
  color: color-mix(in srgb, var(--accent) 76%, white);
  font-size: 12px;
  letter-spacing: -0.01em;
}

.game-actions {
  display: flex;
  gap: 6px;
}

.icon-button {
  display: grid;
  width: 40px;
  height: 40px;
  padding: 0;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 12px;
  outline: none;
  background: rgba(255, 255, 255, 0.035);
  color: var(--muted);
  cursor: pointer;
  transition: border-color 150ms ease, color 150ms ease, transform 150ms ease, background 150ms ease;
}

.icon-button:hover {
  border-color: rgba(var(--accent-rgb), 0.38);
  background: rgba(var(--accent-rgb), 0.08);
  color: var(--ink);
  transform: translateY(-1px);
}

.icon-button:focus-visible,
.primary-button:focus-visible,
.touch-controls button:focus-visible {
  outline: 3px solid rgba(var(--accent-rgb), 0.42);
  outline-offset: 2px;
}

.icon-button svg,
.touch-controls svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.game-stage {
  position: relative;
  min-height: 0;
  overflow: hidden;
  border: 1px solid rgba(var(--accent-rgb), 0.25);
  border-radius: 22px;
  background: #091227;
  box-shadow: 0 26px 90px rgba(0, 0, 0, 0.4);
  isolation: isolate;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
  cursor: crosshair;
  touch-action: none;
}

.stage-vignette {
  position: absolute;
  z-index: 2;
  inset: 0;
  pointer-events: none;
  background:
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.012) 0, rgba(255, 255, 255, 0.012) 1px, transparent 1px, transparent 4px),
    radial-gradient(circle at center, transparent 48%, rgba(1, 6, 16, 0.38) 100%);
  mix-blend-mode: screen, normal;
}

.objective-strip {
  position: absolute;
  z-index: 3;
  top: 13px;
  left: 13px;
  display: flex;
  max-width: min(520px, calc(100% - 26px));
  align-items: center;
  gap: 8px;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: rgba(5, 13, 29, 0.68);
  color: #c8d4e7;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.015em;
  line-height: 1.25;
  pointer-events: none;
  backdrop-filter: blur(10px);
}

.objective-dot {
  width: 7px;
  height: 7px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 13px var(--accent);
}

.touch-controls {
  position: absolute;
  z-index: 4;
  right: 14px;
  bottom: 13px;
  left: 14px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  pointer-events: none;
}

.direction-controls {
  display: grid;
  grid-template-columns: repeat(3, 42px);
  grid-template-rows: repeat(2, 42px);
  gap: 5px;
}

.direction-controls button,
.action-control {
  display: grid;
  width: 42px;
  height: 42px;
  padding: 0;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 12px;
  background: rgba(7, 18, 37, 0.66);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.22);
  color: #c9d7e9;
  cursor: pointer;
  pointer-events: auto;
  touch-action: none;
  backdrop-filter: blur(10px);
}

.direction-controls button[data-control="up"] {
  grid-column: 2;
  grid-row: 1;
}

.direction-controls button[data-control="left"] {
  grid-column: 1;
  grid-row: 2;
}

.direction-controls button[data-control="down"] {
  grid-column: 2;
  grid-row: 2;
}

.direction-controls button[data-control="right"] {
  grid-column: 3;
  grid-row: 2;
}

.direction-controls button.is-pressed,
.action-control.is-pressed {
  border-color: rgba(var(--accent-rgb), 0.58);
  background: rgba(var(--accent-rgb), 0.19);
  color: var(--accent);
  transform: scale(0.94);
}

.action-control {
  width: 64px;
  height: 64px;
  border-color: rgba(var(--accent-rgb), 0.44);
  border-radius: 50%;
  background: rgba(var(--accent-rgb), 0.12);
  box-shadow: 0 0 0 8px rgba(var(--accent-rgb), 0.045), 0 14px 30px rgba(0, 0, 0, 0.26);
  color: var(--accent);
}

.action-control span {
  font-size: 10px;
  font-weight: 1000;
  letter-spacing: 0.06em;
}

.game-modal {
  position: absolute;
  z-index: 8;
  inset: 0;
  display: grid;
  padding: 18px;
  place-items: center;
  background: radial-gradient(circle at 50% 45%, rgba(var(--accent-rgb), 0.12), rgba(4, 9, 21, 0.77));
  backdrop-filter: blur(5px);
  transition: opacity 200ms ease, visibility 200ms ease;
}

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

.modal-card {
  width: min(440px, 100%);
  max-height: 100%;
  overflow: auto;
  padding: 25px;
  border: 1px solid rgba(var(--accent-rgb), 0.28);
  border-radius: 24px;
  background: linear-gradient(145deg, rgba(18, 31, 58, 0.98), rgba(8, 19, 35, 0.98));
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.46), inset 0 1px rgba(255, 255, 255, 0.04);
  text-align: center;
}

.modal-emblem {
  position: relative;
  width: 78px;
  height: 68px;
  margin: 0 auto 15px;
}

.modal-emblem::before,
.modal-emblem::after {
  position: absolute;
  content: "";
  border: 1px solid rgba(var(--accent-rgb), 0.34);
  border-radius: 50%;
  inset: 3px 8px;
}

.modal-emblem::after {
  inset: 13px 18px;
  border-style: dashed;
  animation: slow-spin 9s linear infinite;
}

.modal-emblem span,
.modal-emblem i,
.modal-emblem b {
  position: absolute;
  z-index: 2;
  display: block;
  border-radius: 50%;
  box-shadow: 0 0 18px currentColor;
}

.modal-emblem span {
  top: 7px;
  left: 29px;
  width: 21px;
  height: 21px;
  background: var(--accent);
  color: var(--accent);
}

.modal-emblem i {
  right: 12px;
  bottom: 6px;
  width: 18px;
  height: 18px;
  background: var(--violet);
  color: var(--violet);
}

.modal-emblem b {
  bottom: 4px;
  left: 9px;
  width: 15px;
  height: 15px;
  background: var(--coral);
  color: var(--coral);
}

@keyframes slow-spin {
  to { transform: rotate(360deg); }
}

.modal-card h2 {
  margin: 0;
  font-size: clamp(28px, 5.5vw, 42px);
  font-weight: 950;
  letter-spacing: -0.055em;
  line-height: 0.98;
}

.modal-card > p:not(.modal-shortcuts) {
  max-width: 350px;
  margin: 13px auto 19px;
  color: #aab8ce;
  font-size: 13px;
  line-height: 1.58;
}

.primary-button {
  min-width: 142px;
  padding: 13px 18px;
  border: 0;
  border-radius: 13px;
  outline: none;
  background: var(--accent);
  box-shadow: 0 13px 31px rgba(var(--accent-rgb), 0.2);
  color: #061c1b;
  cursor: pointer;
  font-size: 13px;
  font-weight: 950;
  transition: filter 150ms ease, transform 150ms ease;
}

.primary-button:hover {
  filter: brightness(1.06);
  transform: translateY(-2px);
}

.modal-shortcuts {
  margin: 13px 0 0;
  color: #71829e;
  font-size: 9px;
  font-weight: 850;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.result-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 16px 0 19px;
}

.result-grid[hidden] {
  display: none;
}

.result-grid div {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.035);
}

.result-grid span {
  display: block;
  color: var(--muted);
  font-size: 8px;
  font-weight: 850;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.result-grid strong {
  display: block;
  margin-top: 3px;
  font-size: 20px;
  font-variant-numeric: tabular-nums;
  font-weight: 950;
}

.loading-error {
  position: absolute;
  z-index: 20;
  inset: 0;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 7px;
  background: #091227;
  text-align: center;
}

.loading-error[hidden] {
  display: none;
}

.loading-error strong {
  font-size: 22px;
}

.loading-error span {
  color: var(--muted);
  font-size: 13px;
}

@media (hover: hover) and (pointer: fine) {
  .touch-controls {
    opacity: 0.36;
  }

  .touch-controls:hover,
  .touch-controls:focus-within {
    opacity: 1;
  }
}

@media (max-width: 760px) {
  body {
    padding: 5px;
  }

  .arcade-shell {
    gap: 5px;
  }

  .game-bar {
    min-height: 54px;
    gap: 8px;
    padding: 6px 7px;
    border-radius: 15px;
  }

  .game-identity {
    min-width: 0;
    flex: 1 1 116px;
  }

  .game-mark {
    width: 36px;
    height: 36px;
    border-radius: 11px;
    font-size: 14px;
  }

  .game-copy h1 {
    font-size: 12px;
  }

  .game-copy p {
    font-size: 7px;
  }

  .game-stat {
    min-width: 55px;
    padding: 3px 7px;
  }

  .game-stat span {
    font-size: 6px;
  }

  .game-stat strong {
    font-size: 13px;
  }

  .goal-stat {
    display: none;
  }

  .game-actions {
    gap: 4px;
  }

  .icon-button {
    width: 34px;
    height: 34px;
    border-radius: 10px;
  }

  .icon-button svg {
    width: 15px;
  }

  .game-stage {
    border-radius: 17px;
  }

  .objective-strip {
    top: 8px;
    left: 8px;
    max-width: calc(100% - 16px);
    padding: 6px 8px;
    font-size: 8px;
  }

  .touch-controls {
    right: 9px;
    bottom: 9px;
    left: 9px;
  }

  .direction-controls {
    grid-template-columns: repeat(3, 38px);
    grid-template-rows: repeat(2, 38px);
    gap: 4px;
  }

  .direction-controls button {
    width: 38px;
    height: 38px;
    border-radius: 11px;
  }

  .action-control {
    width: 58px;
    height: 58px;
  }

  .modal-card {
    padding: 21px 17px;
    border-radius: 20px;
  }

  .modal-emblem {
    transform: scale(0.87);
    margin-bottom: 8px;
  }
}

@media (max-width: 480px) {
  .game-stats .game-stat:nth-child(2) {
    display: none;
  }

  .game-copy p {
    display: none;
  }

  .game-identity {
    gap: 7px;
  }

  .modal-card > p:not(.modal-shortcuts) {
    font-size: 12px;
  }
}

@media (max-height: 590px) {
  .modal-emblem {
    display: none;
  }

  .modal-card {
    padding-top: 18px;
    padding-bottom: 18px;
  }

  .modal-card h2 {
    font-size: 28px;
  }

  .modal-card > p:not(.modal-shortcuts) {
    margin-top: 9px;
    margin-bottom: 13px;
  }
}

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