/* Lattice City — endless isometric city builder */
:root {
  --ink: #0d0c0b;
  --panel: #17161450;
  --panel-solid: #171614;
  --line: #2e2a25;
  --text: #efe6d6;
  --mute: #a99e8c;
  --amber: #f2c14e;
  --moss: #6fbf73;
  --water: #5aa9e6;
  --brick: #d9694c;
  --panel-w: 268px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--ink);
  color: var(--text);
  font: 13px/1.45 "Segoe UI", Tahoma, sans-serif;
  overflow: hidden;
}
#app { display: flex; flex-direction: column; height: 100vh; }

/* ---------------- top bar ---------------- */
#topbar {
  display: flex; align-items: center; gap: 14px;
  height: 46px; padding: 0 12px;
  background: linear-gradient(180deg, #1b1917, #131211);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
  font-variant-numeric: tabular-nums;
}
#topbar .brand { color: var(--amber); text-decoration: none; font-weight: 700; letter-spacing: .04em; }
#topbar .brand.small { color: var(--mute); font-weight: 600; font-size: 12px; }
#topbar .brand:hover { color: #ffd97a; }
#topbar .stat { display: flex; flex-direction: column; line-height: 1.1; }
#topbar .stat span { font-size: 9px; letter-spacing: .14em; color: var(--mute); }
#topbar .stat b { font-size: 15px; color: var(--text); }
#topbar .clock { margin-left: 6px; padding: 4px 9px; border: 1px solid var(--line); border-radius: 6px; color: var(--amber); font-size: 12px; }
#topbar .spacer { flex: 1; }
.demand { display: flex; align-items: center; gap: 6px; }
.demand .lbl { font-size: 9px; letter-spacing: .14em; color: var(--mute); }
.demand .bar { display: block; width: 42px; height: 8px; background: #241f1b; border: 1px solid var(--line); border-radius: 3px; overflow: hidden; }
.demand .bar u { display: block; height: 100%; width: 0%; transition: width .4s ease; }
.demand .bar.r u { background: var(--moss); }
.demand .bar.c u { background: var(--water); }
.demand .bar.i u { background: var(--amber); }
.speeds { display: flex; gap: 3px; }
.speeds button {
  min-width: 30px; height: 26px; padding: 0 6px;
  background: #221f1b; color: var(--text); border: 1px solid var(--line);
  border-radius: 5px; cursor: pointer; font-size: 10px; letter-spacing: .06em;
}
.speeds button.on { background: var(--amber); color: #221a08; border-color: var(--amber); }
.icon {
  width: 28px; height: 26px; padding: 0;
  background: #221f1b; color: var(--text); border: 1px solid var(--line);
  border-radius: 5px; cursor: pointer;
}
.icon.off { opacity: .45; }

/* ---------------- stage ---------------- */
#stage { position: relative; flex: 1 1 auto; min-height: 0; overflow: hidden; background: #0a0908; }
#map { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: crosshair; touch-action: none; }

/* ---------------- palette ---------------- */
#palette {
  position: absolute; left: 10px; top: 10px; bottom: 10px; width: var(--panel-w);
  padding: 10px 12px;
  background: rgba(20, 18, 16, .93);
  border: 1px solid var(--line); border-radius: 10px;
  overflow: auto;
  backdrop-filter: blur(2px);
}
#palette h2 { margin: 2px 0 8px; font-size: 11px; letter-spacing: .16em; color: var(--amber); text-transform: uppercase; }
#palette h3 { margin: 14px 0 6px; font-size: 10px; letter-spacing: .16em; color: var(--mute); text-transform: uppercase; }
#tools { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.tool {
  display: flex; flex-direction: column; gap: 3px; align-items: flex-start;
  padding: 7px 8px; background: #1e1b18; color: var(--text);
  border: 1px solid var(--line); border-radius: 7px; cursor: pointer; text-align: left;
}
.tool b { font-size: 12px; }
.tool span { font-size: 9.5px; color: var(--mute); }
.tool:hover { border-color: #4a4238; }
.tool.on { border-color: var(--amber); background: #2a2113; box-shadow: inset 0 0 0 1px #f2c14e55; }
.tool.locked { opacity: .38; cursor: not-allowed; }
.tool.locked::after { content: "locked"; font-size: 8.5px; color: var(--amber); letter-spacing: .1em; }

.meters { display: grid; gap: 6px; }
.meter { display: grid; grid-template-columns: 62px 1fr 54px; align-items: center; gap: 6px; font-size: 10px; color: var(--mute); }
.meter i { display: block; height: 7px; background: #241f1b; border: 1px solid var(--line); border-radius: 3px; overflow: hidden; }
.meter i u { display: block; height: 100%; width: 0%; background: var(--amber); transition: width .35s ease; }
.meter b { font-size: 10px; color: var(--text); text-align: right; }
.goal { margin: 0; font-size: 11.5px; color: var(--text); }
.row { display: flex; gap: 6px; margin-top: 8px; }
.wide {
  flex: 1; padding: 7px 8px; background: #241f1b; color: var(--text);
  border: 1px solid var(--line); border-radius: 6px; cursor: pointer; font-size: 11px;
}
.wide:hover { border-color: var(--amber); }
.wide.danger { color: #ffb4a0; }
.hint { margin: 10px 0 0; font-size: 10px; color: #7c7365; }

/* ---------------- inspector ---------------- */
#inspector {
  position: absolute; right: 10px; top: 210px; width: 264px; max-height: 55%;
  padding: 10px 12px; overflow: auto;
  background: rgba(20, 18, 16, .95);
  border: 1px solid var(--line); border-radius: 10px;
}
#inspector h2 { margin: 0 0 8px; font-size: 13px; color: var(--amber); }
#inspector .kv { display: flex; justify-content: space-between; gap: 8px; font-size: 11px; padding: 2px 0; border-bottom: 1px dotted #2a2622; }
#inspector .kv span { color: var(--mute); }
#inspector.hidden { display: none; }

/* ---------------- events feed (inside the tool panel) ---------------- */
#feed {
  margin: 0 0 12px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #14120f;
}
#feed h3 { margin: 0 0 6px; }
#ticker {
  position: static;
  margin: 0;
  padding: 0 0 4px;
  height: auto;
  max-height: 4.6em;
  overflow: auto;
  background: transparent;
  border: none;
  border-radius: 0;
  font-size: 11px;
  color: var(--mute);
  white-space: normal;
}
#ticker b { color: var(--amber); }
#event-log {
  position: static;
  max-height: 120px;
  overflow-y: auto;
  margin: 0;
  padding: 0;
  background: transparent;
  border: none;
  font: 10px/1.35 ui-monospace, Consolas, monospace;
  color: #e8dcc8;
  pointer-events: auto;
}
#event-log:empty { display: none; }
.event-entry { margin: 2px 0; padding: 2px 4px; border-radius: 2px; }
.event-entry.emergency { background: rgba(226,88,60,.25); border-left: 2px solid #e2583c; }
.event-entry.high { background: rgba(242,193,78,.2); border-left: 2px solid #f2c14e; }
.event-entry.fire { background: rgba(226,88,60,.15); }
.event-entry.dispatch { background: rgba(111,191,115,.2); border-left: 2px solid #6fbf73; }
.event-entry.arrival { background: rgba(100,200,255,.2); border-left: 2px solid #64c8ff; }
.event-entry.medical { background: rgba(255,150,150,.2); border-left: 2px solid #ff8888; }
.event-entry.police { background: rgba(100,150,255,.2); border-left: 2px solid #6496ff; }
.event-entry.normal { background: rgba(200,200,200,.1); }
#toast {
  position: absolute; left: 50%; top: 14px; transform: translateX(-50%);
  padding: 7px 14px; border-radius: 20px;
  background: rgba(242, 193, 78, .95); color: #221a08; font-weight: 700; font-size: 12px;
  opacity: 0; pointer-events: none; transition: opacity .25s ease;
}
#toast.on { opacity: 1; }

/* ---------------- modal ---------------- */
#modal {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(6, 5, 4, .72); z-index: 20;
}
#modal.hidden { display: none; }
#modal .sheet {
  width: min(560px, 92%); max-height: 84%; overflow: auto;
  padding: 18px 20px; background: var(--panel-solid);
  border: 1px solid var(--line); border-radius: 12px;
}
#modal h2 { margin: 0 0 10px; color: var(--amber); font-size: 16px; }
#modal p, #modal li { font-size: 12.5px; color: var(--text); }
#modal ul { margin: 6px 0 10px 18px; padding: 0; }
#modal kbd { background: #241f1b; border: 1px solid var(--line); border-radius: 4px; padding: 1px 5px; font-size: 11px; }

/* ---------------- about ---------------- */
#about { display: none; }
#about h3 { margin: 0; }

/* ---------------- small screens ---------------- */
@media (max-width: 820px) {
  #topbar { height: auto; flex-wrap: wrap; gap: 8px; padding: 6px 8px; }
  #topbar .stat b { font-size: 13px; }
  .demand .bar { width: 30px; }
  #palette {
    left: 6px; right: 6px; top: auto; bottom: 40px; width: auto; max-height: 44vh;
    padding: 8px 10px;
  }
  #tools { grid-template-columns: repeat(3, 1fr); }
  #inspector { left: 6px; right: 6px; width: auto; top: auto; bottom: 40px; max-height: 40vh; }
}

/* ---------------- world map ---------------- */
#minimap-wrap {
  position: absolute; right: 10px; top: 10px; width: 188px; padding: 6px 6px 2px;
  background: rgba(14, 13, 12, .92); border: 1px solid var(--line); border-radius: 10px;
}
#minimap { display: block; width: 176px; height: 176px; cursor: pointer; }
#minimap-label { text-align: center; font-size: 9px; letter-spacing: .18em; color: var(--mute); padding: 2px 0 4px; }
@media (max-width: 820px) {
  #minimap-wrap { width: 118px; right: 6px; top: 6px; padding: 4px; }
  #minimap { width: 110px; height: 110px; }
  #minimap-label { display: none; }
}

/* ---------------- the LYGO listen portal ---------------- */
.radio-dock { display: grid; gap: 5px; padding: 7px 8px; margin: 0 0 10px; border: 1px solid var(--line); border-radius: 8px; background: #14120f; }
.radio-head { display: flex; justify-content: space-between; align-items: baseline; font-size: 9px; letter-spacing: .16em; color: var(--amber); }
.radio-head a { color: var(--mute); text-decoration: none; letter-spacing: .06em; }
.radio-head a:hover { color: var(--amber); }
.radio-dock.collapsed .radio-row, .radio-dock.collapsed input, .radio-dock.collapsed .radio-title, .radio-dock.collapsed .radio-link { display: none; }
.radio-row { display: flex; gap: 5px; }
.radio-row .wide { padding: 5px 6px; font-size: 10px; }
#radioVol { width: 100%; accent-color: var(--amber); height: 14px; }
.radio-title {
  margin: 0; font-size: 10px; line-height: 1.35; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.radio-link { font-size: 9.5px; color: var(--mute); text-decoration: none; letter-spacing: .06em; }
.radio-link:hover { color: var(--amber); }
.radio-head { flex-wrap: wrap; }
.radio-head .radio-dsp {
  flex: 1 0 100%; margin: 3px 0 0; font-size: 8.5px; line-height: 1.5;
  letter-spacing: .03em; color: var(--mute); text-transform: none;
}
.radio-head .radio-dsp a { color: var(--mute); text-decoration: none; }
.radio-head .radio-dsp a:hover { color: var(--amber); }

/* ---------------- camera cluster + options ---------------- */
.camera { display: flex; gap: 2px; }
#topbar .camera .icon { width: 26px; }
#ui-options { font-size: 13px; }
#modal .optlist { display: grid; gap: 8px; margin: 4px 0 14px; }
#modal .opt {
  display: grid; grid-template-columns: 1fr 132px 34px; align-items: center; gap: 10px;
  font-size: 12px; color: var(--text);
}
#modal .opt span { display: flex; flex-direction: column; }
#modal .opt i { font-style: normal; font-size: 10px; color: var(--mute); }
#modal .opt b { font-size: 11px; color: var(--amber); text-align: right; }
#modal .opt input[type="range"] { accent-color: var(--amber); width: 100%; }
#modal .opt.togglerow { grid-template-columns: 1fr 40px 0; }
#modal .opt.togglerow input { width: 16px; height: 16px; accent-color: var(--amber); justify-self: end; }
#modal .row { display: flex; gap: 8px; }

/* the event pill must not stretch the top bar */
#ui-event {
  max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  border-color: #f2c14e66;
}
#topbar { flex-wrap: nowrap; }
#topbar .brand.small { white-space: nowrap; }

/* ---------------- live clock (the city runs on your time) ---------------- */
.liveclock {
  display: flex; align-items: baseline; gap: 6px;
  padding: 4px 10px; border: 1px solid #f2c14e55; border-radius: 6px;
  background: #241f1b;
}
.liveclock b { font-size: 15px; letter-spacing: .06em; color: var(--amber); font-variant-numeric: tabular-nums; }
.liveclock span { font-size: 9px; letter-spacing: .14em; text-transform: uppercase; color: var(--mute); }

/* ---------------- citizen card ---------------- */
.citizen-card {
  background: #1a1816; border: 1px solid var(--line); border-radius: 8px;
  padding: 10px; margin: 8px 0;
}
.citizen-header {
  display: flex; align-items: flex-start; gap: 10px; margin-bottom: 8px;
}
.citizen-avatar {
  width: 64px; height: 64px; border-radius: 50%; object-fit: cover;
  border: 2px solid var(--line); flex-shrink: 0;
}
.citizen-info { flex: 1; min-width: 0; }
.citizen-info h3 { margin: 0 0 4px; font-size: 14px; color: var(--text); }
.archetype {
  display: inline-block; padding: 2px 6px; border-radius: 4px; font-size: 9px;
  font-weight: 600; letter-spacing: .08em; text-transform: uppercase;
}
.archetype.worker { background: #d9694c33; color: #d9694c; }
.archetype.clerk { background: #5aa9e633; color: #5aa9e6; }
.archetype.scholar { background: #d98fe033; color: #d98fe0; }
.archetype.guardian { background: #e2583c33; color: #e2583c; }
.archetype.artisan { background: #f2c14e33; color: #f2c14e; }
.archetype.drifter { background: #a99e8c33; color: #a99e8c; }
.age { font-size: 10px; color: var(--mute); }
.citizen-stats { font-size: 11px; color: var(--text); margin: 6px 0; }
.stat-row { margin: 3px 0; }
.citizen-attrs { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 8px 0; font-size: 10px; }
.attrs-col b { display: block; margin-bottom: 4px; color: var(--amber); }
.stat-mini { display: flex; justify-content: space-between; margin: 2px 0; }
.stat-mini span { color: var(--mute); }
.stat-mini b { color: var(--text); }
.citizen-needs { margin: 8px 0; }
.need-bar { display: grid; grid-template-columns: 70px 1fr 36px; align-items: center; gap: 6px; margin: 3px 0; font-size: 9px; }
.need-bar span { color: var(--mute); text-transform: capitalize; }
.need-bar i { height: 5px; background: #241f1b; border: 1px solid var(--line); border-radius: 2px; overflow: hidden; }
.need-bar i u { display: block; height: 100%; background: var(--amber); transition: width .3s ease; }
.need-bar b { font-size: 9px; color: var(--text); text-align: right; }
.citizen-traits { font-size: 10px; color: var(--mute); margin-top: 6px; }
.citizen-rels { font-size: 10px; color: var(--mute); margin-top: 4px; }

/* ---------------- population dashboard panel ---------------- */
#pop-dashboard {
  position: absolute; right: 10px; top: 10px; width: 300px; max-height: 60%;
  padding: 10px 12px; overflow: auto;
  background: rgba(20, 18, 16, .95); border: 1px solid var(--line); border-radius: 10px;
  z-index: 10;
}
#pop-dashboard.hidden { display: none; }
#pop-dashboard h2 { margin: 0 0 10px; font-size: 13px; color: var(--amber); }
.pop-stat { display: flex; justify-content: space-between; padding: 4px 0; border-bottom: 1px dotted #2a2622; font-size: 11px; }
.pop-stat span { color: var(--mute); }
.pop-stat b { color: var(--text); }
.pop-stat.good b { color: var(--moss); }
.pop-stat.warn b { color: var(--amber); }
.pop-stat.bad b { color: #e2583c; }
.pop-breakdown { margin: 10px 0; font-size: 10px; }
.pop-breakdown h4 { margin: 8px 0 4px; color: var(--amber); font-size: 10px; }
.pop-breakdown .item { display: flex; justify-content: space-between; padding: 2px 0; }
.pop-breakdown .item span { color: var(--mute); }
.pop-breakdown .item b { color: var(--text); }

#econ-dashboard {
  position: absolute; right: 10px; top: 10px; width: 300px; max-height: 60%;
  padding: 10px 12px; overflow: auto;
  background: rgba(20, 18, 16, .95); border: 1px solid var(--line); border-radius: 10px;
  z-index: 10;
}
#econ-dashboard.hidden { display: none; }
#econ-dashboard h2 { margin: 0 0 10px; font-size: 13px; color: var(--amber); }
.workplace-card { font-size: 11px; }
.workplace-header { display: flex; justify-content: space-between; gap: 8px; }
.worker-mini { font-size: 10px; color: var(--mute); }
