/* ============================================================
   Save the Blades 2: Mower Run — Level 2 CSS
   Isolated from Level 1. All selectors prefixed with .mr-
   ============================================================ */

:root {
  --mr-green-bg:  #1a3320;
  --mr-green-mid: #2d5a38;
  --mr-yellow:    #f5c518;
  --mr-radius:    10px;
}

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

body {
  background: var(--mr-green-bg);
  font-family: system-ui, -apple-system, sans-serif;
  color: #e8f5e9;
  min-height: 100vh;
}

/* ---- Page wrapper ---- */
.mr-wrap {
  max-width: 500px;
  margin: 0 auto;
  padding: 12px 12px 28px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ---- Back link ---- */
.mr-back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  min-height: 40px;
  color: #81c784;
  font-weight: 800;
  font-size: 0.88rem;
  text-decoration: none;
  transition: color 0.12s;
}
.mr-back-link:hover,
.mr-back-link:focus-visible {
  color: #a5d6a7;
  text-decoration: underline;
}
.mr-back-link:focus-visible {
  outline: 3px solid rgba(34,197,94,0.4);
  outline-offset: 3px;
  border-radius: 8px;
}

/* ---- Header ---- */
.mr-header { text-align: center; }

.mr-title {
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--mr-yellow);
  text-shadow: 0 2px 6px rgba(0,0,0,0.5);
  line-height: 1.1;
}

.mr-tagline {
  font-size: 0.84rem;
  color: #a5d6a7;
  margin-top: 4px;
  line-height: 1.4;
}

/* ---- HUD ---- */
.mr-hud {
  background: rgba(0,0,0,0.35);
  border-radius: var(--mr-radius);
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.mr-hud-top {
  display: flex;
  align-items: center;
  gap: 10px;
}

.mr-score-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
}

.mr-label {
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: #81c784;
}

.mr-score-val,
#mr-score,
#mr-best {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--mr-yellow);
  font-variant-numeric: tabular-nums;
}

.mr-mult-badge {
  display: none;
  background: #ff9800;
  color: #fff;
  font-size: 0.72rem;
  font-weight: 800;
  padding: 1px 6px;
  border-radius: 10px;
  margin-top: 1px;
}

/* ---- Health bars ---- */
.mr-health-bars {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.mr-health-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.mr-health-label {
  font-size: 0.72rem;
  font-weight: 700;
  color: #c8e6c9;
  white-space: nowrap;
  min-width: 62px;
}

.mr-bar-wrap {
  flex: 1;
  height: 10px;
  background: rgba(255,255,255,0.12);
  border-radius: 5px;
  overflow: hidden;
}

.mr-bar {
  height: 100%;
  width: 100%;
  border-radius: 5px;
  transition: width 0.22s ease, background-color 0.3s ease;
}

.mr-bar-blade { background: #4caf50; }
.mr-bar-tire  { background: #2196f3; }

.mr-pct {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--mr-yellow);
  font-variant-numeric: tabular-nums;
  min-width: 38px;
  text-align: right;
}

/* ---- Shield / status badges ---- */
.mr-shields {
  font-size: 0.72rem;
  color: #aed581;
  font-weight: 700;
  min-height: 14px;
  text-align: center;
}

/* ---- Mute button ---- */
.mr-mute-btn {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 6px;
  color: #c8e6c9;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 4px 10px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s;
}
.mr-mute-btn:hover { background: rgba(255,255,255,0.15); }

/* ---- Canvas wrapper ---- */
.mr-canvas-wrap {
  position: relative;
  width: 100%;
  max-width: 420px;
  margin: 0 auto;
  border-radius: var(--mr-radius);
  overflow: hidden;
  box-shadow: 0 4px 28px rgba(0,0,0,0.55);
  /* portrait 400:640 aspect ratio */
  aspect-ratio: 400 / 640;
  background: #3a8c3a;
  touch-action: none;
}

#mr-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  user-select: none;
}

/* ---- Overlay ---- */
.mr-overlay {
  position: absolute;
  inset: 0;
  background: rgba(14, 34, 14, 0.90);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  padding: 16px;
}

.mr-overlay-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  max-width: 320px;
  width: 100%;
  text-align: center;
}

.mr-overlay-inner h2 {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--mr-yellow);
  text-shadow: 0 2px 8px rgba(0,0,0,0.5);
  line-height: 1.15;
}

.mr-overlay-msg {
  font-size: 0.83rem;
  color: #c8e6c9;
  line-height: 1.5;
  width: 100%;
}

.mr-overlay-msg ul {
  list-style: none;
  margin: 8px 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.mr-overlay-msg li {
  font-size: 0.8rem;
  color: #a5d6a7;
}

/* ---- Buttons ---- */
.mr-btn {
  display: block;
  width: 100%;
  padding: 12px 18px;
  background: var(--mr-yellow);
  color: #1a3320;
  font-size: 1rem;
  font-weight: 800;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
  transition: background 0.12s, transform 0.08s;
}
.mr-btn:hover  { background: #ffe55c; transform: translateY(-1px); }
.mr-btn:active { transform: translateY(0); }

.mr-btn-cta {
  background: #4caf50;
  color: #fff;
}
.mr-btn-cta:hover { background: #66bb6a; }

.mr-btn-ghost {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.22);
  color: #c8e6c9;
  font-size: 0.85rem;
}
.mr-btn-ghost:hover { background: rgba(255,255,255,0.16); }

/* ---- End-screen score display ---- */
.mr-end-score {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--mr-yellow);
}
.mr-end-best {
  font-size: 0.9rem;
  color: #a5d6a7;
}
.mr-end-cause {
  font-size: 0.85rem;
  color: #ef9a9a;
  margin-top: 4px;
}

/* ---- Mobile tap controls ---- */
.mr-mobile-controls {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  pointer-events: none;
  z-index: 5;
  padding: 0 0 6px;
}

.mr-tap-btn {
  pointer-events: all;
  width: 80px;
  height: 60px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 8px;
  color: rgba(255,255,255,0.55);
  font-size: 1.4rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  margin: 0 6px;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: background 0.08s;
}
.mr-tap-btn:active {
  background: rgba(255,255,255,0.2);
}

/* ---- How-to-play details ---- */
.mr-howto {
  background: rgba(0,0,0,0.22);
  border-radius: var(--mr-radius);
  padding: 10px 14px;
  font-size: 0.83rem;
  color: #a5d6a7;
  line-height: 1.55;
}
.mr-howto summary {
  font-weight: 700;
  color: #c8e6c9;
  cursor: pointer;
  user-select: none;
  padding: 2px 0;
}
.mr-howto p { margin-top: 8px; }
.mr-howto ul {
  margin: 6px 0 0 14px;
}
.mr-howto li { margin-bottom: 2px; }

/* ---- Responsive ---- */
@media (max-width: 480px) {
  .mr-wrap { padding: 10px 8px 24px; }
  .mr-title { font-size: 1.45rem; }
  .mr-tap-btn { width: 72px; height: 52px; font-size: 1.2rem; }
}

@media (min-width: 500px) {
  /* On wider screens, allow slightly taller canvas area */
  .mr-canvas-wrap { max-width: 460px; }
}

/* ============================================================
   Active gameplay layout — applied via body.game-active when a
   level is running. Converts the page into a true arcade shell:
   no scrolling, compact HUD, canvas fills remaining viewport.
   Desktop: no changes (media query guards all rules below).
   ============================================================ */

@media (max-width: 640px) {

  /* Lock viewport to screen height — no page scroll during play */
  body.game-active {
    overflow: hidden;
    height: 100dvh;
    height: 100svh;
  }

  /* Stack wrapper fills the locked viewport exactly */
  body.game-active .mr-wrap {
    height: 100dvh;
    height: 100svh;
    max-width: none;
    overflow: hidden;
    padding-top: max(6px, env(safe-area-inset-top));
    padding-bottom: max(6px, env(safe-area-inset-bottom));
    padding-left: 0;
    padding-right: 0;
    gap: 0;
  }

  /* Hide all non-gameplay chrome while playing */
  body.game-active .mr-back-link,
  body.game-active .mr-header,
  body.game-active .mr-howto,
  body.game-active .mr-cta-section,
  body.game-active .game-ad-wrap {
    display: none !important;
  }

  /* ---- Compact arcade HUD ---- */
  body.game-active .mr-hud {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    padding: 4px 8px 3px;
    gap: 0 8px;
    border-radius: 0;
    flex-shrink: 0;
  }

  body.game-active .mr-hud-top {
    flex: 0 0 auto;
    gap: 6px;
    align-items: center;
  }

  body.game-active .mr-score-group {
    flex-direction: row;
    gap: 3px;
    align-items: baseline;
    flex: 0 0 auto;
  }

  body.game-active .mr-label {
    font-size: 0.58rem;
  }

  body.game-active #mr-score,
  body.game-active #mr-best {
    font-size: 0.92rem;
  }

  body.game-active .mr-mult-badge {
    font-size: 0.62rem;
    padding: 0 4px;
  }

  body.game-active .mr-mute-btn {
    font-size: 0.58rem;
    padding: 2px 6px;
    min-height: 0;
  }

  /* Health bars row — full width under the score row */
  body.game-active .mr-health-bars {
    flex: 1 1 100%;
    gap: 2px;
    margin-top: 2px;
  }

  body.game-active .mr-health-row {
    gap: 4px;
  }

  body.game-active .mr-health-label {
    font-size: 0.6rem;
    min-width: 42px;
  }

  body.game-active .mr-bar-wrap {
    height: 7px;
  }

  body.game-active .mr-pct {
    font-size: 0.62rem;
    min-width: 26px;
  }

  /* Shield badges — minimal line, hidden when empty */
  body.game-active .mr-shields {
    flex: 1 1 100%;
    font-size: 0.6rem;
    min-height: 0;
    padding: 0 4px;
    text-align: left;
  }

  /* ---- Canvas: fills all remaining viewport space ---- */
  body.game-active .mr-canvas-wrap {
    flex: 1 1 0;
    min-height: 0;
    width: 100%;
    max-width: none;
    /* Preserve portrait aspect ratio; flex height constrains it;
       max-width: 100% prevents overflow if height is generous */
    aspect-ratio: 400 / 640;
    align-self: center;
    border-radius: 4px;
    margin: 2px auto 0;
    /* Prevent the canvas from expanding past its container */
    max-height: 100%;
  }

  /* Ensure canvas fills its container regardless of its logical size */
  body.game-active #mr-canvas {
    width: 100%;
    height: 100%;
    display: block;
  }

  /* Make tap controls larger and easier to hit during active play */
  body.game-active .mr-tap-btn {
    width: 88px;
    height: 64px;
    font-size: 1.5rem;
    background: rgba(255,255,255,0.12);
  }
}
