/* Plants vs. Zombies web shell. Plain CSS, no external assets. */

:root {
  --bg-deep: #0c150a;
  --lawn-a: #1b3315;
  --lawn-b: #203c19;
  --soil: #3d2715;
  --soil-dark: #24170b;
  --wood: #6a4322;
  --wood-light: #8b5b2f;
  --wood-dark: #3a2412;
  --leaf: #79c043;
  --leaf-bright: #a9e25b;
  --leaf-dark: #2f6316;
  --sun: #ffd84a;
  --parchment: #f4ead0;
  --muted: #cdbd98;
  --danger: #ff8a6b;
  --ui-font: "Trebuchet MS", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --title-font: "Arial Black", "Arial Bold", Gadget, "Trebuchet MS", system-ui, sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
}

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

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: #000;
  color: var(--parchment);
  font-family: var(--ui-font);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body { position: fixed; inset: 0; }

button { font: inherit; color: inherit; }
a { color: var(--leaf-bright); }
a:hover { color: var(--sun); }
[hidden] { display: none !important; }

/* ------------------------------------------------------------------ */
/* Game area                                                            */
/* ------------------------------------------------------------------ */

#canvas-container {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #000;
  padding: var(--safe-t) var(--safe-r) var(--safe-b) var(--safe-l);
}

#canvas-container:fullscreen { width: 100%; height: 100%; background: #000; }
#canvas-container:-webkit-full-screen { width: 100%; height: 100%; background: #000; }

/* Drawing buffer stays at whatever size the engine sets (800x600);
   shell.js sets the CSS width/height to fit 4:3 into the window, or to fill it when stretched. */
canvas#canvas {
  position: relative;
  z-index: 1;
  display: block;
  flex: 0 0 auto;
  width: 800px;
  height: 600px;
  margin: 0;
  padding: 0;
  border: 0;
  outline: none;
  background: transparent;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

#boot-label {
  position: absolute;
  z-index: 0;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  color: rgba(244, 234, 208, 0.75);
  font-size: 15px;
  letter-spacing: 0.04em;
  pointer-events: none;
}

#pvz-soft-keyboard {
  position: absolute;
  top: 0;
  left: 0;
  width: 1px;
  height: 1px;
  padding: 0;
  border: 0;
  margin: 0;
  opacity: 0;
  resize: none;
  pointer-events: none;
  font-size: 16px; /* >= 16px prevents iOS zoom-on-focus */
  z-index: -1;
}

/* ------------------------------------------------------------------ */
/* Loading overlay                                                      */
/* ------------------------------------------------------------------ */

#overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(16px + var(--safe-t)) calc(16px + var(--safe-r)) calc(16px + var(--safe-b)) calc(16px + var(--safe-l));
  overflow-y: auto;
  background: var(--bg-deep);
  transition: opacity 0.45s ease, visibility 0s linear 0s;
}

#overlay.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.45s ease, visibility 0s linear 0.45s;
}

/* Mowed-lawn backdrop: alternating stripes, dusk vignette, soil band. */
#overlay .lawn {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse 120% 85% at 50% 38%, rgba(0, 0, 0, 0) 35%, rgba(4, 8, 3, 0.85) 100%),
    linear-gradient(to bottom, rgba(10, 18, 30, 0.75) 0%, rgba(10, 18, 30, 0) 22%),
    linear-gradient(to top, var(--soil-dark) 0, var(--soil) 7%, rgba(61, 39, 21, 0) 7.2%),
    repeating-linear-gradient(90deg, var(--lawn-a) 0 9vw, var(--lawn-b) 9vw 18vw),
    var(--lawn-a);
}

#overlay .lawn::after {
  /* faint blade texture */
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.18;
  background:
    repeating-linear-gradient(100deg, rgba(255, 255, 255, 0.05) 0 2px, rgba(0, 0, 0, 0) 2px 7px),
    repeating-linear-gradient(80deg, rgba(0, 0, 0, 0.25) 0 1px, rgba(0, 0, 0, 0) 1px 5px);
}

.panel {
  position: relative;
  width: min(560px, 100%);
  margin: auto;
  padding: clamp(18px, 4vw, 34px) clamp(16px, 4.5vw, 40px) clamp(14px, 3vw, 22px);
  text-align: center;
  border-radius: 22px;
  border: 3px solid var(--wood-dark);
  background:
    repeating-linear-gradient(176deg, rgba(255, 255, 255, 0.035) 0 3px, rgba(0, 0, 0, 0) 3px 11px),
    repeating-linear-gradient(181deg, rgba(0, 0, 0, 0.09) 0 1px, rgba(0, 0, 0, 0) 1px 17px),
    linear-gradient(180deg, var(--wood-light) 0%, var(--wood) 55%, #5a381b 100%);
  box-shadow:
    inset 0 2px 0 rgba(255, 230, 180, 0.25),
    inset 0 -4px 0 rgba(0, 0, 0, 0.25),
    0 0 0 6px rgba(20, 12, 5, 0.55),
    0 22px 60px rgba(0, 0, 0, 0.65);
}

.panel::before, .panel::after {
  /* nail heads */
  content: "";
  position: absolute;
  top: 12px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #d9c7a3, #6f5a3c 70%);
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.6);
}
.panel::before { left: 12px; }
.panel::after { right: 12px; }

.title {
  margin: 0;
  line-height: 0.95;
  font-family: var(--title-font);
  font-weight: 900;
  letter-spacing: 0.01em;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: center;
  gap: 0 0.28em;
  user-select: none;
}

.t-plants, .t-zombies {
  font-size: clamp(34px, 8.6vw, 58px);
  text-transform: uppercase;
}

.t-plants {
  color: var(--leaf-bright);
  transform: rotate(-3deg);
  text-shadow:
    0 2px 0 var(--leaf-dark), 2px 0 0 var(--leaf-dark), -2px 0 0 var(--leaf-dark), 0 -2px 0 var(--leaf-dark),
    2px 2px 0 var(--leaf-dark), -2px 2px 0 var(--leaf-dark), 2px -2px 0 var(--leaf-dark), -2px -2px 0 var(--leaf-dark),
    0 6px 0 #173509, 0 9px 14px rgba(0, 0, 0, 0.55);
}

.t-vs {
  font-size: clamp(16px, 3.6vw, 24px);
  font-style: italic;
  color: var(--parchment);
  text-transform: lowercase;
  text-shadow: 0 2px 0 #2b1a0b, 0 0 8px rgba(0, 0, 0, 0.5);
}

.t-zombies {
  color: #c9d1b0;
  transform: rotate(2deg);
  text-shadow:
    0 2px 0 #2c2d22, 2px 0 0 #2c2d22, -2px 0 0 #2c2d22, 0 -2px 0 #2c2d22,
    2px 2px 0 #2c2d22, -2px 2px 0 #2c2d22, 2px -2px 0 #2c2d22, -2px -2px 0 #2c2d22,
    0 6px 0 #18180f, 0 9px 14px rgba(0, 0, 0, 0.55);
}

.subtitle {
  margin: 10px 0 0;
  font-size: 12px;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--muted);
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.6);
}

.view { display: none; margin-top: clamp(16px, 4vw, 26px); }
#overlay[data-state="loading"] .view-loading,
#overlay[data-state="ready"] .view-ready,
#overlay[data-state="error"] .view-error,
#overlay[data-state="exited"] .view-exited { display: block; }

/* Progress bar: a dirt path that grass grows across, with a rolling sod roll. */
.bar {
  position: relative;
  height: 26px;
  border-radius: 13px;
  background:
    radial-gradient(circle at 20% 40%, rgba(255, 255, 255, 0.06) 0 2px, transparent 3px) 0 0 / 22px 14px,
    linear-gradient(180deg, var(--soil-dark), var(--soil));
  border: 2px solid #1b1007;
  box-shadow: inset 0 3px 6px rgba(0, 0, 0, 0.6), 0 1px 0 rgba(255, 230, 180, 0.25);
  overflow: visible;
}

.bar-fill {
  position: absolute;
  left: 2px;
  top: 2px;
  bottom: 2px;
  width: 0%;
  min-width: 0;
  border-radius: 10px;
  background:
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.12) 0 2px, rgba(0, 0, 0, 0) 2px 6px),
    linear-gradient(180deg, var(--leaf-bright) 0%, var(--leaf) 45%, #4c8f24 100%);
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.22), 0 0 10px rgba(169, 226, 91, 0.35);
  transition: width 0.25s ease-out;
  max-width: calc(100% - 4px);
}

.sod {
  position: absolute;
  right: -13px;
  top: 50%;
  width: 30px;
  height: 30px;
  margin-top: -15px;
  border-radius: 50%;
  background:
    repeating-conic-gradient(from 0deg, #5ea22f 0 12deg, #8ccf4c 12deg 24deg),
    #6bb037;
  border: 2px solid #2b5a12;
  box-shadow: inset 0 0 0 5px rgba(61, 39, 21, 0.85), 0 2px 4px rgba(0, 0, 0, 0.5);
  animation: sod-roll 1.1s linear infinite;
  opacity: 0;
  transition: opacity 0.3s;
}
.bar.is-active .sod { opacity: 1; }
.bar.is-indeterminate .bar-fill { animation: grass-breathe 1.6s ease-in-out infinite; }

@keyframes sod-roll { to { transform: rotate(360deg); } }
@keyframes grass-breathe { 50% { filter: brightness(1.18); } }

.status {
  margin: 16px 0 0;
  min-height: 1.4em;
  font-size: clamp(15px, 3.6vw, 18px);
  font-weight: 700;
  color: var(--parchment);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.45);
  font-variant-numeric: tabular-nums;
}

.status-detail {
  margin: 4px 0 0;
  min-height: 1.3em;
  font-size: 13px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* Play button */
.play-btn {
  display: inline-block;
  min-width: min(320px, 100%);
  padding: 16px 34px 18px;
  font-family: var(--title-font);
  font-size: clamp(22px, 5.6vw, 32px);
  font-weight: 900;
  letter-spacing: 0.02em;
  color: #fffbe6;
  text-shadow: 0 2px 0 #1f4a0c, 0 0 6px rgba(0, 0, 0, 0.35);
  border: 3px solid #1d3f0b;
  border-radius: 18px;
  cursor: pointer;
  background: linear-gradient(180deg, #b6ea67 0%, #7cc443 46%, #4f9426 100%);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.55),
    inset 0 -4px 0 rgba(0, 0, 0, 0.22),
    0 6px 0 #18350a,
    0 12px 26px rgba(0, 0, 0, 0.5);
  transition: transform 0.12s ease, filter 0.12s ease, box-shadow 0.12s ease;
  animation: play-pulse 2.2s ease-in-out infinite;
}
.play-btn:hover { filter: brightness(1.08); }
.play-btn:active {
  transform: translateY(4px);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.45), inset 0 -2px 0 rgba(0, 0, 0, 0.22), 0 2px 0 #18350a, 0 6px 14px rgba(0, 0, 0, 0.5);
}
.play-btn:focus-visible { outline: 3px solid var(--sun); outline-offset: 4px; }

@keyframes play-pulse {
  0%, 100% { box-shadow: inset 0 2px 0 rgba(255,255,255,.55), inset 0 -4px 0 rgba(0,0,0,.22), 0 6px 0 #18350a, 0 12px 26px rgba(0,0,0,.5), 0 0 0 0 rgba(255, 216, 74, 0); }
  50%      { box-shadow: inset 0 2px 0 rgba(255,255,255,.55), inset 0 -4px 0 rgba(0,0,0,.22), 0 6px 0 #18350a, 0 12px 26px rgba(0,0,0,.5), 0 0 0 8px rgba(255, 216, 74, 0.18); }
}

.hint, .exit-text {
  margin: 16px 0 0;
  font-size: 13px;
  color: var(--muted);
}
.exit-text { font-size: 18px; color: var(--parchment); margin: 0 0 16px; font-weight: 700; }

/* Error view */
.error-title {
  margin: 0;
  font-size: 20px;
  color: var(--danger);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.5);
}
.error-message {
  margin: 10px 0 0;
  font-size: 15px;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.error-details {
  margin: 12px 0 0;
  text-align: left;
  font-size: 12px;
  color: var(--muted);
}
.error-details summary { cursor: pointer; text-align: center; }
.error-details pre {
  margin: 8px 0 0;
  max-height: 160px;
  overflow: auto;
  padding: 10px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.45);
  color: #e9dcbc;
  font: 11px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin-top: 16px;
}

.btn {
  padding: 9px 18px;
  font-size: 15px;
  font-weight: 700;
  border-radius: 10px;
  border: 2px solid #1d1209;
  background: linear-gradient(180deg, #7d5330, #5b3a1d);
  color: var(--parchment);
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255, 230, 180, 0.3), 0 3px 0 #1d1209;
}
.btn:hover { filter: brightness(1.1); }
.btn:active { transform: translateY(2px); box-shadow: inset 0 1px 0 rgba(255, 230, 180, 0.3), 0 1px 0 #1d1209; }
.btn:focus-visible { outline: 3px solid var(--sun); outline-offset: 2px; }
.btn-primary {
  border-color: #1d3f0b;
  background: linear-gradient(180deg, #8fd04f, #4f9426);
  color: #fffbe6;
  text-shadow: 0 1px 0 #1f4a0c;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.45), 0 3px 0 #18350a;
}

.fineprint {
  margin: clamp(16px, 4vw, 26px) 0 0;
  font-size: 11.5px;
  line-height: 1.5;
  color: rgba(244, 234, 208, 0.62);
}
.fineprint a { color: rgba(244, 234, 208, 0.85); }

/* ------------------------------------------------------------------ */
/* Toolbar                                                              */
/* ------------------------------------------------------------------ */

#toolbar {
  position: absolute;
  z-index: 40;
  top: calc(8px + var(--safe-t));
  left: 50%;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px;
  border-radius: 12px;
  background: rgba(24, 15, 7, 0.84);
  border: 1px solid rgba(139, 91, 47, 0.75);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  transform: translate(-50%, calc(-100% - 20px));
  opacity: 0;
  pointer-events: none;
  transition: transform 0.22s ease, opacity 0.22s ease;
}
#toolbar.is-visible { transform: translate(-50%, 0); opacity: 1; pointer-events: auto; }

.tb-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 34px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--parchment);
  cursor: pointer;
}
.tb-btn:hover { background: rgba(169, 226, 91, 0.16); color: #fff; }
.tb-btn:active { background: rgba(169, 226, 91, 0.26); }
.tb-btn:focus-visible { outline: 2px solid var(--sun); outline-offset: 1px; }
.tb-btn:disabled { opacity: 0.4; cursor: default; background: transparent; }
.tb-btn[aria-pressed="true"] { color: var(--sun); }
/* Icon-only toolbar; labels stay available to screen readers. */
.tb-label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}
.tb-sep { width: 1px; height: 20px; background: rgba(205, 189, 152, 0.25); margin: 0 3px; }

.ic {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.ic-exit, .ic-muted, .ic-fit { display: none; }
.is-fullscreen .ic-enter { display: none; }
.is-fullscreen .ic-exit { display: inline; }
#tb-mute[aria-pressed="true"] .ic-sound { display: none; }
#tb-mute[aria-pressed="true"] .ic-muted { display: inline; }
/* Scale button shows what a click does: stretch (while fitted) or fit back to 4:3 (while stretched). */
#tb-scale[aria-pressed="true"] .ic-stretch { display: none; }
#tb-scale[aria-pressed="true"] .ic-fit { display: inline; }

/* Touch handle that reveals the toolbar during play (no hover on touch screens). */
#toolbar-handle {
  position: absolute;
  z-index: 39;
  top: var(--safe-t);
  left: 50%;
  width: 56px;
  height: 22px;
  margin-left: -28px;
  padding: 0;
  border: 0;
  border-radius: 0 0 10px 10px;
  background: rgba(24, 15, 7, 0.55);
  cursor: pointer;
  display: none;
  opacity: 0.7;
}
#toolbar-handle span {
  display: block;
  width: 22px;
  height: 3px;
  margin: 0 auto;
  border-radius: 2px;
  background: rgba(244, 234, 208, 0.8);
  box-shadow: 0 5px 0 rgba(244, 234, 208, 0.8);
  transform: translateY(-3px);
}
@media (hover: none) and (pointer: coarse) {
  body.is-playing #toolbar-handle { display: block; }
  body.is-playing.toolbar-open #toolbar-handle { display: none; }
}

/* ------------------------------------------------------------------ */
/* Popover, modal, toast                                                */
/* ------------------------------------------------------------------ */

.popover {
  position: absolute;
  z-index: 45;
  top: calc(56px + var(--safe-t));
  left: 50%;
  transform: translateX(-50%);
  width: min(400px, calc(100% - 16px));
  max-height: calc(100% - 72px - var(--safe-t) - var(--safe-b));
  overflow-y: auto;
  padding: 18px 20px 12px;
  border-radius: 14px;
  background: linear-gradient(180deg, #2a1b0e, #1d1209);
  border: 1px solid rgba(139, 91, 47, 0.85);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.6);
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--parchment);
}
.popover h2 { margin: 0 0 8px; font-size: 18px; color: var(--leaf-bright); }
.popover h3 { margin: 14px 0 4px; font-size: 13px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--sun); }
.popover p { margin: 0 0 6px; color: #e8dcbd; }
.popover code { font-size: 12px; color: var(--leaf-bright); }
.popover-close {
  position: absolute;
  top: 8px;
  right: 10px;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}
.popover-close:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }

.modal {
  position: absolute;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.55);
}
.modal-card {
  width: min(420px, 100%);
  padding: 20px 22px 18px;
  text-align: center;
  border-radius: 16px;
  border: 3px solid var(--wood-dark);
  background: linear-gradient(180deg, var(--wood-light), var(--wood));
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.6);
}
.modal-card h2 { margin: 0; font-size: 19px; text-shadow: 0 2px 0 rgba(0, 0, 0, 0.4); }
.modal-card p { margin: 10px 0 0; font-size: 14.5px; line-height: 1.45; white-space: pre-wrap; }

#toast {
  position: absolute;
  z-index: 70;
  left: 50%;
  bottom: calc(18px + var(--safe-b));
  max-width: calc(100% - 32px);
  transform: translate(-50%, 20px);
  padding: 10px 16px;
  border-radius: 10px;
  background: rgba(24, 15, 7, 0.92);
  border: 1px solid rgba(139, 91, 47, 0.85);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  font-size: 14px;
  color: var(--parchment);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
#toast.is-visible { opacity: 1; transform: translate(-50%, 0); }
#toast.is-error { border-color: rgba(255, 138, 107, 0.8); }

.noscript {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-deep);
  color: var(--parchment);
  font: 18px var(--ui-font);
}

/* Small / short screens */
@media (max-height: 520px) {
  .panel { padding-top: 14px; padding-bottom: 10px; }
  .subtitle { display: none; }
  .view { margin-top: 12px; }
  .fineprint { margin-top: 12px; }
  .t-plants, .t-zombies { font-size: clamp(26px, 9vh, 44px); }
  .play-btn { padding: 10px 26px 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .play-btn, .sod, .bar.is-indeterminate .bar-fill { animation: none; }
  #overlay, #toolbar, #toast, .bar-fill { transition: none; }
}
