@import url('https://fonts.googleapis.com/css2?family=Oswald:wght@500;600;700&family=IBM+Plex+Mono:wght@500;600;700&family=Nunito:wght@400;600;700;800&display=swap');

:root {
  --ink-navy: #0F1B2C;
  --panel-slate: #16283F;
  --panel-slate-2: #1D3350;
  --panel-border: #2C4666;
  --paper: #EDE3C8;
  --brass: #C9A24B;
  --brass-bright: #E4C36A;
  --teal: #3FB8AF;
  --amber: #E8A33D;
  --crimson: #C6564C;
  --text-light: #EFE9D8;
  --text-dim: #93A6BC;
  --font-display: 'Oswald', sans-serif;
  --font-mono: 'IBM Plex Mono', monospace;
  --font-body: 'Nunito', sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--ink-navy);
  color: var(--text-light);
  font-family: var(--font-body);
  height: 100%;
}

button {
  font-family: var(--font-body);
  cursor: pointer;
}
button:focus-visible, input:focus-visible {
  outline: 2px solid var(--brass-bright);
  outline-offset: 2px;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  min-height: 560px;
}

/* ---------- Top ledger bar ---------- */
#topBar {
  background: linear-gradient(180deg, var(--panel-slate-2), var(--panel-slate));
  border-bottom: 2px solid var(--brass);
  padding: 10px 18px;
  display: flex;
  align-items: center;
  gap: 22px;
  flex-wrap: wrap;
  flex-shrink: 0;
}
.brandBlock { display: flex; align-items: center; gap: 10px; }
.pawSeal {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--brass);
  color: var(--ink-navy);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  border: 2px solid var(--brass-bright);
  flex-shrink: 0;
}
#cityWorldName {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 19px;
  letter-spacing: 0.5px;
  color: var(--paper);
  text-transform: uppercase;
}
#uniqueResBadge {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--brass-bright);
  letter-spacing: 0.3px;
}

.statGroup { display: flex; gap: 16px; flex-wrap: wrap; }
.statChip {
  display: flex; flex-direction: column;
  font-family: var(--font-mono);
  min-width: 58px;
}
.statChip .lbl {
  font-size: 9px; letter-spacing: 1px; text-transform: uppercase;
  color: var(--text-dim);
}
.statChip .val {
  font-size: 15px; font-weight: 600; color: var(--paper);
}

.meterGroup { display: flex; flex-direction: column; gap: 3px; min-width: 120px; }
.meterLabel { font-family: var(--font-mono); font-size: 9px; color: var(--text-dim); letter-spacing: 0.5px; }
.meterTrack {
  width: 100%; height: 6px; border-radius: 3px;
  background: rgba(255,255,255,0.08);
  overflow: hidden;
}
#congestBar { height: 100%; background: var(--crimson); transition: width 0.4s ease; }

#topBarRight { margin-left: auto; display: flex; align-items: center; gap: 10px; }
#seedForm { display: flex; align-items: center; gap: 6px; }
#seedForm label { font-family: var(--font-mono); font-size: 10px; color: var(--text-dim); }
#seedInput {
  width: 110px; background: var(--ink-navy); border: 1px solid var(--panel-border);
  color: var(--text-light); font-family: var(--font-mono); font-size: 11px;
  padding: 5px 7px; border-radius: 4px;
}
.stampBtn {
  font-family: var(--font-display); font-size: 11px; letter-spacing: 0.5px; text-transform: uppercase;
  background: transparent; color: var(--brass-bright);
  border: 1px solid var(--brass); border-radius: 4px;
  padding: 6px 10px; font-weight: 600;
  transition: background 0.15s ease;
}
.stampBtn:hover { background: rgba(201,162,75,0.15); }

/* ---------- Body layout ---------- */
#appBody { flex: 1; display: flex; min-height: 0; }

#leftPanel {
  width: 240px; flex-shrink: 0;
  background: var(--panel-slate);
  border-right: 1px solid var(--panel-border);
  overflow-y: auto;
  padding: 10px;
}
.paletteSection { margin-bottom: 14px; }
.paletteHeading {
  font-family: var(--font-display); font-size: 11px; letter-spacing: 1px; text-transform: uppercase;
  color: var(--brass-bright);
  border-bottom: 1px solid var(--panel-border);
  padding-bottom: 4px; margin-bottom: 6px;
}
.paletteGrid { display: flex; flex-direction: column; gap: 4px; }
.buildBtn {
  display: grid; grid-template-columns: 22px 1fr auto;
  align-items: center; gap: 8px;
  background: var(--panel-slate-2);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  padding: 6px 8px;
  color: var(--text-light);
  text-align: left;
  font-size: 12px;
}
.buildBtn:hover:not(:disabled) { border-color: var(--brass); }
.buildBtn.selected { border-color: var(--teal); background: rgba(63,184,175,0.12); }
.buildBtn.locked { opacity: 0.45; cursor: not-allowed; }
.buildIcon { font-size: 15px; }
.buildName { font-family: var(--font-body); font-weight: 600; }
.buildCost { font-family: var(--font-mono); font-size: 10px; color: var(--brass-bright); }

#bulldozeRow { padding: 6px 4px 12px; border-bottom: 1px solid var(--panel-border); margin-bottom: 10px; }
#bulldozeBtn {
  width: 100%; padding: 8px; border-radius: 6px;
  background: var(--panel-slate-2); border: 1px solid var(--panel-border);
  color: var(--text-light); font-weight: 700; font-size: 12px;
}
#bulldozeBtn.selected { background: var(--crimson); border-color: var(--crimson); color: white; }

/* ---------- Map ---------- */
#mapWrap {
  flex: 1; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at center, #142238 0%, #0B141F 100%);
  overflow: auto; padding: 14px;
}
#worldCanvas {
  border: 3px solid var(--brass);
  border-radius: 4px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.5);
  image-rendering: pixelated;
}

/* ---------- Right panel ---------- */
#rightPanel {
  width: 340px; flex-shrink: 0;
  background: var(--panel-slate);
  border-left: 1px solid var(--panel-border);
  display: flex; flex-direction: column;
  min-height: 0;
}
#tabBar { display: flex; border-bottom: 1px solid var(--panel-border); flex-shrink: 0; }
.tabBtn {
  flex: 1; background: transparent; border: none;
  color: var(--text-dim); font-family: var(--font-display);
  font-size: 11px; letter-spacing: 0.5px; text-transform: uppercase;
  padding: 10px 4px; border-bottom: 2px solid transparent;
}
.tabBtn.active { color: var(--brass-bright); border-bottom-color: var(--brass); }
.tabBtn:hover { color: var(--paper); }

#tabContent { flex: 1; overflow-y: auto; padding: 10px 12px; min-height: 0; }
.tabPanel { display: none; }
.tabPanel.active { display: block; }

.panelSubhead {
  font-family: var(--font-display); font-size: 11px; letter-spacing: 1px; text-transform: uppercase;
  color: var(--text-dim);
  margin: 12px 0 6px;
}
.panelSubhead:first-child { margin-top: 0; }

.emptyNote {
  font-size: 12px; color: var(--text-dim); font-style: italic;
  padding: 8px 4px;
}

.eventBanner {
  background: rgba(232,163,61,0.12);
  border: 1px solid var(--amber);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 11.5px;
  margin-bottom: 10px;
  line-height: 1.5;
}
.eventBanner .dim { color: var(--text-dim); }

.marketTable { display: flex; flex-direction: column; gap: 5px; }
.marketRow {
  display: grid;
  grid-template-columns: 18px 1fr auto;
  grid-template-areas:
    "icon name price"
    "icon stock stock"
    "sell sell buy";
  gap: 2px 6px;
  align-items: center;
  background: var(--panel-slate-2);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 11px;
}
.marketRow .resIcon { grid-area: icon; font-size: 15px; }
.marketRow .resName { grid-area: name; font-weight: 700; font-family: var(--font-body); }
.marketRow .resPrice { grid-area: price; font-family: var(--font-mono); text-align: right; }
.marketRow .resStock { grid-area: stock; color: var(--text-dim); font-family: var(--font-mono); font-size: 10px; }
.trend.up { color: var(--teal); }
.trend.down { color: var(--crimson); }
.trend.flat { color: var(--text-dim); }
.marketRow .miniBtn.sell { grid-column: 1 / 3; }
.marketRow .miniBtn.buy { grid-column: 3 / 4; }

.miniBtn {
  background: transparent; border: 1px solid var(--panel-border);
  color: var(--brass-bright); border-radius: 4px;
  font-family: var(--font-mono); font-size: 10px;
  padding: 4px 6px; margin-top: 3px;
}
.miniBtn:hover { border-color: var(--brass); background: rgba(201,162,75,0.1); }

.card {
  background: var(--panel-slate-2);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 8px;
  font-size: 12px;
}
.cardTitle { font-weight: 700; margin-bottom: 4px; }
.cardMeta { color: var(--text-dim); font-size: 11px; margin-bottom: 6px; line-height: 1.5; }
.actionBtn {
  width: 100%;
  background: var(--brass); color: var(--ink-navy);
  border: none; border-radius: 5px;
  font-weight: 800; font-size: 11.5px;
  padding: 7px; letter-spacing: 0.3px;
}
.actionBtn:hover { background: var(--brass-bright); }

.progressTrack { height: 6px; border-radius: 3px; background: rgba(255,255,255,0.08); overflow: hidden; margin: 4px 0; }
.progressFill { height: 100%; background: var(--teal); }

.offerRow {
  display: flex; justify-content: space-between; align-items: center;
  gap: 8px; font-size: 11px;
  border-top: 1px dashed var(--panel-border);
  padding-top: 6px; margin-top: 6px;
}

.logRow { font-family: var(--font-mono); font-size: 11px; padding: 4px 0; border-bottom: 1px solid rgba(255,255,255,0.04); line-height: 1.5; }
.logType-success { color: var(--teal); }
.logType-warn { color: var(--crimson); }
.logType-event { color: var(--amber); }
.logType-contract { color: var(--brass-bright); }
.logType-info { color: var(--text-light); }

#bottomBar {
  flex-shrink: 0;
  background: var(--panel-slate-2);
  border-top: 1px solid var(--panel-border);
  padding: 6px 12px;
  display: flex; align-items: center; gap: 10px;
}
#tileInfo {
  font-family: var(--font-mono); font-size: 11px; color: var(--text-dim);
  flex: 1; line-height: 1.5;
}
#speedControls { display: flex; gap: 4px; }
.speedBtn {
  background: var(--panel-slate); border: 1px solid var(--panel-border);
  color: var(--text-dim); border-radius: 4px;
  font-family: var(--font-mono); font-size: 11px; font-weight: 600;
  padding: 5px 9px;
}
.speedBtn.active { color: var(--ink-navy); background: var(--teal); border-color: var(--teal); }

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--panel-border); border-radius: 5px; }

@media (max-width: 900px) {
  #appBody { flex-direction: column; overflow-y: auto; }
  #leftPanel, #rightPanel { width: 100%; max-height: 260px; }
  #mapWrap { order: -1; }
}
