* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --ink: #ece7d6;
  --muted: #9c9681;
  --panel: rgba(26, 27, 24, 0.94);
  --line: rgba(232, 223, 192, 0.14);
  --accent: #a8c67a;
  --font: 'Segoe UI', system-ui, -apple-system, Tahoma, sans-serif;
  --font-mono: Consolas, 'SF Mono', 'Cascadia Mono', monospace;
}

html, body {
  width: 100%; height: 100%; overflow: hidden;
  background: #c8c5b0; font-family: var(--font);
}

#map {
  position: absolute; inset: 0; width: 100%; height: 100%;
  cursor: grab; touch-action: none;
}
#map.dragging { cursor: grabbing; }

/* ---- sidebar ---- */
#hud { position: absolute; top: 0; left: 0; bottom: 0; z-index: 10; pointer-events: none; }

#panel {
  pointer-events: auto; width: 240px; height: 100vh; overflow: hidden auto;
  background: var(--panel); border: none; border-right: 1px solid var(--line); border-radius: 0;
  padding: 14px 12px; color: var(--ink);
  box-shadow: 4px 0 24px rgba(0,0,0,0.25);
  backdrop-filter: blur(12px); transition: width 160ms ease, padding 160ms ease;
  scrollbar-width: thin; scrollbar-color: #555548 transparent;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
#panel h1 { font-size: 14px; line-height: 1.15; letter-spacing: 2.4px; color: var(--ink); font-weight: 700; }
#panel .sub { font-size: 9px; letter-spacing: .3px; color: var(--muted); margin-top: 2px; }

.icon-button {
  flex: 0 0 auto; width: 24px; height: 24px; border: 1px solid var(--line); border-radius: 5px;
  background: rgba(255,255,255,.035); color: var(--muted); font: 16px/1 var(--font); cursor: pointer;
}
.icon-button:hover { color: var(--ink); background: rgba(255,255,255,.07); }
.panel-body { margin-top: 10px; }
#panel.collapsed { width: 44px; padding: 10px; overflow: hidden; }
#panel.collapsed .panel-head > div, #panel.collapsed .panel-body { display: none; }
#panel.collapsed .panel-head { justify-content: center; }
#panel.collapsed .icon-button { color: var(--ink); }

/* ---- mode tabs ---- */
.mode-tabs {
  display: flex; gap: 3px; margin-bottom: 8px; padding: 2px;
  background: rgba(255,255,255,.04); border-radius: 6px; border: 1px solid var(--line);
}
.mode-tab {
  flex: 1; padding: 6px 0; border: 0; border-radius: 4px; background: transparent;
  color: var(--muted); font: 600 10px var(--font); letter-spacing: .8px; text-transform: uppercase;
  cursor: pointer; transition: background 140ms ease, color 140ms ease;
}
.mode-tab:hover { color: var(--ink); background: rgba(255,255,255,.04); }
.mode-tab.active {
  background: rgba(168,198,122,.14); color: #c7dbaa;
  box-shadow: 0 1px 3px rgba(0,0,0,.15);
}

/* ---- search ---- */
.search-row { position: relative; }
.search-row input {
  width: 100%; height: 32px; background: #161713; border: 1px solid var(--line); border-radius: 5px;
  color: var(--ink); font: 11px var(--font); padding: 0 8px 0 30px; outline: none;
}
.search-row input::placeholder { color: #777569; }
.search-row input:focus { border-color: rgba(168,198,122,.65); box-shadow: 0 0 0 2px rgba(168,198,122,.1); }
.search-icon { position: absolute; z-index: 1; left: 10px; top: 10px; width: 10px; height: 10px; border: 1.5px solid #858275; border-radius: 50%; }
.search-icon::after { content: ''; position: absolute; width: 4px; height: 1.5px; background: #858275; right: -3px; bottom: -2px; transform: rotate(45deg); transform-origin: left; }

/* ---- mode status card ---- */
.mode-card {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  margin-top: 8px; padding: 7px 8px; border-radius: 5px;
  background: rgba(168,198,122,.07); border: 1px solid rgba(168,198,122,.16);
}
.mode-label { color: #c7dbaa; font-size: 8px; letter-spacing: 1.1px; font-weight: 700; text-transform: uppercase; }
.mode-detail { color: #888676; font-size: 8px; margin-top: 2px; }
.text-button { flex: 0 0 auto; border: 0; border-radius: 4px; padding: 5px 7px; background: #a8c67a; color: #20251a; font: 700 8px var(--font); letter-spacing: .3px; text-transform: uppercase; cursor: pointer; }
.text-button:hover { background: #bfdc91; }

/* ---- view options ---- */
.group { margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--line); }
.group-title { font-size: 8px; letter-spacing: 1.5px; color: var(--muted); margin-bottom: 3px; text-transform: uppercase; font-weight: 600; }
.opt { display: flex; align-items: center; font-size: 10px; padding: 2px 0; cursor: pointer; user-select: none; }
.switch-row { justify-content: space-between; min-height: 24px; color: #c9c5b5; }
.switch-row input { position: absolute; opacity: 0; pointer-events: none; }
.switch { position: relative; width: 26px; height: 14px; flex: 0 0 auto; border-radius: 10px; background: #4a4a40; transition: background 140ms ease; }
.switch::after { content: ''; position: absolute; left: 2px; top: 2px; width: 10px; height: 10px; border-radius: 50%; background: #a4a293; transition: transform 140ms ease, background 140ms ease; }
.switch-row input:checked + .switch { background: #6e8252; }
.switch-row input:checked + .switch::after { transform: translateX(12px); background: #dce9c9; }
.switch-row input:focus-visible + .switch { outline: 2px solid var(--accent); outline-offset: 2px; }

.hint { margin-top: 8px; font-size: 8px; color: #737166; white-space: nowrap; }
.hint span { color: #4f5047; padding: 0 2px; }

/* ---- legend (bottom-right) ---- */
#legend {
  position: absolute; bottom: 14px; right: 56px; z-index: 10;
  background: var(--panel); border: 1px solid var(--line); border-radius: 7px;
  box-shadow: 0 6px 20px rgba(0,0,0,.25); backdrop-filter: blur(10px);
  pointer-events: auto; min-width: 150px;
}
#legend-toggle {
  display: flex; width: 100%; justify-content: space-between; align-items: center;
  border: 0; background: none; cursor: pointer; text-align: left;
  padding: 7px 10px; color: var(--muted); font: 600 8px var(--font);
  letter-spacing: 1.5px; text-transform: uppercase;
}
#legend-toggle:hover { color: var(--ink); }
#legend-toggle .caret { font-size: 10px; transition: transform 140ms ease; }
#legend.collapsed #legend-toggle .caret { transform: rotate(180deg); }
#legend-body { padding: 0 10px 8px; }
#legend.collapsed #legend-body { display: none; }

.key { position: relative; color: #c9c5b5; min-height: 22px; font-size: 10px; }
.key input { position: absolute; opacity: 0; pointer-events: none; }
.check-dot { width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; flex: 0 0 auto; border: 1px solid rgba(255,255,255,.22); background: var(--key); box-shadow: inset 0 0 0 2px rgba(20,20,18,.28); }
.key input:not(:checked) + .check-dot { background: transparent; opacity: .45; }
.key input:focus-visible + .check-dot { outline: 2px solid var(--accent); outline-offset: 2px; }

.sw { display: inline-block; width: 8px; height: 8px; border-radius: 2px; border: 1px solid rgba(0,0,0,0.35); vertical-align: -1px; margin-right: 4px; }
.bkey { margin: 4px 0 0 18px; padding-left: 8px; border-left: 1px solid var(--line); font-size: 8px; color: #959283; line-height: 1.7; }

/* ---- zoom controls ---- */
#zoom-controls {
  position: absolute; right: 18px; top: 50%; z-index: 10; display: flex; flex-direction: column; align-items: center;
  transform: translateY(-50%); background: var(--panel); border: 1px solid var(--line); border-radius: 9px;
  padding: 5px; box-shadow: 0 8px 24px rgba(0,0,0,.25); backdrop-filter: blur(10px);
}
#zoom-controls button { width: 31px; height: 31px; border: 0; border-radius: 5px; background: transparent; color: #d5d0bf; font: 20px/1 var(--font); cursor: pointer; }
#zoom-controls button:hover { background: rgba(255,255,255,.07); color: #fff; }
.zoom-track-wrap { position: relative; width: 31px; height: 148px; display: grid; place-items: center; }
#zoom-range { width: 132px; height: 4px; transform: rotate(-90deg); appearance: none; background: #515047; border-radius: 3px; cursor: pointer; }
#zoom-range::-webkit-slider-thumb { appearance: none; width: 12px; height: 12px; border-radius: 50%; background: #d9e6c5; border: 2px solid #64794a; box-shadow: 0 0 0 2px rgba(0,0,0,.25); }
#zoom-range::-moz-range-thumb { width: 10px; height: 10px; border-radius: 50%; background: #d9e6c5; border: 2px solid #64794a; }
#tile-threshold { position: absolute; left: 4px; top: 61px; width: 5px; height: 5px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 2px var(--panel); }
#tile-threshold::after { content: ''; position: absolute; left: 6px; top: 2px; width: 5px; border-top: 1px solid #6f8253; }
#projection-button { border-top: 1px solid var(--line) !important; border-radius: 0 0 5px 5px !important; margin-top: 4px; }
.diamond { display: inline-block; width: 12px; height: 12px; border: 1.5px solid #a8a696; transform: rotate(45deg) skew(-12deg,-12deg); }
#projection-button.topdown .diamond { transform: rotate(45deg); background: rgba(168,198,122,.18); border-color: var(--accent); }

/* ---- status bar ---- */
#status { position: absolute; bottom: 14px; left: 16px; z-index: 10; background: var(--panel); border: 1px solid var(--line); border-radius: 7px; padding: 5px 8px; color: #c5c0ae; font: 10px var(--font-mono); display: flex; align-items: center; gap: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.2); }
.status-divider { width: 1px; height: 11px; background: var(--line); }
.render-state { display: inline-flex; align-items: center; gap: 5px; color: #918e80; }
.render-state i { width: 5px; height: 5px; border-radius: 50%; background: #858277; }
.render-state.tiles { color: #bcd797; }
.render-state.tiles i { background: #a8c67a; box-shadow: 0 0 7px rgba(168,198,122,.7); }
.render-state.loading i { animation: pulse 900ms ease-in-out infinite alternate; }
#loading { color: #a8c67a; }
@keyframes pulse { to { opacity: .25; } }

#tooltip { position: absolute; z-index: 20; pointer-events: none; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; color: var(--ink); font-size: 10px; max-width: 220px; box-shadow: 0 5px 16px rgba(0,0,0,.25); }
#tooltip .tt-sub { color: var(--muted); font-size: 9px; margin-top: 1px; }

@media (max-width: 640px) {
  #hud { top: 0; left: 0; }
  #panel { width: min(220px, calc(100vw - 50px)); height: 100vh; padding: 10px; }
  .bkey { display: none; }
  #zoom-controls { right: 10px; }
  #status { left: 10px; bottom: 10px; max-width: calc(100vw - 20px); }
  #status .render-state { display: none; }
  .hint { display: none; }
  #legend { right: 10px; bottom: 10px; }
}

@media (max-height: 760px) {
  .bkey { display: none; }
}
