:root {
  --stb-green-bg: #1a3320;
  --stb-yellow: #f5c518;
  --stb-radius: 10px;
}

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

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

.stb-wrap {
  max-width: 760px;
  margin: 0 auto;
  padding: 14px 14px 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

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

@media (max-width: 640px) {
  .stb-back-link {
    min-height: 44px;
    font-size: 0.9rem;
    padding: 0.2rem 0;
  }
}

/* End-screen "Back to mowNWA.com" in overlay */
.stb-overlay-back {
  display: block;
  margin-top: 12px;
  color: rgba(200, 230, 201, 0.7);
  font-size: 0.82rem;
  font-weight: 600;
  text-decoration: none;
  text-align: center;
  transition: color 0.12s;
}
.stb-overlay-back:hover,
.stb-overlay-back:focus-visible {
  color: #c8e6c9;
  text-decoration: underline;
}
.stb-overlay-back:focus-visible {
  outline: 2px solid rgba(165, 214, 167, 0.5);
  outline-offset: 3px;
  border-radius: 6px;
}
.stb-overlay-back.hidden { display: none !important; }

/* Level 2 link inside overlay — always visible */
.stb-level2-link {
  display: block;
  margin-top: 10px;
  padding: 9px 18px;
  background: rgba(245, 197, 24, 0.15);
  border: 1px solid rgba(245, 197, 24, 0.45);
  border-radius: 8px;
  color: #f5c518;
  font-size: 0.88rem;
  font-weight: 700;
  text-decoration: none;
  text-align: center;
  transition: background 0.14s, color 0.14s;
}
.stb-level2-link:hover,
.stb-level2-link:focus-visible {
  background: rgba(245, 197, 24, 0.28);
  color: #ffe566;
  text-decoration: none;
}
.stb-level2-link:focus-visible {
  outline: 2px solid rgba(245, 197, 24, 0.6);
  outline-offset: 3px;
  border-radius: 8px;
}

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

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

.stb-subtitle {
  font-size: 0.88rem;
  color: #a5d6a7;
  margin-top: 4px;
  line-height: 1.4;
}

/* HUD */
.stb-hud {
  display: flex;
  gap: 8px;
  align-items: center;
  background: rgba(0,0,0,0.35);
  border-radius: var(--stb-radius);
  padding: 8px 14px;
  flex-wrap: wrap;
}

.stb-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  flex: 1;
  min-width: 72px;
}

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

.stb-stat-val {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--stb-yellow);
  font-variant-numeric: tabular-nums;
}

.stb-health { flex: 2; }

.stb-health-bar-wrap {
  width: 100%;
  height: 8px;
  background: rgba(255,255,255,0.12);
  border-radius: 4px;
  overflow: hidden;
  margin: 2px 0;
}

.stb-health-bar {
  height: 100%;
  width: 100%;
  background: #4caf50;
  border-radius: 4px;
  transition: width 0.2s ease, background-color 0.3s ease;
}

/* Canvas wrapper — desktop aspect ratio; overridden to portrait on mobile */
.stb-canvas-wrap {
  position: relative;
  width: min(100%, 720px);
  margin: 0 auto;
  border-radius: var(--stb-radius);
  overflow: hidden;
  box-shadow: 0 4px 28px rgba(0,0,0,0.55);
  aspect-ratio: 700 / 480;
  background: #4a9652;
}

#stbCanvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: pointer;
}

/* Overlay */
.stb-overlay {
  position: absolute;
  inset: 0;
  background: rgba(18, 40, 18, 0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  backdrop-filter: blur(1px);
}

.stb-overlay.hidden { display: none; }

.stb-overlay-inner {
  text-align: center;
  padding: 28px 22px;
  max-width: 380px;
}

.stb-overlay-inner h2 {
  font-size: 1.7rem;
  font-weight: 800;
  color: var(--stb-yellow);
  margin-bottom: 10px;
  line-height: 1.2;
}

.stb-overlay-inner p {
  color: #c8e6c9;
  font-size: 0.93rem;
  line-height: 1.55;
  margin-bottom: 18px;
}

/* Buttons */
.stb-btn {
  background: var(--stb-yellow);
  color: #1a2e1a;
  border: none;
  padding: 12px 30px;
  border-radius: 8px;
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 0.01em;
  transition: background 0.12s, transform 0.1s;
}

.stb-btn:hover  { background: #ffd740; transform: scale(1.04); }
.stb-btn:active { transform: scale(0.97); }

.stb-btn-cta {
  background: #43a047;
  color: #fff;
  display: block;
  width: 100%;
  margin-top: 10px;
}
.stb-btn-cta:hover  { background: #66bb6a; transform: scale(1.04); }

.hidden { display: none !important; }

/* How to play — details/summary disclosure */
.stb-howto {
  font-size: 0.8rem;
  color: #81c784;
  background: rgba(0,0,0,0.22);
  padding: 9px 13px;
  border-radius: 8px;
  line-height: 1.65;
}

.stb-howto summary {
  cursor: pointer;
  font-weight: 700;
  color: #a5d6a7;
  list-style: none;
  user-select: none;
  padding: 2px 0;
}
.stb-howto summary::-webkit-details-marker { display: none; }
.stb-howto summary::marker { display: none; }
.stb-howto summary::before { content: '\25B6\00A0\00A0'; font-size: 0.75em; }
.stb-howto[open] summary::before { content: '\25BC\00A0\00A0'; }
.stb-howto[open] p { margin-top: 8px; }
.stb-howto p { margin: 0; color: #81c784; }
.stb-howto strong { color: #a5d6a7; }
.stb-icon-hint { font-size: 0.95rem; }

/* Sound toggle */
.stb-sound-btn {
  background: rgba(255,255,255,0.08);
  color: #a5d6a7;
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  letter-spacing: 0.03em;
  white-space: nowrap;
  align-self: center;
  transition: background 0.12s, color 0.12s;
  touch-action: manipulation;
}
.stb-sound-btn:hover  { background: rgba(255,255,255,0.15); color: #e8f5e9; }
.stb-sound-btn:active { background: rgba(255,255,255,0.05); }

/* Responsive — mobile (portrait canvas + near-fullscreen layout) */
@media (max-width: 640px) {
  body {
    min-height: 100vh;
    min-height: 100svh;
  }

  .stb-wrap {
    width: 100%;
    max-width: none;
    padding: 4px 4px 8px;
    gap: 6px;
  }

  /* Hide subtitle to save vertical space */
  .stb-subtitle { display: none; }

  .stb-canvas-wrap {
    width: 100%;
    max-width: none;
    border-radius: 6px;
    /* Portrait ratio matching 420×620 JS logical canvas */
    aspect-ratio: 420 / 620;
    /* CSS clamps height — when max-height kicks in, width shrinks to preserve ratio */
    max-height: 72vh;
    max-height: 72svh;
    margin: 0 auto;
  }

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

  .stb-overlay-inner {
    padding: 16px 14px;
    max-width: 100%;
  }

  .stb-overlay-inner h2 { font-size: 1.4rem; }
  .stb-overlay-inner p  { font-size: 0.85rem; line-height: 1.45; }

  .stb-btn {
    min-height: 44px;
    padding: 11px 22px;
  }

  .stb-sound-btn {
    min-height: 36px;
  }

  .stb-howto {
    font-size: 0.78rem;
  }
}

/* Responsive — small mobile */
@media (max-width: 480px) {
  .stb-title      { font-size: 1.5rem; }
  .stb-stat-val   { font-size: 0.95rem; }
  .stb-stat-label { font-size: 0.6rem; }
  .stb-sound-btn  { font-size: 0.65rem; padding: 4px 8px; }
  .stb-hud        { padding: 6px 10px; gap: 6px; }
  .stb-stat       { min-width: 60px; }
}

/* ============================================================
   Active gameplay layout — body.game-active on mobile only.
   Locks the viewport, hides non-gameplay chrome, compact HUD,
   canvas fills all remaining space.
   Desktop: untouched (media query guards all rules below).
   ============================================================ */

@media (max-width: 640px) {

  body.game-active {
    overflow: hidden;
    height: 100dvh;
    height: 100svh;
  }

  body.game-active .stb-wrap {
    height: 100dvh;
    height: 100svh;
    max-width: none;
    overflow: hidden;
    padding-top: max(4px, env(safe-area-inset-top));
    padding-bottom: max(4px, env(safe-area-inset-bottom));
    padding-left: 0;
    padding-right: 0;
    gap: 0;
  }

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

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

  body.game-active .stb-stat {
    flex-direction: row;
    gap: 3px;
    align-items: center;
    flex: 0 0 auto;
    min-width: 0;
  }

  body.game-active .stb-stat-label {
    font-size: 0.56rem;
    white-space: nowrap;
  }

  body.game-active .stb-stat-val {
    font-size: 0.9rem;
  }

  /* Health stat stays flex-direction column to keep bar visible */
  body.game-active .stb-health {
    flex: 1 1 auto;
    flex-direction: column;
    gap: 1px;
    min-width: 60px;
  }

  body.game-active .stb-health-bar-wrap {
    height: 6px;
    margin: 0;
  }

  body.game-active .stb-sound-btn {
    font-size: 0.58rem;
    padding: 2px 7px;
    min-height: 0;
    flex-shrink: 0;
  }

  /* ---- Canvas fills remaining space ---- */
  body.game-active .stb-canvas-wrap {
    flex: 1 1 0;
    min-height: 0;
    width: 100%;
    max-width: none;
    /* Preserve the portrait mobile aspect ratio */
    aspect-ratio: 420 / 620;
    align-self: center;
    border-radius: 4px;
    margin: 2px auto 0;
    max-height: 100%;
  }

  body.game-active #stbCanvas {
    width: 100%;
    height: 100%;
    display: block;
  }
}
