:root {
  color-scheme: dark;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  --ink: #f7fafc;
  --muted: #b8c2cc;
  --panel: rgba(15, 23, 42, 0.84);
  --panel-solid: #111827;
  --line: rgba(255, 255, 255, 0.16);
  --accent: #36d399;
  --accent-2: #38bdf8;
  --danger: #fb7185;
  --warn: #fbbf24;
}

* {
  box-sizing: border-box;
}

html,
body,
#app {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  background: #0a101c;
  color: var(--ink);
}

button,
input {
  font: inherit;
}

#app {
  position: relative;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.topbar,
.build-panel,
.city-panel,
.inspector,
.minimap-shell,
.toast,
.join-card {
  position: absolute;
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(14px);
}

.topbar {
  top: 14px;
  left: 14px;
  right: 14px;
  min-height: 58px;
  display: grid;
  grid-template-columns: minmax(150px, 1.2fr) repeat(5, minmax(92px, 0.75fr));
  gap: 8px;
  align-items: center;
  padding: 8px;
  border-radius: 8px;
}

.brand,
.stat {
  min-width: 0;
  height: 42px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.06);
}

.brand {
  font-weight: 800;
}

.brand-mark {
  width: 24px;
  height: 24px;
  display: inline-grid;
  place-items: center;
  border-radius: 5px;
  background:
    linear-gradient(90deg, transparent 42%, #26364c 43% 57%, transparent 58%),
    linear-gradient(0deg, transparent 42%, #26364c 43% 57%, transparent 58%),
    #4ade80;
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.2);
  flex: 0 0 auto;
}

.stat {
  justify-content: space-between;
}

.stat span,
.selected-detail,
#city-message {
  color: var(--muted);
}

.stat strong {
  white-space: nowrap;
  font-size: 0.98rem;
}

.build-panel {
  left: 14px;
  top: 88px;
  width: 294px;
  max-height: calc(100% - 168px);
  display: flex;
  flex-direction: column;
  border-radius: 8px;
  overflow: hidden;
}

.city-panel {
  top: 88px;
  right: 14px;
  width: 308px;
  display: flex;
  flex-direction: column;
  border-radius: 8px;
  overflow: hidden;
}

.panel-block + .panel-block {
  border-top: 1px solid var(--line);
}

.panel-title {
  padding: 12px 14px;
  font-weight: 800;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
}

.panel-title.compact {
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 12px;
}

.connection-status {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.connection-status.online {
  color: #bbf7d0;
}

.connection-status.offline {
  color: #fecdd3;
}

.build-list {
  overflow: auto;
  padding: 8px;
}

.build-button {
  width: 100%;
  min-height: 64px;
  margin: 0 0 8px;
  display: grid;
  grid-template-columns: 38px 1fr auto;
  gap: 10px;
  align-items: center;
  color: var(--ink);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.07);
  cursor: pointer;
  text-align: left;
  transition:
    transform 140ms ease,
    background 140ms ease,
    border-color 140ms ease;
}

.build-button:hover {
  transform: translateY(-1px);
  border-color: rgba(74, 222, 128, 0.5);
  background: rgba(74, 222, 128, 0.12);
}

.build-button.active {
  border-color: rgba(74, 222, 128, 0.95);
  background: rgba(74, 222, 128, 0.18);
}

.build-button.locked,
.build-button.disabled {
  opacity: 0.56;
}

.build-button.disabled {
  cursor: not-allowed;
}

.tool-icon {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: var(--icon-color, #38bdf8);
  color: #07111f;
  font-weight: 900;
  box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.18);
}

.tool-copy {
  min-width: 0;
}

.tool-name,
.tool-meta,
.tool-cost {
  display: block;
}

.tool-name {
  font-weight: 800;
}

.tool-meta {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.78rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tool-cost {
  color: #d9f99d;
  font-weight: 800;
  white-space: nowrap;
}

.demand-list {
  display: grid;
  gap: 10px;
  padding: 10px 12px 12px;
}

.demand-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px 10px;
  align-items: center;
  font-size: 0.82rem;
}

.demand-row strong {
  font-size: 0.78rem;
}

.demand-track {
  grid-column: 1 / -1;
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.11);
}

.demand-fill {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  transition: width 240ms ease;
}

.demand-fill.residential {
  background: #35d07f;
}

.demand-fill.commercial {
  background: #38bdf8;
}

.demand-fill.industry {
  background: #fbbf24;
}

.demand-fill.power {
  background: #fde047;
}

.demand-fill.water {
  background: #67e8f9;
}

.players-list {
  display: grid;
  gap: 6px;
  max-height: 126px;
  overflow: auto;
  padding: 9px 10px 11px;
}

.player-pill {
  min-width: 0;
  min-height: 30px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
  font-size: 0.82rem;
}

.player-dot {
  width: 10px;
  height: 10px;
  flex: 0 0 auto;
  border-radius: 999px;
  background: var(--player-color, #38bdf8);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.08);
}

.player-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.inspector {
  left: 14px;
  bottom: 14px;
  right: 214px;
  min-height: 58px;
  display: grid;
  grid-template-columns: auto auto 1fr;
  gap: 12px;
  align-items: center;
  padding: 10px 14px;
  border-radius: 8px;
}

.minimap-shell {
  right: 14px;
  bottom: 14px;
  width: 184px;
  height: 184px;
  padding: 2px;
  border-radius: 8px;
}

#minimap {
  display: block;
  width: 180px;
  height: 180px;
  border-radius: 6px;
  background: #20351d;
}

.toast {
  left: 50%;
  bottom: 92px;
  max-width: min(520px, calc(100% - 28px));
  padding: 10px 14px;
  border-radius: 8px;
  transform: translate(-50%, 20px);
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.join-screen {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(7, 17, 31, 0.36);
  backdrop-filter: blur(6px);
}

.join-screen.hidden {
  display: none;
}

.join-card {
  position: relative;
  width: min(430px, 100%);
  display: grid;
  gap: 12px;
  padding: 18px;
  border-radius: 8px;
}

.join-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 900;
  font-size: 1.1rem;
}

.join-card label {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

.join-controls {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.join-controls input {
  min-width: 0;
  height: 42px;
  padding: 0 12px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 6px;
  outline: none;
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink);
}

.join-controls input:focus {
  border-color: rgba(74, 222, 128, 0.72);
}

.join-controls button {
  height: 42px;
  padding: 0 14px;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #06140d;
  font-weight: 900;
  cursor: pointer;
}

#join-status {
  min-height: 18px;
  color: var(--muted);
  font-size: 0.84rem;
}

@media (max-width: 920px) {
  .topbar {
    grid-template-columns: repeat(3, minmax(92px, 1fr));
    right: 10px;
    left: 10px;
  }

  .brand {
    grid-column: span 3;
  }

  .build-panel {
    top: auto;
    left: 10px;
    right: 10px;
    bottom: 84px;
    width: auto;
    max-height: 190px;
  }

  .city-panel {
    top: 198px;
    right: 10px;
    width: min(280px, calc(100% - 20px));
  }

  .players-block {
    display: none;
  }

  .build-list {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(220px, 1fr);
    overflow-x: auto;
    overflow-y: hidden;
  }

  .inspector {
    left: 10px;
    right: 10px;
    bottom: 10px;
    min-height: 60px;
    grid-template-columns: auto auto;
  }

  #city-message {
    grid-column: 1 / -1;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  .minimap-shell {
    display: none;
  }
}

@media (max-width: 560px) {
  .topbar {
    min-height: 0;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
    padding: 6px;
  }

  .brand {
    grid-column: 1 / -1;
  }

  .brand,
  .stat {
    height: 36px;
    padding: 0 8px;
    font-size: 0.83rem;
  }

  .build-panel {
    max-height: 168px;
  }

  .city-panel {
    top: 190px;
    width: min(240px, calc(100% - 20px));
  }

  .demand-list {
    gap: 7px;
    padding: 8px 10px 10px;
  }

  .demand-row {
    font-size: 0.75rem;
  }

  .build-button {
    grid-template-columns: 34px 1fr auto;
    min-height: 58px;
  }

  .tool-meta {
    display: none;
  }

  .inspector {
    font-size: 0.86rem;
  }

  .join-controls {
    grid-template-columns: 1fr;
  }
}
