* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  background: #1a1a22;
  color: #f2f2f2;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 1100px;
  margin: 0 auto;
}

#hud {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 12px;
  padding: 10px 14px;
  background: linear-gradient(#1c1c26, #121218);
  border-bottom: 1px solid #2a2a36;
  flex-shrink: 0;
}

#title {
  font-weight: 800;
  letter-spacing: -0.02em;
  color: #ff5c5c;
}

#levels {
  display: flex;
  gap: 4px;
}

#levels button {
  padding: 4px 7px;
  font-size: 11px;
  background: #2a2a36;
}

#levels button.on,
#sandbox-mats button.on,
#difficulty button.on,
#player-collision button.on {
  background: #ff5c5c;
}

#stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 220px;
  display: flex;
  flex-direction: column;
}

#held-item {
  position: absolute;
  z-index: 3;
  top: 32px;
  right: 10px;
  pointer-events: auto;
  background: rgba(18, 18, 24, 0.82);
  color: #fff;
  font-size: 13px;
  font-weight: 800;
  padding: 4px 8px;
  border-radius: 8px;
  white-space: nowrap;
}

#btn-fire {
  position: absolute;
  z-index: 4;
  left: 12px;
  right: auto;
  bottom: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 96px;
  min-height: 76px;
  padding: 10px 18px;
  border: 3px solid #ff5c5c;
  border-radius: 18px;
  background: #1a1a22;
  color: #fff;
  line-height: 1.1;
  opacity: 0.5;
  touch-action: manipulation;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.35);
}

#btn-fire .fire-kicker {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

#btn-fire .fire-sub {
  font-size: 12px;
  font-weight: 700;
  opacity: 1;
  max-width: 9.5em;
}

#btn-fire:active {
  transform: scale(0.97);
  background: #2a2a36;
}

@media (pointer: coarse) {
  #btn-fire {
    min-width: 112px;
    min-height: 88px;
    left: 14px;
    right: auto;
    bottom: 14px;
  }
  #btn-fire .fire-kicker {
    font-size: 22px;
  }
}

#sandbox-mats {
  position: absolute;
  z-index: 3;
  top: 8px;
  left: 10px;
  width: max-content;
  max-width: calc(100% - 20px);
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  pointer-events: none;
}

#sandbox-mats button,
#difficulty button,
#player-collision button {
  padding: 4px 7px;
  font-size: 11px;
  background: #2a2a36;
  pointer-events: auto;
}

#hint {
  flex: 1;
  font-size: 13px;
  opacity: 0.85;
}

#fps {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  opacity: 0.85;
  min-width: 92px;
  text-align: right;
}

#race-time {
  font-size: 13px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  min-width: 64px;
  text-align: right;
}

#status {
  font-size: 13px;
  font-weight: 600;
  min-width: 120px;
  text-align: right;
}

#game {
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
  display: block;
  background: #87b8e8;
  cursor: crosshair;
}

#draw-area {
  flex: 0 0 auto;
  background: #16161e;
  border-top: 1px solid #2a2a36;
  padding: 8px 12px 12px;
}

#draw-label {
  font-size: 12px;
  opacity: 0.7;
  margin-bottom: 2px;
}

#erase-hint {
  font-size: 12px;
  opacity: 0.7;
  margin: 0 0 6px;
}

#pad {
  width: 100%;
  height: 160px;
  display: block;
  background: #f7f4ec;
  border: 2px solid #d7d0c3;
  border-radius: 12px;
  cursor: crosshair;
  touch-action: none;
  box-shadow: inset 0 1px 0 #fff;
}

#manual-hint {
  font-size: 12px;
  font-weight: 700;
  color: #ffd27a;
  margin: 0 0 6px;
}

#presets {
  display: flex;
  gap: 4px;
  margin-top: 8px;
  flex-wrap: wrap;
}

#presets button {
  padding: 4px 8px;
  font-size: 12px;
  background: #2a2a36;
}

#presets button.on {
  background: #245c38;
}

#draw-controls {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  align-items: center;
  flex-wrap: wrap;
}

#difficulty,
#player-collision,
#drive-mode {
  display: flex;
  gap: 4px;
  align-items: center;
}

.ctl-label {
  font-size: 11px;
  font-weight: 700;
  opacity: 0.85;
  white-space: nowrap;
}

#drive-mode button.on {
  background: #ff5c5c;
}

#seed-box {
  display: flex;
  gap: 4px;
  align-items: center;
}

#seed-input {
  width: 7.2em;
  border: none;
  border-radius: 8px;
  padding: 6px 8px;
  font: 700 13px ui-monospace, monospace;
  letter-spacing: 0.04em;
  background: #f7f4ec;
  color: #1a1a22;
}

#seed-box button {
  padding: 6px 10px;
  font-size: 12px;
}

#overlay-time {
  font-size: 36px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  margin: 0 0 8px;
  color: #ffd166;
}

button {
  appearance: none;
  border: none;
  border-radius: 8px;
  padding: 8px 16px;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  background: #2e2e3a;
  color: #fff;
}

button:hover {
  background: #3c3c4c;
}

#btn-again, #btn-restart {
  background: #ff4d4d;
}

#btn-again:hover, #btn-restart:hover {
  background: #ff6a6a;
}

#btn-next {
  background: #245c38;
}

#btn-next:hover {
  background: #2f7a4a;
}

#overlay-card .actions {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.hidden {
  display: none !important;
}

#overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
}

#overlay-card {
  background: #1e1e28;
  border: 1px solid #3a3a4a;
  border-radius: 14px;
  padding: 24px 28px;
  text-align: center;
  min-width: 260px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}

#overlay-card h2 {
  margin-bottom: 8px;
  font-size: 28px;
}

#overlay-card p {
  margin-bottom: 16px;
  opacity: 0.85;
}

@media (max-width: 640px) {
  #hud {
    flex-wrap: wrap;
    gap: 4px 12px;
  }
  #hint {
    flex-basis: 100%;
    font-size: 12px;
  }
  #status {
    min-width: 0;
  }
}

@media (max-height: 700px) {
  #pad {
    height: 120px;
  }
}
