:root {
  --bg: #0c0e12; --panel: #161a22; --panel-2: #1d2230; --line: #2a3142;
  --text: #e6e8ee; --muted: #8a93a8; --accent: #d4a85a; --primary: #3b82f6;
  --danger: #e5534b; --ok: #2bb673;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: #8ab4ff; }
button, input, select { font: inherit; color: inherit; }
button {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 6px 10px; cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
a.btn {
  display: inline-block; background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px;
  padding: 6px 10px; color: var(--text); text-decoration: none; white-space: nowrap;
}
a.btn:hover { border-color: var(--accent); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
button.link { background: none; border: 0; padding: 0; color: #8ab4ff; }
button.danger, .danger { color: var(--danger); }
input, select { background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; }
.muted { color: var(--muted); }
.error { color: var(--danger); }
.warn { color: #f0b429; }
form.inline { display: inline; }

.topbar {
  display: flex; align-items: center; gap: 14px; padding: 8px 16px; height: 50px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; color: var(--accent); text-decoration: none; white-space: nowrap; }
.topbar-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-nav { display: flex; align-items: center; gap: 10px; }
.who { color: var(--muted); }
.lang-picker { padding: 3px 6px; font-size: 13px; }
.badge { padding: 3px 8px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); }

.messages { padding: 8px 16px 0; }
.msg { padding: 8px 12px; border-radius: 6px; margin-bottom: 6px; background: var(--panel-2); }
.msg-error { border-left: 3px solid var(--danger); }
.msg-success { border-left: 3px solid var(--ok); }

.page { max-width: 1000px; margin: 20px auto; padding: 0 16px; }
.page.narrow { max-width: 380px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px; margin-bottom: 16px; }
.card h2 { margin-top: 0; font-size: 16px; }
.card label { display: block; margin-bottom: 10px; }
.card label input, .card label select { display: block; width: 100%; margin-top: 4px; }
.row-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; }
.row-form label { flex: 1 1 200px; margin: 0; }
.row-form label.check { flex: 0 0 auto; display: flex; align-items: center; gap: 6px; }
.row-form label.check input { width: auto; display: inline; margin: 0; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); }
.table th { color: var(--muted); font-weight: 500; }

/* editor */
body.editor { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }
body.editor .messages { position: absolute; top: 56px; right: 16px; z-index: 1000; }
.editor-layout { flex: 1; display: flex; min-height: 0; position: relative; }
.sidebar {
  width: 320px; flex: 0 0 320px; display: flex; flex-direction: column; gap: 8px; padding: 10px;
  background: var(--panel); border-right: 1px solid var(--line);
  /* Scroll as a whole when the panels don't fit (e.g. a selection panel
     opened) instead of pushing the bottom ones off screen. */
  overflow-y: auto; overscroll-behavior: contain;
}
.panel { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px; flex-shrink: 0; }
/* The member list takes the spare height but never shrinks below ~220px;
   it scrolls on its own. */
.panel.grow { flex: 1 0 220px; min-height: 220px; display: flex; flex-direction: column; overflow: hidden; }
details.panel > summary {
  cursor: pointer; list-style: none; margin: 0; font-size: 13px; text-transform: uppercase;
  letter-spacing: .04em; color: var(--muted); font-weight: 700; display: flex; justify-content: space-between;
}
details.panel > summary::-webkit-details-marker { display: none; }
details.panel > summary::after { content: "▾"; }
details.panel:not([open]) > summary::after { content: "▸"; }
details.panel[open] > summary { margin-bottom: 8px; }
.panel h3 { margin: 0 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.panel h3 .rk { color: var(--accent); text-transform: none; }
#search { width: 100%; }
.toggles { display: flex; flex-direction: column; gap: 2px; margin-top: 8px; color: var(--muted); font-size: 13px; }
.stats { margin-top: 8px; font-size: 13px; }
.hint { color: var(--muted); font-size: 12px; margin: 8px 0 0; }
.tool-row { display: flex; gap: 6px; }
.tool { flex: 1; display: flex; align-items: center; gap: 4px; justify-content: center; padding: 6px 4px; font-size: 13px; }
.tool img { width: 22px; height: 22px; object-fit: contain; }
.tool.active { border-color: var(--accent); background: #2a2415; }
.panel h3.sub { margin-top: 10px; }
.tool-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
.tool-grid .tool { justify-content: flex-start; font-size: 12px; padding: 4px 6px; }
.tool-grid .tool img { width: 20px; height: 20px; }
.mode-banner {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%); z-index: 1000;
  background: #2a2415; border: 1px solid var(--accent); border-radius: 8px; padding: 6px 8px 6px 12px;
  display: flex; align-items: center; gap: 10px; box-shadow: 0 6px 20px rgba(0, 0, 0, .4);
}
.mode-banner[hidden] { display: none; }
.kv { font-size: 13px; color: var(--muted); }
.kv b { color: var(--text); }
.btn-row { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.field { display: block; font-size: 13px; color: var(--muted); margin-top: 8px; }
.field input { width: 100%; margin-top: 4px; }

.member-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.member-list li.member {
  display: grid; grid-template-columns: 20px 1fr auto; grid-template-rows: auto auto; column-gap: 6px;
  padding: 5px 6px; border-radius: 6px; cursor: pointer;
}
.member-list li.member:hover { background: #262c3b; }
.member-list li.member.selected { background: #2f3850; outline: 1px solid var(--accent); }
.member-list .st { grid-row: 1 / 3; align-self: center; }
.member-list .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.member-list .rk { color: var(--accent); font-size: 12px; }
.member-list .wh { grid-column: 2 / 4; color: var(--muted); font-size: 12px; }
.warnings { list-style: none; margin: 0; padding: 0; max-height: 140px; overflow-y: auto; font-size: 13px; }
.warnings li { padding: 3px 0; cursor: pointer; }

#map { flex: 1; background: #07080b url("../images/background.8ee0e7130543.png") center / cover; }
#map.placing { cursor: crosshair; }
.leaflet-container { background: transparent; }
.hive-tip { background: #11151d; color: var(--text); border: 1px solid var(--line); box-shadow: none; }
.hive-tip::before { display: none; }
.mine-tip { display: flex; gap: 8px; align-items: center; }
.mine-tip img { width: 34px; height: 34px; object-fit: contain; }

.ctx-menu {
  position: absolute; z-index: 1000; min-width: 170px; padding: 4px;
  background: #11151d; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 6px 20px rgba(0, 0, 0, .45);
  display: flex; flex-direction: column; gap: 2px;
}
.ctx-menu[hidden] { display: none; }
.ctx-menu .ctx-title { padding: 4px 8px 6px; font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--line); margin-bottom: 2px; }
.ctx-menu button { background: none; border: 0; border-radius: 5px; text-align: left; padding: 6px 8px; }
.ctx-menu button:hover:not(:disabled) { background: #262c3b; }

.confirm-pop {
  position: fixed; z-index: 2000; width: 300px; padding: 12px;
  background: #11151d; border: 1px solid var(--accent); border-radius: 8px; box-shadow: 0 8px 24px rgba(0, 0, 0, .5);
}
.confirm-pop .confirm-text { font-size: 13px; line-height: 1.5; }
.confirm-pop .btn-row { justify-content: flex-end; margin-top: 10px; }

.toast {
  position: absolute; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 1000; max-width: 90%;
  background: #11151d; border: 1px solid var(--line); border-left: 3px solid var(--ok); border-radius: 8px;
  padding: 10px 14px; box-shadow: 0 6px 20px rgba(0, 0, 0, .4);
}
.toast.error { border-left-color: var(--danger); }
.toast-action { margin-left: 12px; padding: 3px 10px; border-color: var(--accent); color: var(--accent); background: none; }

@media (max-width: 800px) {
  .editor-layout { flex-direction: column-reverse; }
  .sidebar { width: auto; flex: 0 0 42%; border-right: 0; border-top: 1px solid var(--line); overflow-y: auto; }
  .panel.grow { min-height: 200px; }
  .topbar { height: auto; flex-wrap: wrap; }
}
