:root {
  color-scheme: dark;
  --bg: #0d1610;
  --panel: rgba(24, 38, 28, 0.94);
  --panel-2: rgba(35, 54, 39, 0.94);
  --panel-3: rgba(16, 28, 20, 0.96);
  --line: rgba(188, 154, 86, 0.32);
  --line-strong: rgba(224, 190, 104, 0.58);
  --text: #f5f1dc;
  --muted: #c7c1a5;
  --accent: #66d48a;
  --accent-2: #78d8ff;
  --danger: #f07167;
  --gold: #f4c96b;
  --shadow: rgba(0, 0, 0, 0.42);
  --hp-red: #8f4c43;
  --pixel-dark: #071008;
  --pixel-mid: #172515;
  --pixel-line: #b89452;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(rgba(8, 14, 9, 0.72), rgba(8, 14, 9, 0.82)),
    url("assets/backgrounds/forest-canvas.png") center / cover;
  background-attachment: scroll;
  color: var(--text);
  font-family: "Segoe UI", "Yu Gothic UI", Meiryo, sans-serif;
}

body::before {
  content: "";
  inset: 0;
  pointer-events: none;
  position: fixed;
  background: linear-gradient(90deg, rgba(2, 8, 4, 0.36), transparent 18%, transparent 82%, rgba(2, 8, 4, 0.36));
}

button {
  border: 2px solid rgba(245, 221, 148, 0.52);
  border-radius: 2px;
  background: #4aa466;
  box-shadow: 3px 3px 0 rgba(2, 8, 4, 0.72);
  color: #08150d;
  cursor: pointer;
  font: inherit;
  font-weight: 800;
  min-height: 40px;
  padding: 9px 12px;
}

button:hover {
  filter: brightness(1.08) saturate(1.05);
}

button:disabled {
  cursor: not-allowed;
  filter: grayscale(0.7);
  opacity: 0.55;
}

.shell {
  display: grid;
  grid-template-columns: minmax(560px, 1fr) 360px;
  gap: 18px;
  margin: 0 auto;
  max-width: 1390px;
  min-height: 100vh;
  padding: 18px;
  position: relative;
}

.game-stage {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 520px;
  position: relative;
}

.field-wrap {
  display: flex;
  justify-content: center;
  position: relative;
}

.field-actions {
  align-items: stretch;
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(180px, 260px) minmax(220px, 320px);
  justify-content: center;
  margin-top: 2px;
}

.field-actions button {
  min-width: 0;
}

.field-actions .speed-control {
  gap: 6px;
  min-width: 0;
  padding: 8px 10px;
}

canvas {
  aspect-ratio: 3 / 2;
  background: #132015;
  border: 2px solid var(--line-strong);
  border-radius: 2px;
  box-shadow: inset 0 0 0 3px rgba(17, 29, 20, 0.78), 6px 6px 0 rgba(2, 8, 4, 0.52);
  display: block;
  height: auto;
  image-rendering: pixelated;
  max-height: min(calc(100vh - 86px), 680px);
  touch-action: none;
  user-select: none;
  width: min(100%, 1020px, calc((100vh - 86px) * 1.5));
}

.field-hud {
  align-items: center;
  color: #ffffff;
  display: flex;
  gap: 10px;
  justify-content: space-between;
  left: 18px;
  pointer-events: none;
  position: absolute;
  right: 18px;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.86), 0 0 8px rgba(0, 0, 0, 0.8);
  top: 10px;
  z-index: 2;
}

.field-hud span {
  font-size: 17px;
  font-weight: 800;
  letter-spacing: 0;
  white-space: nowrap;
}

.field-hud strong {
  color: #fff6c8;
  font-size: 22px;
  margin-left: 4px;
}

.field-hud span + span {
  display: none;
}

.light-render-notice {
  animation: slow-pulse 1.9s ease-in-out infinite;
  background: rgba(8, 12, 10, 0.74);
  border: 1px solid rgba(255, 246, 200, 0.72);
  border-radius: 2px;
  color: #fff1a8;
  display: none;
  font-size: 14px;
  font-weight: 900;
  line-height: 1;
  padding: 7px 10px;
  pointer-events: none;
  position: absolute;
  right: 18px;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.72);
  top: 10px;
  z-index: 3;
}

.light-render-notice.is-visible {
  display: block;
}

@keyframes slow-pulse {
  0%,
  100% {
    opacity: 0.42;
  }
  50% {
    opacity: 0.95;
  }
}

.label {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.life-gauge,
.wave-progress-gauge {
  align-items: center;
  background: rgba(2, 6, 4, 0.88);
  border: 2px solid rgba(184, 148, 82, 0.72);
  border-radius: 2px;
  bottom: 6%;
  box-shadow: 3px 3px 0 rgba(1, 5, 3, 0.58);
  color: #ffffff;
  display: flex;
  height: 26px;
  justify-content: center;
  left: 18px;
  overflow: hidden;
  position: absolute;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.84);
  width: min(320px, 34%);
  z-index: 2;
}

.wave-progress-gauge {
  left: auto;
  right: 18px;
}

.life-gauge-fill,
.wave-progress-fill {
  background: var(--hp-red);
  height: 100%;
  left: 0;
  position: absolute;
  top: 0;
  transition: width 180ms ease;
  width: 100%;
}

.wave-progress-fill {
  background: var(--hp-red);
  width: 0%;
}

.life-gauge span,
.wave-progress-gauge span {
  font-size: 13px;
  font-weight: 900;
  position: relative;
  z-index: 1;
}

.toast {
  background: rgba(10, 17, 12, 0.92);
  border: 1px solid var(--line-strong);
  border-radius: 2px;
  bottom: 14px;
  color: var(--text);
  left: 50%;
  line-height: 1.35;
  max-width: min(340px, calc(100vw - 28px));
  opacity: 0;
  padding: 10px 14px;
  pointer-events: none;
  position: absolute;
  transform: translateX(-50%) translateY(12px);
  transition: opacity 160ms ease, transform 160ms ease;
  white-space: normal;
  z-index: 10;
}

.toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.panel {
  background:
    rgba(16, 29, 18, 0.94),
    url("assets/tiles/grass-dark.png");
  background-size: auto, 144px 144px;
  border: 2px solid var(--line);
  border-radius: 2px;
  box-shadow: inset 0 0 0 2px rgba(4, 12, 7, 0.7), 5px 5px 0 rgba(1, 5, 3, 0.58);
  display: flex;
  flex-direction: column;
  gap: 0;
  max-height: calc(100vh - 36px);
  overflow: auto;
  padding: 16px;
}

.brand {
  display: none;
  border-bottom: 1px solid var(--line);
  padding-bottom: 14px;
}

.points-banner {
  align-items: center;
  background: rgba(10, 22, 13, 0.96);
  border: 2px solid var(--line-strong);
  border-bottom: 0;
  border-radius: 2px;
  display: flex;
  justify-content: space-between;
  padding: 8px 12px;
  position: sticky;
  top: 0;
  z-index: 8;
}

.points-banner span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
}

.points-banner strong {
  color: #fff6c8;
  font-size: 24px;
}

.brand h1 {
  color: #fff6c8;
  font-size: 27px;
  letter-spacing: 0;
  line-height: 1.15;
  margin: 0 0 8px;
  text-shadow: 0 2px 0 #172414;
}

.brand p {
  color: var(--muted);
  display: none;
  line-height: 1.5;
  margin: 0;
}

.tabs {
  background: rgba(8, 16, 11, 0.86);
  border: 2px solid var(--line-strong);
  border-radius: 2px;
  border-top: 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  padding: 4px;
  position: sticky;
  top: 45px;
  z-index: 8;
}

.tab {
  background: transparent;
  box-shadow: none;
  color: var(--muted);
  min-height: 34px;
}

.tab.is-active,
.remove-tab.is-active {
  background: #263f2b;
  color: var(--text);
}

.remove-tab.is-active {
  background: #56312d;
  border-color: rgba(240, 113, 103, 0.72);
  color: #fff1ec;
}

.panel-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 10px;
}

.is-hidden {
  display: none;
}

.tower-list {
  display: grid;
  gap: 10px;
}

.tower-card,
.selection {
  background: var(--tower-bg, rgba(31, 49, 36, 0.78));
  border: 2px solid rgba(218, 184, 99, 0.48);
  border-radius: 2px;
  padding: 10px;
}

.tower-card {
  cursor: pointer;
  min-height: 92px;
  position: relative;
  text-align: left;
  transform-origin: center;
  transition: transform 120ms steps(2, end), border-width 120ms steps(2, end);
}

.tower-card:disabled,
.tower-card.is-unaffordable,
.selection button.is-unaffordable {
  cursor: not-allowed;
  filter: grayscale(0.9) brightness(0.72);
  opacity: 0.52;
}

.tower-card:disabled .cost,
.selection button:disabled {
  color: rgba(245, 241, 220, 0.55);
}

.tower-card.is-active {
  border-color: var(--tower-color, var(--accent));
  border-width: 4px;
  box-shadow: inset 0 0 0 3px rgba(245, 241, 220, 0.32), 4px 4px 0 rgba(2, 8, 4, 0.66);
  transform: scale(1.045);
  z-index: 2;
}

.tower-card-main,
.selection-main {
  align-items: center;
  display: grid;
  gap: 10px;
  grid-template-columns: 72px 1fr;
}

.tower-card-copy {
  min-width: 0;
}

.tower-card-icon,
.selection-icon {
  background: rgba(4, 12, 7, 0.7);
  border: 2px solid var(--tower-color, rgba(245, 221, 148, 0.36));
  border-radius: 2px;
  display: block;
  height: 72px;
  image-rendering: pixelated;
  object-fit: contain;
  width: 72px;
}

.selection-icon {
  height: 92px;
  width: 92px;
}

.selection-main {
  grid-template-columns: 92px 1fr;
}

.tower-title {
  align-items: center;
  display: flex;
  gap: 6px;
  justify-content: space-between;
  margin-bottom: 5px;
  min-width: 0;
}

.tower-title strong {
  color: #fff2b8;
  font-size: 16px;
  line-height: 1.1;
}

.cost {
  color: var(--gold);
  font-size: 17px;
  font-weight: 900;
  line-height: 1;
  white-space: nowrap;
}

.stats {
  color: var(--muted);
  display: grid;
  font-size: 12px;
  gap: 3px 5px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  line-height: 1.15;
}

.tower-effect {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
  margin: 4px 0 0;
}

.actions {
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr;
}

.speed-control,
.debug-tools {
  background: rgba(8, 16, 11, 0.82);
  border: 2px solid var(--line);
  border-radius: 2px;
  display: grid;
  gap: 10px;
  padding: 12px;
}

.speed-label {
  align-items: center;
  color: var(--muted);
  display: flex;
  font-size: 13px;
  justify-content: space-between;
}

.speed-label strong {
  color: var(--text);
  font-size: 15px;
}

input[type="range"] {
  accent-color: var(--accent);
  cursor: pointer;
  touch-action: none;
  user-select: none;
  width: 100%;
}

.debug-tools summary {
  color: var(--text);
  cursor: pointer;
  font-weight: 800;
}

.debug-actions {
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr 1fr;
  margin-top: 10px;
}

.debug-toggle,
.debug-wave,
.debug-history {
  align-items: center;
  color: var(--muted);
  display: flex;
  font-size: 13px;
  gap: 10px;
  margin-top: 10px;
}

.debug-toggle input {
  accent-color: var(--accent);
  height: 18px;
  width: 18px;
}

.debug-history label,
.debug-wave label {
  color: var(--text);
  font-weight: 800;
  text-transform: uppercase;
}

.debug-history select,
.debug-wave input {
  background: rgba(4, 10, 7, 0.92);
  border: 2px solid rgba(218, 184, 99, 0.36);
  border-radius: 2px;
  color: var(--text);
  font: inherit;
  padding: 9px 10px;
}

.debug-history select {
  min-width: 0;
  width: 100%;
}

.debug-wave input {
  width: 86px;
}

.debug-tools textarea {
  background: rgba(4, 10, 7, 0.92);
  border: 2px solid rgba(218, 184, 99, 0.36);
  border-radius: 2px;
  color: var(--text);
  font: 12px Consolas, monospace;
  height: 140px;
  margin-top: 10px;
  padding: 9px;
  resize: vertical;
  width: 100%;
}

.ghost {
  background: rgba(8, 16, 11, 0.72);
  border-color: rgba(222, 200, 145, 0.36);
  box-shadow: none;
  color: var(--text);
}

.ghost.is-active {
  border-color: var(--danger);
  color: #ffd6d2;
}

.upgrade-row {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.upgrade-row button {
  flex: 1;
}

.special-row {
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr;
  margin-top: 12px;
}

.special-row button {
  background: #5b9ea1;
  color: #07121a;
}

.empty {
  color: var(--muted);
}

.orientation-message {
  display: none;
}

@media (max-width: 980px) and (orientation: portrait) {
  .shell {
    grid-template-columns: 1fr;
  }

  canvas {
    height: auto;
  }

  .panel {
    max-height: none;
  }
}

@media (max-width: 980px) and (orientation: landscape) {
  body {
    overflow: hidden;
  }

  .shell {
    gap: 8px;
    grid-template-columns: minmax(0, 1fr) minmax(210px, 238px);
    height: 100svh;
    max-width: none;
    min-height: 0;
    padding: 8px;
  }

  .game-stage {
    gap: 6px;
    min-height: 0;
  }

  canvas {
    height: auto;
    max-height: calc(100svh - 74px);
    min-height: 0;
    max-width: 100%;
    width: min(100%, calc((100svh - 74px) * 1.5));
  }

  .field-actions {
    gap: 6px;
    grid-template-columns: minmax(124px, 180px) minmax(170px, 240px);
  }

  .field-actions button {
    min-height: 34px;
    padding: 6px 14px;
  }

  .field-actions .speed-control {
    padding: 5px 8px;
  }

  .field-actions .speed-label {
    font-size: 11px;
  }

  .field-actions .speed-label strong {
    font-size: 13px;
  }

  .field-hud {
    left: 10px;
    right: 10px;
    top: 7px;
  }

  .light-render-notice {
    right: 10px;
    top: 7px;
  }

  .field-hud span {
    font-size: 13px;
  }

  .field-hud strong {
    font-size: 17px;
  }

  .life-gauge,
  .wave-progress-gauge {
    bottom: 6%;
    height: 22px;
    left: 10px;
    width: min(260px, 32%);
  }

  .wave-progress-gauge {
    left: auto;
    right: 10px;
  }

  .panel {
    gap: 0;
    max-height: calc(100svh - 16px);
    min-width: 0;
    padding: 8px;
  }

  .brand {
    padding-bottom: 8px;
  }

  .brand h1 {
    font-size: 17px;
    margin-bottom: 4px;
  }

  .points-banner {
    padding: 7px 9px;
  }

  .points-banner strong {
    font-size: 19px;
  }

  .tabs {
    top: 45px;
  }

  .tab {
    font-size: 13px;
    min-height: 30px;
    padding: 5px 6px;
  }

  .brand p {
    display: none;
  }

  .tower-list {
    gap: 7px;
  }

  .tower-card,
  .selection {
    padding: 6px;
  }

  .tower-card-main {
    gap: 6px;
    grid-template-columns: 34px 1fr;
  }

  .tower-card-icon,
  .selection-icon {
    height: 34px;
    width: 34px;
  }

  .tower-card {
    min-height: 52px;
  }

  .tower-title {
    margin-bottom: 3px;
  }

  .tower-title strong {
    font-size: 13px;
  }

  .cost {
    font-size: 20px;
  }

  .stats {
    font-size: 10px;
    gap: 2px 4px;
    line-height: 1.1;
  }

  .tower-effect {
    display: none;
  }
}

@media (max-width: 620px) and (orientation: portrait) {
  body {
    height: 100svh;
    overflow: hidden;
    width: 100svw;
  }

  .shell {
    filter: none;
    gap: 8px;
    grid-template-columns: minmax(0, 1fr) minmax(210px, 238px);
    height: 100svw;
    left: 50%;
    max-width: none;
    min-height: 0;
    overflow: hidden;
    padding: 8px;
    pointer-events: auto;
    position: fixed;
    top: 50%;
    transform: translate(-50%, -50%) rotate(90deg);
    transform-origin: center center;
    width: 100svh;
  }

  .orientation-message {
    display: none;
  }

  .game-stage {
    gap: 6px;
    min-height: 0;
  }

  canvas {
    height: auto;
    max-height: calc(100svw - 74px);
    min-height: 0;
    max-width: 100%;
    width: min(100%, calc((100svw - 74px) * 1.5));
  }

  .field-actions {
    gap: 6px;
    grid-template-columns: minmax(124px, 180px) minmax(170px, 240px);
  }

  .field-actions button {
    min-height: 34px;
    padding: 6px 14px;
  }

  .field-actions .speed-control {
    padding: 5px 8px;
  }

  .field-actions .speed-label {
    font-size: 11px;
  }

  .field-actions .speed-label strong {
    font-size: 13px;
  }

  .field-hud {
    left: 10px;
    right: 10px;
    top: 7px;
  }

  .light-render-notice {
    right: 10px;
    top: 7px;
  }

  .field-hud span {
    font-size: 13px;
  }

  .field-hud strong {
    font-size: 17px;
  }

  .life-gauge,
  .wave-progress-gauge {
    bottom: 6%;
    height: 22px;
    left: 10px;
    width: min(260px, 32%);
  }

  .wave-progress-gauge {
    left: auto;
    right: 10px;
  }

  .panel {
    gap: 0;
    max-height: calc(100svw - 16px);
    min-width: 0;
    padding: 8px;
  }

  .brand {
    padding-bottom: 8px;
  }

  .brand h1 {
    font-size: 17px;
    margin-bottom: 4px;
  }

  .points-banner {
    padding: 7px 9px;
  }

  .points-banner strong {
    font-size: 19px;
  }

  .tabs {
    top: 45px;
  }

  .tab {
    font-size: 13px;
    min-height: 30px;
    padding: 5px 6px;
  }

  .brand p {
    display: none;
  }

  .tower-list {
    gap: 7px;
  }

  .tower-card,
  .selection {
    padding: 6px;
  }

  .tower-card-main {
    gap: 6px;
    grid-template-columns: 34px 1fr;
  }

  .tower-card-icon,
  .selection-icon {
    height: 34px;
    width: 34px;
  }

  .tower-card {
    min-height: 52px;
  }

  .tower-title {
    margin-bottom: 3px;
  }

  .tower-title strong {
    font-size: 13px;
  }

  .cost {
    font-size: 20px;
  }

  .stats {
    font-size: 10px;
    gap: 2px 4px;
    line-height: 1.1;
  }

  .tower-effect {
    display: none;
  }
}

@media (max-width: 620px) and (orientation: portrait) {
  .shell {
    padding: 8px;
  }

  .actions {
    grid-template-columns: 1fr;
  }

  .tower-card-main {
    grid-template-columns: 40px 1fr;
  }

  .tower-card-icon {
    height: 40px;
    width: 40px;
  }
}

.production .debug-tools,
.production .debug-tools[hidden] {
  border: 0 !important;
  display: none !important;
  height: 0 !important;
  margin: 0 !important;
  overflow: hidden !important;
  padding: 0 !important;
  visibility: hidden !important;
}
