:root {
  --bg: #0f1720;
  --panel: #18222e;
  --panel-2: #1f2c3a;
  --line: #2c3a4a;
  --text: #e6edf3;
  --muted: #9fb0c0;
  --accent: #4aa3df;
  --good: #2e9e5b;
  --caution: #e0a948;
  --bad: #d04a4a;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  background: var(--bg);
  color: var(--text);
}

#app { display: grid; grid-template-columns: 320px 1fr; height: 100vh; position: relative; }

/* 사이드바 */
#sidebar {
  background: var(--panel);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
#sidebar header h1 { font-size: 17px; margin: 0 0 2px; line-height: 1.25; }
#sidebar .sub { margin: 0; font-size: 12px; color: var(--muted); }

.control { display: flex; flex-direction: column; gap: 8px; }
.ctl-label { font-size: 12px; color: var(--muted); font-weight: 600; }

.seg { display: flex; background: var(--panel-2); border-radius: 8px; padding: 3px; gap: 3px; }
.seg button {
  flex: 1; border: 0; background: transparent; color: var(--muted);
  padding: 7px 4px; border-radius: 6px; font-size: 12px; cursor: pointer; font-weight: 600;
}
.seg button.active { background: var(--accent); color: #fff; }

select, input[type="range"] { width: 100%; }
select {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 6px; padding: 7px; font-size: 13px;
}
.year-ends { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); }
.chk { font-size: 12px; color: var(--muted); display: flex; gap: 6px; align-items: center; cursor: pointer; }
#year-display { color: var(--text); font-weight: 700; }

/* 범례 */
#legend { display: flex; flex-direction: column; gap: 5px; font-size: 12px; }
.legend-row { display: flex; align-items: center; gap: 8px; }
.legend-swatch { width: 14px; height: 14px; border-radius: 3px; flex-shrink: 0; border: 1px solid rgba(255,255,255,.2); }
.legend-swatch.circle { border-radius: 50%; }

.note { font-size: 12px; color: var(--muted); }
#sidebar footer { margin-top: auto; border-top: 1px solid var(--line); padding-top: 12px; font-size: 12px; }
#sidebar footer a { color: var(--accent); text-decoration: none; }
#sidebar footer a:hover { text-decoration: underline; }
.muted { color: var(--muted); font-size: 11px; margin: 6px 0 0; }

/* 지도 */
#map { width: 100%; height: 100%; }

/* 상세 패널 */
#detail {
  position: absolute; top: 0; right: 0; width: 360px; height: 100%;
  background: var(--panel); border-left: 1px solid var(--line);
  overflow-y: auto; padding: 16px 16px 40px; box-shadow: -8px 0 24px rgba(0,0,0,.3);
}
#detail-close {
  position: sticky; top: 0; float: right; background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 6px; width: 30px; height: 30px;
  font-size: 18px; cursor: pointer; line-height: 1;
}
#detail h2 { font-size: 15px; margin: 4px 0 2px; }
#detail h3 { font-size: 13px; margin: 16px 0 6px; color: var(--accent); border-bottom: 1px solid var(--line); padding-bottom: 4px; }
#detail .kv { display: grid; grid-template-columns: 110px 1fr; gap: 3px 8px; font-size: 12px; }
#detail .kv dt { color: var(--muted); }
#detail .kv dd { margin: 0; word-break: break-word; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 12px; font-weight: 700; color: #fff; }
.badge.good { background: var(--good); }
.badge.caution { background: var(--caution); color: #2a2a2a; }
.badge.bad { background: var(--bad); }

table.mini { width: 100%; border-collapse: collapse; font-size: 11.5px; }
table.mini th, table.mini td { text-align: left; padding: 3px 5px; border-bottom: 1px solid var(--line); }
table.mini th { color: var(--muted); font-weight: 600; }

.prov { font-size: 11px; color: var(--muted); background: var(--panel-2); border-radius: 6px; padding: 8px; margin-top: 6px; }
.prov code { color: var(--text); word-break: break-all; }

.facies-chip {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 30px; height: 22px; padding: 0 6px; border-radius: 4px;
  font-weight: 700; font-size: 12px; color: #1a1a1a;
}

svg.spark { width: 100%; height: 90px; display: block; }
.spark-note { font-size: 11px; color: var(--muted); margin: 2px 0 0; }

/* MapLibre 팝업 다크 */
.maplibregl-popup-content { background: var(--panel); color: var(--text); border: 1px solid var(--line); font-size: 12px; }
.maplibregl-popup-anchor-bottom .maplibregl-popup-tip { border-top-color: var(--panel); }
.maplibregl-popup-anchor-top .maplibregl-popup-tip { border-bottom-color: var(--panel); }

@media (max-width: 760px) {
  #app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  #sidebar { max-height: 42vh; }
  #detail { width: 100%; }
}
