:root {
  color-scheme: dark;
  font-family: "Courier New", Consolas, monospace;
  background: #05070e;
  color: #f3f6ff;
  --app-height: 100vh;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  touch-action: none;
  background: #05070e;
}

button,
input,
textarea,
select {
  font: inherit;
}

.app {
  position: relative;
  width: 100%;
  height: var(--app-height);
  min-height: 100vh;
  overflow: hidden;
  background: #05070e;
}

#gameCanvas {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
  cursor: none;
}

.screen-noise {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  pointer-events: none;
  z-index: 1;
  opacity: 0.12;
  background:
    linear-gradient(to bottom, rgba(255, 255, 255, 0.02) 0, rgba(255, 255, 255, 0.02) 1px, transparent 1px, transparent 3px),
    linear-gradient(to right, rgba(255, 255, 255, 0.02) 0, rgba(255, 255, 255, 0.02) 1px, transparent 1px, transparent 2px);
  background-size: 100% 3px, 2px 100%;
}

.overlay {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: center;
  padding:
    calc(var(--safe-top) + 20px)
    calc(var(--safe-right) + 20px)
    calc(var(--safe-bottom) + 20px)
    calc(var(--safe-left) + 20px);
  background: rgba(5, 7, 14, 0.42);
}

.menu {
  flex-direction: column;
}

.hidden {
  display: none;
}

.debug-panel {
  position: absolute;
  left: calc(var(--safe-left) + 10px);
  right: calc(var(--safe-right) + 10px);
  bottom: calc(var(--safe-bottom) + 10px);
  z-index: 7;
  padding: 10px 12px;
  border: 2px solid #ff4d8d;
  background: rgba(10, 14, 28, 0.94);
  color: #f3f6ff;
  font-size: 12px;
  line-height: 1.4;
  pointer-events: none;
}

.debug-panel strong {
  display: block;
  margin-bottom: 6px;
  color: #ffd166;
}

.debug-panel pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font: inherit;
}

.title-stack {
  width: min(100%, 560px);
  text-align: center;
  display: grid;
  gap: 10px;
  justify-items: center;
}

.mode-line {
  margin: 0;
  color: #ffd166;
  font-size: 14px;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
  line-height: 1;
}

h1 {
  font-size: clamp(54px, 11vw, 110px);
  color: #f3f6ff;
  text-shadow:
    0 0 0 #f3f6ff,
    4px 4px 0 #ff4d8d,
    -4px -4px 0 #47f0ff;
}

h2 {
  font-size: clamp(32px, 8vw, 56px);
}

.subtitle {
  margin: 0;
  color: #47f0ff;
  font-size: clamp(20px, 4vw, 28px);
}

.title-actions {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}

.pixel-panel {
  position: relative;
  width: min(860px, 100%);
  max-height: min(100%, calc(var(--app-height) - var(--safe-top) - var(--safe-bottom) - 40px));
  padding: 24px;
  border: 4px solid #47f0ff;
  background: rgba(10, 14, 28, 0.96);
  box-shadow:
    0 0 0 4px rgba(255, 77, 141, 0.22),
    0 18px 60px rgba(0, 0, 0, 0.5);
  overflow: auto;
}

.compact-panel {
  max-width: 520px;
  text-align: center;
}

.rules-panel {
  max-width: 680px;
}

.level-panel {
  max-width: 920px;
}

.eyebrow,
.summary-lead {
  margin: 0 0 12px;
  color: rgba(243, 246, 255, 0.74);
}

.menu-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 18px;
  justify-content: center;
}

.pixel-button {
  min-width: 176px;
  min-height: 48px;
  padding: 10px 14px;
  border: 3px solid #d9e2ff;
  background: #0b1020;
  color: #f3f6ff;
  cursor: pointer;
  box-shadow:
    inset 0 -3px 0 rgba(0, 0, 0, 0.38),
    0 0 0 1px rgba(255, 255, 255, 0.06);
}

.pixel-button:hover {
  border-color: #47f0ff;
  color: #47f0ff;
}

.pixel-button:active {
  transform: translateY(1px);
}

.pixel-button.primary {
  border-color: #ffffff;
  background: #151d35;
  color: #ffffff;
}

.pixel-button.large {
  min-width: 240px;
  min-height: 58px;
  animation: blink 1s steps(2, jump-none) infinite;
}

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

.summary-card {
  border: 2px solid rgba(71, 240, 255, 0.34);
  padding: 12px;
}

.summary-label {
  display: block;
  color: rgba(243, 246, 255, 0.72);
  font-size: 12px;
}

.summary-value {
  display: block;
  margin-top: 6px;
  color: #ffd166;
  font-size: 28px;
}

.upgrade-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-top: 20px;
}

.upgrade-card {
  width: 100%;
  border: 3px solid rgba(71, 240, 255, 0.34);
  background: #0e1324;
  color: #f3f6ff;
  padding: 16px;
  text-align: left;
  cursor: pointer;
}

.upgrade-card:hover {
  border-color: #ffd166;
}

.upgrade-rarity {
  display: inline-block;
  margin-bottom: 10px;
  color: #ffd166;
  font-size: 12px;
}

.upgrade-title {
  display: block;
  margin-bottom: 8px;
  font-size: 18px;
}

.upgrade-desc {
  display: block;
  color: rgba(243, 246, 255, 0.78);
  line-height: 1.6;
  font-size: 14px;
}

.rules-list {
  margin: 18px 0 22px;
  padding-left: 20px;
  color: rgba(243, 246, 255, 0.82);
  line-height: 1.8;
}

@keyframes blink {
  0%,
  49% {
    filter: brightness(1);
  }

  50%,
  100% {
    filter: brightness(1.3);
  }
}

@media (max-width: 860px) {
  .upgrade-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 680px) {
  .summary-grid {
    grid-template-columns: 1fr;
  }

  .overlay {
    padding:
      calc(var(--safe-top) + 14px)
      calc(var(--safe-right) + 14px)
      calc(var(--safe-bottom) + 14px)
      calc(var(--safe-left) + 14px);
  }

  .title-actions,
  .menu-actions {
    flex-direction: column;
    width: 100%;
  }

  .pixel-button {
    width: 100%;
  }

  .pixel-panel {
    max-height: min(100%, calc(var(--app-height) - var(--safe-top) - var(--safe-bottom) - 28px));
  }
}
