:root {
  /* NYC flag palette: harbor blue, white, Dutch/MTA orange. */
  --paper: #f5f4f0;
  --paper-raised: #fbfbf9;
  --ink: #0d2b52;
  --ink-soft: #b7c6d6;
  --ink-soft-text: #3d5570;
  --accent: #f2711c;
  --display: 'Cormorant Garamond', 'Times New Roman', serif;
  --body: 'Source Serif 4', 'Georgia', serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--body);
  overflow: hidden;
}

button {
  font-family: var(--body);
  cursor: pointer;
}

/* ---------------- top bar ---------------- */

#top-bar {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  padding: 0 1.25rem;
  border-bottom: 2px solid var(--ink);
  background: var(--paper-raised);
}

#top-bar-left {
  display: flex;
  align-items: baseline;
  gap: 1.25rem;
  min-width: 0;
}

#back-link {
  font-size: 12px;
  color: var(--ink-soft-text);
  text-decoration: none;
  white-space: nowrap;
}
#back-link:hover { color: var(--accent); }

#top-bar-left h1 {
  font-family: var(--display);
  font-weight: 600;
  font-size: 22px;
  margin: 0;
  white-space: nowrap;
}
#top-bar-left h1 span { color: var(--accent); }

#top-bar-stats {
  display: flex;
  gap: 1.5rem;
  flex: 1;
  justify-content: center;
  min-width: 0;
}
.stat { display: flex; flex-direction: column; align-items: center; line-height: 1.2; }
.stat-label { font-size: 10px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-soft-text); }
.stat-value { font-family: var(--display); font-size: 17px; font-weight: 600; }

#top-bar-controls { display: flex; align-items: center; gap: 0.5rem; }

#speed-controls { display: flex; border: 1px solid var(--ink); }
#speed-controls button {
  background: var(--paper);
  border: none;
  border-right: 1px solid var(--ink);
  padding: 6px 10px;
  font-size: 11px;
  color: var(--ink);
}
#speed-controls button:last-child { border-right: none; }
#speed-controls button.active { background: var(--ink); color: var(--paper); }

#top-bar-controls > button {
  background: var(--paper);
  border: 1px solid var(--ink);
  padding: 6px 12px;
  font-size: 12px;
}
#top-bar-controls > button:hover { background: var(--ink); color: var(--paper); }

/* ---------------- body layout ---------------- */

#game-body {
  display: flex;
  height: calc(100% - 64px);
}

#tool-panel, #info-panel {
  width: 230px;
  flex: 0 0 230px;
  overflow-y: auto;
  background: var(--paper-raised);
  padding: 0.75rem;
}
#tool-panel { border-right: 2px solid var(--ink); }
#info-panel { border-left: 2px solid var(--ink); }

.panel-section {
  border-bottom: 1px solid var(--ink-soft);
  padding-bottom: 0.85rem;
  margin-bottom: 0.85rem;
}
.panel-section:last-child { border-bottom: none; }

.panel-section h2 {
  font-family: var(--display);
  font-size: 14px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 0 0 0.5rem;
  color: var(--ink-soft-text);
}

.muted { color: var(--ink-soft-text); font-size: 13px; }

.tool-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.tool-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  border: 1px solid var(--ink);
  background: var(--paper);
  padding: 6px 8px;
  font-size: 11px;
  text-align: left;
  line-height: 1.25;
}
.tool-btn .swatch { width: 14px; height: 14px; border: 1px solid rgba(26,24,20,0.4); }
.tool-btn.selected { background: var(--ink); color: var(--paper); }
.tool-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.tool-btn .tool-name { font-weight: 600; }
.tool-btn .tool-cost { color: var(--ink-soft-text); font-size: 10px; }
.tool-btn.selected .tool-cost { color: var(--ink-soft); }

.checkbox-row { display: flex; align-items: center; gap: 6px; font-size: 12px; margin-bottom: 4px; }

#tool-detail p { margin: 0; font-size: 12.5px; line-height: 1.45; }
#tool-detail .tool-detail-title { font-family: var(--display); font-weight: 600; font-size: 15px; margin-bottom: 3px; }

/* ---------------- map ---------------- */

#map-viewport {
  flex: 1;
  overflow: auto;
  background: #3d6485;
  position: relative;
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
}

#map-canvas { image-rendering: pixelated; cursor: crosshair; display: block; }

#tile-tooltip {
  position: fixed;
  pointer-events: none;
  background: var(--ink);
  color: var(--paper);
  font-size: 11.5px;
  padding: 6px 9px;
  border: 1px solid var(--accent);
  max-width: 220px;
  line-height: 1.4;
  z-index: 50;
}
#tile-tooltip.hidden { display: none; }
#tile-tooltip strong { color: #ffc78a; }

/* ---------------- info panel widgets ---------------- */

.demand-row { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.demand-label { font-family: var(--display); font-weight: 700; width: 14px; }
.demand-bar { flex: 1; height: 8px; background: var(--ink-soft); position: relative; }
.demand-fill { position: absolute; left: 50%; height: 100%; background: var(--accent); }

.kv { display: flex; justify-content: space-between; font-size: 12.5px; margin-bottom: 3px; }
.kv span:first-child { color: var(--ink-soft-text); }

#tax-rate-slider { width: 100%; margin: 4px 0 10px; }

#district-panel h3 { font-family: var(--display); font-size: 16px; margin: 0 0 4px; }
#district-panel .kv { font-size: 12px; }

#event-log { list-style: none; margin: 0; padding: 0; max-height: 220px; overflow-y: auto; }
#event-log li { font-size: 11.5px; padding: 5px 0; border-bottom: 1px solid var(--ink-soft); line-height: 1.4; }
#event-log li:last-child { border-bottom: none; }
#event-log .log-year { font-family: var(--display); font-weight: 700; color: var(--accent); margin-right: 4px; }

/* ---------------- modals ---------------- */

.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(26,24,20,0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  padding: 1.5rem;
}
.modal-backdrop.hidden { display: none; }

.modal {
  background: var(--paper-raised);
  border: 2px solid var(--ink);
  max-width: 480px;
  width: 100%;
  padding: 1.75rem;
  max-height: 85vh;
  overflow-y: auto;
}
.modal-wide { max-width: 640px; }

.modal h2 {
  font-family: var(--display);
  font-size: 24px;
  margin: 0 0 0.4rem;
}
.modal h3 {
  font-family: var(--display);
  font-size: 17px;
  color: var(--ink-soft-text);
  margin: 0 0 0.9rem;
  font-style: italic;
  font-weight: 500;
}
.modal p { line-height: 1.55; font-size: 14.5px; }

#event-modal-options { display: flex; flex-direction: column; gap: 8px; margin-top: 1rem; }
#event-modal-options button {
  border: 1px solid var(--ink);
  background: var(--paper);
  padding: 10px 14px;
  text-align: left;
  font-size: 14px;
}
#event-modal-options button:hover { background: var(--ink); color: var(--paper); }

.modal button.secondary, #final-continue-btn {
  margin-top: 1rem;
  border: 1px solid var(--ink);
  background: var(--paper);
  padding: 8px 16px;
  font-size: 13px;
}
.modal button.secondary:hover, #final-continue-btn:hover { background: var(--ink); color: var(--paper); }

.help-body p { margin: 0 0 0.9rem; }

#saveload-slots { display: flex; flex-direction: column; gap: 8px; }
.save-slot {
  border: 1px solid var(--ink);
  padding: 10px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--paper);
  cursor: pointer;
  font-size: 13px;
}
.save-slot:hover { background: var(--ink); color: var(--paper); }
.save-slot .slot-meta { font-size: 11px; color: var(--ink-soft-text); }
.save-slot:hover .slot-meta { color: var(--ink-soft); }

/* ---------------- responsive ---------------- */

@media (max-width: 900px) {
  #tool-panel, #info-panel { width: 190px; flex-basis: 190px; }
  #top-bar-stats { display: none; }
}
