:root {
  --bg: #1a2330;
  --panel: #243044;
  --text: #e8eef6;
  --muted: #9aabbf;
  --accent: #3ecf8e;
  --joy: 118px;
  --knob: 54px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Tahoma, sans-serif;
  user-select: none;
  touch-action: manipulation;
}

body.modal-open {
  overflow: hidden;
  position: fixed;
  inset: 0;
  width: 100%;
}

.rotate-hint {
  display: none;
}

.app {
  width: min(100%, 720px);
  margin: 0 auto;
  padding: 12px;
  text-align: center;
}

.top {
  margin-bottom: 10px;
}

.hud-left {
  display: contents;
}

.title {
  margin: 0 0 2px;
  font-size: 1.6rem;
  letter-spacing: 0.04em;
}

.level-label {
  margin: 0 0 6px;
  color: #f0c75e;
  font-size: 0.95rem;
  font-weight: 700;
}

.hint {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.35;
}

.status {
  margin: 0;
  color: var(--accent);
  font-size: 0.95rem;
  font-weight: 600;
  min-height: 1.3em;
}

.stage-wrap {
  display: flex;
  justify-content: center;
  background: #0f1620;
  border: 3px solid #3a4d66;
  border-radius: 12px;
  padding: 6px;
  margin: 0 auto 14px;
  width: fit-content;
  max-width: 100%;
}

#game {
  display: block;
  width: min(100%, 608px);
  height: auto;
  image-rendering: pixelated;
  background: #1c2836;
}

.mobile-controls {
  position: fixed;
  inset: 0;
  z-index: 40;
  pointer-events: none;
}

.joystick {
  position: absolute;
  left: max(12px, env(safe-area-inset-left, 0px));
  bottom: max(12px, env(safe-area-inset-bottom, 0px));
  pointer-events: auto;
  opacity: 0.42;
  transition: opacity 0.15s ease;
}

.joystick.is-active {
  opacity: 0.78;
}

.joystick-base {
  width: var(--joy);
  height: var(--joy);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  border: 2px solid rgba(255, 255, 255, 0.22);
  box-shadow: inset 0 0 0 8px rgba(0, 0, 0, 0.08);
  position: relative;
  touch-action: none;
}

.joystick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: var(--knob);
  height: var(--knob);
  margin-left: calc(var(--knob) / -2);
  margin-top: calc(var(--knob) / -2);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.28);
  border: 2px solid rgba(255, 255, 255, 0.4);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
  will-change: transform;
}

.joystick.is-active .joystick-knob {
  background: rgba(62, 207, 142, 0.45);
  border-color: rgba(168, 240, 205, 0.7);
}

.bomb-fab {
  position: absolute;
  right: max(14px, env(safe-area-inset-right, 0px));
  bottom: max(18px, env(safe-area-inset-bottom, 0px));
  pointer-events: auto;
  width: 78px;
  height: 78px;
  border: 2px solid rgba(255, 255, 255, 0.28);
  border-radius: 50%;
  background: rgba(192, 57, 43, 0.38);
  color: #fff;
  font-size: 1.85rem;
  cursor: pointer;
  opacity: 0.45;
  touch-action: none;
  transition: opacity 0.15s ease, transform 0.1s ease;
}

.bomb-fab:active,
.bomb-fab.is-active {
  opacity: 0.82;
  transform: scale(0.94);
  background: rgba(192, 57, 43, 0.62);
}

.overlay {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  background: rgba(8, 12, 18, 0.78);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 1000;
  box-sizing: border-box;
}

.overlay.is-open {
  display: flex;
}

.overlay-card {
  width: min(100%, 340px);
  margin: auto;
  background: #1e2a38;
  border: 2px solid #4a6078;
  border-radius: 16px;
  padding: 22px 18px;
  text-align: center;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}

.overlay-title {
  margin: 0 0 8px;
  font-size: 1.35rem;
  font-weight: 700;
  color: #7dcea0;
}

#lose-screen .overlay-title {
  color: #ff7a3a;
}

.overlay-text {
  margin: 0 0 16px;
  color: #c5d0dc;
}

.overlay-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.btn {
  appearance: none;
  border: none;
  border-radius: 10px;
  padding: 12px 18px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  background: #2ecc71;
  color: #102018;
}

.btn-secondary {
  background: #3a4a5c;
  color: #f2f5f8;
}

/* Класс mode-mobile ставит game.js (учитывает landscape телефона) */
body.mode-mobile {
  height: 100%;
  height: 100dvh;
  overflow: hidden;
}

body.mode-mobile .app {
  width: 100%;
  height: 100%;
  height: 100dvh;
  margin: 0;
  padding: 0;
  position: relative;
}

body.mode-mobile .top.hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 30;
  margin: 0;
  padding: 8px 12px;
  padding-top: max(8px, env(safe-area-inset-top, 0px));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(10, 14, 22, 0.55), transparent);
}

body.mode-mobile .hud-left {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

body.mode-mobile .title {
  font-size: 1rem;
  margin: 0;
}

body.mode-mobile .level-label {
  margin: 0;
  font-size: 0.82rem;
}

body.mode-mobile .status {
  font-size: 0.82rem;
  min-height: 0;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
}

body.mode-mobile .desktop-only {
  display: none;
}

body.mode-mobile .stage-wrap {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  background: #0f1620;
}

body.mode-mobile #game {
  width: 100%;
  height: 100%;
  max-width: none;
  object-fit: cover;
}

body.mode-mobile .joystick {
  left: max(18px, env(safe-area-inset-left, 0px));
  bottom: max(16px, env(safe-area-inset-bottom, 0px));
}

body.mode-mobile .bomb-fab {
  right: max(22px, env(safe-area-inset-right, 0px));
  bottom: max(22px, env(safe-area-inset-bottom, 0px));
}

body.mode-mobile.mode-portrait .rotate-hint {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: #121821;
  padding: 24px;
  text-align: center;
}

.rotate-title {
  margin: 0 0 10px;
  font-size: 1.4rem;
  font-weight: 700;
}

.rotate-text {
  margin: 0;
  color: var(--muted);
  max-width: 260px;
  line-height: 1.4;
}

body.mode-mobile.mode-portrait .app,
body.mode-mobile.mode-portrait .mobile-controls {
  visibility: hidden;
}

body:not(.mode-mobile) .mobile-controls {
  display: none;
}

body:not(.mode-mobile) .rotate-hint {
  display: none !important;
}
