:root {
  --ink: #1e3527;
  --cream: #fff8dc;
  --cream-soft: #f5edcd;
  --leaf: #6ea843;
  --leaf-dark: #244c33;
  --red: #e84836;
  --red-dark: #9e2d25;
  --gold: #ffd55a;
  --wood: #8a5b36;
  --panel: rgba(25, 48, 35, 0.91);
  --panel-line: rgba(255, 248, 220, 0.22);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background-color: #14261b;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.018) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.018) 1px, transparent 1px);
  background-size: 28px 28px;
  color: var(--cream);
  font-family:
    "Microsoft YaHei",
    "PingFang SC",
    "Noto Sans SC",
    sans-serif;
  overscroll-behavior: none;
}

button {
  font: inherit;
}

button:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 3px;
}

#app {
  position: absolute;
  top: 50%;
  left: 50%;
  width: min(100vw, 56.25dvh);
  height: min(100dvh, 177.7778vw);
  min-height: 0;
  overflow: hidden;
  isolation: isolate;
  border: 1px solid rgba(255, 248, 220, 0.12);
  border-radius: 11px;
  background: #203a2b;
  box-shadow:
    0 28px 80px rgba(4, 15, 8, 0.48),
    0 5px 20px rgba(4, 15, 8, 0.25);
  transform: translate(-50%, -50%);
}

#gameCanvas {
  position: absolute;
  top: 0;
  right: auto;
  bottom: auto;
  left: 0;
  z-index: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: crosshair;
}

#app::after {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  content: "";
  box-shadow: inset 0 0 110px rgba(21, 41, 29, 0.28);
}

.hud {
  position: absolute;
  z-index: 5;
  top: 13px;
  left: 12px;
  right: 12px;
  display: grid;
  grid-template-areas:
    "brand actions"
    "fence fence";
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.brand {
  grid-area: brand;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 4px 10px 4px 4px;
  border: 1px solid var(--panel-line);
  border-radius: 7px;
  background: var(--panel);
  justify-self: start;
}

.brand-seal {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  flex: 0 0 auto;
  border: 2px solid rgba(255, 248, 220, 0.55);
  border-radius: 50%;
  background: var(--panel);
  box-shadow: 0 5px 0 rgba(18, 38, 26, 0.24);
}

.brand-seal svg {
  width: 26px;
  fill: var(--leaf);
  stroke: var(--cream);
  stroke-width: 1.6;
  stroke-linecap: round;
}

.brand-copy {
  display: flex;
  min-width: 0;
  flex-direction: column;
  line-height: 1;
  text-shadow: 0 2px 0 rgba(21, 41, 29, 0.4);
}

.brand-copy strong {
  font-size: 16px;
  font-weight: 900;
  white-space: nowrap;
}

.brand-copy small {
  margin-top: 5px;
  color: rgba(255, 248, 220, 0.64);
  font-size: 8px;
  font-weight: 800;
  letter-spacing: 0.16em;
}

.fence-status {
  grid-area: fence;
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 10px;
  padding: 7px 11px;
  border: 1px solid var(--panel-line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 6px 0 rgba(18, 38, 26, 0.18);
  backdrop-filter: blur(8px);
}

.status-label {
  color: rgba(255, 248, 220, 0.72);
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
}

.health-track {
  position: relative;
  height: 9px;
  flex: 1;
  overflow: hidden;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.3);
}

.health-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 100%;
  border-radius: inherit;
  background: #8fc952;
  transition:
    width 220ms ease,
    background-color 220ms ease;
}

.fence-status b {
  min-width: 19px;
  color: var(--cream);
  font-size: 13px;
  text-align: right;
}

.hud-actions {
  grid-area: actions;
  display: flex;
  align-items: center;
  justify-self: end;
  gap: 9px;
  pointer-events: auto;
}

.wave-label {
  padding: 8px 11px;
  border: 1px solid var(--panel-line);
  border-radius: 7px;
  background: var(--panel);
  color: var(--cream);
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
}

.plant-status {
  display: flex;
  height: 37px;
  min-width: 70px;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 0 9px;
  border: 1px solid rgba(143, 201, 82, 0.42);
  border-radius: 7px;
  background: var(--panel);
  color: #9bd45e;
}

.plant-status svg {
  width: 19px;
  fill: rgba(143, 201, 82, 0.2);
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.plant-status b {
  color: var(--cream);
  font-size: 11px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.icon-button {
  display: grid;
  width: 37px;
  height: 37px;
  padding: 0;
  place-items: center;
  border: 1px solid var(--panel-line);
  border-radius: 7px;
  background: var(--panel);
  color: var(--cream);
  cursor: pointer;
}

.icon-button svg {
  width: 20px;
  fill: currentColor;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-button .sound-off {
  display: none;
}

.icon-button.muted .sound-off {
  display: block;
}

.icon-button.muted .sound-on {
  display: none;
}

.control-hint {
  position: absolute;
  z-index: 4;
  top: 106px;
  bottom: auto;
  left: 50%;
  margin: 0;
  padding: 7px 12px;
  border-radius: 6px;
  background: rgba(26, 47, 34, 0.76);
  color: rgba(255, 248, 220, 0.82);
  font-size: 11px;
  font-weight: 700;
  pointer-events: none;
  transform: translateX(-50%);
  transition: opacity 220ms ease;
  backdrop-filter: blur(6px);
}

.announcement {
  position: absolute;
  z-index: 4;
  top: 23%;
  left: 50%;
  width: min(92%, 640px);
  color: var(--cream);
  font-size: 34px;
  font-weight: 900;
  opacity: 0;
  pointer-events: none;
  text-align: center;
  text-shadow:
    0 3px 0 rgba(29, 57, 38, 0.55),
    0 10px 28px rgba(25, 48, 35, 0.32);
  transform: translate(-50%, 10px) rotate(-1deg);
}

.announcement.show {
  animation: announce 1.45s ease both;
}

@keyframes announce {
  0% {
    opacity: 0;
    transform: translate(-50%, 18px) scale(0.9) rotate(-1deg);
  }
  18%,
  70% {
    opacity: 1;
    transform: translate(-50%, 0) scale(1) rotate(-1deg);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -10px) scale(1.03) rotate(-1deg);
  }
}

.screen {
  position: absolute;
  z-index: 10;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 28px;
  background: rgba(19, 43, 28, 0.48);
  transition:
    opacity 220ms ease,
    visibility 220ms ease;
  backdrop-filter: blur(2px);
}

.screen.hidden {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}

.start-content,
.result-content {
  display: flex;
  width: min(680px, 92%);
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--gold);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.22em;
}

.start-content h1 {
  margin: 0;
  color: var(--cream);
  font-family:
    "Microsoft YaHei",
    "PingFang SC",
    sans-serif;
  font-size: 56px;
  font-weight: 900;
  line-height: 1.05;
  text-shadow:
    0 4px 0 #294e35,
    0 7px 0 rgba(22, 42, 28, 0.32),
    0 20px 50px rgba(17, 37, 25, 0.3);
}

.tagline {
  margin: 16px 0 25px;
  color: rgba(255, 248, 220, 0.9);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.75;
  text-shadow: 0 2px 10px rgba(18, 38, 26, 0.42);
}

.primary-button {
  display: flex;
  min-width: 180px;
  height: 50px;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 0 24px;
  border: 0;
  border-radius: 7px;
  background: var(--gold);
  box-shadow:
    0 5px 0 #b77d32,
    0 12px 24px rgba(20, 42, 27, 0.24);
  color: #2b3d25;
  cursor: pointer;
  font-size: 14px;
  font-weight: 900;
  transition:
    transform 140ms ease,
    box-shadow 140ms ease,
    background-color 140ms ease;
}

.primary-button:hover {
  background: #ffe27f;
  transform: translateY(-2px);
  box-shadow:
    0 7px 0 #b77d32,
    0 15px 28px rgba(20, 42, 27, 0.27);
}

.primary-button:active {
  transform: translateY(3px);
  box-shadow:
    0 2px 0 #b77d32,
    0 8px 18px rgba(20, 42, 27, 0.2);
}

.primary-button svg {
  width: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.start-legend {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  flex-wrap: wrap;
  margin-top: 26px;
  color: rgba(255, 248, 220, 0.66);
  font-size: 11px;
  font-weight: 700;
}

.start-legend span {
  display: flex;
  align-items: center;
  gap: 7px;
}

.legend-dot {
  display: block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  box-shadow: 0 0 0 3px rgba(255, 248, 220, 0.08);
}

.legend-dot.red {
  background: #ed5743;
}

.legend-dot.green {
  background: #87c654;
}

.legend-dot.blue {
  background: #86ddea;
}

.result-screen {
  background: rgba(18, 38, 26, 0.6);
}

.result-content h2 {
  margin: 0;
  color: var(--cream);
  font-size: 44px;
  font-weight: 900;
  line-height: 1.15;
  text-shadow: 0 4px 0 rgba(24, 48, 31, 0.55);
}

.result-copy {
  margin: 13px 0 25px;
  color: rgba(255, 248, 220, 0.75);
  font-size: 14px;
}

.result-stats {
  display: grid;
  width: min(440px, 86%);
  grid-template-columns: repeat(3, 1fr);
  margin-bottom: 27px;
  border-top: 1px solid rgba(255, 248, 220, 0.2);
  border-bottom: 1px solid rgba(255, 248, 220, 0.2);
}

.result-stats div {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 16px 10px;
}

.result-stats div + div {
  border-left: 1px solid rgba(255, 248, 220, 0.14);
}

.result-stats span {
  color: rgba(255, 248, 220, 0.55);
  font-size: 10px;
  font-weight: 700;
}

.result-stats strong {
  color: var(--cream);
  font-size: 24px;
  font-variant-numeric: tabular-nums;
}

.rotate-note {
  position: absolute;
  z-index: 7;
  right: 16px;
  bottom: 105px;
  display: none;
  padding: 7px 10px;
  border: 1px solid var(--panel-line);
  border-radius: 6px;
  background: var(--panel);
  color: rgba(255, 248, 220, 0.72);
  font-size: 10px;
  pointer-events: none;
}

#app[data-phase="ready"] .control-hint,
#app[data-phase="won"] .control-hint,
#app[data-phase="lost"] .control-hint {
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 8px);
}

@media (max-width: 820px) {
  .hud {
    top: 10px;
    right: 10px;
    left: 10px;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
  }

  .brand-copy small,
  .status-label {
    display: none;
  }

  .brand-seal {
    width: 34px;
    height: 34px;
  }

  .brand-seal svg {
    width: 20px;
  }

  .brand-copy strong {
    font-size: 14px;
  }

  .fence-status {
    padding: 7px 9px;
  }

  .hud-actions {
    gap: 5px;
  }

  .wave-label {
    padding: 7px 8px;
    font-size: 9px;
  }

  .plant-status {
    min-width: 61px;
    height: 33px;
    padding: 0 7px;
  }

  .plant-status svg {
    width: 15px;
  }

  .plant-status b {
    font-size: 10px;
  }

  .icon-button {
    width: 33px;
    height: 33px;
  }

  .control-hint {
    top: 94px;
  }

  .start-content h1 {
    font-size: 45px;
  }

  .tagline {
    margin: 12px 0 20px;
    font-size: 13px;
  }

  .result-content h2 {
    font-size: 40px;
  }

  .start-legend {
    margin-top: 20px;
  }
}

@media (max-height: 520px) {
  .hud {
    top: 8px;
  }

  .brand-seal {
    width: 32px;
    height: 32px;
  }

  .brand-copy small {
    display: none;
  }

  .fence-status {
    padding-top: 6px;
    padding-bottom: 6px;
  }

  .control-hint {
    top: 82px;
  }

  .start-content h1 {
    font-size: 43px;
  }

  .tagline {
    margin: 9px 0 14px;
    font-size: 12px;
  }

  .primary-button {
    height: 43px;
  }

  .start-legend {
    margin-top: 13px;
  }

  .result-content h2 {
    font-size: 36px;
  }

  .result-copy {
    margin: 8px 0 14px;
  }

  .result-stats {
    margin-bottom: 16px;
  }

  .result-stats div {
    padding: 9px;
  }
}

@media (orientation: landscape) and (max-height: 620px) {
  .rotate-note {
    display: block;
  }

  .rotate-note {
    right: 8px;
    bottom: 82px;
  }
}

@media (max-width: 520px) {
  #app {
    border: 0;
    border-radius: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
