/* ---- Map Blueprint — layout & toolbar ---- */
/* Theme is driven by config.json (--accent / --accent-dim are overridden at
   runtime by the inline script in index.html). Values here are the defaults. */
:root {
  --bg: #0a0a0a;
  --panel: #141414;
  --panel-2: #1c1c1c;
  --line: #2c2c2c;
  --text: #d8d8d8;
  --muted: #8a8a8a;
  --accent: #3f8f4f;
  --accent-dim: #1c3a24;
  --canvas-bg: #0d0d0d;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }

/* themed scrollbars (match the dark UI instead of the default OS bar) */
* { scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--line);
  border-radius: 8px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover { background: var(--accent-dim); background-clip: padding-box; }
::-webkit-scrollbar-corner { background: transparent; }
body {
  display: flex;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  user-select: none;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

/* ---- Toolbar ---- */
#toolbar {
  width: 240px;
  flex: 0 0 240px;
  height: 100vh;
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 12px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 2px 0 8px;
  border-bottom: 1px solid var(--line);
}
.brand-logo {
  width: 100%;
  max-width: 200px;
  height: auto;
  filter: drop-shadow(0 2px 6px rgba(160, 16, 21, 0.35));
}
.brand-sub {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--accent);
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.8);
}
.maps-link {
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
  text-decoration: none;
}
.maps-link:hover { color: var(--text); }
.lang-switch {
  margin-top: 8px;
  -webkit-appearance: none; -moz-appearance: none; appearance: none;
  background-color: var(--panel-2); color: var(--muted);
  border: 1px solid var(--line); border-radius: 8px;
  font-size: 12px; font-family: inherit; line-height: 1.2;
  padding: 5px 24px 5px 9px; cursor: pointer;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2 4l4 4 4-4' stroke='%239aa6a0' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 8px center;
}
.lang-switch:hover { color: var(--text); border-color: var(--accent); }
.lang-switch option { background: var(--panel); color: var(--text); }
.panel h2 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--muted);
  margin: 0 0 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* ---- Tool buttons ---- */
.tool-row { display: flex; flex-wrap: wrap; gap: 6px; }
.brush-row { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.brush-row input[type="range"] { flex: 1 1 auto; min-width: 0; accent-color: var(--accent); }
.brush-cap { font-size: 11px; color: var(--muted); }
.brush-val { font-size: 12px; color: var(--text); width: 18px; text-align: right; }
.measure-modes { display: flex; gap: 4px; flex: 1 1 auto; min-width: 0; }
.measure-mode-btn {
  flex: 1 1 0;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: 6px;
  padding: 5px 4px;
  font-size: 11px;
  cursor: pointer;
}
.measure-mode-btn:hover { border-color: var(--accent-dim); }
.measure-mode-btn.active { border-color: var(--accent); background: var(--accent-dim); color: var(--text); }
/* MORTUMUS-ONLY: walk-time (do not ship) — START */
#measureWalkRow #measureWalkBtn { white-space: nowrap; padding: 5px 8px; }
#measureWalkRow #measureWalkSpeed {
  flex: 0 0 52px; width: 52px; min-width: 0;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 6px; padding: 5px 6px; font-size: 11px;
}
#measureWalkRow #measureWalkSpeed:disabled { opacity: 0.45; }
/* MORTUMUS-ONLY: walk-time (do not ship) — END */
/* MORTUMUS-ONLY: zone category dropdown (Unity import bridge — do not ship) — START */
.zone-cat {
  flex: 1 1 100%;          /* full-width second row so the zone name keeps its space */
  margin: 2px 0 0 30px;    /* indent under the name (past the swatch) */
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 6px;
  font-size: 11px; padding: 4px 6px;
  cursor: pointer;
}
.zone-cat:hover { border-color: var(--accent-dim); }
/* MORTUMUS-ONLY: zone category dropdown — END */
.tool-btn {
  flex: 1 1 64px;
  min-width: 64px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 4px;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  transition: border-color .12s, background .12s;
}
.tool-btn span { font-size: 11px; color: var(--muted); }
.tool-btn:hover { border-color: var(--accent-dim); }
.tool-btn.active {
  border-color: var(--accent);
  background: var(--accent-dim);
}
.tool-btn.active span { color: var(--text); }

.mini-btn {
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 6px;
  min-width: 30px;
  height: 30px;
  font-size: 16px;
  cursor: pointer;
}
.mini-btn:hover { border-color: var(--accent); }

.wide-btn {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 8px;
  padding: 9px;
  font-size: 13px;
  cursor: pointer;
  margin-bottom: 6px;
  text-align: left;
}
.wide-btn:hover { border-color: var(--accent); }
.wide-btn.danger-btn { border-color: #7a2e2e; color: #e08a8a; }
.wide-btn.danger-btn:hover { border-color: #c0392b; background: #3a1f1f; }

/* ---- Zone list ---- */
.zone-list { display: flex; flex-direction: column; gap: 4px; }
.zone-item {
  display: flex;
  align-items: center;
  flex-wrap: wrap;        /* lets the category dropdown wrap to its own row */
  gap: 6px 8px;
  padding: 9px 8px;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
}
.zone-item:hover { background: var(--panel-2); }
.zone-item.selected { border-color: var(--accent); background: var(--accent-dim); }
.zone-swatch {
  width: 22px; height: 22px;
  border-radius: 5px;
  flex: 0 0 22px;
  padding: 0;
  border: 1px solid rgba(255,255,255,.25);
  background: none;
  cursor: pointer;
}
/* big click target: selecting is a plain span, not an editable field */
.zone-name {
  flex: 1;
  color: var(--text);
  font-size: 14px;
  padding: 4px 2px;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}
.zone-edit, .zone-del {
  opacity: 0;
  background: none; border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
  padding: 2px 4px;
}
.zone-edit:hover, .zone-del:hover { color: var(--text); }
.zone-item:hover .zone-edit,
.zone-item:hover .zone-del { opacity: 1; }

/* ---- Marker palette ---- */
.marker-list { display: flex; flex-direction: column; gap: 4px; }
.marker-grid { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.marker-group-label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--muted);
  margin: 4px 0 2px;
  cursor: pointer;
  user-select: none;
  padding: 2px 0;
}
.marker-group-label:hover { color: var(--text); }
.marker-caret { font-size: 9px; width: 9px; display: inline-block; }
.marker-btn {
  width: 36px; height: 36px;
  font-size: 20px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.marker-btn:hover { border-color: var(--accent-dim); }
.marker-btn.selected { border-color: var(--accent); background: var(--accent-dim); }

.check { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); margin-top: 8px; }
.hint { font-size: 11px; color: var(--muted); margin-top: 6px; }
kbd {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 10px;
}

/* ---- Presence ---- */
.presence-list { display: flex; flex-direction: column; gap: 4px; }
.presence-item { display: flex; align-items: center; gap: 7px; font-size: 13px; }
.presence-dot { width: 10px; height: 10px; border-radius: 50%; flex: 0 0 10px; }

.status {
  margin-top: auto;
  font-size: 11px;
  color: var(--muted);
  padding-top: 8px;
  border-top: 1px solid var(--line);
}
.status.ok { color: #6ee7a0; }
.status.err { color: #ff8585; }

/* ---- Stage / canvas ---- */
#stage { position: relative; flex: 1 1 auto; height: 100vh; }
#map { display: block; width: 100%; height: 100%; cursor: crosshair; background: var(--canvas-bg); touch-action: none; }
#minimap {
  position: absolute;
  top: 12px; right: 12px;
  width: 270px; height: 196px;
  min-width: 150px; max-width: 700px;
  background: rgba(0,0,0,.55);
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0,0,0,.5);
  touch-action: none;
}
#minimap.hidden { display: none; }
.coords {
  position: absolute;
  bottom: 10px; right: 12px;
  background: rgba(0,0,0,.55);
  color: var(--muted);
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 6px;
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}

/* ---- Server resource indicator (bottom-right, above the coords readout) ---- */
.server-stats {
  position: absolute;
  bottom: 34px; right: 12px;
  display: flex;
  flex-direction: column;
  gap: 1px;
  background: rgba(0,0,0,.55);
  font-size: 11px;
  line-height: 1.4;
  padding: 4px 8px;
  border-radius: 6px;
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}
.server-stats[hidden] { display: none; }
.server-stats .ss-row { white-space: nowrap; }
.server-stats .ss-lbl { display: inline-block; min-width: 30px; color: var(--muted); opacity: .75; }
.server-stats .ss-val { color: var(--text); }
/* On phones/tablets the bottom-right corner holds the pan/draw FAB — hide to avoid overlap. */
@media (max-width: 900px) { .server-stats { display: none; } }

/* ---- Mobile drawer toggle (hidden on desktop) ---- */
.menu-fab {
  display: none;
  position: fixed;
  top: calc(10px + env(safe-area-inset-top, 0px));
  left: calc(10px + env(safe-area-inset-left, 0px));
  z-index: 50;
  width: 46px; height: 46px;
  align-items: center; justify-content: center;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 10px;
  font-size: 22px;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0,0,0,.5);
}
.toolbar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(0,0,0,.5);
}

/* ---- Floating Undo (touch only; bottom-left, clear of minimap + coords) ---- */
.undo-fab {
  display: none;
  position: fixed;
  bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  left: calc(12px + env(safe-area-inset-left, 0px));
  z-index: 50;
  width: 52px; height: 52px;
  align-items: center; justify-content: center;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 50%;
  font-size: 26px;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0,0,0,.55);
}
.undo-fab:active { background: var(--accent-dim); border-color: var(--accent); }

/* ---- Pan/Draw mode toggle (touch only; bottom-right) ---- */
.mode-fab {
  display: none;
  position: fixed;
  bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  right: calc(12px + env(safe-area-inset-right, 0px));
  z-index: 50;
  width: 56px; height: 56px;
  align-items: center; justify-content: center;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 50%;
  font-size: 26px;
  cursor: pointer;
  box-shadow: 0 2px 12px rgba(0,0,0,.6);
}
/* highlighted when in pan mode (one finger scrolls) */
.mode-fab.active { background: var(--accent-dim); border-color: var(--accent); }

/* ---- Phones + portrait tablets: sidebar becomes a slide-in drawer ---- */
@media (max-width: 900px) {
  .menu-fab { display: flex; }
  .undo-fab { display: flex; }
  .mode-fab { display: flex; }
  #toolbar {
    position: fixed;
    top: 0; left: 0;
    width: min(86vw, 300px);
    flex: none;
    z-index: 40;
    transform: translateX(-100%);
    transition: transform .22s ease;
    padding-top: calc(12px + env(safe-area-inset-top, 0px));
    box-shadow: 2px 0 18px rgba(0,0,0,.55);
  }
  body.nav-open #toolbar { transform: translateX(0); }
  body.nav-open .toolbar-backdrop { display: block; }
  /* #stage is flex:1 and the fixed sidebar leaves the flow, so the canvas goes full-bleed */
}

/* ---- Small phones: shrink minimap, respect safe areas ---- */
@media (max-width: 640px) {
  #minimap {
    width: 120px; height: 88px;
    top: calc(10px + env(safe-area-inset-top, 0px));
    right: calc(10px + env(safe-area-inset-right, 0px));
  }
  /* corners hold the FABs (undo bottom-left, pan/draw bottom-right) → center the coords */
  .coords {
    bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    right: auto;
    left: 50%;
    transform: translateX(-50%);
  }
}

/* ---- Touch / coarse-pointer: reveal hover-only buttons & enlarge tap targets ---- */
@media (hover: none), (pointer: coarse) {
  /* rename/delete buttons on zone AND layer rows are hover-revealed on desktop — always show on touch */
  .zone-edit, .zone-del { opacity: 1; font-size: 18px; padding: 6px 8px; }
  .marker-btn { width: 44px; height: 44px; font-size: 22px; }
  .mini-btn { min-width: 44px; height: 44px; font-size: 20px; }
  .zone-swatch { width: 28px; height: 28px; flex-basis: 28px; }
  .zone-item { padding: 12px 8px; }
  .tool-btn { min-height: 56px; }
  .check input[type="checkbox"] { width: 20px; height: 20px; }
}
