:root {
  --bg: #10131a;
  --panel: #181d26;
  --panel2: #202733;
  --line: #2c3544;
  --text: #e8ecf2;
  --sub: #93a0b4;
  --accent: #f0a43a;
  --accent-ink: #1a1203;
  --bad: #ff5d5d;
  --ok: #52d08a;
  --radius: 10px;
  --top: 52px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 14px/1.4 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }

.btn { background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 7px 12px; }
.btn:hover { border-color: #46526a; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.danger { color: var(--bad); border-color: #5a2f33; }
.btn.small { padding: 4px 9px; font-size: 13px; }
.btn[disabled] { opacity: .5; cursor: default; }
.btn.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
input[type=text], input[type=password], input[type=number], select, textarea {
  background: #0f131a; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #f0a43a66; border-color: var(--accent); }
textarea { resize: vertical; min-height: 70px; }
label.f { display: block; margin-bottom: 10px; }
label.f > span { display: block; color: var(--sub); font-size: 12px; margin-bottom: 3px; }
.row { display: flex; gap: 8px; align-items: center; }
.row > * { flex: 1; }
.err { color: var(--bad); min-height: 18px; margin: 6px 0; }
.muted { color: var(--sub); }

#app { display: flex; flex-direction: column; height: 100%; overflow: hidden; }
#top { height: var(--top); background: var(--panel); border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 12px; padding: 0 12px; position: relative; z-index: 1200; }
.brand { font-weight: 700; letter-spacing: .3px; white-space: nowrap; }
.brand b { color: var(--accent); }
#mapTabs { display: flex; background: #0f131a; border: 1px solid var(--line); border-radius: 9px; padding: 2px; }
#mapTabs button { background: none; border: 0; padding: 6px 12px; border-radius: 7px; color: var(--sub); }
#mapTabs button.on { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
#searchBox { position: relative; width: 300px; max-width: 34vw; }
#searchRes { position: absolute; top: 40px; left: 0; right: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 9px; overflow: hidden; display: none; box-shadow: 0 10px 30px #0008; }
#searchRes div { padding: 8px 10px; cursor: pointer; display: flex; gap: 8px; align-items: baseline; }
#searchRes div:hover, #searchRes div.sel { background: var(--panel2); }
#searchRes small { color: var(--sub); }
.spacer { flex: 1; }
#userMenu { position: relative; }
#userBtn { background: var(--panel2); border: 1px solid var(--line); border-radius: 9px; padding: 6px 10px; display: flex; gap: 8px; align-items: center; }
.role { font-size: 11px; padding: 1px 7px; border-radius: 99px; background: #2b3a52; color: #b9d3ff; }
.role.admin { background: #4a2d1a; color: #ffc48a; }
.role.moderator { background: #1f4130; color: #9be8bd; }
#userDrop { position: absolute; right: 0; top: 44px; min-width: 210px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 6px; display: none; box-shadow: 0 10px 30px #0008; }
#userDrop button, #userDrop a { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 8px 10px; border-radius: 7px; color: var(--text); text-decoration: none; }
#userDrop button:hover, #userDrop a:hover { background: var(--panel2); }
#btnPanel { display: none; }

#main { flex: 1; position: relative; min-height: 0; display: flex; overflow: hidden; }
#mapWrap { flex: 1; position: relative; min-width: 0; }
#map { position: absolute; inset: 0; background: #0b0e13; outline: 0; }
#side { width: 300px; background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto; padding: 12px; flex: none; }
#side h3 { margin: 14px 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .8px; color: var(--sub); }
#side h3:first-child { margin-top: 0; }
.chk { display: flex; align-items: center; gap: 8px; padding: 4px 2px; cursor: pointer; user-select: none; }
.chk input { width: 16px; height: 16px; accent-color: var(--accent); }
.dot { width: 11px; height: 11px; border-radius: 50%; flex: none; border: 1px solid #0006; }
.chk .cnt { margin-left: auto; color: var(--sub); font-size: 12px; }
.tools { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.mlist { margin-top: 6px; }
.mlist .it { display: flex; gap: 8px; align-items: center; padding: 6px 4px; border-radius: 7px; cursor: pointer; }
.mlist .it:hover { background: var(--panel2); }
.mlist .it span.t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mlist .it .lock { margin-left: auto; font-size: 11px; color: var(--sub); }
.rolebox { margin-top: 14px; padding: 10px; background: var(--panel2); border-radius: 9px; font-size: 12.5px; color: var(--sub); }
.rolebox b { color: var(--text); }
.links { display: flex; gap: 8px; margin-bottom: 4px; }

#coords { position: absolute; left: 10px; bottom: 10px; z-index: 900; background: #10151dd9; border: 1px solid var(--line); border-radius: 8px; padding: 5px 10px; font-variant-numeric: tabular-nums; cursor: pointer; backdrop-filter: blur(4px); }
#toolHint { position: absolute; left: 50%; transform: translateX(-50%); top: 12px; z-index: 950; background: #10151df2; border: 1px solid var(--accent); border-radius: 10px; padding: 8px 12px; display: none; gap: 10px; align-items: center; max-width: 92%; }
#gridX, #gridY { position: absolute; z-index: 800; pointer-events: none; font-size: 11px; color: #fff; text-shadow: 0 0 3px #000, 0 0 3px #000; font-variant-numeric: tabular-nums; }
#gridX { left: 0; right: 0; top: 0; height: 16px; }
#gridY { left: 0; top: 0; bottom: 0; width: 30px; }
#gridX i, #gridY i { position: absolute; font-style: normal; background: #0008; padding: 0 3px; border-radius: 3px; }
#gridX i { transform: translateX(-50%); top: 1px; }
#gridY i { transform: translateY(-50%); left: 1px; }
.tool-on { cursor: crosshair !important; }
.tool-on .leaflet-interactive { cursor: crosshair !important; }

#ctxMenu { position: absolute; z-index: 1100; background: var(--panel); border: 1px solid var(--line); border-radius: 9px; padding: 4px; display: none; min-width: 190px; box-shadow: 0 8px 24px #000a; }
#ctxMenu button { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 7px 10px; border-radius: 6px; }
#ctxMenu button:hover { background: var(--panel2); }
#ctxMenu .hd { padding: 5px 10px; color: var(--sub); font-size: 12px; }

dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 14px; padding: 18px; width: min(460px, 94vw); box-shadow: 0 20px 60px #000b; }
dialog::backdrop { background: #000a; }
dialog h2 { margin: 0 0 12px; font-size: 17px; }
.swatches { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.sw { width: 24px; height: 24px; border-radius: 50%; border: 2px solid transparent; padding: 0; }
.sw.on { border-color: #fff; }
.swatches input[type=color] { width: 30px; height: 26px; padding: 0; border: 0; background: none; }
.dlgbtn { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; }
.dlgbtn .left { margin-right: auto; }

.leaflet-container { font: inherit; background: #0b0e13; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--panel); color: var(--text); }
.leaflet-popup-content { margin: 12px 14px; min-width: 200px; max-width: 280px; }
.leaflet-container a.leaflet-popup-close-button { color: var(--sub); }
.leaflet-bar a { background: var(--panel); color: var(--text); border-bottom-color: var(--line); }
.leaflet-bar a:hover { background: var(--panel2); }
.pp h4 { margin: 0 0 4px; font-size: 15px; }
.pp .chip { display: inline-block; font-size: 11px; padding: 1px 8px; border-radius: 99px; background: var(--panel2); margin-bottom: 6px; }
.pp .descr { white-space: pre-wrap; word-break: break-word; max-height: 160px; overflow: auto; margin: 4px 0 8px; }
.pp .meta { font-size: 11.5px; color: var(--sub); margin-bottom: 8px; }
.pp .acts { display: flex; gap: 6px; flex-wrap: wrap; }

.mk { background: none; border: 0; }
.mk .pin { width: 30px; height: 30px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg); display: flex; align-items: center; justify-content: center; border: 2px solid #fff; box-shadow: 0 2px 6px #0009; }
.mk .pin span { transform: rotate(45deg); font-size: 15px; line-height: 1; }
.mk.mods .pin { border-style: dashed; opacity: .85; }
.mk .lbl { position: absolute; left: 50%; top: 33px; transform: translateX(-50%); white-space: nowrap; font-size: 12px; font-weight: 600; text-shadow: 0 0 3px #000, 0 0 3px #000, 0 0 5px #000; display: none; pointer-events: none; }
.z-hi .mk .lbl { display: block; }


.ruler-dot { background: var(--accent); border: 2px solid #fff; border-radius: 50%; }

@media (max-width: 820px) {
  #btnPanel { display: block; }
  #side { position: absolute; right: 0; top: 0; bottom: 0; z-index: 1000; transform: translateX(100%); transition: transform .2s; width: min(300px, 86vw); box-shadow: -10px 0 30px #0008; }
  #side.open { transform: none; }
  #top { height: auto; flex-wrap: wrap; padding: 6px 10px; gap: 6px 8px; }
  #searchBox { order: 5; flex: 1 1 100%; width: auto; max-width: none; }
  .spacer { flex: 1; }
  .brand { display: none; }
  #userBtn .nm { display: none; }
  #boardTitle { max-width: 40vw; }
  #bMap { display: none; }
}

.chip { display: inline-block; font-size: 11.5px; padding: 1px 9px; border-radius: 99px; background: var(--panel2); color: var(--sub); border: 1px solid var(--line); }
#boardTitle { display: flex; align-items: center; gap: 8px; min-width: 0; max-width: 28vw; }
#boardTitle b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hintline { font-size: 12px; color: var(--sub); margin: 4px 0 6px; }
#overlayMsg { position: absolute; inset: 0; z-index: 1500; display: none; align-items: center; justify-content: center; background: #0b0e13ee; text-align: center; padding: 24px; }
#overlayMsg div { max-width: 360px; }

.place { background: none; border: 0; white-space: nowrap; pointer-events: none; color: #fff; text-shadow: 0 0 3px #000, 0 0 3px #000, 0 0 6px #000; }
.place span { position: absolute; transform: translate(-50%, -50%); }
.place-capital span { font-size: 18px; font-weight: 800; letter-spacing: .6px; }
.place-city span { font-size: 16px; font-weight: 700; letter-spacing: .4px; }
.place-village span { font-size: 12.5px; font-weight: 600; }
.place-local span { font-size: 11px; font-weight: 500; color: #ffe9b8; }
.place-marine span { font-size: 11.5px; font-style: italic; color: #a6dcff; }
.place-hill span { font-size: 11px; color: #d9c7a0; }
.place-hill span::before { content: "▲ "; font-size: 9px; }
.place-camp span::before { content: "⛺ "; }
.place-ruin span::before { content: "▪ "; }
.place-other span { font-size: 11px; }

.ulabel { background: none; border: 0; white-space: nowrap; font-weight: 700; text-shadow: 0 0 3px #000, 0 0 3px #000, 0 0 6px #000; cursor: pointer; }
.ulabel span { position: absolute; transform: translate(-50%, -50%); }

.blist .brow { display: flex; gap: 8px; align-items: center; padding: 10px; border: 1px solid var(--line); border-radius: 10px; margin-bottom: 8px; background: var(--panel2); }
.blist .brow .info { flex: 1; min-width: 0; }
.blist .brow .info b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.blist .brow .info small { color: var(--sub); }
.blist .brow .act { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.newbox { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-bottom: 12px; }
.newbox select { grid-column: 1; }
.linkbox { display: flex; gap: 6px; margin: 8px 0; }
.linkbox input { flex: 1; font-size: 12.5px; }
dialog.wide { width: min(620px, 96vw); }
table.t { width: 100%; border-collapse: collapse; font-size: 13px; }
table.t td, table.t th { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.t th { color: var(--sub); font-weight: 500; }
.scroll { max-height: 55vh; overflow: auto; }
