:root {
  --accent: #12a150;
  --accent-ink: #ffffff;
  --ink: #1f2328;
  --muted: #6b7280;
  --line: #e5e7eb;
  --card: #ffffff;
  --shadow: 0 2px 6px rgba(0, 0, 0, .12), 0 8px 24px rgba(0, 0, 0, .08);
  --radius: 12px;
  --overlay-opacity: .9;
  font-family: "Pretendard Variable", Pretendard, system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body { background: #2b2d31; }
button, input, select, textarea { font: inherit; color: inherit; }

.ms {
  font-family: "Material Symbols Rounded";
  font-weight: 500;
  font-size: 20px;
  line-height: 1;
  font-variation-settings: "FILL" 1, "opsz" 20;
  display: inline-block;
  vertical-align: middle;
  user-select: none;
}

#map { position: fixed; inset: 0; background: #2b2d31; }
.mode-plain #map, .mode-blank #map { background: #f3f1ec; }
.mode-plain .leaflet-tile-pane { opacity: .22; filter: grayscale(1) contrast(.9); }
.mode-blank .leaflet-tile-pane { display: none; }
.leaflet-container { font-family: inherit; }

.leaflet-pane.cm-vector { opacity: var(--overlay-opacity); }
.leaflet-pane > svg path.cm-district.leaflet-interactive { pointer-events: visibleStroke; }
.busy .cm-poi { pointer-events: none; }
.busy .leaflet-interactive { cursor: crosshair; }

/* ------------------------------------------------------------- labels */
.leaflet-labels-pane { pointer-events: none; }
.cm-label {
  position: absolute; left: 0; top: 0;
  white-space: nowrap;
  pointer-events: none;
  paint-order: stroke fill;
  -webkit-text-stroke: 3px rgba(255, 255, 255, .95);
  text-shadow: none;
}
.cm-road { font-size: 12px; font-weight: 600; color: #4a4336; transform-origin: 0 0; }
.cm-road.major { color: #6b4a12; }
.cm-road.rail { color: #555; }
.cm-area { font-size: 12px; font-weight: 600; color: #5e564a; }
.cm-area.park { color: #2f7a2f; }
.cm-area.water { color: #2a6fb0; font-style: italic; }
.cm-area.district { font-size: 16px; font-weight: 800; letter-spacing: .12em; color: #6c4fb8; }
.cm-place { font-weight: 800; color: #2b2b2b; }
.cm-place.i1 { font-size: 19px; }
.cm-place.i2 { font-size: 15px; }
.cm-place.i3 { font-size: 13px; font-weight: 700; }

.cm-poi {
  position: absolute; left: 0; top: 0;
  display: flex; align-items: center; gap: 4px;
  pointer-events: auto; cursor: pointer;
  white-space: nowrap;
}
.cm-poi .pin {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--c); color: #fff;
  display: grid; place-items: center;
  box-shadow: 0 0 0 2px #fff, 0 1px 3px rgba(0, 0, 0, .35);
}
.cm-poi .pin .ms { font-size: 14px; }
.cm-poi b {
  font-size: 12px; font-weight: 700; color: #222;
  paint-order: stroke fill;
  -webkit-text-stroke: 3px rgba(255, 255, 255, .95);
}
.cm-poi.sel .pin { box-shadow: 0 0 0 3px #fff, 0 0 0 6px var(--accent); }
.cm-player {
  display: flex; align-items: center; gap: 4px; white-space: nowrap;
  font-size: 12px; font-weight: 700; color: #fff;
}
.cm-player i { width: 12px; height: 12px; border-radius: 50%; background: #ff5a36; box-shadow: 0 0 0 2px #fff; }
.cm-player span { background: rgba(0, 0, 0, .6); padding: 1px 6px; border-radius: 8px; }

/* ------------------------------------------------------------- side panel + search */
#side {
  position: fixed; top: 12px; left: 12px; z-index: 1000;
  width: 380px; max-width: calc(100vw - 24px);
  display: flex; flex-direction: column; gap: 8px;
  max-height: calc(100vh - 24px);
}
#searchbox {
  display: flex; align-items: center; gap: 8px;
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 0 8px 0 14px; height: 48px;
  border: 2px solid transparent;
}
#searchbox:focus-within { border-color: var(--accent); }
#searchbox > .ms { color: var(--accent); }
#q { flex: 1; border: 0; outline: 0; background: transparent; font-size: 15px; min-width: 0; }
#q::-webkit-search-cancel-button { display: none; }
.icon-btn { border: 0; background: transparent; cursor: pointer; padding: 6px; border-radius: 8px; color: var(--muted); display: grid; place-items: center; }
.icon-btn:hover { background: #f3f4f6; }

#panel {
  position: relative;
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  overflow: auto; min-height: 0;
}
#panel-close { position: absolute; top: 8px; right: 8px; z-index: 1; }
#panel-body { padding: 18px 18px 16px; }
#panel h2 { font-size: 20px; margin: 0 32px 4px 0; line-height: 1.3; word-break: keep-all; }
#panel h3 { font-size: 14px; margin: 16px 0 8px; color: var(--muted); font-weight: 600; }
.kind-chip { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; color: var(--muted); }
.kind-chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c, #999); }
.desc { white-space: pre-wrap; line-height: 1.6; margin: 12px 0 0; font-size: 14px; }
.facts { margin: 14px 0 0; padding: 12px 0 0; border-top: 1px solid var(--line); display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; font-size: 13px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; display: flex; align-items: center; gap: 6px; font-variant-numeric: tabular-nums; }
.facts code { font-family: ui-monospace, "JetBrains Mono", monospace; font-size: 12px; background: #f3f4f6; padding: 2px 6px; border-radius: 6px; }
.meta { margin-top: 14px; font-size: 12px; color: var(--muted); }
.btn-row { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  border: 1px solid var(--line); background: #fff; border-radius: 10px;
  padding: 8px 12px; cursor: pointer; font-size: 14px; font-weight: 600;
}
.btn:hover { background: #f9fafb; }
.btn.primary, button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: #d93025; }
.btn .ms { font-size: 18px; }
.mini { border: 0; background: transparent; cursor: pointer; color: var(--muted); padding: 2px; border-radius: 6px; }
.mini:hover { background: #f3f4f6; color: var(--ink); }
.mini .ms { font-size: 16px; }

.results { list-style: none; margin: 0; padding: 6px 0; }
.results li button {
  width: 100%; display: flex; align-items: center; gap: 12px; text-align: left;
  border: 0; background: transparent; padding: 10px 16px; cursor: pointer;
}
.results li button:hover, .results li button:focus-visible { background: #f5f7f6; outline: none; }
.results .ico { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; background: var(--c, #9ca3af); color: #fff; flex: none; }
.results .ico .ms { font-size: 18px; }
.results .t { font-weight: 600; font-size: 15px; }
.results .s { color: var(--muted); font-size: 12px; margin-top: 2px; }
.empty { padding: 20px 18px; color: var(--muted); font-size: 14px; }

/* forms */
.form { display: grid; gap: 12px; margin-top: 12px; }
.form label { display: grid; gap: 6px; font-size: 13px; font-weight: 600; color: #374151; }
.form input, .form select, .form textarea {
  border: 1px solid #d1d5db; border-radius: 10px; padding: 9px 11px; font-size: 14px; font-weight: 400; background: #fff;
}
.form textarea { min-height: 84px; resize: vertical; }
.form input:focus, .form select:focus, .form textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.form .hint { font-size: 12px; color: var(--muted); font-weight: 400; }
.form .two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.cats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.cats button {
  display: grid; justify-items: center; gap: 4px; padding: 8px 2px; font-size: 11px; font-weight: 600;
  border: 1px solid var(--line); border-radius: 10px; background: #fff; cursor: pointer;
}
.cats button .ms { color: var(--c); }
.cats button[aria-pressed="true"] { border-color: var(--accent); background: #ecf8f1; }

.history li button { align-items: flex-start; }
.history .t { font-size: 14px; }
.tag { font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 6px; background: #eef2ff; color: #3949ab; margin-right: 4px; }
.tag.delete { background: #fdecea; color: #c62828; }
.tag.create { background: #e8f5e9; color: #2e7d32; }

/* ------------------------------------------------------------- top right / controls */
#topright { position: fixed; top: 12px; right: 12px; z-index: 1000; display: flex; gap: 8px; }
#account { display: flex; gap: 8px; }
.pill {
  display: inline-flex; align-items: center; gap: 6px; height: 40px; padding: 0 14px;
  border: 0; border-radius: 20px; background: var(--card); box-shadow: var(--shadow);
  font-weight: 600; font-size: 14px; cursor: pointer;
}
.pill.on { background: var(--accent); color: #fff; }
.pill .ms { font-size: 18px; }

#controls { position: fixed; right: 12px; top: 64px; z-index: 1000; display: grid; gap: 8px; justify-items: end; }
.ctl {
  width: 40px; height: 40px; border: 0; background: var(--card); box-shadow: var(--shadow);
  border-radius: 10px; display: grid; place-items: center; cursor: pointer; color: #374151;
}
.ctl-group { display: grid; box-shadow: var(--shadow); border-radius: 10px; overflow: hidden; }
.ctl-group .ctl { box-shadow: none; border-radius: 0; }
.ctl-group .ctl + .ctl { border-top: 1px solid var(--line); }
.ctl:hover { background: #f9fafb; }
#layers-pop {
  background: var(--card); box-shadow: var(--shadow); border-radius: var(--radius);
  padding: 12px; width: 240px; display: grid; gap: 12px; font-size: 13px;
}
#layers-pop[hidden] { display: none; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); background: #f3f4f6; border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: transparent; padding: 7px 0; border-radius: 8px; cursor: pointer; font-weight: 600; color: var(--muted); }
.seg button[aria-pressed="true"] { background: #fff; color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, .12); }
.row { display: grid; gap: 6px; font-weight: 600; color: #374151; }
.row.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.row input[type=range] { accent-color: var(--accent); width: 100%; }

#editbar, #drawbar {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 1000;
  display: flex; align-items: center; gap: 2px; padding: 6px;
  background: var(--card); box-shadow: var(--shadow); border-radius: 14px;
  max-width: calc(100vw - 24px); overflow-x: auto;
}
#editbar[hidden], #drawbar[hidden] { display: none; }
#editbar button, #drawbar button {
  display: grid; justify-items: center; gap: 2px; min-width: 56px; padding: 6px 8px;
  border: 0; background: transparent; border-radius: 10px; cursor: pointer; font-size: 12px; font-weight: 600; color: #374151;
}
#editbar button:hover, #drawbar button:hover { background: #f3f4f6; }
#editbar button[aria-pressed="true"] { background: #ecf8f1; color: var(--accent); }
#drawbar button.primary { background: var(--accent); color: #fff; }
#editbar .sep { width: 1px; align-self: stretch; background: var(--line); margin: 4px 4px; }
#draw-hint { font-size: 13px; color: var(--muted); padding: 0 10px; max-width: 280px; }

#coords {
  position: fixed; left: 12px; bottom: 12px; z-index: 900;
  background: rgba(255, 255, 255, .92); border-radius: 8px; padding: 4px 10px;
  font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; box-shadow: 0 1px 3px rgba(0, 0, 0, .15);
}
.leaflet-control-scale { margin-bottom: 12px !important; margin-right: 12px !important; }
.leaflet-control-scale-line { background: rgba(255, 255, 255, .85); border-color: #555; font-weight: 600; }

#toast {
  position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%) translateY(10px); z-index: 2000;
  background: #1f2328; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.error { background: #c62828; }

dialog#login { border: 0; border-radius: 16px; padding: 0; width: min(380px, calc(100vw - 32px)); box-shadow: var(--shadow); }
dialog#login::backdrop { background: rgba(0, 0, 0, .35); }
#login-form { padding: 22px; display: grid; gap: 12px; }
#login-form h2 { margin: 0; font-size: 20px; }
#login-form label { display: grid; gap: 6px; font-size: 13px; font-weight: 600; }
#login-form input { border: 1px solid #d1d5db; border-radius: 10px; padding: 10px 12px; font-size: 15px; }
#login-form .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
#login-form .actions button { border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 9px 16px; font-weight: 600; cursor: pointer; }
#login-form .actions button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.muted { color: var(--muted); font-size: 13px; margin: 0; line-height: 1.5; }
.error { color: #c62828; font-size: 13px; margin: 0; }

.leaflet-popup-content { font-size: 13px; margin: 10px 14px; }
.leaflet-popup-content .xz { font-weight: 700; font-variant-numeric: tabular-nums; }
.leaflet-popup-content .mini { margin-left: 4px; }

/* ------------------------------------------------------------- phones: panel becomes a bottom sheet */
@media (max-width: 640px) {
  #side { top: 10px; left: 10px; right: 10px; width: auto; max-width: none; max-height: none; }
  #searchbox { margin-right: 108px; }
  #panel {
    position: fixed; left: 0; right: 0; bottom: 0; max-height: 55vh;
    border-radius: 16px 16px 0 0;
  }
  #topright { top: 14px; right: 10px; }
  #account .pill .label { display: none; }
  #controls { top: 70px; right: 10px; }
  #editbar, #drawbar { bottom: 12px; }
  body.panel-open #editbar, body.panel-open #drawbar, body.panel-open #coords { display: none; }
  #coords { bottom: 10px; left: 10px; }
}
