/* ============================================================
   PolyCity — UI styles
   ============================================================ */
:root {
  --bg: #0b1020;
  --panel: rgba(13, 18, 34, 0.82);
  --panel-solid: #10162a;
  --line: rgba(255, 255, 255, 0.09);
  --text: #e8ecf4;
  --dim: #9aa3b5;
  --accent: #35e08a;
  --blue: #4aa8ff;
  --orange: #ffb020;
  --red: #ff5f56;
  --radius: 12px;
  font-size: 15px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0; height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, Ubuntu, sans-serif;
}

#app { position: fixed; inset: 0; }
#app canvas { display: block; }

#hud { position: fixed; inset: 0; pointer-events: none; }
#hud > * { pointer-events: auto; }
.hidden { display: none !important; }
.muted { opacity: .55; font-weight: 400; }
.dim { opacity: .6; }
.good { color: var(--accent); }
.bad { color: var(--red); }

/* =================== top bar =================== */
#topbar {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 8px 12px;
  background: linear-gradient(to bottom, rgba(8, 11, 22, 0.92), rgba(8, 11, 22, 0.55) 80%, transparent);
  backdrop-filter: blur(8px);
}
.tb-left { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; min-width: 0; }
.tb-right { display: flex; align-items: center; gap: 6px; }

#cityBadge { display: flex; flex-direction: column; line-height: 1.1; margin-right: 6px; }
#cityName { font-weight: 800; font-size: 17px; letter-spacing: .3px; white-space: nowrap; }
#milestoneTitle { font-size: 11px; color: var(--accent); text-transform: uppercase; letter-spacing: 1.2px; }

.stat { display: flex; align-items: center; gap: 5px; background: rgba(255,255,255,.06);
  border: 1px solid var(--line); border-radius: 999px; padding: 4px 11px; font-size: 14px; white-space: nowrap; }
.stat b { font-variant-numeric: tabular-nums; }
.stat .ico { font-size: 13px; filter: saturate(.9); }

.tbtn {
  width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--line);
  background: rgba(255,255,255,.06); color: var(--text); font-size: 17px; cursor: pointer;
  transition: background .15s, transform .05s;
}
.tbtn:hover { background: rgba(255,255,255,.14); }
.tbtn:active { transform: scale(.94); }

#speedControls { display: flex; gap: 3px; margin-right: 8px; background: rgba(255,255,255,.06);
  padding: 3px; border-radius: 10px; border: 1px solid var(--line); }
.spd { border: none; background: transparent; color: var(--dim); font-size: 11px; width: 40px;
  height: 30px; border-radius: 7px; cursor: pointer; letter-spacing: -1px; }
.spd.active { background: var(--accent); color: #04220f; font-weight: 700; }
.spd:hover:not(.active) { color: var(--text); background: rgba(255,255,255,.08); }

#rciBars { margin-left: 2px; opacity: .95; }

/* =================== toolbar =================== */
#toolbar {
  position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: stretch; gap: 6px; max-width: calc(100vw - 24px);
  background: var(--panel); backdrop-filter: blur(10px);
  border: 1px solid var(--line); border-radius: 16px; padding: 6px 8px;
  overflow-x: auto; scrollbar-width: none;
}
#toolbar::-webkit-scrollbar { display: none; }

/* labeled sections, SimCity-style */
.tb-group { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 0 3px; }
.tb-group + .tb-group { border-left: 1px solid var(--line); padding-left: 9px; }
.tb-cap { font-size: 8.5px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase;
  color: var(--dim); opacity: .85; user-select: none; }
.tb-row { display: flex; gap: 4px; }

.tl-btn {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-width: 64px; padding: 6px 6px 5px; border-radius: 11px; border: 1px solid transparent;
  background: rgba(255,255,255,.03); color: var(--text); cursor: pointer; transition: all .13s;
}
.tl-btn:hover { background: rgba(255,255,255,.09); border-color: var(--line); transform: translateY(-1px); }
.tl-btn.active { background: rgba(53,224,138,.16); border-color: rgba(53,224,138,.65);
  box-shadow: 0 0 14px rgba(53,224,138,.25) inset; }
.tl-ico svg { width: 30px; height: 30px; border-radius: 7px; }
.tl-label { font-size: 10.5px; color: var(--text); white-space: nowrap; line-height: 1.1; }
.tl-btn.active .tl-label { color: var(--accent); }
.tl-cost { font-size: 9px; color: #7ddba3; opacity: .9; line-height: 1; }
.tl-key {
  position: absolute; top: 4px; right: 5px; font-size: 8.5px; line-height: 13px;
  color: var(--dim); border: 1px solid var(--line); border-radius: 4px; padding: 0 3px;
  pointer-events: none;
}
.tl-btn.poor { opacity: .45; filter: saturate(.4); }
.tl-btn.poor .tl-cost { color: #ff7a7a; }

/* floating "current tool" chip above the bar */
#toolReadout {
  position: absolute; bottom: 92px; left: 50%; transform: translate(-50%, 6px);
  display: flex; align-items: center; gap: 8px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 6px 12px 6px 8px; pointer-events: none; opacity: 0;
  transition: opacity .15s, transform .15s; max-width: min(70vw, 420px);
}
#toolReadout.show { opacity: 1; transform: translate(-50%, 0); }
#toolReadout .tr-ico svg { width: 24px; height: 24px; border-radius: 6px; }
#toolReadout b { font-size: 12.5px; white-space: nowrap; }
#toolReadout .tr-tip { font-size: 11px; color: var(--dim); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; }

/* =================== toasts =================== */
#toasts { position: absolute; top: 64px; left: 12px; display: flex; flex-direction: column; gap: 8px; max-width: 340px; }
.toast {
  display: flex; gap: 9px; align-items: flex-start;
  background: var(--panel); border: 1px solid var(--line); border-left: 3px solid var(--blue);
  padding: 10px 13px; border-radius: 10px; font-size: 13.5px; line-height: 1.35;
  animation: slidein .25s ease; backdrop-filter: blur(8px);
  transition: opacity .5s, transform .5s;
}
.toast.warn { border-left-color: var(--orange); }
.toast.danger { border-left-color: var(--red); animation: shake .4s; }
.toast.success { border-left-color: var(--accent); }
.toast.gone { opacity: 0; transform: translateX(-16px); }
@keyframes slidein { from { opacity: 0; transform: translateY(-8px); } }
@keyframes shake { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-4px);} 75% { transform: translateX(4px);} }

/* =================== tooltip & popup =================== */
#tooltip {
  position: fixed; z-index: 60; pointer-events: none;
  background: rgba(5, 8, 16, .92); border: 1px solid var(--line);
  padding: 5px 10px; border-radius: 8px; font-size: 12.5px; color: var(--text);
}
#tooltip.bad { color: var(--red); border-color: rgba(255,95,86,.5); }

#infoPopup {
  position: fixed; z-index: 55; width: 225px;
  background: var(--panel); backdrop-filter: blur(10px);
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
  font-size: 13px; box-shadow: 0 12px 32px rgba(0,0,0,.45);
}
.ip-head { display: flex; justify-content: space-between; align-items: center;
  padding: 8px 12px; background: rgba(255,255,255,.06); font-weight: 700; }
.ip-close { background: none; border: none; color: var(--dim); font-size: 16px; cursor: pointer; }
.ip-row { display: flex; justify-content: space-between; padding: 5px 12px; }
.ip-row:nth-child(odd) { background: rgba(255,255,255,.03); }
.ip-row b { font-variant-numeric: tabular-nums; }

/* =================== cards / quests =================== */
.card {
  background: var(--panel); backdrop-filter: blur(10px);
  border: 1px solid var(--line); border-radius: var(--radius);
}
#questBox {
  position: absolute; top: 64px; right: 12px; width: 250px; padding: 10px 12px;
  font-size: 12.5px; max-height: 46vh; overflow-y: auto;
}
.q-head { margin-bottom: 6px; letter-spacing: .3px; }
.q-item { padding: 3px 0; color: var(--dim); }
.q-item.done { color: var(--accent); text-decoration: line-through; opacity: .8; }

/* =================== side panel =================== */
#sidePanelRight {
  position: absolute; top: 64px; right: 12px; width: 285px; max-height: calc(100vh - 160px);
  overflow-y: auto;
}
.sp-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px 8px; }
.sp-head h3 { margin: 0; font-size: 15px; }
.sp-close { background: none; border: none; color: var(--dim); font-size: 19px; cursor: pointer; }
.sp-body { padding: 0 14px 14px; font-size: 13px; }
.tax-row input[type=range] { width: 100%; accent-color: var(--accent); }
.hint { color: var(--dim); font-size: 12px; line-height: 1.45; }
table.ledger { width: 100%; border-collapse: collapse; margin-top: 10px; }
table.ledger td { padding: 6px 2px; border-bottom: 1px solid var(--line); }
table.ledger td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.kv-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px; }
.kv-grid div { background: rgba(255,255,255,.05); border-radius: 9px; padding: 8px 10px; }
.kv-grid span { display: block; font-size: 11px; color: var(--dim); }
.kv-grid b { font-size: 15px; font-variant-numeric: tabular-nums; }
.meter label { font-size: 12px; color: var(--dim); }
.meter-bar { height: 8px; border-radius: 99px; background: rgba(255,255,255,.09); overflow: hidden; margin-top: 4px; }
.meter-bar i { display: block; height: 100%; background: var(--blue); border-radius: 99px; }
.meter-bar i.hot { background: var(--red); }
#chartPop, #chartFunds { width: 100%; background: rgba(255,255,255,.04); border-radius: 8px; }
h4 { margin: 12px 0 4px; font-size: 12.5px; color: var(--dim); }

/* =================== minimap =================== */
#minimapWrap {
  position: absolute; right: 12px; bottom: 90px;
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
  box-shadow: 0 10px 26px rgba(0,0,0,.4);
}
#minimap { display: block; image-rendering: pixelated; }

/* =================== modals =================== */
.modal-back {
  position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center;
  background: rgba(4, 6, 12, .6); backdrop-filter: blur(3px); animation: fadein .18s ease;
}
@keyframes fadein { from { opacity: 0; } }
.modal-card {
  width: min(600px, calc(100vw - 28px)); max-height: calc(100vh - 40px); overflow-y: auto;
  background: var(--panel-solid); border: 1px solid var(--line); border-radius: 16px;
  padding: 22px 24px; box-shadow: 0 24px 70px rgba(0,0,0,.55);
}
.modal-card h2 { margin: 0 0 10px; }
.modal-card h3 { margin: 18px 0 8px; font-size: 14px; color: var(--dim); text-transform: uppercase; letter-spacing: 1px; }
.help-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 560px) { .help-cols { grid-template-columns: 1fr; } }
.help-cols ul, .help-cols ol { margin: 6px 0; padding-left: 18px; font-size: 13px; line-height: 1.65; }
.help-book { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 640px) { .help-book { grid-template-columns: 1fr; } }
.hb-item { display: flex; gap: 10px; background: rgba(255,255,255,.045); border-radius: 10px; padding: 9px 11px; font-size: 12px; line-height: 1.45; }
.hb-item em { color: var(--dim); font-style: normal; font-size: 11px; }
.hb-ico svg { width: 21px; height: 21px; margin-top: 2px; color: var(--accent); }

.btn {
  border: 1px solid var(--line); background: rgba(255,255,255,.07); color: var(--text);
  padding: 9px 16px; border-radius: 10px; cursor: pointer; font-size: 13.5px;
  transition: background .14s;
}
.btn:hover { background: rgba(255,255,255,.13); }
.btn.primary { background: var(--accent); border-color: transparent; color: #04220f; font-weight: 700; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--red); }
.btn.sm { padding: 5px 10px; font-size: 12px; border-radius: 8px; }
.btn:disabled { opacity: .35; cursor: default; }
.menu-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; }

.slot-row { display: flex; align-items: center; gap: 8px; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 13px; flex-wrap: wrap; }
.slot-row span { flex: 1; min-width: 120px; }
.settings label { display: flex; align-items: center; gap: 9px; padding: 6px 0; font-size: 13.5px; cursor: pointer; }
.settings input { accent-color: var(--accent); width: 16px; height: 16px; }

.fld { display: block; margin: 14px 0; font-size: 13px; color: var(--dim); }
.fld input, .fld select {
  display: block; width: 100%; margin-top: 6px; padding: 10px 12px;
  background: rgba(255,255,255,.06); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px; font-size: 14px; outline: none;
}
.fld input:focus, .fld select:focus { border-color: var(--accent); }
.seedrow { display: flex !important; gap: 8px; margin-top: 6px; }
.seedrow input { flex: 1; margin-top: 0 !important; }
.modal-card .btn.primary { width: 100%; margin-top: 14px; padding: 12px; font-size: 15px; }

/* =================== boot screen =================== */
#bootScreen {
  position: fixed; inset: 0; z-index: 200; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(1200px 700px at 50% 30%, #14204a, #0b1020 70%);
  transition: opacity .6s;
}
#bootScreen.off { opacity: 0; pointer-events: none; }
.boot-inner { text-align: center; }
.boot-inner h1 { font-size: 52px; margin: 0; letter-spacing: 8px; font-weight: 900; }
.boot-inner h1 span { color: var(--accent); }
.boot-inner p { color: var(--dim); margin: 8px 0 22px; }
.boot-bar { width: 220px; height: 4px; background: rgba(255,255,255,.1); border-radius: 99px; margin: 0 auto; overflow: hidden; }
.boot-bar i { display: block; width: 40%; height: 100%; background: var(--accent); border-radius: 99px; animation: boot 1.1s ease-in-out infinite alternate; }
@keyframes boot { from { transform: translateX(-60%); } to { transform: translateX(320%); } }

/* =================== responsive =================== */
@media (max-width: 760px) {
  :root { font-size: 13.5px; }
  #topbar { padding: 6px 8px; }
  .stat { padding: 3px 8px; font-size: 12.5px; }
  #cityName { font-size: 14px; }
  .tl-btn { min-width: 52px; }
  .tl-ico svg { width: 26px; height: 26px; }
  .tl-key { display: none; }
  .tb-cap { font-size: 7.5px; }
  #toolReadout { bottom: 96px; }
  .tl-label { font-size: 9px; }
  #questBox { display: none; }
  #minimapWrap { bottom: 110px; right: 8px; }
  #minimap { width: 120px; height: 120px; }
  .spd { width: 30px; }
}
