:root {
  color-scheme: dark;
  --bg: #111c16;
  --surface: rgba(20, 30, 23, 0.94);
  --surface-strong: rgba(22, 34, 26, 0.97);
  --border: rgba(246, 200, 76, 0.42);
  --text: #f7faf3;
  --muted: #b4c7b7;
  --gold: #f8c630;
  --leaf: #45d158;
  --cyan: #5ce8ff;
  --crimson: #ff546e;
  font-family: "Avenir Next", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  width: 100%;
  height: 100dvh;
  min-height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

[hidden] { display: none !important; }

#yard-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100dvh;
  min-height: 100%;
  display: block;
  touch-action: none;
}

.topbar {
  position: fixed;
  z-index: 12;
  top: max(8px, env(safe-area-inset-top));
  left: max(10px, env(safe-area-inset-left));
  right: max(10px, env(safe-area-inset-right));
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.topbar a, .topbar button { pointer-events: auto; }

.home-btn {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: rgba(18, 28, 21, 0.88);
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
}

.home-btn img { display: block; border-radius: 6px; }

.wordmark {
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.7);
}

.top-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 6px;
}

.icon-btn, .pill-btn {
  height: 34px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(18, 28, 21, 0.88);
  color: var(--text);
  font-weight: 850;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.icon-btn { width: 34px; font-size: 15px; }
.pill-btn { padding: 0 10px; font-size: 12px; }
.pill-btn.active { background: var(--gold); color: #1a1206; border-color: transparent; }

.icon-btn[aria-pressed="true"] {
  background: var(--leaf);
  color: #0e2412;
  border-color: transparent;
}

/* Integrate portal #game-seo-info seamlessly into .top-actions as a subtle 34x34 icon button */
.top-actions #game-seo-info {
  position: static !important;
  inset: auto !important;
  width: auto;
  z-index: 2;
  pointer-events: auto;
}

.top-actions #game-seo-info summary {
  width: 34px;
  min-width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(18, 28, 21, 0.88);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.top-actions #game-seo-info summary:hover,
.top-actions #game-seo-info[open] summary {
  background: rgba(34, 52, 39, 0.96);
  border-color: var(--gold);
}

.top-actions #game-seo-info .game-info-content {
  position: fixed;
  top: max(50px, calc(env(safe-area-inset-top) + 42px));
  right: max(10px, env(safe-area-inset-right));
  width: min(480px, calc(100vw - 20px));
  max-height: calc(100dvh - 70px);
  border-radius: 16px;
  border: 1.5px solid var(--border);
  background: var(--surface-strong);
  color: var(--text);
  padding: 16px 18px;
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.6);
}

.top-actions #game-seo-info .game-info-content h2,
.top-actions #game-seo-info .game-info-content a {
  color: var(--gold);
}

.top-actions #game-seo-info .game-info-content p {
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  line-height: 1.55;
}

.plant-svg {
  display: block;
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
}

.seed-card .plant-svg {
  width: 32px;
  height: 32px;
}

.pick-card .plant-svg {
  width: 30px;
  height: 30px;
}

.alm-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 3px;
}

.alm-head strong {
  margin-bottom: 0;
}

/* Battle Seed Tray HUD */
.battle-hud {
  position: fixed;
  z-index: 6;
  top: max(8px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  width: min(760px, calc(100% - 170px));
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
}

@media (max-width: 720px) {
  .battle-hud {
    top: max(46px, calc(env(safe-area-inset-top) + 40px));
    width: calc(100% - 14px);
  }
}

.seed-tray {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 7px;
  border-radius: 14px;
  background: rgba(45, 29, 17, 0.92);
  border: 1.5px solid rgba(248, 198, 48, 0.48);
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.45);
  max-width: 100%;
  overflow-x: auto;
}

.sun-bank {
  flex: 0 0 auto;
  min-width: 52px;
  padding: 4px 6px;
  border-radius: 10px;
  background: rgba(255, 212, 59, 0.16);
  border: 1px solid rgba(255, 212, 59, 0.45);
  text-align: center;
  line-height: 1.1;
}

.sun-ico { display: block; font-size: 15px; }
.sun-bank b { font-size: 13px; color: var(--gold); font-variant-numeric: tabular-nums; }

.seed-slots {
  display: flex;
  gap: 4px;
}

.seed-card {
  position: relative;
  width: 54px;
  height: 52px;
  border-radius: 9px;
  border: 1.5px solid rgba(255, 255, 255, 0.2);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.14), rgba(20, 32, 22, 0.9));
  color: var(--text);
  padding: 2px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  overflow: hidden;
  flex: 0 0 auto;
}

.seed-card .s-ico { display: flex; align-items: center; justify-content: center; height: 32px; margin-top: 2px; }
.seed-card .s-cost { font-size: 10px; font-weight: 900; color: #ffe58a; }
.seed-card .s-key { position: absolute; top: 1px; left: 3px; font-size: 8.5px; color: rgba(255, 255, 255, 0.65); font-weight: 800; }
.seed-card .s-cd { position: absolute; inset: 0; background: rgba(8, 12, 10, 0.72); transform-origin: top; pointer-events: none; }

.seed-card.selected {
  border-color: var(--gold);
  box-shadow: 0 0 0 2px rgba(248, 198, 48, 0.65);
  transform: translateY(-2px);
}

.seed-card.cant {
  opacity: 0.5;
}

.tool-slots {
  display: flex;
  gap: 4px;
  margin-left: 2px;
}

.tool-btn {
  width: 44px;
  height: 48px;
  border-radius: 10px;
  border: 1.5px solid rgba(255, 255, 255, 0.24);
  background: rgba(24, 38, 28, 0.92);
  color: var(--text);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}

.tool-btn b { font-size: 10px; color: var(--leaf); }
.tool-btn.active { border-color: var(--leaf); box-shadow: 0 0 0 2px rgba(69, 209, 88, 0.6); background: rgba(45, 96, 56, 0.95); }
.tool-btn.shovel.active { border-color: var(--crimson); box-shadow: 0 0 0 2px rgba(255, 84, 110, 0.6); }

.wave-row {
  display: flex;
  align-items: center;
  gap: 6px;
  width: min(320px, 90%);
}

.wave-badge {
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(18, 28, 21, 0.86);
  border: 1px solid rgba(255, 255, 255, 0.16);
  font-size: 10.5px;
  font-weight: 850;
  white-space: nowrap;
}

.wave-track {
  flex: 1;
  height: 7px;
  border-radius: 999px;
  background: rgba(16, 22, 18, 0.84);
  border: 1px solid rgba(255, 255, 255, 0.16);
  overflow: hidden;
}

.wave-track i {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #45d158, #f8c630);
  transition: width 0.2s ease;
}

.boss-bar-wrap {
  width: min(340px, 92%);
  padding: 4px 10px;
  border-radius: 10px;
  background: rgba(40, 12, 18, 0.9);
  border: 1px solid rgba(255, 84, 110, 0.65);
}

.boss-bar-wrap span { display: block; font-size: 10px; font-weight: 900; color: #ffb3c0; letter-spacing: 0.08em; margin-bottom: 3px; }
.boss-track { height: 8px; border-radius: 999px; background: rgba(255, 255, 255, 0.14); overflow: hidden; }
.boss-track i { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, #ff3355, #ff9933); transition: width 0.15s ease; }

.wave-banner {
  position: fixed;
  z-index: 8;
  left: 50%;
  top: 44%;
  transform: translate(-50%, -50%);
  padding: 10px 22px;
  border-radius: 14px;
  background: rgba(155, 22, 34, 0.92);
  border: 2px solid #ffd166;
  color: #fff6d6;
  font-size: clamp(16px, 3.2vw, 24px);
  font-weight: 950;
  letter-spacing: 0.06em;
  text-align: center;
  pointer-events: none;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.6);
}

.toast {
  position: fixed;
  z-index: 9;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  pointer-events: none;
  max-width: calc(100% - 24px);
  text-align: center;
}

.toast:not(:empty) {
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(18, 28, 21, 0.92);
  border: 1px solid var(--gold);
  color: #fff3cc;
  font-size: 12px;
  font-weight: 850;
}

/* Overlays */
.overlay-root {
  position: fixed;
  z-index: 10;
  inset: 0;
  background: rgba(9, 15, 11, 0.62);
  backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(54px, env(safe-area-inset-top)) 12px max(14px, env(safe-area-inset-bottom));
  overflow-y: auto;
  touch-action: pan-y;
}

.overlay-card {
  width: min(640px, 100%);
  max-height: 86dvh;
  overflow-y: auto;
  background: var(--surface-strong);
  border: 1.5px solid var(--border);
  border-radius: 20px;
  padding: 18px 16px;
  box-shadow: 0 24px 54px rgba(0, 0, 0, 0.62);
}

.eyebrow { margin: 0 0 4px; font-size: 11px; font-weight: 900; letter-spacing: 0.14em; color: var(--gold); text-transform: uppercase; }
.overlay-card h1, .overlay-card h2 { margin: 0 0 6px; font-size: clamp(21px, 4.8vw, 30px); line-height: 1.1; font-weight: 950; }
.sub { margin: 0 0 12px; font-size: 13px; line-height: 1.45; color: var(--muted); }

.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.btn {
  flex: 1 1 130px;
  height: 42px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  font-size: 13px;
  font-weight: 850;
  cursor: pointer;
}
.btn.primary { background: linear-gradient(135deg, #4be364, #28a745); color: #0a2410; border: none; }
.btn.gold { background: linear-gradient(135deg, #ffd147, #f0932b); color: #1f1205; border: none; }

.tabs { display: flex; gap: 5px; overflow-x: auto; margin-bottom: 10px; }
.tab-btn {
  flex: 1 0 auto;
  padding: 6px 10px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.05);
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 850;
  cursor: pointer;
}
.tab-btn.active { background: var(--gold); color: #1c1205; border-color: transparent; }

.stage-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; }
@media (max-width: 460px) { .stage-grid { grid-template-columns: repeat(2, 1fr); } }

.stage-btn {
  padding: 10px 6px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  cursor: pointer;
  text-align: center;
}
.stage-btn.cleared { border-color: rgba(69, 209, 88, 0.55); background: rgba(69, 209, 88, 0.12); }
.stage-btn.boss { border-color: rgba(255, 84, 110, 0.65); background: rgba(255, 84, 110, 0.14); }
.stage-btn:disabled { opacity: 0.36; cursor: default; }
.stage-btn b { display: block; font-size: 14px; }
.stage-btn small { display: block; font-size: 10.5px; color: var(--muted); margin-top: 2px; }

.pick-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 6px; margin-top: 8px; }
.pick-card {
  padding: 7px 6px;
  border-radius: 11px;
  border: 1.5px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  cursor: pointer;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 6px;
}
.pick-card.on { border-color: var(--leaf); background: rgba(69, 209, 88, 0.18); }
.pick-card .p-ico { font-size: 20px; }
.pick-card strong { display: block; font-size: 11.5px; }
.pick-card small { display: block; font-size: 10px; color: var(--gold); }

.scout-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  padding: 7px 9px;
  border-radius: 11px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(255, 255, 255, 0.1);
  margin-bottom: 8px;
  font-size: 11.5px;
}

.almanac-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 7px; }
.alm-card {
  padding: 9px 10px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  font-size: 11.5px;
}
.alm-card strong { font-size: 13px; display: block; margin-bottom: 3px; }
.alm-card p { margin: 2px 0; color: var(--muted); line-height: 1.38; }
.alm-card .meta { color: var(--gold); font-weight: 800; font-size: 11px; }

.controls-note { margin: 10px 0 0; font-size: 11px; color: var(--muted); text-align: center; }

@media (max-width: 560px) {
  .seed-card { width: 42px; height: 46px; }
  .seed-card .plant-svg { width: 25px; height: 25px; }
  .seed-card .s-ico { height: 26px; }
  .tool-btn { width: 38px; height: 44px; font-size: 14px; }
}

/* Mandatory landscape gate for portrait phones */
.rotate-gate {
  position: fixed;
  z-index: 25;
  inset: 0;
  background: rgba(11, 20, 14, 0.96);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(20px, env(safe-area-inset-top)) 20px max(20px, env(safe-area-inset-bottom));
  text-align: center;
}

.rotate-card {
  width: min(340px, 100%);
  padding: 24px 20px;
  border-radius: 20px;
  background: var(--surface-strong);
  border: 1.5px solid var(--border);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.65);
}

.rotate-icon {
  font-size: 46px;
  line-height: 1.1;
  margin-bottom: 10px;
  animation: tilt-phone 2s ease-in-out infinite;
}

@keyframes tilt-phone {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(-90deg); }
}

.rotate-card h2 {
  margin: 0 0 8px;
  font-size: 20px;
  color: var(--gold);
}

.rotate-card p {
  margin: 0 0 14px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--muted);
}

/* Full-height compact layout for short screens & mobile landscape (height <= 520px) */
@media (max-height: 520px) {
  .topbar {
    top: max(4px, env(safe-area-inset-top));
    left: max(8px, env(safe-area-inset-left));
    right: max(8px, env(safe-area-inset-right));
  }
  .home-btn,
  .icon-btn,
  .pill-btn,
  .top-actions #game-seo-info summary {
    height: 30px;
  }
  .home-btn,
  .icon-btn,
  .top-actions #game-seo-info summary {
    width: 30px;
    min-width: 30px;
  }
  .wordmark {
    display: none;
  }
  .battle-hud {
    top: max(4px, env(safe-area-inset-top));
    width: fit-content;
    max-width: min(560px, calc(100% - 316px));
    gap: 3px;
  }
  .seed-tray {
    padding: 3px 5px;
    border-radius: 11px;
    gap: 3px;
  }
  .sun-bank {
    min-width: 40px;
    padding: 2px 4px;
  }
  .sun-ico { font-size: 12px; }
  .sun-bank b { font-size: 11px; }
  .seed-card {
    width: 40px;
    height: 40px;
    border-radius: 8px;
  }
  .seed-card .plant-svg {
    width: 24px;
    height: 24px;
  }
  .seed-card .s-ico {
    height: 24px;
    margin-top: 1px;
  }
  .seed-card .s-cost { font-size: 9px; }
  .tool-btn {
    width: 34px;
    height: 38px;
    font-size: 13px;
  }
  .wave-row {
    width: min(260px, 85%);
  }
  .wave-badge {
    font-size: 9.5px;
    padding: 1px 6px;
  }
  .overlay-root {
    align-items: stretch;
    padding: max(38px, calc(env(safe-area-inset-top) + 34px)) 10px max(6px, env(safe-area-inset-bottom));
  }
  .overlay-card {
    width: min(760px, 100%);
    height: 100%;
    max-height: 100%;
    padding: 12px 14px;
    border-radius: 16px;
    margin: 0 auto;
  }
  .overlay-card h1,
  .overlay-card h2 {
    font-size: 20px;
    margin-bottom: 4px;
  }
  .sub {
    margin-bottom: 8px;
    font-size: 12px;
  }
  .btn {
    height: 36px;
    font-size: 12.5px;
  }
  .btn-row {
    margin-top: 8px;
    gap: 6px;
  }
  .controls-note {
    margin-top: 6px;
    font-size: 10px;
  }
}
