:root {
  --ink: #f7fbff;
  --muted: #a9b5c6;
  --dim: #6d7788;
  --panel: rgba(8, 12, 18, 0.78);
  --panel-strong: rgba(7, 10, 15, 0.92);
  --line: rgba(255, 255, 255, 0.16);
  --line-strong: rgba(255, 255, 255, 0.28);
  --cyan: #20f4ff;
  --pink: #ff4fd8;
  --lime: #9cff4a;
  --amber: #ffca3a;
  --violet: #9c7cff;
  --orange: #ff7a30;
  --shadow: 0 18px 60px rgba(0, 0, 0, 0.45);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #05070a;
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button {
  font: inherit;
  cursor: pointer;
}

.app {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  background: #05070a;
}

#gameCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.scanline {
  pointer-events: none;
  position: absolute;
  inset: 0;
  background:
    linear-gradient(rgba(255, 255, 255, 0.028) 1px, transparent 1px) 0 0 / 100% 4px,
    radial-gradient(circle at 52% 115%, rgba(255, 255, 255, 0.1), transparent 36%);
  opacity: 0.34;
  mix-blend-mode: screen;
}

.topbar,
.tower-dock,
.inspector,
.command-bar,
.menu-panel,
.level-panel,
.dialog {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(20px);
}

.topbar {
  position: absolute;
  z-index: 4;
  top: calc(12px + env(safe-area-inset-top));
  left: calc(12px + env(safe-area-inset-left));
  right: calc(12px + env(safe-area-inset-right));
  display: grid;
  grid-template-columns: minmax(190px, 280px) minmax(280px, 1fr) auto;
  align-items: center;
  gap: 12px;
  min-height: 56px;
  padding: 8px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-mark {
  position: relative;
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  border: 1px solid rgba(32, 244, 255, 0.85);
  border-radius: 8px;
  background:
    radial-gradient(circle at 50% 50%, rgba(255, 79, 216, 0.38), transparent 34%),
    linear-gradient(135deg, rgba(32, 244, 255, 0.2), rgba(156, 124, 255, 0.16)),
    #081018;
  box-shadow:
    0 0 22px rgba(32, 244, 255, 0.42),
    inset 0 0 20px rgba(255, 255, 255, 0.08);
}

.brand-mark::before,
.brand-mark::after {
  content: "";
  position: absolute;
  inset: 9px;
  border: 2px solid var(--amber);
  border-radius: 50%;
}

.brand-mark::after {
  inset: 13px 3px;
  border-color: var(--cyan);
}

.brand strong,
.brand span,
.resource-strip span,
.tower-card strong,
.tower-card span,
.tower-stat,
.inspector span,
#hintText {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand strong {
  display: block;
  font-size: 0.92rem;
  font-weight: 860;
}

.brand span {
  display: block;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 720;
}

.resource-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(78px, 1fr));
  gap: 8px;
  min-width: 0;
}

.resource-strip span,
.tower-stat,
.menu-badges span,
.level-meta span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink);
  font-size: 0.78rem;
  font-weight: 820;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.icon-button,
.speed-button,
.primary-button,
.ghost-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.1);
  font-weight: 840;
  transition:
    transform 150ms ease,
    border-color 150ms ease,
    background 150ms ease,
    box-shadow 150ms ease;
}

.icon-button:hover,
.speed-button:hover,
.primary-button:hover,
.ghost-button:hover,
.tower-card:hover,
.level-card:hover {
  transform: translateY(-1px);
  border-color: rgba(32, 244, 255, 0.62);
  box-shadow:
    0 0 22px rgba(32, 244, 255, 0.22),
    inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.icon-button:focus-visible,
.speed-button:focus-visible,
.primary-button:focus-visible,
.ghost-button:focus-visible,
.tower-card:focus-visible,
.level-card:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 3px;
}

.icon-button {
  width: 38px;
  padding: 0;
}

.speed-button {
  min-width: 48px;
  padding: 0 10px;
}

.pause-icon {
  position: relative;
  width: 14px;
  height: 16px;
}

.pause-icon::before,
.pause-icon::after {
  content: "";
  position: absolute;
  top: 1px;
  bottom: 1px;
  width: 4px;
  border-radius: 2px;
  background: currentColor;
}

.pause-icon::before {
  left: 1px;
}

.pause-icon::after {
  right: 1px;
}

.primary-button,
.ghost-button {
  min-width: 126px;
  padding: 0 16px;
}

.primary-button {
  border-color: rgba(156, 255, 74, 0.68);
  background:
    linear-gradient(135deg, rgba(156, 255, 74, 0.34), rgba(32, 244, 255, 0.2)),
    rgba(255, 255, 255, 0.1);
}

.ghost-button.compact {
  min-width: 84px;
  min-height: 34px;
}

.tower-dock {
  position: absolute;
  z-index: 3;
  top: 86px;
  left: calc(12px + env(safe-area-inset-left));
  width: 232px;
  max-height: calc(100vh - 160px);
  overflow: auto;
  padding: 10px;
}

.tower-card {
  position: relative;
  width: 100%;
  min-height: 72px;
  margin-bottom: 8px;
  padding: 10px 10px 10px 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  text-align: left;
  background: rgba(255, 255, 255, 0.08);
  transition:
    transform 150ms ease,
    border-color 150ms ease,
    box-shadow 150ms ease;
}

.tower-card.is-selected {
  border-color: var(--tower-color);
  box-shadow:
    0 0 22px color-mix(in srgb, var(--tower-color), transparent 70%),
    inset 0 0 0 1px color-mix(in srgb, var(--tower-color), transparent 48%);
}

.tower-card.is-disabled {
  opacity: 0.45;
}

.tower-card::before {
  content: "";
  position: absolute;
  top: 14px;
  left: 12px;
  width: 24px;
  height: 24px;
  border: 2px solid var(--tower-color);
  border-radius: 7px;
  box-shadow: 0 0 18px var(--tower-color);
  transform: rotate(45deg);
}

.tower-card strong {
  display: block;
  font-size: 0.86rem;
}

.tower-card span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 720;
}

.tower-cost {
  position: absolute;
  top: 9px;
  right: 10px;
  color: var(--tower-color);
  font-size: 0.75rem;
  font-weight: 900;
}

.inspector {
  position: absolute;
  z-index: 3;
  top: 86px;
  right: calc(12px + env(safe-area-inset-right));
  width: 260px;
  min-height: 170px;
  padding: 12px;
}

.inspector h3 {
  margin: 0;
  font-size: 1.05rem;
}

.inspector p {
  margin: 6px 0 12px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 710;
  line-height: 1.4;
}

.inspector-empty {
  display: grid;
  min-height: 140px;
  place-content: center;
  gap: 6px;
  color: var(--muted);
  text-align: center;
}

.inspector-empty strong {
  color: var(--ink);
}

.tower-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}

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

.target-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  margin-bottom: 10px;
}

.target-row button {
  min-width: 0;
  min-height: 30px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.07);
  font-size: 0.72rem;
  font-weight: 830;
}

.target-row button.is-active {
  border-color: var(--cyan);
  color: var(--ink);
}

.command-bar {
  position: absolute;
  z-index: 4;
  left: 50%;
  bottom: calc(14px + env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: auto auto minmax(180px, 420px);
  align-items: center;
  gap: 10px;
  width: min(760px, calc(100vw - 28px));
  min-height: 58px;
  padding: 9px;
  transform: translateX(-50%);
}

.app[data-screen="menu"] .tower-dock,
.app[data-screen="menu"] .inspector,
.app[data-screen="menu"] .command-bar,
.app[data-screen="levels"] .tower-dock,
.app[data-screen="levels"] .inspector,
.app[data-screen="levels"] .command-bar,
.app[data-screen="result"] .tower-dock,
.app[data-screen="result"] .inspector,
.app[data-screen="result"] .command-bar {
  pointer-events: none;
  opacity: 0;
}

#hintText {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 720;
}

.screen,
.overlay {
  pointer-events: none;
  position: absolute;
  inset: 0;
  z-index: 6;
  display: grid;
  place-items: center;
  padding: 92px 20px 86px;
  overflow: auto;
  opacity: 0;
  transform: translateY(10px);
  transition:
    opacity 180ms ease,
    transform 180ms ease;
  -webkit-overflow-scrolling: touch;
}

.screen.is-active,
.overlay.is-active {
  pointer-events: auto;
  opacity: 1;
  transform: translateY(0);
}

.menu-panel,
.level-panel,
.dialog {
  width: min(740px, calc(100vw - 32px));
  max-width: calc(100vw - 32px);
  overflow: hidden;
}

.menu-panel {
  padding: 30px;
}

.kicker {
  margin: 0 0 10px;
  color: var(--cyan);
  font-size: 0.76rem;
  font-weight: 880;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(2.7rem, 8vw, 5.2rem);
  line-height: 0.94;
}

h1 span {
  display: block;
}

h2 {
  font-size: clamp(1.8rem, 4vw, 3.2rem);
  line-height: 1;
}

.menu-actions,
.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 24px;
}

.menu-badges,
.level-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

.menu-badges span,
.level-meta span {
  justify-content: flex-start;
  min-width: 0;
  max-width: 100%;
  color: var(--muted);
}

.level-panel {
  padding: 18px;
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.level-card {
  position: relative;
  min-height: 164px;
  overflow: hidden;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  text-align: left;
  background: rgba(255, 255, 255, 0.08);
  transition:
    transform 150ms ease,
    border-color 150ms ease,
    box-shadow 150ms ease;
}

.level-card::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(135deg, var(--field-a), transparent 48%),
    radial-gradient(circle at 82% 18%, var(--field-b), transparent 32%);
  opacity: 0.86;
}

.level-card > * {
  position: relative;
}

.level-card strong {
  display: block;
  margin-bottom: 8px;
  font-size: 1.02rem;
}

.level-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 720;
  line-height: 1.35;
}

.level-card small {
  position: absolute;
  left: 14px;
  bottom: 14px;
  color: var(--field-color);
  font-size: 0.75rem;
  font-weight: 900;
}

.overlay {
  background: rgba(0, 0, 0, 0.22);
}

.dialog {
  max-width: 460px;
  padding: 24px;
  text-align: center;
}

.dialog-actions {
  justify-content: center;
}

.result-line {
  margin: 14px 0 0;
  color: var(--muted);
  font-weight: 760;
}

@media (max-width: 1040px) {
  .topbar {
    grid-template-columns: minmax(180px, 1fr) auto;
  }

  .resource-strip {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .tower-dock {
    top: auto;
    right: 12px;
    bottom: calc(78px + env(safe-area-inset-bottom));
    width: auto;
    max-height: 118px;
    display: flex;
    gap: 8px;
    overflow-x: auto;
    overflow-y: hidden;
  }

  .tower-card {
    width: 178px;
    flex: 0 0 178px;
    margin-bottom: 0;
  }

  .inspector {
    top: auto;
    right: 12px;
    bottom: calc(204px + env(safe-area-inset-bottom));
    width: min(340px, calc(100vw - 24px));
  }
}

@media (max-width: 760px) {
  .topbar {
    top: calc(8px + env(safe-area-inset-top));
    left: calc(8px + env(safe-area-inset-left));
    right: auto;
    width: min(374px, calc(100vw - 16px));
    max-width: calc(100vw - 16px);
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 7px;
    padding: 7px;
    overflow: hidden;
  }

  .brand {
    gap: 8px;
  }

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

  .brand strong {
    font-size: 0.82rem;
  }

  .brand span {
    font-size: 0.68rem;
  }

  .top-actions {
    gap: 6px;
  }

  .icon-button {
    width: 34px;
    min-height: 34px;
  }

  .speed-button {
    min-width: 42px;
    min-height: 34px;
    padding: 0 8px;
  }

  .resource-strip {
    width: 100%;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
  }

  .resource-strip span {
    min-width: 0;
    min-height: 30px;
    padding: 0 5px;
    font-size: 0.68rem;
  }

  .tower-dock {
    left: 8px;
    right: auto;
    width: min(374px, calc(100vw - 16px));
    max-width: calc(100vw - 16px);
    bottom: calc(72px + env(safe-area-inset-bottom));
  }

  .inspector {
    display: none;
  }

  .command-bar {
    left: calc(8px + env(safe-area-inset-left));
    bottom: calc(8px + env(safe-area-inset-bottom));
    grid-template-columns: minmax(0, 1fr) auto;
    width: min(374px, calc(100vw - 16px));
    max-width: calc(100vw - 16px);
    gap: 8px;
    transform: none;
  }

  .command-bar .primary-button,
  .command-bar .ghost-button {
    min-height: 36px;
    padding: 0 10px;
  }

  #hintText {
    display: none;
  }

  .screen,
  .overlay {
    justify-items: start;
    align-items: start;
    padding: 118px 12px 194px;
  }

  .menu-panel {
    width: min(350px, calc(100vw - 24px));
    max-width: calc(100vw - 24px);
    padding: 22px;
  }

  .level-panel,
  .dialog {
    width: min(350px, calc(100vw - 24px));
    max-width: calc(100vw - 24px);
  }

  h1 {
    font-size: clamp(2.15rem, 11vw, 3rem);
    line-height: 1.02;
  }

  .menu-actions,
  .dialog-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .primary-button,
  .ghost-button {
    min-width: 0;
  }

  .menu-actions .primary-button,
  .menu-actions .ghost-button,
  .dialog-actions .primary-button,
  .dialog-actions .ghost-button {
    width: 100%;
  }

  .menu-badges {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .menu-badges span {
    min-height: 34px;
    padding: 0 7px;
    justify-content: center;
    text-align: center;
    white-space: normal;
    line-height: 1.12;
    font-size: 0.7rem;
  }

  .level-panel {
    max-height: calc(100dvh - 132px);
    overflow: auto;
  }

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

  .level-card {
    min-height: 130px;
  }
}

@media (max-height: 560px) and (orientation: landscape) {
  .topbar {
    min-height: 46px;
  }

  .resource-strip span {
    min-height: 28px;
  }

  .screen,
  .overlay {
    padding-top: 74px;
  }

  .menu-panel {
    padding: 20px;
  }

  .tower-dock {
    max-height: 102px;
  }
}
