:root {
  color-scheme: light;
  --app-bg: #eef1f6;
  --panel: rgba(255, 255, 255, 0.92);
  --panel-solid: #ffffff;
  --text: #17213a;
  --muted: #6f778a;
  --line: #e2e6ee;
  --primary: #275ee7;
  --primary-hover: #1f52cf;
  --danger: #d9485f;
  --radius-lg: 22px;
  --radius-md: 14px;
  --shadow: 0 20px 60px rgba(32, 43, 73, 0.11);
  --font: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: radial-gradient(circle at 16% 0%, rgba(78, 116, 224, 0.12), transparent 34%), var(--app-bg);
  color: var(--text);
  overflow: hidden;
}
button, input { font: inherit; }
button { color: inherit; }

.app-shell { height: 100vh; display: flex; flex-direction: column; }
.topbar {
  height: 72px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 26px; border-bottom: 1px solid rgba(210, 215, 227, 0.8);
  background: rgba(246, 248, 252, 0.78); backdrop-filter: blur(18px); flex: none;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 12px; background: #18234a;
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px; padding: 9px;
  transform: rotate(-2deg); box-shadow: 0 7px 18px rgba(24, 35, 74, 0.22);
}
.brand-mark span { background: #6bcfff; border-radius: 20px; transform: skewY(-18deg); }
.brand-mark span:nth-child(2) { opacity: .78; }
.brand-mark span:nth-child(3) { opacity: .55; }
.brand-name { font-weight: 750; letter-spacing: -0.025em; font-size: 18px; }
.brand-subtitle { font-size: 11px; color: var(--muted); margin-top: 1px; }
.top-actions { display: flex; gap: 10px; }
.button {
  border: 0; border-radius: 11px; min-height: 40px; padding: 0 16px;
  cursor: pointer; transition: .18s ease; font-weight: 650; font-size: 13px;
}
.button-ghost { background: rgba(255,255,255,.7); box-shadow: inset 0 0 0 1px var(--line); }
.button-ghost:hover { background: #fff; transform: translateY(-1px); }
.button-primary { background: var(--primary); color: #fff; box-shadow: 0 8px 20px rgba(39, 94, 231, .24); }
.button-primary:hover { background: var(--primary-hover); transform: translateY(-1px); }

.workspace { min-height: 0; flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) 410px; gap: 18px; padding: 18px; }
.canvas-panel, .sidebar {
  background: var(--panel); border: 1px solid rgba(220, 225, 235, .85);
  border-radius: var(--radius-lg); box-shadow: var(--shadow); overflow: hidden; min-height: 0;
}
.canvas-panel { display: flex; flex-direction: column; }
.canvas-toolbar {
  min-height: 48px; padding: 0 16px; flex: none; display: flex; align-items: center;
  justify-content: space-between; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 12px;
}
.status-wrap { display: flex; align-items: center; gap: 8px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #48b989; box-shadow: 0 0 0 4px rgba(72,185,137,.12); }
.status-dot.loading { background: #e5aa40; box-shadow: 0 0 0 4px rgba(229,170,64,.13); }
.status-dot.error { background: #d9485f; box-shadow: 0 0 0 4px rgba(217,72,95,.12); }
.canvas-hint { text-align: right; }
.stage-wrap {
  flex: 1; min-height: 0; margin: 14px; border-radius: 17px; overflow: hidden;
  background: #263f91; position: relative; display: grid; place-items: center;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.06);
}
#mapSvg { display: block; width: 100%; height: 100%; touch-action: none; cursor: grab; }
#mapSvg:active { cursor: grabbing; }
.region-path { transition: fill .16s ease, filter .16s ease; cursor: pointer; }
.region-path:hover { filter: brightness(1.13); }
.city-label { cursor: grab; user-select: none; }
.city-label:active { cursor: grabbing; }
.zoom-controls {
  position: absolute; z-index: 12; right: 14px; bottom: 14px; display: flex; flex-direction: column;
  border-radius: 12px; overflow: hidden; box-shadow: 0 8px 24px rgba(13, 24, 57, .24);
}
.zoom-controls button {
  width: 42px; height: 40px; border: 0; border-bottom: 1px solid rgba(24,35,74,.1);
  background: rgba(255,255,255,.94); color: #26365e; cursor: pointer; font-size: 21px; font-weight: 650;
}
.zoom-controls button:last-child { border-bottom: 0; font-size: 17px; }
.zoom-controls button:hover { background: #eef3ff; color: var(--primary); }
.map-tooltip {
  position: absolute; z-index: 20; pointer-events: none; padding: 7px 10px; border-radius: 9px;
  background: rgba(16, 23, 49, .92); color: #fff; font-size: 12px;
  box-shadow: 0 10px 25px rgba(0,0,0,.18); transform: translate(10px, 10px);
}
.loading-card {
  position: absolute; inset: 0; z-index: 15; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 8px; color: rgba(255,255,255,.95); background: rgba(30,49,111,.8);
  backdrop-filter: blur(5px); text-align: center; transition: opacity .2s ease, visibility .2s ease;
}
.loading-card.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.loading-card span { max-width: 340px; font-size: 12px; color: rgba(255,255,255,.66); }
.spinner, .search-spinner {
  width: 23px; height: 23px; border-radius: 50%; border: 2px solid rgba(255,255,255,.26);
  border-top-color: #fff; animation: spin .75s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.sidebar { display: flex; flex-direction: column; }
.tabs { display: grid; grid-template-columns: repeat(4, 1fr); padding: 8px; gap: 4px; border-bottom: 1px solid var(--line); flex: none; }
.tab {
  border: 0; background: transparent; min-height: 38px; border-radius: 10px; cursor: pointer;
  color: var(--muted); font-size: 12px; font-weight: 650; transition: .15s ease;
}
.tab:hover { background: #f2f4f8; color: var(--text); }
.tab.active { background: #e9efff; color: #2455d1; }
.tab-panel { display: none; min-height: 0; overflow-y: auto; padding-bottom: 14px; }
.tab-panel.active { display: block; }
#tab-cities.active { display: flex; flex-direction: column; }
.control-section { padding: 18px 18px 20px; border-bottom: 1px solid var(--line); }
.control-section:last-child { border-bottom: 0; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 13px; }
h2 { margin: 0; font-size: 14px; letter-spacing: -0.01em; }
.section-description { margin: -3px 0 14px; font-size: 12px; line-height: 1.5; color: var(--muted); }
.city-data-note { margin: 12px 0 0; }
.text-button { border: 0; padding: 0; background: transparent; color: #4169cf; cursor: pointer; font-size: 12px; }
.text-button:hover { text-decoration: underline; }
.field { display: flex; flex-direction: column; gap: 7px; font-size: 12px; color: var(--muted); }
.field input[type="text"], .field input[type="number"], .search-box input, .city-name-input {
  width: 100%; border: 1px solid var(--line); border-radius: 10px; background: #fff;
  min-height: 40px; padding: 0 11px; color: var(--text); outline: 0; transition: .16s ease;
}
.field input:focus, .search-box input:focus, .city-name-input:focus { border-color: #80a1ee; box-shadow: 0 0 0 3px rgba(66,105,207,.12); }
.toggle-row { margin-top: 12px; display: flex; align-items: center; gap: 9px; font-size: 12px; color: var(--muted); cursor: pointer; }
.toggle-row input, .layer-toggles input { accent-color: var(--primary); }

.preset-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.preset-card { border: 1px solid var(--line); border-radius: 11px; padding: 6px; background: #fff; cursor: pointer; font-size: 10px; color: var(--muted); }
.preset-card:hover, .preset-card.active { border-color: #88a7ee; box-shadow: 0 0 0 2px rgba(66,105,207,.08); color: var(--text); }
.preset-preview { height: 38px; border-radius: 7px; display: block; margin-bottom: 6px; position: relative; overflow: hidden; }
.preset-preview::before { content:""; position:absolute; width:55%; height:45%; left:23%; top:26%; border-radius: 50% 35% 48% 24%; transform: rotate(-8deg); }
.preset-slide { background:#263f91; }.preset-slide::before{background:#556da5; box-shadow: 14px 3px 0 -5px #64c8ff;}
.preset-light { background:#f3f5f9; }.preset-light::before{background:#bdc6d7; box-shadow: 14px 3px 0 -5px #275ee7;}
.preset-mono { background:#16191f; }.preset-mono::before{background:#555b66; box-shadow: 14px 3px 0 -5px #f1f2f5;}
.color-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px 8px; }
.color-field { font-size: 10px; color: var(--muted); display: flex; flex-direction: column; gap: 6px; }
.color-field input { width: 100%; height: 31px; padding: 2px; border: 1px solid var(--line); border-radius: 8px; background: #fff; cursor: pointer; }
.palette { display: flex; gap: 9px; align-items: center; margin-bottom: 13px; }
.palette-color, .custom-color { width: 30px; height: 30px; border-radius: 50%; flex: none; cursor: pointer; }
.palette-color { border: 3px solid #fff; background: var(--swatch); box-shadow: 0 0 0 1px #d8dde7; }
.palette-color.active { box-shadow: 0 0 0 2px #283967; transform: scale(1.04); }
.custom-color { position: relative; overflow: hidden; border: 1px solid #d8dde7; background: conic-gradient(#f66,#fd6,#6e6,#6cf,#86f,#f6c,#f66); }
.custom-color input { position: absolute; inset: -12px; opacity: 0; cursor: pointer; }

.search-box { position: relative; min-width: 0; }
.search-action { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; align-items: start; }
.search-button, .open-city-button {
  border: 0; border-radius: 10px; min-height: 40px; padding: 0 13px; background: #eaf0ff;
  color: #2857ca; font-size: 11px; font-weight: 700; cursor: pointer;
}
.search-button:hover, .open-city-button:hover { background: #dce6ff; }
.open-city-button { width: 100%; margin-top: 10px; }
.suggestions {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 30; background: #fff;
  border: 1px solid var(--line); border-radius: 11px; box-shadow: 0 14px 35px rgba(31,42,71,.16);
  max-height: 260px; overflow-y: auto;
}
.suggestion-item { width:100%; border:0; background:#fff; text-align:left; padding:10px 11px; cursor:pointer; font-size:12px; border-bottom:1px solid #edf0f5; }
.suggestion-item:last-child { border-bottom:0; }
.suggestion-item:hover { background:#f3f6fc; }
.suggestion-item small { display:block; color:var(--muted); margin-top:3px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.search-spinner { width:17px; height:17px; position:absolute; right:12px; top:12px; border-color:#d4d9e3; border-top-color:#3c64cb; }

.selection-list { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; max-height: 180px; overflow-y: auto; }
.selection-item { display: grid; grid-template-columns: 13px minmax(0,1fr) 26px; align-items: center; gap: 8px; min-height: 34px; padding: 4px 4px 4px 9px; background: #f6f7fa; border-radius: 9px; font-size: 11px; }
.selection-swatch { width: 10px; height: 10px; border-radius: 50%; }
.selection-name { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.icon-button { width: 25px; height: 25px; border:0; border-radius:7px; background:transparent; color:#8a91a0; cursor:pointer; font-size:17px; line-height:1; }
.icon-button:hover { background:#e8ebf1; color:var(--danger); }
.empty-state { padding: 28px 12px; text-align: center; color: #9299a8; font-size: 12px; line-height: 1.5; }
.empty-state.compact { padding: 13px 8px; }
.range-field { display:flex; flex-direction:column; gap:6px; margin-top:12px; }
.range-field:first-of-type { margin-top:0; }
.range-field > span { display:flex; justify-content:space-between; color:var(--muted); font-size:11px; }
.range-field input { width:100%; accent-color:var(--primary); }

.city-section { flex: none; }
.grow-section { flex: 1; min-height: 0; border-bottom: 0; display: flex; flex-direction: column; }
.city-list { display:flex; flex-direction:column; gap:9px; min-height:0; }
.city-item { border:1px solid var(--line); border-radius:12px; padding:11px; background:#fff; }
.city-item-header { display:grid; grid-template-columns:10px minmax(0,1fr) 26px; align-items:center; gap:8px; }
.city-dot { width:9px; height:9px; background:var(--dot-color,#fff); border-radius:50%; box-shadow:0 0 0 1px rgba(0,0,0,.1); }
.city-name-input { min-height:32px; font-size:12px; padding:0 8px; }
.city-meta { color:var(--muted); font-size:10px; margin:6px 0 9px 18px; overflow:hidden; white-space:nowrap; text-overflow:ellipsis; }
.city-offsets { display:grid; grid-template-columns:1fr 1fr; gap:10px; }
.city-offsets label { font-size:9px; color:var(--muted); display:flex; flex-direction:column; gap:4px; }
.city-offsets input { width:100%; accent-color:var(--primary); }

.selected-city-card { margin-top: 12px; min-height: 52px; border-radius: 11px; background: #f4f6fa; padding: 11px 12px; display: flex; flex-direction: column; justify-content: center; }
.selected-city-card span, .selected-city-card small { color: var(--muted); font-size: 11px; }
.selected-city-card strong { font-size: 13px; }
.selected-city-card small { margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.layer-toggles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; }
.layer-toggles label { min-height: 38px; padding: 0 8px; border: 1px solid var(--line); border-radius: 10px; background: #fff; display: flex; align-items: center; gap: 6px; font-size: 10px; cursor: pointer; }
.layer-swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.layer-swatch.roads { background: #8292bd; }
.layer-swatch.green { background: #66aa78; }
.layer-swatch.water { background: #67b9e8; }
.city-marker-list { display: flex; flex-direction: column; gap: 7px; }
.city-marker-item { display: grid; grid-template-columns: 12px minmax(0,1fr) 26px; align-items: center; gap: 8px; padding: 8px; border: 1px solid var(--line); border-radius: 10px; background: #fff; cursor: pointer; }
.city-marker-item:hover { border-color: #a5b8e8; }
.city-marker-item strong, .city-marker-item small { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.city-marker-item strong { font-size: 11px; }
.city-marker-item small { color: var(--muted); font-size: 9px; margin-top: 3px; }
.city-marker-symbol { width: 10px; height: 10px; border-radius: 50%; background: #275ee7; box-shadow: 0 0 0 3px rgba(39,94,231,.12); }
.city-marker-symbol.poi { border-radius: 3px; background: #8b5dd7; box-shadow: 0 0 0 3px rgba(139,93,215,.12); }

.resolution-presets { display:grid; grid-template-columns:repeat(2,1fr); gap:7px; margin-bottom:14px; }
.resolution-presets button { border:1px solid var(--line); background:#fff; border-radius:9px; min-height:35px; font-size:11px; cursor:pointer; }
.resolution-presets button:hover, .resolution-presets button.active { border-color:#7fa0ed; background:#f0f4ff; color:#2455d1; }
.dimension-grid { display:grid; grid-template-columns:1fr 18px 1fr; align-items:end; gap:6px; }
.dimension-separator { padding-bottom:11px; color:var(--muted); text-align:center; }
.export-section { display:flex; flex-direction:column; gap:8px; }
.export-section .section-heading { margin-bottom:5px; }
.export-button { border:1px solid var(--line); background:#fff; border-radius:12px; min-height:58px; padding:10px 12px; text-align:left; cursor:pointer; display:flex; flex-direction:column; gap:3px; transition:.16s ease; }
.export-button:hover { transform:translateY(-1px); box-shadow:0 8px 22px rgba(30,44,76,.09); border-color:#9bb2e7; }
.export-button span { font-weight:750; font-size:13px; }
.export-button small { color:var(--muted); font-size:10px; }
.export-button.svg span { color:#7352ce; }.export-button.png span { color:#176fc4; }.export-button.jpg span { color:#bd6f22; }
.note-section p { margin:0; font-size:11px; line-height:1.55; color:var(--muted); }

@media (max-width: 1100px) {
  body { overflow:auto; }
  .app-shell { height:auto; min-height:100vh; }
  .workspace { grid-template-columns:1fr; }
  .canvas-panel { height:70vh; min-height:520px; }
  .sidebar { min-height:680px; }
}
@media (max-width: 620px) {
  .topbar { padding:0 14px; }
  .brand-subtitle, .button-ghost, .canvas-hint { display:none; }
  .workspace { padding:8px; gap:8px; }
  .canvas-panel, .sidebar { border-radius:16px; }
  .canvas-panel { min-height:430px; height:56vh; }
  .stage-wrap { margin:8px; }
  .color-grid { grid-template-columns:repeat(2,1fr); }
  .tab { font-size: 11px; padding: 0 3px; }
  .tabs { gap: 2px; padding: 6px; }
  .layer-toggles { grid-template-columns: 1fr; }
  .zoom-controls { right: 9px; bottom: 9px; }
  .zoom-controls button { width: 38px; height: 36px; }
}
