:root {
  color-scheme: dark;
  --bg: #161a1d;
  --panel: #20262b;
  --panel-strong: #2b3339;
  --text: #f4efe4;
  --muted: #b9b1a4;
  --accent: #d7a84d;
  --accent-strong: #f0c56a;
  --danger: #d46a5d;
  --ok: #7fb069;
  --border: #3d474f;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background: radial-gradient(circle at top left, #29343a, var(--bg) 48rem);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  min-height: 2.75rem;
  padding: 0.65rem 0.8rem;
  background: var(--panel-strong);
  color: var(--text);
  cursor: pointer;
  font: inherit;
}

button:hover,
button.active {
  border-color: var(--accent);
  color: var(--accent-strong);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

#app {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 1rem;
  width: 100%;
  height: 100dvh;
  min-height: 0;
  padding: 1rem;
}

#play-area {
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(20rem, 28vw, 25rem);
  gap: 1rem;
  min-width: 0;
  min-height: 0;
}

#game-panel,
#sidebar {
  min-width: 0;
  min-height: 0;
}

#game-panel {
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 1rem;
  background: rgba(8, 11, 13, 0.55);
  overflow: hidden;
}

#map {
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  display: block;
  touch-action: manipulation;
  user-select: none;
}

#sidebar {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  overflow: auto;
}

#status-card h1,
.card h2 {
  margin: 0;
}

#status-card p {
  margin: 0.25rem 0 0;
  color: var(--muted);
}

#status-card {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 1rem;
  border: 1px solid var(--border);
  border-radius: 1rem;
  min-height: 5.4rem;
  padding: 0.95rem 1rem;
  background: rgba(32, 38, 43, 0.92);
}

.title-block {
  width: clamp(12rem, 22vw, 16rem);
  min-width: 0;
  max-width: 16rem;
}

.title-block h1 {
  margin: 0;
  line-height: 0;
}

.site-logo {
  display: block;
  width: 100%;
  min-width: 0;
  height: auto;
  object-fit: contain;
}

.card {
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: 1rem;
  background: rgba(32, 38, 43, 0.92);
}

.card h2 {
  margin-bottom: 0.75rem;
  font-size: 1rem;
}

#status {
  display: flex;
  align-items: stretch;
  gap: 0.5rem;
  margin: 0;
  overflow-x: auto;
  padding-bottom: 0.1rem;
}

#status dt {
  margin-bottom: 0.12rem;
  color: var(--muted);
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

#status dd {
  margin: 0;
  text-align: left;
  font-size: 0.86rem;
  font-weight: 700;
}

.stat-item {
  min-width: max-content;
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 0.65rem;
  padding: 0.35rem 0.5rem;
  background: rgba(9, 12, 14, 0.28);
}

#build-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem;
}

.build-group-picker {
  display: grid;
  gap: 0.35rem;
  margin-bottom: 0.75rem;
  color: var(--muted);
  font-size: 0.8rem;
}

#build-group {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  min-height: 2.75rem;
  padding: 0.55rem 0.65rem;
  background: var(--panel-strong);
  color: var(--text);
  font: inherit;
}

.build-option {
  display: grid;
  grid-template-columns: 2.75rem minmax(0, 1fr);
  align-items: start;
  gap: 0.5rem;
  width: 100%;
  text-align: left;
}

.build-option img {
  width: 2.5rem;
  height: 2.5rem;
  object-fit: contain;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 0.5rem;
  background: rgba(0, 0, 0, 0.2);
}

.build-option:disabled {
  opacity: 0.5;
}

.build-option.locked {
  border-style: dashed;
}

.build-option:disabled img {
  filter: grayscale(0.75);
}

.build-option-body {
  display: grid;
  gap: 0.2rem;
  min-width: 0;
  align-content: start;
}

.build-option small,
#selection,
#log {
  color: var(--muted);
}

#build-selected,
#upgrade-selected,
#demolish-selected,
#end-turn {
  width: 100%;
}

.selection-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.45rem;
}

.selection-actions button {
  min-height: 2.45rem;
  padding-inline: 0.45rem;
}

.sidebar-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem;
  margin-top: auto;
}

.sidebar-actions button {
  width: 100%;
}

#restart-game {
  grid-column: 1 / -1;
}

.danger-button {
  border-color: rgba(212, 106, 93, 0.55);
  background: rgba(97, 35, 31, 0.92);
  color: #ffd8d3;
}

.danger-button:hover {
  border-color: #ff8a7d;
  color: #fff0ee;
}

#end-turn {
  min-width: 8rem;
}

#log {
  margin: 0;
  padding-left: 1.25rem;
  max-height: 14rem;
  overflow: auto;
}

#log li + li {
  margin-top: 0.35rem;
}

.ok {
  color: var(--ok);
}

.danger {
  color: var(--danger);
}

.resource-delta {
  margin-left: 0.2rem;
  font-size: 0.8em;
}

.resource-delta.positive {
  color: var(--ok);
}

.resource-delta.negative {
  color: var(--danger);
}

.resource-delta.neutral {
  color: var(--muted);
}

.hidden {
  display: none !important;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(5, 7, 8, 0.72);
  backdrop-filter: blur(6px);
}

.modal-card {
  width: min(56rem, 100%);
  max-height: min(44rem, 92dvh);
  overflow: auto;
  display: grid;
  grid-template-columns: minmax(18rem, 1fr) minmax(18rem, 0.9fr);
  border: 1px solid var(--border);
  border-radius: 1rem;
  background: #20262b;
  box-shadow: 0 1.5rem 5rem rgba(0, 0, 0, 0.55);
}

.help-card,
.stats-card,
.confirm-card {
  width: min(52rem, 100%);
  max-height: min(42rem, 92dvh);
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 1rem;
  background: #20262b;
  box-shadow: 0 1.5rem 5rem rgba(0, 0, 0, 0.55);
}

.confirm-card {
  width: min(28rem, 100%);
}

.confirm-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.65rem;
}

.help-header {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 1rem;
  border-bottom: 1px solid var(--border);
  padding: 1rem 1.25rem;
  background: rgba(32, 38, 43, 0.96);
}

.help-header h2,
.help-header p,
.help-content h3,
.help-content p {
  margin: 0;
}

.help-header h2 {
  margin-top: 0.2rem;
  font-size: 1.45rem;
}

.help-content {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.9rem;
  padding: 1.25rem;
}

.help-content section {
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 0.8rem;
  padding: 0.85rem;
  background: rgba(0, 0, 0, 0.16);
}

.help-content h3 {
  margin-bottom: 0.45rem;
  color: var(--accent-strong);
  font-size: 0.95rem;
}

.help-content p {
  color: var(--muted);
  line-height: 1.45;
}

.help-content p + p {
  margin-top: 0.45rem;
}

.stats-content {
  display: grid;
  gap: 1rem;
  padding: 1.25rem;
}

.stats-section {
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 0.85rem;
  padding: 1rem;
  background: rgba(0, 0, 0, 0.16);
}

.stats-section h3,
.stats-section h4,
.stats-section p {
  margin: 0;
}

.stats-section h3 {
  margin-bottom: 0.75rem;
  color: var(--accent-strong);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.stats-block {
  display: grid;
  gap: 0.45rem;
}

.stats-block h4 {
  color: var(--text);
  font-size: 0.95rem;
}

.stats-list {
  margin: 0;
  padding-left: 1.15rem;
  color: var(--muted);
}

.stats-list li + li {
  margin-top: 0.25rem;
}

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

#milestone-image {
  width: 100%;
  height: 100%;
  min-height: 24rem;
  object-fit: cover;
  background: #11181c;
}

#landing-image {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 24rem;
  object-fit: cover;
  object-position: center center;
  background: #11181c;
}

.modal-content {
  display: grid;
  align-content: start;
  gap: 0.85rem;
  padding: 1.25rem;
}

.modal-content h2,
.modal-content h3,
.modal-content p {
  margin: 0;
}

.modal-content h2 {
  font-size: 1.6rem;
}

.landing-content p {
  color: var(--muted);
  line-height: 1.5;
}

.landing-card {
  border-color: rgba(240, 197, 106, 0.35);
}

.modal-check-option {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  color: var(--muted);
  font-size: 0.92rem;
}

.modal-check-option input {
  width: 1.05rem;
  height: 1.05rem;
  accent-color: var(--accent-strong);
}

.modal-content h3,
.eyebrow {
  color: var(--accent-strong);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.75rem;
}

#milestone-description,
#milestone-effect {
  color: var(--muted);
  line-height: 1.45;
}

#milestone-unlocks {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem;
}

.unlock-item {
  display: grid;
  grid-template-columns: 2.5rem minmax(0, 1fr);
  align-items: center;
  gap: 0.5rem;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 0.65rem;
  padding: 0.45rem;
  background: rgba(0, 0, 0, 0.18);
}

.unlock-item img {
  width: 2.25rem;
  height: 2.25rem;
  object-fit: contain;
}

@media (max-width: 980px) {
  body {
    overflow: auto;
  }

  #app {
    height: auto;
    min-height: 100dvh;
  }

  #status-card,
  #play-area {
    grid-template-columns: 1fr;
  }

  #status-card {
    align-items: stretch;
  }

  .title-block {
    min-width: 0;
  }

  .help-header {
    align-items: stretch;
    flex-direction: column;
  }

  .help-content {
    grid-template-columns: 1fr;
  }

  #game-panel {
    height: min(68dvh, 42rem);
    min-height: 24rem;
  }

  #sidebar {
    overflow: visible;
  }

  .sidebar-actions {
    margin-top: 0;
  }

  .modal-card {
    grid-template-columns: 1fr;
  }

  #milestone-image {
    min-height: 14rem;
  }

  #landing-image {
    min-height: 14rem;
  }
}

@media (max-width: 640px) {
  #app {
    gap: 0.65rem;
    padding: 0.6rem;
  }

  #status-card {
    gap: 0.7rem;
    padding: 0.75rem;
  }

  #status-card p {
    font-size: 0.85rem;
  }

  #status {
    gap: 0.4rem;
  }

  .stat-item {
    padding: 0.4rem 0.55rem;
  }

  #play-area,
  #sidebar {
    gap: 0.65rem;
  }

  #game-panel {
    height: min(54dvh, 30rem);
    min-height: 18rem;
  }

  .card {
    padding: 0.75rem;
  }

  .build-option {
    grid-template-columns: 2.25rem minmax(0, 1fr);
    gap: 0.4rem;
    padding: 0.55rem;
  }

  .build-option img {
    width: 2rem;
    height: 2rem;
  }

  .build-option strong,
  .build-option small {
    font-size: 0.82rem;
  }

  #log {
    max-height: 10rem;
  }

  .modal {
    padding: 0.6rem;
  }

  .modal-card,
  .help-card,
  .stats-card {
    max-height: 92dvh;
  }

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