/* ── TOKENS (GhostEcos theme) ── */
:root {
  --accent:      #D97757;
  --accent-glow: rgba(217, 119, 87, 0.45);
  --accent-dim:  rgba(217, 119, 87, 0.15);
  --bg:          #000;
  --panel:       rgba(13, 13, 13, 0.82);
  --panel-brd:   rgba(255, 255, 255, 0.10);
  --text:        #fff;
  --text-dim:    rgba(255, 255, 255, 0.55);
  --text-muted:  rgba(255, 255, 255, 0.28);
  --font:        -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
  --r:           14px;
}

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
}

button { cursor: pointer; background: none; border: none; color: inherit; font-family: var(--font); }

/* ── MAP ── */
#map { position: fixed; inset: 0; background: #0b1a26; z-index: 0; }
#sim { position: fixed; inset: 0; z-index: 450; pointer-events: none; }
#map.drawing { cursor: crosshair; }
#map.erasing { cursor: not-allowed; }

/* ── PANEL BASE ── */
.panel {
  position: fixed;
  z-index: 500;
  background: var(--panel);
  border: 1px solid var(--panel-brd);
  border-radius: var(--r);
  backdrop-filter: blur(14px) saturate(140%);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.55);
}
.hidden { display: none !important; }

/* ── STATE BANNER ── */
#banner {
  top: 14px; left: 80px;
  display: flex; align-items: center; gap: 11px;
  padding: 10px 14px 10px 11px;
  max-width: min(72vw, 330px);
}
.flag-chip {
  width: 38px; height: 38px; flex-shrink: 0;
  border-radius: 10px;
  background: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.25), 0 0 12px var(--accent-glow);
  display: grid; place-items: center;
  transition: transform .15s ease;
}
.flag-chip:hover { transform: scale(1.06); }
.flag-chip svg { width: 22px; height: 22px; color: #fff; }
.banner-text { min-width: 0; }
#state-name {
  width: 100%;
  background: none; border: none; outline: none;
  color: var(--text); font-size: 17px; font-weight: 650;
  letter-spacing: .2px;
}
#state-name::placeholder { color: var(--text-muted); font-weight: 500; }
.stats { font-size: 12.5px; color: var(--text-dim); margin-top: 1px; display: flex; gap: 6px; }
.stats .dot { color: var(--text-muted); }
#stat-area { color: var(--accent); font-weight: 600; }

/* ── TOOLBAR ── */
#toolbar {
  left: 14px; top: 50%; transform: translateY(-50%);
  display: flex; flex-direction: column; gap: 4px;
  padding: 6px;
  width: 58px;
  max-height: 92vh; overflow-y: auto; scrollbar-width: none;
}
#toolbar::-webkit-scrollbar { display: none; }
#toolbar .tool-section-label { display: none; }
#toolbar:not(.collapsed) #territory-tools-label { display: block; }
.tool:disabled { opacity: .32; cursor: default; }
.tool:disabled:hover { background: none; color: var(--text-dim); }

/* collapse the toolbar to the left */
.tb-collapse { width: 46px; height: 28px; flex-shrink: 0; display: grid; place-items: center; color: var(--text-muted); border-radius: 9px; margin-bottom: 2px; }
.tb-collapse:hover { background: rgba(255,255,255,0.07); color: var(--text); }
.tb-collapse svg { width: 18px; height: 18px; transition: transform .2s ease; }
#toolbar.collapsed { padding: 6px; gap: 0; width: 58px; }
#toolbar.collapsed .tb-collapse svg { transform: rotate(180deg); }
#toolbar.collapsed .tool, #toolbar.collapsed .tool-sep, #toolbar.collapsed .tool-section-label, #toolbar.collapsed .sim-config { display: none; }
.tool {
  width: 46px; height: 46px;
  border-radius: 11px;
  display: grid; place-items: center;
  position: relative;
  color: var(--text-dim);
  transition: background .15s ease, color .15s ease, transform .1s ease;
}
.tool svg { width: 24px; height: 24px; }
.tool-labeled {
  width: 100%; height: 35px; min-height: 35px; padding: 0 10px;
  display: flex; align-items: center; justify-content: flex-start; gap: 9px;
  text-align: left;
}
.tool-labeled .tool-icon { width: 24px; height: 24px; flex: 0 0 24px; display: grid; place-items: center; }
.tool-labeled .tool-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12.5px; font-weight: 650; letter-spacing: .05px; }
#toolbar .tool[data-tool="district"].tool-labeled { height: 52px; flex-direction: column; justify-content: center; gap: 0; padding: 2px 4px; }
#toolbar .tool[data-tool="district"].tool-labeled .tool-label { font-size: 10px; line-height: 12px; }
.tool-dirt .tool-icon { color: #d39a65; }
.tool-oneway .tool-icon { color: #8ed1ff; }
.tool-section-label { padding: 5px 10px 1px; color: var(--text-muted); font-size: 10px; font-weight: 800; letter-spacing: .11em; }
.tool:hover { background: rgba(255,255,255,0.07); color: var(--text); }
.tool:active { transform: scale(0.92); }
.tool.active {
  background: var(--accent-dim);
  color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent-glow);
}
.tool-badge {
  position: absolute; right: 3px; bottom: 3px;
  min-width: 15px; height: 15px; padding: 0 2px;
  display: grid; place-items: center;
  border-radius: 5px; background: rgba(15, 18, 22, .88);
  color: var(--text); font: 800 10px/1 system-ui, sans-serif;
  pointer-events: none;
}
#tool-tooltip {
  position: fixed; left: 0; top: 0; z-index: 1200; max-width: 240px; padding: 8px 10px;
  border: 1px solid var(--panel-brd); border-radius: 8px; background: rgba(11, 13, 18, .97);
  color: var(--text); box-shadow: 0 5px 18px rgba(0,0,0,.55); font-size: 12px; line-height: 1.3;
  font-weight: 550; white-space: normal; pointer-events: none; opacity: 0; visibility: hidden;
  transform: translateY(-50%) translateX(-4px); transition: opacity .12s ease, transform .12s ease;
}
#tool-tooltip.visible { opacity: 1; visibility: visible; transform: translateY(-50%) translateX(0); }
.road-direction { background: transparent; border: 0; }
.road-direction span {
  display: block; font: 800 18px/20px system-ui, sans-serif;
  text-shadow: 0 1px 3px rgba(0,0,0,.9); white-space: nowrap;
}
.tool-sep { height: 1px; background: var(--panel-brd); margin: 3px 6px; }
.sim-config {
  width: 46px; height: 46px; padding: 0; border-radius: 11px; position: relative;
  color: var(--text-dim); background: rgba(255,255,255,0.045);
  font-size: 0; display: grid; place-items: center;
}
.sim-config svg { width: 22px; height: 22px; }
.sim-config:hover { color: var(--text); background: rgba(255,255,255,0.09); }

/* ── DRAW BAR ── */
#draw-bar {
  bottom: 22px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px;
  padding: 9px 9px 9px 16px;
}
#draw-hint { font-size: 13.5px; color: var(--text-dim); white-space: nowrap; }
.mini {
  padding: 7px 14px; border-radius: 9px; font-size: 13px; font-weight: 600;
  background: rgba(255,255,255,0.08); color: var(--text);
  transition: background .15s ease, opacity .15s ease;
}
.mini:hover { background: rgba(255,255,255,0.15); }
.mini.plan { background: rgba(242,194,0,0.12); color: #f2c200; }
.mini.plan:hover { background: rgba(242,194,0,0.22); }
.mini.plan.active { background: #f2c200; color: #1a0f0a; }
.mini.primary { background: var(--accent); color: #1a0f0a; }
.mini.primary:hover { filter: brightness(1.08); }
.mini.primary:disabled { opacity: .4; cursor: not-allowed; filter: grayscale(.4); }
.mini.ghost { background: none; color: var(--text-dim); }
.mini.ghost:hover { background: rgba(255,255,255,0.06); color: var(--text); }

/* ── EDIT PANEL ── */
#edit {
  top: 14px; left: 50%; transform: translateX(-50%);
  padding: 11px 14px; min-width: 250px; max-width: 86vw;
}
.edit-head { display: flex; align-items: center; gap: 9px; }
#edit-title { font-size: 15px; font-weight: 650; }
#edit-meta { font-size: 12.5px; color: var(--accent); font-weight: 600; }
.edit-collapse { margin-left: auto; width: 26px; height: 26px; display: grid; place-items: center; color: var(--text-dim); border-radius: 7px; }
.edit-collapse:hover { background: rgba(255,255,255,0.08); color: var(--text); }
.edit-collapse svg { width: 16px; height: 16px; transition: transform .2s ease; }
#edit.collapsed .edit-collapse svg { transform: rotate(180deg); }
#edit.collapsed .edit-hint, #edit.collapsed .edit-actions { display: none; }
.edit-hint { font-size: 11.5px; color: var(--text-dim); margin: 5px 0 9px; line-height: 1.4; }
.edit-hint b { color: var(--text); font-weight: 600; }
.edit-actions { display: flex; gap: 8px; }
.mini.danger { background: rgba(224,36,94,0.16); color: #ff6b93; }
.mini.danger:hover { background: rgba(224,36,94,0.28); }

/* ── CITIZEN INFO ── */
#citizen {
  top: 50%; right: 14px; transform: translateY(-50%);
  padding: 12px 14px; width: 232px; max-width: 86vw; z-index: 600;
}
.cz-head { display: flex; align-items: center; gap: 9px; margin-bottom: 8px; }
#cz-name { font-size: 15px; font-weight: 650; }
.cz-close { margin-left: auto; width: 26px; height: 26px; display: grid; place-items: center; color: var(--text-dim); border-radius: 7px; }
.cz-close:hover { background: rgba(255,255,255,0.08); color: var(--text); }
.cz-close svg { width: 15px; height: 15px; }
#cz-body .cz-row { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; color: var(--text-dim); padding: 5px 0; border-top: 1px solid rgba(255,255,255,0.07); }
#cz-body .cz-row:first-child { border-top: none; }
#cz-body .cz-row b { color: var(--text); font-weight: 600; }
.cz-foot { font-size: 11px; color: var(--text-dim); margin-top: 9px; line-height: 1.4; opacity: .85; }

/* simulation settings */
#sim-panel {
  left: 278px; top: 50%; transform: translateY(-50%);
  width: 286px; max-width: calc(100vw - 300px); padding: 14px;
  z-index: 650;
}
.sim-panel-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.sim-panel-head b { font-size: 15px; }
.sim-control { display: grid; grid-template-columns: 1fr; gap: 5px; margin: 10px 0; color: var(--text-dim); font-size: 12px; }
.sim-control select { width: 100%; padding: 8px 9px; border: 1px solid rgba(255,255,255,.12); border-radius: 8px; background: #191919; color: var(--text); font: inherit; }
.sim-control input[type=range] { width: 100%; accent-color: var(--accent); }
.sim-control output { color: var(--accent); font-weight: 700; }
.sim-panel-hint { margin: 11px 0; color: var(--text-dim); font-size: 11px; line-height: 1.4; }
#sim-panel-apply { width: 100%; }

/* edit handles on map */
.edit-handle {
  border-radius: 50%;
  box-shadow: 0 1px 5px rgba(0,0,0,.55);
  cursor: grab;
}
.edit-handle:active { cursor: grabbing; }
.h-move { width: 16px; height: 16px; background: #fff; box-shadow: 0 0 0 2px var(--accent), 0 1px 5px rgba(0,0,0,.55); }
.h-rot  { width: 15px; height: 15px; background: #15C26B; box-shadow: 0 0 0 2px #fff, 0 1px 5px rgba(0,0,0,.55); }
.h-size { width: 15px; height: 15px; border-radius: 3px; background: #F5A623; box-shadow: 0 0 0 2px #fff, 0 1px 5px rgba(0,0,0,.55); }
.h-vert { width: 14px; height: 14px; background: #fff; box-shadow: 0 0 0 2px var(--accent), 0 1px 5px rgba(0,0,0,.55); }
.h-mid  { width: 11px; height: 11px; background: var(--accent); opacity: .72; box-shadow: 0 0 0 2px #fff, 0 1px 4px rgba(0,0,0,.5); cursor: copy; }

/* ── ROAD CONTEXT MENU ── */
#ctx-menu { z-index: 700; display: flex; flex-direction: column; padding: 5px; min-width: 184px; }
.ctx-item { text-align: left; padding: 9px 12px; border-radius: 8px; font-size: 13.5px; color: var(--text); white-space: nowrap; }
.ctx-item:hover { background: var(--accent-dim); color: var(--accent); }

/* ── SEGMENT-SELECT BAR ── */
#gen-bar { bottom: 22px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 10px; padding: 9px 9px 9px 16px; max-width: 94vw; flex-wrap: wrap; }
#gen-hint { font-size: 13.5px; color: var(--text-dim); white-space: nowrap; }
#gen-zones { display: flex; gap: 3px; }
.zone { padding: 6px 11px; border-radius: 8px; font-size: 12.5px; font-weight: 600; color: var(--text-dim); background: rgba(255,255,255,0.06); }
.zone:hover { color: var(--text); background: rgba(255,255,255,0.12); }
.zone.active { background: var(--accent-dim); color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent-glow); }
#walk-bar { bottom: 22px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 10px; padding: 9px 14px; }
#walk-bar > span { font-size: 13.5px; color: var(--text-dim); }
#border-bar { bottom: 22px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 10px; padding: 9px 9px 9px 16px; max-width: 94vw; flex-wrap: wrap; }
#border-bar > span { font-size: 13px; color: var(--text-dim); }

/* ── COUNTRY NAMEPLATE (видна при отдалении) ── */
.country-label-wrap { pointer-events: none; }
.country-label {
  position: absolute; transform: translate(-50%, -50%); white-space: nowrap;
  padding: 4px 12px; border-radius: 999px;
  background: rgba(8,11,18,0.80); color: #fff;
  font: 700 13px/1.1 system-ui, -apple-system, 'Segoe UI', sans-serif;
  letter-spacing: .02em;
  border: 1.5px solid var(--c, #D97757);
  box-shadow: 0 2px 12px rgba(0,0,0,.55);
  text-shadow: 0 1px 2px rgba(0,0,0,.6);
}
#walk-opts { display: flex; gap: 3px; }

/* traffic light marker */
.tl { width: 9px; height: 24px; background: #1a1a1a; border: 1px solid rgba(255,255,255,0.25); border-radius: 3px; display: flex; flex-direction: column; align-items: center; justify-content: space-around; padding: 2px 0; box-shadow: 0 1px 3px rgba(0,0,0,0.6); }
.tl i { width: 5px; height: 5px; border-radius: 50%; }
.tl i:nth-child(1) { background: #ff5247; }
.tl i:nth-child(2) { background: #ffcf3f; }
.tl i:nth-child(3) { background: #46d06a; }
/* traffic light — top view box */
.tl-top { width: 11px; height: 11px; background: #15171b; border: 1px solid rgba(255,255,255,0.35); border-radius: 2px; box-shadow: 0 1px 3px rgba(0,0,0,0.6); }

/* ── TOAST ── */
#toast {
  bottom: 74px; left: 50%; transform: translateX(-50%);
  padding: 9px 16px; font-size: 13.5px; font-weight: 600; white-space: nowrap;
  animation: toast-in .18s ease;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 6px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ── LAYER SWITCH ── */
#layers {
  bottom: 22px; right: 14px;
  display: flex; padding: 4px; gap: 2px;
}
.layer {
  padding: 7px 13px; border-radius: 9px; font-size: 12.5px; font-weight: 600;
  color: var(--text-dim);
}
.layer:hover { color: var(--text); }
.layer.active { background: var(--accent-dim); color: var(--accent); }

/* ── PALETTE ── */
#palette {
  top: 62px; left: 14px;
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px;
  padding: 12px;
}
.swatch {
  width: 30px; height: 30px; border-radius: 8px;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.2);
  transition: transform .12s ease;
}
.swatch:hover { transform: scale(1.12); }
.swatch.active { box-shadow: inset 0 0 0 2px #fff, 0 0 10px currentColor; }

/* ── MAP MARKERS (buildings) ── */
.build-marker {
  display: grid; place-items: center;
  width: 30px; height: 30px;
  border-radius: 9px;
  background: rgba(13,13,13,0.86);
  box-shadow: 0 2px 8px rgba(0,0,0,0.6), inset 0 0 0 1px rgba(255,255,255,0.14);
  color: #fff;
}
.build-marker svg { width: 19px; height: 19px; }
.build-marker.tree  { color: #7ec88a; }
.build-marker.house { color: #fff; }

/* transport markers */
.transport-marker {
  display: grid; place-items: center; min-width: 30px; height: 26px; padding: 0 6px;
  border-radius: 8px; background: rgba(10,13,18,.92); border: 1px solid currentColor;
  position: relative; box-shadow: 0 2px 8px rgba(0,0,0,.65); color: #fff; font: 800 10px/1 system-ui, sans-serif;
  white-space: nowrap;
}
.transport-marker.station { color: #ffd25a; }
.transport-marker.station.connected { color: #9dffbd; border-color: #38d878; }
.transport-marker.station.connected::after { content: ''; position: absolute; top: -5px; right: -5px; width: 9px; height: 9px; border: 2px solid #eafff1; border-radius: 50%; background: #19c96c; box-shadow: 0 0 8px rgba(25,201,108,.8); }
.transport-marker.exit { color: #7ee59a; }
.transport-marker.parking { color: #d6dde1; }
.station-platform { fill: #8d7651; fill-opacity: .84; stroke: #e4c875; stroke-width: 1.4; }
.station-building { fill: #5a4352; fill-opacity: .96; stroke: #ffd975; stroke-width: 1.4; }
.station-platform.connected { fill: #477758; stroke: #42dc83; }
.station-building.connected { fill: #315b48; stroke: #42dc83; }
.parking-field { fill: #4b545b; fill-opacity: .88; stroke: #c4cbd0; stroke-width: 1.5; }
.parking-stall { stroke: rgba(255,255,255,.75); stroke-width: 1; }

/* ── LEAFLET OVERRIDES (dark) ── */
.leaflet-control-zoom { border: none !important; box-shadow: 0 8px 30px rgba(0,0,0,.55) !important; margin: 14px !important; }
.leaflet-control-zoom a {
  background: var(--panel) !important;
  color: var(--text) !important;
  border: 1px solid var(--panel-brd) !important;
  backdrop-filter: blur(14px);
  width: 34px !important; height: 34px !important; line-height: 34px !important;
  font-size: 19px !important;
}
.leaflet-control-zoom a:first-child { border-radius: 11px 11px 0 0 !important; }
.leaflet-control-zoom a:last-child  { border-radius: 0 0 11px 11px !important; }
.leaflet-control-zoom a:hover { background: rgba(40,40,40,0.9) !important; color: var(--accent) !important; }
.leaflet-control-attribution {
  background: rgba(0,0,0,0.55) !important; color: var(--text-muted) !important;
  font-size: 10px !important; padding: 2px 7px !important; border-radius: 8px 0 0 0 !important;
}
.leaflet-control-attribution a { color: var(--text-dim) !important; }

/* vertex handles while drawing (anchored via iconAnchor, no margin offset) */
.vertex-dot {
  width: 12px; height: 12px;
  border-radius: 50%; background: var(--accent);
  box-shadow: 0 0 0 2px #fff, 0 0 8px var(--accent-glow);
}
/* snapped vertex — green ring, signals "joined to existing road" */
.vertex-dot.snapped { background: #15C26B; box-shadow: 0 0 0 2px #fff, 0 0 10px rgba(21,194,107,.7); }

/* ── РЕЖИМЫ (локал/мир) + МУЛЬТИПЛЕЕР ── */
#mode-toggle { top: 14px; left: 50%; transform: translateX(-50%); display: flex; gap: 3px; padding: 4px; z-index: 500; }
.mode-btn { font-size: 12.5px; font-weight: 650; padding: 6px 13px; border-radius: 8px; color: var(--text-dim); }
.mode-btn.active { background: var(--accent); color: #1a0f0a; }
.mode-btn:not(.active):hover { background: rgba(255,255,255,0.08); color: var(--text); }
#mp-bar { top: 56px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 12px; padding: 7px 14px; font-size: 13px; z-index: 500; }
#mp-bar b { color: var(--accent); font-weight: 700; }
#mp-bar #mp-pop { color: var(--text-dim); }
#mp-login { position: fixed; inset: 0; z-index: 2000; display: grid; place-items: center; background: rgba(0,0,0,0.55); backdrop-filter: blur(3px); }
.mp-login-box { position: static; width: 300px; max-width: 90vw; padding: 20px; display: flex; flex-direction: column; gap: 10px; }
.mp-login-title { font-size: 17px; font-weight: 700; }
.mp-login-sub { font-size: 12px; color: var(--text-dim); margin-bottom: 4px; line-height: 1.45; }
.mp-login-box input { background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.12); border-radius: 9px; padding: 10px 12px; color: var(--text); font-size: 14px; outline: none; }
.mp-login-box input:focus { border-color: var(--accent); }
.mp-login-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 6px; }
