/* ---- Reset & base ---- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: #1a2a10;
  color: #f0ead8;
  height: 100dvh;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

/* ---- Screens ---- */
.screen {
  display: none;
  width: 100%;
  height: 100dvh;
}

.screen.active {
  display: flex;
  flex-direction: column;
}

/* ---- Main menu ---- */
#screen-menu {
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #2a4a14 0%, #1a2a08 100%);
}

.menu-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
  padding: 2rem;
  width: 100%;
  max-width: 340px;
}

.menu-logo {
  font-size: 5rem;
  line-height: 1;
  filter: drop-shadow(0 4px 12px rgba(0,0,0,0.5));
  animation: sway 3s ease-in-out infinite;
}

@keyframes sway {
  0%, 100% { transform: rotate(-6deg); }
  50% { transform: rotate(6deg); }
}

.menu-title {
  font-size: 2.8rem;
  font-weight: 900;
  letter-spacing: -0.5px;
  color: #f0e060;
  text-shadow: 0 2px 8px rgba(0,0,0,0.6);
}

.menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  width: 100%;
}

/* ---- Buttons ---- */
.btn-primary {
  display: block;
  width: 100%;
  padding: 1rem 1.5rem;
  background: #f0c030;
  color: #2a1a00;
  border: none;
  border-radius: 14px;
  font-size: 1.2rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 0 #b08010, 0 6px 16px rgba(0,0,0,0.35);
  transition: transform 0.08s, box-shadow 0.08s;
  letter-spacing: 0.2px;
}

.btn-primary:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #b08010, 0 2px 8px rgba(0,0,0,0.3);
}

.btn-secondary {
  display: block;
  width: 100%;
  padding: 0.9rem 1.5rem;
  background: #4a7030;
  color: #e8f0d0;
  border: 2px solid #6a9a48;
  border-radius: 14px;
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 0 #2a4018, 0 6px 16px rgba(0,0,0,0.3);
  transition: transform 0.08s, box-shadow 0.08s;
}

.btn-secondary:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #2a4018, 0 2px 8px rgba(0,0,0,0.25);
}

.btn-ghost {
  background: transparent;
  border: none;
  color: #a0c080;
  font-size: 0.95rem;
  cursor: pointer;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.btn-ghost:active {
  opacity: 0.6;
}

.btn-back {
  background: transparent;
  border: none;
  color: #c0d8a0;
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.2rem 0.6rem;
  border-radius: 8px;
  flex-shrink: 0;
}

.btn-back:active {
  background: rgba(255,255,255,0.1);
}

/* ---- Overlay screens (adventure / sandbox) ---- */
#screen-adventure,
#screen-sandbox {
  background: linear-gradient(160deg, #2a4a14 0%, #1a2a08 100%);
}

.overlay-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1rem 0.5rem;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  flex-shrink: 0;
}

.overlay-header h2 {
  font-size: 1.4rem;
  font-weight: 700;
  color: #f0e060;
}

.overlay-footer {
  padding: 1rem;
  border-top: 1px solid rgba(255,255,255,0.08);
  display: flex;
  justify-content: center;
  flex-shrink: 0;
}

/* ---- Mission list ---- */
.mission-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.mission-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 1rem 1.2rem;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 12px;
  color: #e8f0d8;
  font-size: 1.05rem;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  transition: background 0.12s;
}

.mission-btn:active {
  background: rgba(255,255,255,0.12);
}

.mission-btn.done {
  border-color: #78c040;
  color: #a0e060;
}

.mission-btn.locked {
  opacity: 0.4;
  cursor: not-allowed;
}

.mission-btn:disabled {
  cursor: not-allowed;
}

.mission-check {
  display: inline-block;
  width: 1.4em;
  text-align: center;
  color: #78c040;
  font-weight: 900;
}

/* ---- Sandbox form ---- */
.sandbox-form {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.sandbox-form label {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  font-size: 0.95rem;
  color: #c0d8a0;
  font-weight: 500;
}

.slider-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.slider-row input[type="range"] {
  flex: 1;
  accent-color: #f0c030;
  height: 6px;
}

.slider-val {
  min-width: 2.5em;
  text-align: right;
  color: #f0e060;
  font-weight: 700;
  font-size: 1.05rem;
}

.checkbox-label {
  flex-direction: row !important;
  align-items: center;
  gap: 0.6rem !important;
}

.checkbox-label input[type="checkbox"] {
  width: 1.2rem;
  height: 1.2rem;
  accent-color: #f0c030;
  flex-shrink: 0;
}

.sub-field {
  padding-left: 1.8rem;
}

.env-select {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 8px;
  color: #f0ead8;
  padding: 0.45rem 0.6rem;
  font-size: 1rem;
  width: 100%;
}

.num-input {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 8px;
  color: #f0ead8;
  padding: 0.4rem 0.6rem;
  font-size: 1rem;
  width: 5rem;
}

.pos-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

/* ---- Game screen ---- */
#screen-game {
  background: #101810;
}

#hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
  height: 48px;
  background: rgba(0,0,0,0.55);
  flex-shrink: 0;
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: #f0e8c0;
}

#hud-timer {
  color: #f0e060;
}

#hud-timer.timer-low {
  color: #ff5040;
  animation: pulse 0.6s ease-in-out infinite alternate;
}

@keyframes pulse {
  from { opacity: 1; }
  to { opacity: 0.5; }
}

#canvas-wrap {
  flex: 1;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #101810;
  touch-action: none;
}

#game-canvas {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  cursor: crosshair;
  touch-action: none;
}

#action-bar {
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 1rem;
  background: rgba(0,0,0,0.55);
  flex-shrink: 0;
}

.btn-action {
  width: 100%;
  max-width: 360px;
  padding: 1rem;
  border: none;
  border-radius: 14px;
  font-size: 1.15rem;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 0.3px;
  background: #f0c030;
  color: #2a1a00;
  box-shadow: 0 4px 0 #b08010, 0 6px 16px rgba(0,0,0,0.4);
  transition: transform 0.08s, box-shadow 0.08s, background 0.12s, opacity 0.12s;
}

.btn-action:active:not(:disabled) {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #b08010, 0 2px 8px rgba(0,0,0,0.3);
}

.btn-action.dimmed {
  background: #404840;
  color: #708060;
  box-shadow: 0 2px 0 #252c20, 0 4px 10px rgba(0,0,0,0.35);
  cursor: default;
}

/* ---- End screens ---- */
#screen-win,
#screen-lose {
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #2a4a14 0%, #1a2a08 100%);
}

.end-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.2rem;
  padding: 2rem;
  width: 100%;
  max-width: 340px;
  text-align: center;
}

.end-icon {
  font-size: 4.5rem;
  line-height: 1;
}

.end-inner h2 {
  font-size: 2.2rem;
  font-weight: 900;
  color: #f0e060;
  text-shadow: 0 2px 8px rgba(0,0,0,0.5);
}

.end-inner p {
  font-size: 1.1rem;
  color: #c0d8a0;
}

.end-buttons {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  width: 100%;
  margin-top: 0.5rem;
}
