:root {
  --bg: #0e1116;
  --panel: #161b22;
  --panel-2: #1e2530;
  --border: #2a313c;
  --text: #e6edf3;
  --muted: #9aa7b4;
  --accent: #ff8c1a;
  --accent-2: #ffd11a;
  --good: #2ec27e;
  --warn: #f5a623;
  --bad: #e5484d;
  --blue: #2f81f7;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.screen { position: absolute; inset: 0; }
.hidden { display: none !important; }

/* ----------------------------- MAP SCREEN ----------------------------- */
.map-header {
  padding: 14px 22px;
  background: linear-gradient(90deg, #1a1f27, #11151b);
  border-bottom: 1px solid var(--border);
}
.map-header h1 { margin: 0; font-size: 20px; }
.map-header p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }

.map-layout {
  position: absolute;
  top: 70px; bottom: 0; left: 0; right: 0;
  display: grid;
  grid-template-columns: 1fr 360px;
}
#map { width: 100%; height: 100%; background: #0b0e12; }

.map-panel {
  background: var(--panel);
  border-left: 1px solid var(--border);
  padding: 18px;
  overflow-y: auto;
}
.map-panel h2 { font-size: 15px; margin: 0 0 12px; }

.field { display: block; margin-bottom: 14px; font-size: 13px; color: var(--muted); }
.field > span { display: block; margin-bottom: 5px; }
.field.inline { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.field.inline > span { margin: 0; flex: 1; }
.field.inline input, .field.inline select { width: 90px; }

input[type="text"], input[type="number"], select {
  background: var(--panel-2); border: 1px solid var(--border);
  color: var(--text); border-radius: 7px; padding: 8px 10px; font-size: 13px;
  width: 100%;
}
input[type="range"] { width: 100%; accent-color: var(--accent); }

.search-row { display: flex; gap: 6px; }
.search-row input { flex: 1; }

button {
  background: var(--panel-2); border: 1px solid var(--border);
  color: var(--text); border-radius: 7px; padding: 8px 12px;
  font-size: 13px; cursor: pointer; transition: .15s;
}
button:hover { border-color: var(--accent); }
button:disabled { opacity: .4; cursor: not-allowed; }
button.primary { background: var(--accent); color: #1a1205; border-color: var(--accent); font-weight: 600; }
button.primary:hover { filter: brightness(1.08); }
button.big { width: 100%; padding: 12px; font-size: 15px; margin-top: 8px; }
button.link { background: none; border: none; color: var(--blue); padding: 4px; }

.coord-box {
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 8px; padding: 12px; margin-bottom: 16px; font-size: 13px;
}
.coord-box > div { margin-bottom: 4px; }
.place-name { color: var(--accent-2); margin-top: 8px !important; font-style: italic; }

.streetview-box { margin-bottom: 16px; }
.streetview-box summary { cursor: pointer; color: var(--blue); font-size: 13px; padding: 6px 0; }
.streetview-box .hint { font-size: 11px; color: var(--muted); margin: 6px 0; }
.streetview-box input { margin-bottom: 8px; }
.streetview-box button { width: 100%; margin-bottom: 8px; }
#streetview { width: 100%; height: 220px; border-radius: 8px; overflow: hidden; }
#streetview:empty { display: none; }

.hint { font-size: 11px; color: var(--muted); line-height: 1.5; }

/* ----------------------------- SIM SCREEN ----------------------------- */
#viewport { position: absolute; inset: 0; }
#viewport canvas { display: block; }

#hud {
  position: absolute; top: 16px; left: 16px;
  background: rgba(18, 22, 28, .88);
  border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 14px; min-width: 210px; backdrop-filter: blur(6px);
  font-size: 13px;
}
.hud-title { font-weight: 700; margin-bottom: 8px; color: var(--accent); letter-spacing: .04em; text-transform: uppercase; font-size: 11px; }
.metric { display: flex; justify-content: space-between; padding: 3px 0; }
.metric span { color: var(--muted); }
.metric b { font-variant-numeric: tabular-nums; }
.los {
  margin-top: 10px; padding: 6px 8px; border-radius: 6px; text-align: center;
  font-weight: 700; font-size: 12px; background: var(--panel-2);
}
.los.a, .los.b { background: rgba(46,194,126,.2); color: var(--good); }
.los.c, .los.d { background: rgba(245,166,35,.2); color: var(--warn); }
.los.e, .los.f { background: rgba(229,72,77,.2); color: var(--bad); }

#control-panel {
  position: absolute; top: 0; right: 0; bottom: 0; width: 320px;
  background: var(--panel); border-left: 1px solid var(--border);
  padding: 14px; overflow-y: auto;
}
.panel-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.panel-head h2 { margin: 0; font-size: 16px; }

fieldset {
  border: 1px solid var(--border); border-radius: 8px;
  margin: 0 0 14px; padding: 12px;
}
legend { font-size: 12px; color: var(--accent); padding: 0 6px; font-weight: 600; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; margin-bottom: 8px; color: var(--text); cursor: pointer; }
.check input { width: auto; }

.taper-info { font-size: 11px; color: var(--accent-2); margin-top: 6px; line-height: 1.5; }

.actions { display: flex; gap: 8px; margin-bottom: 12px; }
.actions button { flex: 1; }

.view-buttons { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.view-buttons span { font-size: 12px; color: var(--muted); width: 100%; }
.view-buttons button { flex: 1; min-width: 60px; padding: 6px; font-size: 12px; }

#loading {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(14,17,22,.7); z-index: 50;
}
.spinner {
  width: 44px; height: 44px; border: 4px solid var(--border);
  border-top-color: var(--accent); border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 760px) {
  .map-layout { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .map-panel { border-left: none; border-top: 1px solid var(--border); max-height: 45vh; }
  #control-panel { width: 100%; height: 45vh; top: auto; bottom: 0; }
  #hud { font-size: 11px; min-width: 160px; }
}
