:root {
  --bg: #0d1117;
  --panel: rgba(0,0,0,0.35);
  --text: #e6edf3;
  --accent: #2ea043;
  --warn: #f39c12;
  --bad: #e5534b;
  /* Telegram theme overrides */
  --tg-bg: var(--bg);
  --tg-text: var(--text);
  --tg-accent: var(--accent);
}

html, body {
  height: 100%;
  overflow: hidden;
  touch-action: none;            /* disable default swipe/scroll/pinch */
  overscroll-behavior: none;     /* prevent “bounce” on drag */
  -webkit-user-select: none;     /* prevent accidental text selection */
  user-select: none;
}

html, body, #gameCanvas, #start-screen {
  -webkit-user-select: none;
  -webkit-touch-callout: none; /* disables iOS copy/save popup */
  -webkit-user-drag: none;
  user-select: none;
  touch-action: manipulation;  /* prevents long-press zoom/context menus */
}

canvas, #game {
  touch-action: none;            /* ensure the game area captures touches */
}

body {
  margin: 0;
  background: var(--tg-bg);
  color: var(--tg-text);
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

#game-root {
  position: fixed;
  inset: 0;
  width: 100dvw;
  height: 100dvh;
  overflow: hidden;
}

#gameCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
  z-index: 0;
  /* no background; we draw full-frame in JS */
}

[hidden] { display: none !important; }

/* Full-screen overlays */
.overlay-screen {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  background: linear-gradient(180deg, rgba(0,0,0,0.35), rgba(0,0,0,0.55));
  z-index: 10;
  pointer-events: auto;
}

.overlay-screen:not([hidden]) { display: grid; }

.overlay-panel {
  width: min(92vw, 560px);
  padding: clamp(16px, 4vw, 28px);
  background: color-mix(in srgb, var(--panel), transparent 20%);
  backdrop-filter: blur(6px) saturate(1.1);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 16px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.35);
  text-align: center;
}

.overlay-title,
.start-title {
  margin: 0 0 12px;
  font-family: 'Press Start 2P', system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  font-size: clamp(22px, 4.6vw, 34px);
  line-height: 1.2;
  color: #fff;
  text-shadow: 0 2px 0 rgba(0,0,0,0.25);
}

.overlay-message {
  margin: 0;
  font-family: 'Press Start 2P', system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  font-size: clamp(13px, 2.6vw, 16px);
  color: rgba(255,255,255,0.9);
}

.start-panel {
  text-align: center;
}

.start-intro {
  margin: 0 0 18px;
  font-size: clamp(13px, 2.6vw, 16px);
  color: rgba(255,255,255,0.9);
}

.start-btn {
  --btn-bg: var(--tg-accent);
  appearance: none;
  border: 0;
  border-radius: 12px;
  padding: 14px 20px;
  width: min(260px, 70%);
  font-family: 'Press Start 2P', system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  font-size: clamp(14px, 3.6vw, 16px);
  color: #0c2614;
  background: linear-gradient(180deg, color-mix(in srgb, var(--btn-bg), white 18%), var(--btn-bg));
  box-shadow: 0 6px 0 color-mix(in srgb, var(--btn-bg), black 40%), 0 10px 24px rgba(0,0,0,0.35);
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease, filter 120ms ease;
}
.start-btn:hover { filter: brightness(1.05); }
.start-btn:active {
  transform: translateY(2px);
  box-shadow: 0 4px 0 color-mix(in srgb, var(--btn-bg), black 40%), 0 8px 18px rgba(0,0,0,0.35);
}

/* Alternative button style used for small dialog/confirm buttons where the
   green underside (from --btn-bg) is undesirable. Uses neutral gray tones. */
.alt-btn {
  appearance: none;
  border: 0;
  border-radius: 10px;
  padding: 8px 12px;
  font-family: 'Press Start 2P', system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  font-size: clamp(12px, 3.2vw, 14px);
  color: #ffffff;
  background: linear-gradient(180deg, color-mix(in srgb, #666, white 10%), #666);
  box-shadow: 0 6px 0 rgba(0,0,0,0.45), 0 10px 18px rgba(0,0,0,0.32);
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease, filter 120ms ease;
}
.alt-btn:hover { filter: brightness(1.05); }
.alt-btn:active {
  transform: translateY(2px);
  box-shadow: 0 4px 0 rgba(0,0,0,0.45), 0 8px 16px rgba(0,0,0,0.30);
}

/* Exit button (floating) */
.exit-btn {
  position: fixed;
  left: 12px;
  top: 12px;
  z-index: 9999;
  padding: 8px 10px;
  border-radius: 8px;
  border: none;
  background: #af1c1c;
  color: #fff;
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
}
.exit-btn:hover { filter: brightness(1.1); }
.exit-btn:active { transform: translateY(1px); box-shadow: 0 2px 0 rgba(133, 8, 8, 0.45); }

/* Alt button modifiers */
.alt-btn--danger { background: #d9534f; }
.alt-btn--secondary { background: #666; }

/* Exit confirm screen should sit above other overlays */
.exit-confirm-screen { z-index: 10000; }

/* Debug tools */
.debug-toggle {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 11010;
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(13, 17, 23, 0.82);
  color: #f5f5f5;
  font-size: 12px;
  font-family: inherit;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.debug-toggle:hover { background: rgba(28, 34, 43, 0.92); border-color: rgba(255, 255, 255, 0.35); }
.debug-toggle:active { transform: translateY(1px); }

.debug-panel {
  position: fixed;
  top: 50px;
  right: 12px;
  width: 240px;
  padding: 14px 16px 16px;
  border-radius: 12px;
  background: rgba(13, 17, 23, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.16);
  box-shadow: 0 18px 36px rgba(0, 0, 0, 0.45);
  color: #f6f8fa;
  font-size: 13px;
  z-index: 11020;
  display: flex;
  flex-direction: column;
  gap: 12px;
  /* make panel responsive on small screens */
  box-sizing: border-box;
  /* prefer a compact fixed width where possible but allow shrinking */
  width: auto;
  max-width: 320px;
  min-width: 180px;
  overflow: visible;
}

.debug-panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.85);
}

.debug-panel__header button {
  border: none;
  background: transparent;
  color: inherit;
  font-size: 18px;
  line-height: 1;
  padding: 2px 6px;
  cursor: pointer;
  border-radius: 6px;
}
.debug-panel__header button:hover { background: rgba(255, 255, 255, 0.12); }

.debug-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.debug-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.72);
}

.debug-form input[type="number"] {
  box-sizing: border-box;
  width: 100%;
  max-width: 100%;
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.08);
  color: #f6f8fa;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.debug-form label {
  /* ensure long labels wrap instead of forcing panel wider */
  word-break: break-word;
  hyphens: auto;
}

.debug-actions button {
  /* allow buttons to shrink on narrow screens */
  min-width: 0;
}

/* Mobile-specific adjustments: make the panel fill available width with margins */
@media (max-width: 480px) {
  .debug-panel {
    left: 12px;
    right: 12px;
    width: calc(100% - 24px);
    max-width: none;
    padding: 10px;
    font-size: 13px;
  }

  .debug-form label {
    font-size: 12px;
  }

  .debug-form input[type="number"] {
    font-size: 13px;
  }

  .debug-actions {
    gap: 6px;
  }
}
.debug-form input[type="number"]:focus {
  border-color: rgba(147, 197, 253, 0.8);
  background: rgba(147, 197, 253, 0.18);
}

.debug-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.debug-actions button {
  flex: 1 1 auto;
  padding: 6px 8px;
  border-radius: 6px;
  border: none;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: rgba(147, 197, 253, 0.28);
  color: #fff;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}
.debug-actions button:hover { background: rgba(147, 197, 253, 0.45); }
.debug-actions button:active { transform: translateY(1px); }
.debug-actions button[data-action="refresh"] { background: rgba(255, 255, 255, 0.2); }
.debug-actions button[data-action="refresh"]:hover { background: rgba(255, 255, 255, 0.32); }
.debug-actions button[data-action="max"] { background: rgba(76, 217, 100, 0.35); }
.debug-actions button[data-action="max"]:hover { background: rgba(76, 217, 100, 0.5); }

.debug-hint {
  margin: 0;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(255, 255, 255, 0.55);
  text-align: right;
}

@media (max-width: 420px) {
  .overlay-panel { border-radius: 14px; }
  .start-btn { border-radius: 10px; }
}

@media (max-width: 520px) {
  .overlay-screen {
    padding-inline: 10vw;       /* adds space left & right relative to screen width */
    box-sizing: border-box;     /* ensures no overflow */
  }

  .overlay-panel {
    width: 100%;                /* fill the padded area, not full viewport */
    max-width: 480px;           /* optional cap */
  }
}
