:root {
  color-scheme: dark;
  --ink: #edf4ee;
  --muted: #a8b5ae;
  --panel: rgba(20, 28, 28, 0.86);
  --panel-strong: rgba(16, 23, 24, 0.96);
  --line: rgba(255, 255, 255, 0.14);
  --accent: #8fd36f;
  --accent-2: #6bd1c8;
  --warn: #ffcf6f;
  --bad: #ff7b7b;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #070b0c;
  color: var(--ink);
}

button,
input {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink);
  min-height: 42px;
  padding: 0 16px;
  cursor: pointer;
}

button:hover {
  border-color: rgba(255, 255, 255, 0.34);
  background: rgba(255, 255, 255, 0.13);
}

button:active {
  transform: translateY(1px);
}

#game-canvas {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: block;
  cursor: crosshair;
}

.screen-layer {
  position: fixed;
  inset: 0;
  display: none;
  place-items: center;
  padding: 24px;
  background: linear-gradient(180deg, rgba(16, 23, 25, 0.18), rgba(9, 12, 14, 0.72));
}

.screen-layer,
#game-ui {
  display: none !important;
}

body[data-screen="menu"] #menu-screen,
body[data-screen="settings"] #settings-screen,
body[data-screen="closed"] #closed-screen {
  display: grid;
}

.menu-panel,
.settings-panel {
  width: min(430px, calc(100vw - 36px));
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.38);
  padding: 30px;
}

.menu-panel.compact {
  width: min(360px, calc(100vw - 36px));
}

.kicker {
  margin: 0 0 7px;
  color: var(--accent-2);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

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

h2 {
  font-size: 1.35rem;
}

.menu-actions {
  display: grid;
  gap: 10px;
  margin-top: 28px;
}

.primary-action {
  background: linear-gradient(180deg, #9adc78, #5faf52);
  border-color: rgba(230, 255, 217, 0.4);
  color: #0c180e;
  font-weight: 900;
}

.primary-action:hover {
  background: linear-gradient(180deg, #b4ed91, #6fbd61);
}

.setting-row {
  display: grid;
  grid-template-columns: 100px 1fr 58px;
  align-items: center;
  gap: 12px;
  margin-top: 18px;
  color: var(--muted);
}

.setting-row strong {
  color: var(--ink);
  text-align: right;
}

.checkbox-row {
  grid-template-columns: 100px 1fr;
}

.checkbox-row input {
  justify-self: start;
}

#game-ui {
  position: fixed;
  inset: 0;
  display: none;
  pointer-events: none;
}

body[data-screen="game"] #game-ui {
  display: block;
}

.topbar,
.inspector,
.build-palette {
  pointer-events: auto;
}

.topbar {
  position: fixed;
  top: 12px;
  left: 12px;
  right: 12px;
  display: flex;
  align-items: stretch;
  gap: 8px;
}

.stat-block {
  min-width: 92px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 8px 12px;
}

.stat-block span {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
}

.stat-block strong {
  display: block;
  margin-top: 2px;
  font-size: 1.1rem;
}

.topbar-actions {
  display: flex;
  gap: 8px;
  margin-left: auto;
}

.inspector {
  position: fixed;
  top: 76px;
  right: 12px;
  width: 260px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 16px;
}

.inspector dl {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 9px 14px;
  margin: 18px 0 0;
}

.inspector dt {
  color: var(--muted);
}

.inspector dd {
  margin: 0;
  text-align: right;
  font-weight: 800;
}

.message-line {
  min-height: 20px;
  margin: 16px 0 0;
  color: var(--warn);
  font-weight: 700;
}

.build-palette {
  position: fixed;
  left: 50%;
  bottom: 16px;
  display: flex;
  gap: 10px;
  transform: translateX(-50%);
}

.tool-button {
  width: 138px;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
  background: rgba(20, 30, 31, 0.88);
}

.tool-button span,
.tool-button strong {
  overflow-wrap: anywhere;
}

.tool-button strong {
  color: var(--warn);
}

.tool-button.is-selected {
  border-color: rgba(143, 211, 111, 0.88);
  box-shadow: 0 0 0 1px rgba(143, 211, 111, 0.3) inset;
}

@media (max-width: 900px) {
  .topbar {
    flex-wrap: wrap;
  }

  .stat-block {
    min-width: 74px;
    padding: 7px 9px;
  }

  .topbar-actions {
    width: 100%;
    margin-left: 0;
  }

  .topbar-actions button {
    flex: 1 1 0;
  }

  .inspector {
    left: 12px;
    right: 12px;
    top: auto;
    bottom: 82px;
    width: auto;
    display: none;
  }

  .build-palette {
    left: 8px;
    right: 8px;
    bottom: 10px;
    transform: none;
  }

  .tool-button {
    width: auto;
    flex: 1 1 0;
    min-width: 0;
    padding: 0 9px;
  }
}
