:root {
  color-scheme: dark;
  --bg: #080a10;
  --panel: rgba(22, 28, 39, 0.96);
  --text: #ffffff;
  --muted: #c5d1e2;
  --button: #2e5494;
  --button-hover: #3d6ab8;
  --button-active: #1f3d70;
  --line: rgba(159, 190, 255, 0.18);
  --gold: #ffe45e;
  --cyan: #4ee7ff;
}

* {
  box-sizing: border-box;
}

html,
body,
#app {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  font-family: Arial, Helvetica, sans-serif;
}

button,
input,
select {
  font: inherit;
}

#gameCanvas {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: block;
  background: #04070d;
  touch-action: none;
}

.hidden {
  display: none !important;
}

.menu {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: radial-gradient(circle at 50% 28%, rgba(29, 58, 92, 0.28), transparent 42%), rgba(8, 10, 16, 0.78);
}

.menu-panel {
  width: min(640px, calc(100vw - 30px));
  max-height: min(1040px, calc(100vh - 30px));
  overflow: auto;
  padding: 30px 38px 34px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.46);
}

.menu-panel h1 {
  margin: 0 0 18px;
  text-align: center;
  color: var(--text);
  font-size: 44px;
  line-height: 1.1;
}

.field,
.setting-row {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 17px;
  font-weight: 700;
}

.field {
  margin: 0 0 13px;
}

.menu-options,
.mode-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin: 0 0 18px;
}

.submenu {
  margin-top: 4px;
}

.settings-block {
  margin: 0 0 16px;
}

.menu-intro {
  display: grid;
  gap: 14px;
  justify-items: center;
  margin-top: 4px;
}

.menu-intro img {
  width: min(100%, 471px);
  max-height: 270px;
  display: block;
  object-fit: contain;
  border: 1px solid var(--line);
  background: #04070d;
}

.menu-intro p {
  max-width: 520px;
  margin: 0;
  color: #d6e2f3;
  text-align: center;
  font-size: 20px;
  line-height: 1.35;
}

.setting-row {
  grid-template-columns: minmax(0, 1fr) 120px;
  align-items: center;
  margin: 0 0 10px;
}

input,
select {
  width: 100%;
  height: 44px;
  border: 1px solid rgba(166, 195, 255, 0.18);
  border-radius: 0;
  background: #080c14;
  color: var(--text);
  text-align: center;
  font-size: 24px;
  font-weight: 700;
  outline: none;
}

input:focus,
select:focus {
  border-color: rgba(78, 231, 255, 0.75);
}

.primary,
.pause,
.secondary {
  width: 100%;
  min-height: 52px;
  margin: 0 0 13px;
  border: 0;
  border-radius: 0;
  background: var(--button);
  color: var(--text);
  font-size: 26px;
  font-weight: 800;
  cursor: pointer;
}

.menu-options .primary,
.mode-options .secondary {
  margin-bottom: 0;
}

.secondary {
  min-height: 46px;
  background: #162235;
  border: 1px solid rgba(166, 195, 255, 0.18);
  color: var(--muted);
  font-size: 18px;
}

.menu-choice.active,
.secondary.active {
  background: var(--button-active);
  color: var(--text);
  border-color: rgba(78, 231, 255, 0.56);
}

.primary:hover,
.pause:hover,
.secondary:hover {
  background: var(--button-hover);
}

.primary:active,
.pause:active,
.secondary:active {
  background: var(--button-active);
}

.settings-title {
  margin: 4px 0 11px;
  color: #d4e1f6;
  text-align: center;
  font-size: 20px;
  font-weight: 800;
}

.status {
  min-height: 48px;
  margin: 2px 0 13px;
  display: grid;
  place-items: center;
  color: #c1ccdc;
  text-align: center;
  white-space: pre-line;
  font-size: 20px;
}

.session-list {
  min-height: 68px;
  padding: 18px;
  background: #0b0f18;
  color: #d3dce9;
  text-align: center;
  font-size: 20px;
  line-height: 1.35;
}

.session-list button {
  min-height: 42px;
  margin: 0 0 10px;
  font-size: 20px;
}

.hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  color: var(--text);
  font-weight: 800;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.85);
}

.hud-left {
  position: absolute;
  top: 26px;
  left: 30px;
  font-size: 28px;
  line-height: 1.42;
}

.game-status {
  position: absolute;
  top: 26px;
  left: 25%;
  width: 50%;
  text-align: center;
  font-size: 34px;
  line-height: 1.22;
  white-space: pre-line;
}

.score {
  position: absolute;
  top: 26px;
  right: 30px;
  width: 360px;
  text-align: right;
  font-size: 28px;
  line-height: 1.3;
  white-space: pre-line;
}

.pause {
  position: absolute;
  left: 50%;
  bottom: 66px;
  width: 190px;
  min-height: 44px;
  transform: translateX(-50%);
  pointer-events: auto;
  font-size: 22px;
}

.network-toggle {
  position: absolute;
  right: 30px;
  top: 176px;
  width: 160px;
  min-height: 40px;
  border: 0;
  background: rgba(46, 84, 148, 0.92);
  color: var(--text);
  font-size: 19px;
  font-weight: 800;
  pointer-events: auto;
  cursor: pointer;
}

.network-toggle:hover {
  background: var(--button-hover);
}

.network-panel {
  position: absolute;
  top: 226px;
  right: 30px;
  width: 330px;
  padding: 18px;
  background: rgba(13, 18, 27, 0.94);
  border: 1px solid var(--line);
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.44);
  pointer-events: auto;
  text-shadow: none;
}

.network-panel h2 {
  margin: 0 0 14px;
  font-size: 20px;
  line-height: 1.1;
}

.network-panel label {
  display: grid;
  grid-template-columns: 1fr 96px 52px;
  gap: 10px;
  align-items: center;
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 14px;
}

.network-panel input[type="range"] {
  height: 24px;
  padding: 0;
  background: transparent;
  border: 0;
}

.network-panel .network-toggle-row {
  grid-template-columns: 1fr 24px 52px;
}

.network-panel input[type="checkbox"] {
  width: 20px;
  height: 20px;
  margin: 0;
  justify-self: center;
  accent-color: var(--cyan);
}

.network-panel strong {
  color: var(--text);
  text-align: right;
  font-size: 14px;
}

.network-panel p {
  margin: 10px 0 0;
  color: #d4e1f6;
  font-size: 13px;
  line-height: 1.35;
}

.network-stats {
  display: grid;
  gap: 7px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.network-stats div {
  display: grid;
  grid-template-columns: 86px minmax(0, 1fr);
  gap: 10px;
  align-items: baseline;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.25;
}

.network-stats span {
  color: #98aac2;
  font-weight: 800;
}

.network-stats strong {
  color: var(--text);
  text-align: right;
  font-size: 13px;
  overflow-wrap: anywhere;
}

.help {
  position: absolute;
  left: 50%;
  bottom: 22px;
  width: calc(100vw - 60px);
  transform: translateX(-50%);
  color: #c8d6e6;
  text-align: center;
  font-size: 18px;
  line-height: 1.25;
}

.touch-controls,
.touch-shortcuts,
.fullscreen-toggle {
  display: none;
}

.touch-mode .hud:not(.hidden) .touch-controls,
.touch-mode .hud:not(.hidden) .fullscreen-toggle {
  display: block;
}

.touch-mode .hud:not(.hidden) .touch-shortcuts {
  display: flex;
}

.touch-mode .help {
  display: none;
}

.touch-mode .hud-left {
  top: 20px;
  left: 24px;
  font-size: 24px;
}

.touch-mode .game-status {
  top: 24px;
  left: 22%;
  width: 50%;
  font-size: 30px;
}

.touch-mode .score {
  top: 72px;
  right: 24px;
  width: 190px;
  font-size: 24px;
}

.touch-controls {
  position: absolute;
  inset: 0;
  pointer-events: none;
  touch-action: none;
}

.touch-joystick {
  position: absolute;
  left: max(22px, env(safe-area-inset-left));
  bottom: max(22px, env(safe-area-inset-bottom));
  width: 148px;
  height: 148px;
  border: 2px solid rgba(174, 215, 255, 0.42);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(78, 231, 255, 0.13), rgba(8, 13, 23, 0.42));
  box-shadow: 0 14px 42px rgba(0, 0, 0, 0.36), inset 0 0 32px rgba(78, 231, 255, 0.08);
  pointer-events: auto;
  touch-action: none;
}

.touch-joystick::before {
  content: "";
  position: absolute;
  left: 18px;
  right: 18px;
  top: 50%;
  height: 2px;
  transform: translateY(-50%);
  background: rgba(210, 232, 255, 0.24);
}

.touch-joystick-thumb {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 58px;
  height: 58px;
  border: 2px solid rgba(255, 255, 255, 0.58);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  background: rgba(78, 231, 255, 0.28);
  box-shadow: 0 8px 26px rgba(0, 0, 0, 0.36), inset 0 0 18px rgba(255, 255, 255, 0.14);
}

.touch-shoot {
  position: absolute;
  right: max(24px, env(safe-area-inset-right));
  bottom: max(30px, env(safe-area-inset-bottom));
  width: 128px;
  height: 128px;
  border: 2px solid rgba(255, 228, 94, 0.58);
  border-radius: 50%;
  background: radial-gradient(circle at 50% 42%, rgba(255, 228, 94, 0.3), rgba(86, 123, 178, 0.34));
  box-shadow: 0 14px 42px rgba(0, 0, 0, 0.36), inset 0 0 32px rgba(255, 228, 94, 0.1);
  pointer-events: auto;
  touch-action: none;
}

.touch-shoot::before,
.touch-shoot::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  border-radius: 50%;
  transform: translate(-50%, -50%);
}

.touch-shoot::before {
  width: 44px;
  height: 44px;
  border: 7px solid rgba(255, 255, 255, 0.86);
}

.touch-shoot::after {
  width: 18px;
  height: 18px;
  background: rgba(255, 255, 255, 0.9);
}

.touch-shoot.active {
  background: radial-gradient(circle at 50% 42%, rgba(255, 244, 164, 0.62), rgba(86, 123, 178, 0.6));
}

.touch-shortcuts {
  position: absolute;
  left: 50%;
  bottom: max(26px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  gap: 9px;
  pointer-events: auto;
}

.touch-key,
.fullscreen-toggle {
  width: 54px;
  height: 42px;
  border: 1px solid rgba(174, 215, 255, 0.38);
  border-radius: 0;
  background: rgba(13, 18, 27, 0.68);
  color: var(--text);
  font-size: 17px;
  font-weight: 900;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.85);
  pointer-events: auto;
  touch-action: manipulation;
}

.touch-next {
  width: 76px;
}

.touch-key:disabled {
  opacity: 0.42;
}

.fullscreen-toggle {
  position: absolute;
  top: max(18px, env(safe-area-inset-top));
  right: max(22px, env(safe-area-inset-right));
}

.fullscreen-toggle span,
.fullscreen-toggle span::before,
.fullscreen-toggle span::after {
  position: absolute;
  inset: 10px;
  display: block;
  border: 3px solid rgba(255, 255, 255, 0.86);
}

.fullscreen-toggle span {
  border-left: 0;
  border-bottom: 0;
}

.fullscreen-toggle span::before,
.fullscreen-toggle span::after {
  content: "";
  inset: auto;
  width: 12px;
  height: 12px;
}

.fullscreen-toggle span::before {
  left: 10px;
  bottom: 10px;
  border-top: 0;
  border-right: 0;
}

.fullscreen-toggle span::after {
  right: 10px;
  bottom: 10px;
  border-top: 0;
  border-left: 0;
}

.fullscreen-toggle.active span {
  inset: 14px;
}

@media (max-width: 760px) {
  .menu-panel {
    width: calc(100vw - 32px);
    padding: 24px;
    overflow-x: hidden;
  }

  .menu-panel h1 {
    font-size: 36px;
  }

  .primary {
    font-size: 21px;
  }

  .menu-options,
  .mode-options {
    grid-template-columns: 1fr;
  }

  .secondary {
    font-size: 17px;
  }

  .menu-intro img {
    max-height: 220px;
  }

  .menu-intro p {
    font-size: 17px;
  }

  .settings-title {
    font-size: 18px;
    line-height: 1.25;
  }

  .setting-row {
    grid-template-columns: 1fr;
  }

  .hud-left,
  .score {
    font-size: 16px;
  }

  .game-status {
    top: 58px;
    left: 8%;
    width: 84%;
    font-size: 20px;
  }

  .help {
    font-size: 12px;
  }

  .network-toggle {
    right: 18px;
    top: 128px;
    width: 118px;
    min-height: 34px;
    font-size: 15px;
  }

  .network-panel {
    top: 168px;
    right: 18px;
    width: calc(100vw - 36px);
  }

  .network-panel label {
    grid-template-columns: 1fr;
    gap: 5px;
  }

  .network-panel .network-toggle-row {
    grid-template-columns: 1fr 24px 52px;
  }

  .network-panel strong {
    text-align: left;
  }
}

@media (max-width: 760px) and (pointer: coarse) {
  .hud-left,
  .score {
    max-width: 31vw;
  }

  .hud-left {
    top: 18px;
    left: 16px;
    font-size: 16px;
  }

  .score {
    top: 62px;
    right: 16px;
    width: 136px;
    font-size: 16px;
  }

  .game-status {
    top: 58px;
    left: 32%;
    width: 36%;
    font-size: 18px;
  }

  .touch-joystick {
    width: 132px;
    height: 132px;
  }

  .touch-joystick-thumb {
    width: 52px;
    height: 52px;
  }

  .touch-shoot {
    width: 116px;
    height: 116px;
  }

  .touch-key,
  .fullscreen-toggle {
    width: 48px;
    height: 38px;
    font-size: 15px;
  }

  .touch-next {
    width: 68px;
  }
}
