/* ============================================================
   AntSwarm — all visual styling
   ------------------------------------------------------------
   A warm, storybook summer-lawn swarm game. Painted garden
   behind everything; a living ribbon of ants follows an amber
   lead scout. UI is clean and friendly, never retro: deep leaf
   green translucent cards, cream text, amber accents, soft
   blur, generous spacing, rounded 22px cards.

   Owns: .stage .hud .chip .chip b .topbar .overlay
         .overlay.show .card .title .tagline .howto .btn
         .btn.primary .statrow .stat .stat b  + #muteBtn
   Portrait phone first (412x732), works up to desktop.
   ============================================================ */

:root {
  --leaf-deep:   #10281a;
  --leaf-deeper: #0b1a12;
  --leaf-lift:   #173626;
  --cream:       #fdf6e3;
  --amber:       #ffc94a;
  --amber-soft:  #ffd76b;
  --green:       #7ee08a;
  --radius-card: 22px;
  --radius-btn:  14px;
  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto,
             "Helvetica Neue", Arial, sans-serif;
}

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

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--leaf-deeper);
  color: var(--cream);
  font-family: var(--font-ui);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ------------------------------------------------------------
   App shell — full viewport, stage fills what the HUD leaves
   ------------------------------------------------------------ */
#app {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background:
    radial-gradient(120% 90% at 50% 0%, #1a3d28 0%, #0d1f15 70%, #0a1710 100%);
  color: var(--cream);
  font-family: var(--font-ui);
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.stage {
  position: relative;
  display: block;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  overflow: hidden;
  background: #16301f;
}

.stage > canvas,
.stage canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  outline: none;
}

/* ------------------------------------------------------------
   HUD — floating chips over the lawn
   ------------------------------------------------------------ */
.hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  padding-top: max(10px, env(safe-area-inset-top));
  padding-left: max(12px, env(safe-area-inset-left));
  padding-right: max(12px, env(safe-area-inset-right));
  pointer-events: none;
  background: linear-gradient(180deg, rgba(8, 20, 13, 0.55), rgba(8, 20, 13, 0));
}

.topbar {
  display: flex;
  flex: 1 1 auto;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  min-width: 0;
  pointer-events: none;
}

.chip {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  flex: 0 0 auto;
  padding: 7px 12px;
  border-radius: 999px;
  font-size: 12px;
  line-height: 1.25;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
  color: rgba(253, 246, 227, 0.66);
  background: rgba(16, 40, 26, 0.62);
  border: 1px solid rgba(253, 246, 227, 0.12);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.28),
              inset 0 1px 0 rgba(255, 255, 255, 0.05);
  backdrop-filter: blur(10px) saturate(1.15);
  -webkit-backdrop-filter: blur(10px) saturate(1.15);
  pointer-events: none;
}

.chip b {
  font-size: 14px;
  line-height: 1.15;
  text-transform: none;
  color: var(--cream);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

#antsChip b  { color: #ffe9b0; }
#foodChip b  { color: var(--green); }
#levelChip b { color: var(--amber); }
#scoreChip b { color: var(--cream); }

/* mute — small round ghost button */
#muteBtn {
  pointer-events: auto;
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  min-width: 44px;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid rgba(253, 246, 227, 0.18);
  background: rgba(16, 40, 26, 0.55);
  color: var(--cream);
  font-family: inherit;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  backdrop-filter: blur(10px) saturate(1.15);
  -webkit-backdrop-filter: blur(10px) saturate(1.15);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.28);
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.12s ease, background 0.18s ease,
              border-color 0.18s ease;
}
#muteBtn:hover  { background: rgba(16, 40, 26, 0.82); border-color: rgba(253, 246, 227, 0.3); }
#muteBtn:active { transform: scale(0.92); }
#muteBtn:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 2px;
}

/* ------------------------------------------------------------
   Overlays — start + game over
   ------------------------------------------------------------ */
.overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  padding-top: max(20px, env(safe-area-inset-top));
  padding-bottom: max(20px, env(safe-area-inset-bottom));
  z-index: 30;
  overflow-y: auto;
  background:
    radial-gradient(130% 100% at 50% 0%,
      rgba(12, 30, 19, 0.42) 0%,
      rgba(8, 20, 13, 0.78) 100%);
  backdrop-filter: blur(3px) saturate(1.05);
  -webkit-backdrop-filter: blur(3px) saturate(1.05);
}

.overlay.show {
  display: flex;
  animation: overlayIn 0.26s ease both;
}

@keyframes overlayIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ------------------------------------------------------------
   Card
   ------------------------------------------------------------ */
.card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: min(400px, 100%);
  max-height: 100%;
  margin: auto;
  padding: 28px 24px;
  border-radius: var(--radius-card);
  text-align: center;
  color: var(--cream);
  background:
    linear-gradient(180deg,
      rgba(26, 62, 40, 0.94) 0%,
      rgba(16, 40, 26, 0.96) 100%);
  border: 1px solid rgba(253, 246, 227, 0.13);
  box-shadow:
    0 26px 70px rgba(0, 0, 0, 0.52),
    0 2px 0 rgba(255, 255, 255, 0.04) inset,
    0 -30px 60px rgba(126, 224, 138, 0.05) inset;
  backdrop-filter: blur(16px) saturate(1.15);
  -webkit-backdrop-filter: blur(16px) saturate(1.15);
  overflow-y: auto;
  animation: cardIn 0.36s cubic-bezier(0.2, 0.9, 0.3, 1.15) both;
}

@keyframes cardIn {
  from { opacity: 0; transform: translateY(14px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0)    scale(1); }
}

.title {
  margin: 0;
  font-family: var(--font-ui);
  font-size: clamp(28px, 8.5vw, 38px);
  font-weight: 600;
  letter-spacing: 0.055em;
  line-height: 1.06;
  color: var(--cream);
  text-shadow: 0 2px 28px rgba(255, 201, 74, 0.22);
}

.tagline {
  margin: 0 0 4px;
  font-size: 15px;
  font-weight: 400;
  line-height: 1.45;
  letter-spacing: 0.005em;
  color: rgba(253, 246, 227, 0.62);
}

/* how-to list */
.howto {
  display: grid;
  gap: 10px;
  margin: 2px 0 8px;
  padding: 0;
  list-style: none;
  text-align: left;
  font-size: 14px;
  line-height: 1.45;
  color: rgba(253, 246, 227, 0.87);
}

.howto li,
.howto p {
  position: relative;
  margin: 0;
  padding-left: 24px;
}

.howto p { padding-left: 0; }

.howto li::before {
  content: "";
  position: absolute;
  left: 5px;
  top: 0.5em;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--amber);
  box-shadow: 0 0 10px rgba(255, 201, 74, 0.7);
}

.howto b,
.howto strong {
  color: var(--cream);
  font-weight: 600;
}

/* ------------------------------------------------------------
   Buttons
   ------------------------------------------------------------ */
.btn {
  appearance: none;
  -webkit-appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 48px;
  padding: 12px 20px;
  border-radius: var(--radius-btn);
  border: 1px solid rgba(253, 246, 227, 0.18);
  background: rgba(253, 246, 227, 0.08);
  color: var(--cream);
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1.2;
  cursor: pointer;
  text-align: center;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  transition: transform 0.12s ease, background 0.18s ease,
              box-shadow 0.18s ease, border-color 0.18s ease;
}

.btn:hover {
  background: rgba(253, 246, 227, 0.15);
  border-color: rgba(253, 246, 227, 0.28);
}

.btn:active { transform: scale(0.97); }

.btn:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 3px;
}

.btn.primary {
  background: linear-gradient(180deg, var(--amber-soft) 0%, var(--amber) 100%);
  border-color: rgba(120, 84, 0, 0.22);
  color: #14261a;
  font-weight: 700;
  letter-spacing: 0.03em;
  box-shadow:
    0 12px 26px rgba(255, 201, 74, 0.3),
    0 1px 0 rgba(255, 255, 255, 0.55) inset;
}

.btn.primary:hover {
  background: linear-gradient(180deg, #ffe28c 0%, #ffd25c 100%);
  box-shadow:
    0 14px 30px rgba(255, 201, 74, 0.4),
    0 1px 0 rgba(255, 255, 255, 0.65) inset;
}

.btn.primary:active { transform: scale(0.97); }

/* stacked buttons inside a card (or inside a wrapper row) */
.card .btn + .btn { margin-top: 0; }

.btnrow {
  display: flex;
  gap: 10px;
  width: 100%;
}
.btnrow .btn { margin-top: 0; }

/* ------------------------------------------------------------
   Game-over stats
   ------------------------------------------------------------ */
#overTitle {
  margin: 0;
  font-size: clamp(22px, 6.4vw, 28px);
  font-weight: 600;
  letter-spacing: 0.03em;
  line-height: 1.15;
  color: var(--cream);
  text-shadow: 0 2px 24px rgba(255, 201, 74, 0.18);
}

#overStats {
  margin: 2px 0 6px;
  font-size: 14px;
  line-height: 1.6;
  color: rgba(253, 246, 227, 0.82);
  white-space: pre-line;
}

.statrow {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 2px 0 6px;
  white-space: normal;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 12px 8px;
  border-radius: 14px;
  background: rgba(253, 246, 227, 0.06);
  border: 1px solid rgba(253, 246, 227, 0.09);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  line-height: 1.25;
  color: rgba(253, 246, 227, 0.72);
}

.stat b {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: none;
  line-height: 1.05;
  color: var(--cream);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

/* ------------------------------------------------------------
   Small screens / short screens
   ------------------------------------------------------------ */
@media (max-height: 660px) {
  .card { padding: 22px 20px; gap: 10px; }
  .title { font-size: clamp(24px, 7.5vw, 30px); }
  .tagline { font-size: 14px; }
  .howto { font-size: 13px; gap: 8px; margin-bottom: 4px; }
  .stat { padding: 9px 6px; }
  .stat b { font-size: 17px; }
}

@media (max-width: 360px) {
  .chip { padding: 7px 11px; font-size: 12px; }
  .chip b { font-size: 14px; }
  .stat { font-size: 12px; }
}

/* ------------------------------------------------------------
   Desktop / wide screens — centre the action, roomier HUD
   ------------------------------------------------------------ */
@media (min-width: 720px) {
  .hud { padding: 14px 20px; gap: 10px; }
  .topbar { gap: 10px; }
  .chip { padding: 8px 14px; }
  .card { width: min(440px, 100%); padding: 34px 32px; gap: 14px; }
  .howto { font-size: 15px; gap: 12px; }
}

/* ------------------------------------------------------------
   Reduced motion
   ------------------------------------------------------------ */
@media (prefers-reduced-motion: reduce) {
  .overlay.show,
  .card { animation: none; }
  .btn,
  #muteBtn { transition: none; }
}
