/* Use border-box globally to avoid unexpected overflow from padding/borders */
*, *::before, *::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  /* Prevent global scrollbars — inner panels manage their own scrolling */
  overflow: hidden;
}

body.maze-page {
  background:
    radial-gradient(circle at top, #1c2733 0%, #0a0f15 55%, #06080c 100%);
  color: #e8eef6;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

canvas {
  display: block;
}

.canvas-stage {
  position: relative;
  height: 100%;
}

.maze-layout {
  width: 100vw;
  padding: 12px; /* use padding instead of margin to avoid adding to viewport height */
  display: grid;
  grid-template-columns: 1fr;
  gap: 0;
  align-items: start;
  min-height: 100vh;
  box-sizing: border-box;
}

.maze-layout > .panel:first-child {
  margin: 0;
  border-radius: 16px;
  height: calc(100vh - 24px); /* accounts for container padding */
}

.panel {
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 16px;
  background: rgba(7, 12, 18, 0.72);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
  overflow: hidden;
}

.panel-label {
  padding: 10px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #93a4b8;
}

#renderCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

.canvas-hud {
  position: absolute;
  top: 14px;
  left: 14px;
  z-index: 2;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(6, 10, 15, 0.72);
  border: 1px solid rgba(121, 174, 242, 0.3);
  backdrop-filter: blur(8px);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.28);
  pointer-events: none;
}

.canvas-hud-label {
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #93a4b8;
  margin-bottom: 4px;
}

.canvas-hud-value {
  font-size: 22px;
  font-weight: 700;
  line-height: 1;
  color: #eef5ff;
  text-shadow: 0 0 12px rgba(121, 174, 242, 0.35);
  transition: all 0.2s ease;
}

.canvas-hud-value.low-time {
  color: #ff4444;
  text-shadow: 0 0 16px rgba(255, 68, 68, 0.6);
  animation: pulse-warning 0.6s infinite;
}

@keyframes pulse-warning {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.7;
  }
}

.canvas-hud-row {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 11px;
  color: #dbe6f2;
}

.canvas-hud-row span {
  color: #93a4b8;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.canvas-hud-row strong {
  color: #79aef2;
  font-weight: 600;
}

.game-over-overlay {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: rgba(0, 0, 0, 0.78);
  text-align: center;
  padding: 20px;
}

.game-over-overlay[hidden] {
  display: none;
}

.p5-particles-container {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}

.p5-game-over-panel {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  background: rgba(0, 0, 0, 0.95);
  z-index: 9999;
}

.p5-game-over-panel[hidden] {
  display: none;
  pointer-events: none;
}

.p5-start-panel {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  background: rgba(0, 0, 0, 0.95);
  z-index: 9999;
}

.p5-start-panel[hidden] {
  display: none;
  pointer-events: none;
}

.p5-sketch-container {
  position: relative;
  width: 100%;
  height: 100%;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.game-over-info {
  position: relative;
  z-index: 10;
  text-align: center;
  padding: 20px;
}

.game-over-info .game-over-text {
  margin-top: 0;
  font-size: clamp(24px, 4vw, 40px);
  font-weight: 700;
  color: #f3f7ff;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.game-over-info .game-over-subtext {
  font-size: 14px;
  color: #c9d8ea;
  letter-spacing: 0.05em;
}

.game-over-image {
  width: min(70%, 460px);
  max-height: 52vh;
  object-fit: contain;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.45);
}

.game-over-text {
  margin-top: 4px;
  font-size: clamp(24px, 4vw, 40px);
  font-weight: 700;
  color: #f3f7ff;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.game-over-subtext {
  font-size: 14px;
  color: #c9d8ea;
  letter-spacing: 0.05em;
}

.control-panel {
  padding: 16px;
  overflow-y: auto;
  max-height: 400px;
}

#control-panel-section {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  width: 100%;
  margin: 0;
  border-radius: 16px 16px 0 0;
  max-height: 40vh;
  overflow-y: auto;
  z-index: 1000;
}

.control-group {
  margin-bottom: 20px;
}

.control-group h3 {
  margin: 0 0 12px;
  font-size: 13px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: #93a4b8;
  font-weight: 600;
}

.button-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.game-button {
  padding: 10px 16px;
  background: #17314c;
  border: 1px solid #284055;
  border-radius: 8px;
  color: #eef5ff;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  flex: 1;
  min-width: 100px;
}

.game-button:hover {
  background: #1f3a57;
  border-color: #3a5070;
  box-shadow: 0 4px 12px rgba(125, 180, 255, 0.15);
}

.game-button:active {
  background: #17314c;
  border-color: #7db4ff;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.3);
}

.slider-group {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  font-size: 13px;
  color: #dbe6f2;
}

.slider-group label {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
}

.slider-group input[type="range"] {
  flex: 1;
  min-width: 100px;
  height: 6px;
  background: #1f3a57;
  border: none;
  border-radius: 3px;
  outline: none;
  -webkit-appearance: none;
  cursor: pointer;
}

.slider-group input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  background: #79aef2;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(121, 174, 242, 0.4);
}

.slider-group input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  background: #79aef2;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(121, 174, 242, 0.4);
}

.slider-group span {
  min-width: 30px;
  text-align: right;
  color: #79aef2;
  font-weight: 500;
}

.status-display {
  background: rgba(25, 40, 55, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  padding: 12px;
  font-size: 12px;
}

.status-line {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  color: #dbe6f2;
}

.status-line strong {
  color: #93a4b8;
  min-width: 60px;
}

.status-line span {
  color: #79aef2;
  font-weight: 500;
}

.status-message {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  color: #91a4b8;
  font-size: 11px;
  line-height: 1.5;
}

@media (max-width: 720px) {
  .maze-layout {
    width: calc(100vw - 16px);
    margin: 8px auto 16px;
    grid-template-columns: 1fr;
  }

  #renderCanvas {
    height: 52vh;
  }
}
