:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #14181f;
  --muted: #6b7280;
  --line: #e2e5ea;
  --accent: #1d4ed8;
  --sea: #eef2f7;
  --land: #ffffff;
  --border: #a8b0bb;
}

* { box-sizing: border-box; }

/* display из авторских правил (.auth — grid, .app — flex) перебивает
   display:none, который атрибут hidden получает из стилей браузера,
   поэтому скрытый экран продолжал занимать место. */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  font: 15px/1.45 system-ui, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

button { font: inherit; cursor: pointer; }

.primary {
  background: var(--accent); color: #fff; border: 0;
  border-radius: 8px; padding: 10px 16px; font-weight: 600;
}
.primary:hover { background: #1e40af; }

.ghost {
  background: #fff; border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 12px; color: var(--ink);
}
.ghost:hover { border-color: var(--border); }

/* ---------- вход ---------- */

.auth {
  min-height: 100%;
  display: grid; place-items: center;
  padding: 24px;
}
.auth-card {
  width: 100%; max-width: 380px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 28px;
  display: flex; flex-direction: column; gap: 14px;
  box-shadow: 0 8px 30px rgba(20, 24, 31, .06);
}
.auth-card h1 { margin: 0; font-size: 22px; }
.auth-sub { margin: 0; color: var(--muted); font-size: 14px; }
.auth-card label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.auth-card input {
  font: inherit; padding: 9px 11px;
  border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink);
}
.auth-card input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.auth-error { margin: 0; color: #b91c1c; font-size: 13px; }

.tabs { display: flex; gap: 4px; background: var(--bg); padding: 4px; border-radius: 9px; }
.tab {
  flex: 1; border: 0; background: transparent; padding: 7px;
  border-radius: 6px; color: var(--muted); font-weight: 500;
}
.tab.is-active { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.08); }

/* ---------- каркас ---------- */

.app { height: 100%; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; white-space: nowrap; }
.who { margin-left: auto; display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); }

.search { position: relative; flex: 1; max-width: 460px; }
.search input {
  width: 100%; font: inherit; padding: 8px 12px;
  border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink);
}
.search input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }

.results {
  position: absolute; z-index: 20; top: calc(100% + 4px); left: 0; right: 0;
  margin: 0; padding: 4px; list-style: none; max-height: 340px; overflow-y: auto;
  background: #fff; border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 10px 30px rgba(20,24,31,.12);
}
.results li { padding: 7px 10px; border-radius: 6px; cursor: pointer; display: flex; gap: 8px; align-items: baseline; }
.results li:hover, .results li.is-active { background: var(--bg); }
.results .r-name { font-weight: 500; }
.results .r-meta { color: var(--muted); font-size: 12px; margin-left: auto; }
.results .r-zh { color: var(--muted); font-size: 13px; }

.main { flex: 1; display: flex; min-height: 0; }

.map-wrap { position: relative; flex: 1; min-width: 0; background: var(--sea); }
#map { width: 100%; height: 100%; display: block; }

.map-controls { position: absolute; top: 12px; left: 12px; display: flex; gap: 8px; flex-wrap: wrap; }
#city-mode { font: inherit; font-size: 13px; cursor: pointer; max-width: 220px; }

.legend {
  position: absolute; left: 12px; bottom: 12px;
  background: rgba(255,255,255,.94); border: 1px solid var(--line);
  border-radius: 10px; padding: 9px 12px; font-size: 13px;
  display: flex; flex-direction: column; gap: 5px;
}
.legend-row { display: flex; align-items: center; gap: 8px; }
.sw { width: 17px; height: 13px; border-radius: 3px; border: 1px solid var(--border); display: inline-block; }
.sw-lived   { background: #d1fae5; border-color: #047857; }
.sw-visited { background: #dbeafe; border-color: #1d4ed8; }
.sw-transit { background: #fef3c7; border-color: #b45309; }
.sw-want    { background: #f3e8ff; border-color: #7e22ce; }
.sw-city    { background: #1d4ed8; border-radius: 50%; width: 13px; border-color: #fff; }
.sw-city-empty { background: #fff; border-radius: 50%; width: 13px; border-color: #64748b; }

/* ---------- карта ---------- */

.unit {
  fill: var(--land);
  stroke: var(--border);
  stroke-width: 0.7;
  vector-effect: non-scaling-stroke;
  cursor: pointer;
}
.unit:hover { stroke: var(--accent); stroke-width: 1.8; }
.unit.is-selected { stroke: var(--accent); stroke-width: 2.4; }

/* Неотмеченный округ прозрачен, чтобы сквозь него читалась штриховка
   провинции: иначе, зайдя в отмеченную провинцию, вы видели бы её белой.
   Именно transparent, а не none — прозрачная заливка всё ещё принимает клики. */
#layer-prefectures .unit {
  fill: transparent;
  stroke-width: 0.5;
  stroke: #b9c0ca;
}

.city-dot {
  fill: #ef4444; stroke: #fff; stroke-width: 1.5;
  cursor: pointer;
}
.city-dot:hover { stroke: var(--accent); }
/* Город без пометки — полый кружок: видно, что здесь есть что отметить. */
.city-dot.is-empty { stroke: #64748b; }
.city-dot.is-empty:hover { stroke: var(--accent); fill: #dbeafe; }
.city-label {
  font-size: 11px; fill: var(--ink); paint-order: stroke;
  stroke: #fff; stroke-width: 3; stroke-linejoin: round;
  pointer-events: none; user-select: none;
}

/* ---------- боковая панель ---------- */

.side {
  width: 340px; flex: none; background: var(--panel);
  border-left: 1px solid var(--line); overflow-y: auto;
  display: flex; flex-direction: column;
}

.stats {
  padding: 12px 16px; border-bottom: 1px solid var(--line);
  font-size: 13px; color: var(--muted); display: flex; gap: 16px;
}
.stats b { color: var(--ink); font-size: 17px; display: block; font-weight: 700; }

.panel { padding: 16px; display: flex; flex-direction: column; gap: 16px; }
.hint { color: var(--muted); font-size: 14px; margin: 0; }

.unit-head h2 { margin: 0 0 2px; font-size: 19px; }
.unit-head .sub { color: var(--muted); font-size: 13px; }
.unit-head .parent { color: var(--muted); font-size: 12px; margin-top: 4px; }

.section { border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
.section > h3 { margin: 0 0 9px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--line); background: #fff; border-radius: 999px;
  padding: 5px 12px; font-size: 13px;
}
.chip:hover { border-color: var(--border); }
.chip.is-on { border-color: transparent; font-weight: 600; }
.chip[data-status="lived"].is-on   { background: #d1fae5; color: #065f46; }
.chip[data-status="visited"].is-on { background: #dbeafe; color: #1e3a8a; }
.chip[data-status="transit"].is-on { background: #fef3c7; color: #92400e; }
.chip[data-status="want"].is-on    { background: #f3e8ff; color: #6b21a8; }
.chip.clear { margin-left: auto; color: var(--muted); }

.note {
  width: 100%; margin-top: 9px; min-height: 74px; resize: vertical;
  font: inherit; padding: 8px 10px; border: 1px solid var(--line);
  border-radius: 8px; background: #fff; color: var(--ink);
}
.note:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.note-state { font-size: 12px; color: var(--muted); min-height: 16px; margin-top: 3px; }

.sub-list { display: flex; flex-direction: column; gap: 1px; margin-top: 9px; }
.sub-row { display: flex; align-items: center; gap: 2px; }
.sub-check {
  width: 16px; height: 16px; flex: none; margin: 0 4px 0 2px;
  accent-color: var(--accent); cursor: pointer;
}
.sub-check-spacer {
  width: 16px; flex: none; margin: 0 4px 0 2px;
  text-align: center; color: #047857; font-size: 13px;
}
.sub-item {
  display: flex; align-items: baseline; gap: 8px; padding: 5px 8px;
  border-radius: 6px; cursor: pointer; font-size: 14px; border: 0;
  background: none; text-align: left; flex: 1; min-width: 0;
}
.sub-item:hover { background: var(--bg); }
.sub-item .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; border: 1px solid var(--border); }
.sub-item .sub-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sub-item .sub-name.is-capital { font-weight: 600; }
.sub-item .zh { color: var(--muted); font-size: 12px; margin-left: auto; flex: none; }

/* ---------- публикация и режим чтения ---------- */

.share { padding: 0 16px 16px; }
.share .section { border-color: var(--line); }

.toggle { display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }
.toggle input { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }

.hint.small { font-size: 12px; margin: 7px 0 0; }

.share-name {
  width: 100%; margin-top: 10px; font: inherit; padding: 7px 10px;
  border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink);
}
.share-name:focus, .share-link:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }

.link-row { display: flex; gap: 6px; margin-top: 8px; }
.share-link {
  flex: 1; min-width: 0; font: inherit; font-size: 12px; padding: 7px 9px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--muted);
}
.link-actions { display: flex; align-items: center; gap: 10px; margin-top: 8px; }

.ro-badge {
  background: #fef3c7; color: #92400e; border-radius: 999px;
  padding: 3px 10px; font-size: 12px; font-weight: 600;
}
#who-shared #owner-name { color: var(--ink); font-weight: 500; }
.who a.ghost { text-decoration: none; }

.chip.is-static { cursor: default; display: inline-block; }
.note-text { margin: 9px 0 0; font-size: 14px; white-space: pre-wrap; }

a.primary { text-decoration: none; text-align: center; display: block; }

@media (max-width: 860px) {
  .main { flex-direction: column; }
  .side { width: auto; height: 46%; border-left: 0; border-top: 1px solid var(--line); }
  .search { max-width: none; }
}
