* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --panel-bg: rgba(11, 18, 32, 0.78);
  --panel-border: rgba(255, 255, 255, 0.12);
  --panel-shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
  --text-main: #e8eefc;
}

html, body {
  width: 100%;
  min-height: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(180deg, #0b1220 0%, #111b2e 100%);
  display: grid;
  place-items: center;
  font-family: Arial, sans-serif;
  color: var(--text-main);
  overflow: hidden;
  touch-action: manipulation;
}

button, a {
  font-family: inherit;
}

.app-shell {
  width: min(100vw, 1180px);
  padding: 12px;
}

.game-frame {
  position: relative;
  width: min(96vw, 1100px);
  margin: 0 auto;
}

canvas {
  display: block;
  width: 100%;
  height: min(82vh, calc(100vw * 0.625));
  min-height: 320px;
  max-height: 88vh;
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: #78b96d;
  box-shadow: var(--panel-shadow);
  touch-action: none;
}

.hud-overlay {
  position: absolute;
  inset: 16px 16px 16px 16px;
  pointer-events: none;
  z-index: 12;
  transition: opacity 0.2s ease;
}

.hud-overlay.hidden {
  opacity: 0;
  visibility: hidden;
}

.menu-toggle,
.menu-panel,
.brand-link,
.cookie-banner,
.menu-modal,
.close-modal,
.wasd-visual {
  pointer-events: auto;
}

.menu-toggle {
  position: absolute;
  top: 0;
  right: 0;
  width: 52px;
  height: 52px;
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  background: var(--panel-bg);
  color: #fff;
  font-size: 28px;
  cursor: pointer;
  box-shadow: 0 12px 26px rgba(0, 0, 0, 0.22);
}

.menu-panel {
  position: absolute;
  top: 60px;
  right: 0;
  width: 220px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  border-radius: 16px;
  background: rgba(10, 15, 28, 0.95);
  border: 1px solid var(--panel-border);
  box-shadow: 0 18px 38px rgba(0, 0, 0, 0.35);
}

.hidden-panel {
  display: none !important;
}

.menu-item {
  border: 1px solid rgba(255,255,255,0.1);
  background: rgba(255,255,255,0.05);
  color: #fff;
  border-radius: 12px;
  padding: 12px 14px;
  text-align: left;
  font-size: 16px;
  cursor: pointer;
}

.menu-item:hover,
.cookie-btn:hover,
.play-button:hover,
.brand-link:hover,
.close-modal:hover {
  transform: translateY(-1px);
}

.wasd-visual {
  position: absolute;
  top: 0;
  left: 0;
  display: grid;
  gap: 8px;
  justify-items: center;
  padding: 10px 12px;
  border-radius: 16px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  box-shadow: 0 12px 26px rgba(0, 0, 0, 0.22);
}

.wasd-row {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: center;
}

.wasd-key {
  width: 42px;
  height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.14);
  background: rgba(255,255,255,0.08);
  color: #fff;
  font-size: 18px;
  font-weight: 700;
  user-select: none;
}


.brand-link {
  position: absolute;
  left: 0;
  bottom: 0;
  text-decoration: none;
  color: #ffffff;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 10px 14px;
  border-radius: 14px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  box-shadow: 0 12px 26px rgba(0, 0, 0, 0.22);
}

.cookie-banner {
  position: absolute;
  right: 0;
  bottom: 0;
  width: min(320px, calc(100vw - 32px));
  padding: 14px;
  border-radius: 16px;
  background: rgba(10, 15, 28, 0.95);
  border: 1px solid var(--panel-border);
  box-shadow: 0 18px 38px rgba(0, 0, 0, 0.35);
}

.cookie-title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 6px;
}

.cookie-text {
  font-size: 14px;
  line-height: 1.4;
  color: rgba(232, 238, 252, 0.92);
}

.cookie-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 12px;
}

.cookie-btn {
  border: 1px solid rgba(255,255,255,0.1);
  background: rgba(255,255,255,0.05);
  color: #fff;
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
}

.cookie-btn.primary,
.play-button {
  background: linear-gradient(180deg, #3f73ff 0%, #1f4fff 100%);
  box-shadow: 0 14px 30px rgba(31, 79, 255, 0.35);
  border: none;
}

.start-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: minmax(110px, 130px) 1fr minmax(110px, 130px);
  align-items: center;
  gap: 18px;
  padding: 24px 18px;
  background: rgba(5, 9, 18, 0.26);
  border-radius: 18px;
  z-index: 8;
}

.start-overlay.hidden {
  display: none;
}

.start-card {
  width: min(86vw, 340px);
  margin: 0 auto;
  padding: 28px 24px 20px;
  text-align: center;
  border-radius: 22px;
  background: rgba(10, 15, 28, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.42);
}

.start-title {
  font-size: 40px;
  font-weight: 800;
  letter-spacing: 0.08em;
  margin-bottom: 18px;
}

.play-button {
  border-radius: 14px;
  padding: 14px 30px;
  font-size: 22px;
  font-weight: 700;
  cursor: pointer;
  color: #fff;
}

.color-picker-label {
  font-size: 14px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: rgba(232, 238, 252, 0.72);
  margin-bottom: 10px;
}

.color-picker {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-bottom: 18px;
}

.color-swatch {
  width: 30px;
  height: 30px;
  border-radius: 10px;
  border: 2px solid rgba(255,255,255,0.18);
  background: var(--swatch);
  cursor: pointer;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.18);
}

.color-swatch.selected {
  transform: translateY(-2px) scale(1.08);
  border-color: rgba(255,255,255,0.95);
  box-shadow: 0 0 0 3px rgba(255,255,255,0.16), 0 12px 24px rgba(0, 0, 0, 0.3);
}


.ad-under-play {
  width: 100%;
  min-height: 150px;
  margin-top: 18px;
  border-radius: 14px;
  padding: 14px 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.04);
  border: 1px dashed rgba(255,255,255,0.18);
}

.side-ad {
  align-self: center;
  width: 100%;
  min-height: 280px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 18px;
  background: rgba(10, 15, 28, 0.78);
  border: 1px dashed rgba(255,255,255,0.18);
  box-shadow: 0 18px 38px rgba(0, 0, 0, 0.28);
}

.ad-label {
  color: rgba(255,255,255,0.82);
  font-size: 20px;
  font-weight: 700;
  text-align: center;
  padding: 12px;
}

.ad-label-small {
  font-size: 15px;
}

.mobile-zoom-controls {
  position: absolute;
  right: 18px;
  left: auto;
  top: 50%;
  bottom: auto;
  transform: translateY(-50%);
  display: none;
  flex-direction: column;
  gap: 10px;
  z-index: 10;
}

.zoom-button {
  width: 54px;
  height: 54px;
  border-radius: 16px;
  border: 1px solid rgba(255,255,255,0.18);
  background: rgba(10, 15, 28, 0.76);
  color: #fff;
  font-size: 30px;
  font-weight: 700;
  box-shadow: 0 10px 24px rgba(0,0,0,0.24);
}

.menu-modal-backdrop {
  position: absolute;
  inset: 0;
  z-index: 14;
  background: rgba(3, 6, 14, 0.48);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
}

.menu-modal {
  position: relative;
  width: min(520px, 92vw);
  max-height: min(76vh, 560px);
  overflow: auto;
  padding: 24px 22px 20px;
  border-radius: 22px;
  background: rgba(10, 15, 28, 0.97);
  border: 1px solid rgba(255,255,255,0.14);
  box-shadow: 0 24px 60px rgba(0,0,0,0.42);
}

.close-modal {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 38px;
  height: 38px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(255,255,255,0.06);
  color: #fff;
  font-size: 24px;
  cursor: pointer;
}

.info-panel {
  display: none;
  line-height: 1.55;
  color: rgba(232, 238, 252, 0.95);
}

.info-panel.active {
  display: block;
}

.info-panel h2 {
  margin-top: 0;
  margin-bottom: 12px;
}

.mobile-joystick {
  position: absolute;
  left: 18px;
  bottom: 18px;
  width: 138px;
  height: 138px;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 9;
  touch-action: none;
}

.joystick-base {
  position: relative;
  width: 132px;
  height: 132px;
  border-radius: 50%;
  background: rgba(7, 11, 20, 0.22);
  border: 2px solid rgba(255, 255, 255, 0.18);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.24);
}

.joystick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  background: rgba(255, 255, 255, 0.78);
  border: 2px solid rgba(15, 20, 35, 0.22);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.22);
}

@media (max-width: 900px) {
  .start-overlay {
    grid-template-columns: 1fr;
    justify-items: center;
    gap: 14px;
  }

  .side-ad {
    width: min(86vw, 340px);
    min-height: 72px;
  }

  .side-ad-left {
    order: 2;
  }

  .start-card {
    order: 1;
  }

  .side-ad-right {
    order: 3;
  }
}

@media (hover: none) and (pointer: coarse) {
  body {
    place-items: stretch;
    background: #0b1220;
  }

  .app-shell {
    width: 100vw;
    padding: 0;
  }

  .game-frame {
    width: 100vw;
    height: 100vh;
  }

  canvas {
    width: 100vw;
    height: 100vh;
    min-height: 100vh;
    max-height: 100vh;
    border-radius: 0;
    border: none;
  }

  .game-frame.playing .mobile-joystick.active {
    display: flex;
  }

  .game-frame.playing .mobile-zoom-controls {
    display: flex;
  }

  .hud-overlay {
    inset: 12px 12px 12px 12px;
  }

  .brand-link {
    font-size: 21px;
    padding: 8px 12px;
  }

  .wasd-visual {
    display: none;
  }

  .menu-toggle {
    width: 46px;
    height: 46px;
    font-size: 24px;
  }

  .cookie-banner {
    width: min(300px, calc(100vw - 24px));
  }

  .start-overlay {
    border-radius: 0;
  }

  .start-card {
    width: min(92vw, 360px);
    padding-bottom: 0;
  }

  .ad-under-play {
    min-height: clamp(180px, 28vh, 260px);
    margin-top: 16px;
    border-bottom-left-radius: 22px;
    border-bottom-right-radius: 22px;
  }

  .color-swatch {
    width: 34px;
    height: 34px;
  }
}


@media (hover: none) and (pointer: coarse) and (orientation: portrait) {
  body {
    overflow: hidden;
  }

  .app-shell {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
  }

  .game-frame {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 100vh;
    height: 100vw;
    transform: translate(-50%, -50%) rotate(90deg);
    transform-origin: center center;
  }
}
