:root {
  color-scheme: light;
  --surface: #fbfcfd;
  --plane: #eef2f5;
  --ink: #14202b;
  --ink-2: #4d5b67;
  --muted: #85919b;
  --line: #dde3e8;
  --line-strong: #c4ccd3;
  --focus: #2a78d6;
  --ref: #2a78d6;
  --sim: #6c7a86;
  --up: #b4352f;
  --down: #2a63b8;
  --radius-s: 6px;
  --radius-m: 10px;
  --font: "IBM Plex Sans KR", system-ui, -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --surface: #161b20;
    --plane: #1e252c;
    --ink: #eef2f5;
    --ink-2: #b9c3cc;
    --muted: #87939d;
    --line: #2a333b;
    --line-strong: #3a454f;
    --ref: #3987e5;
    --sim: #9aa6b1;
    --up: #ec7a6f;
    --down: #6fa3ec;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface: #161b20; --plane: #1e252c; --ink: #eef2f5; --ink-2: #b9c3cc;
  --muted: #87939d; --line: #2a333b; --line-strong: #3a454f; --ref: #3987e5;
  --sim: #9aa6b1; --up: #ec7a6f; --down: #6fa3ec;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--surface);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, p { margin: 0; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* Layout: map fills the left, comparison panel on the right */
.app {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 440px;
  height: 100dvh;
}
.map-wrap { position: relative; min-height: 0; background: var(--plane); }
.map { position: absolute; inset: 0; }
.map-fallback {
  position: absolute; inset: 0; display: grid; place-content: center; gap: 8px;
  padding: 32px; max-width: 520px; margin: auto; color: var(--ink-2);
}
.fallback-title { color: var(--ink); font-weight: 600; font-size: 16px; }
.map-legend {
  position: absolute; left: 12px; bottom: 12px; z-index: 5;
  display: flex; gap: 14px; flex-wrap: wrap;
  padding: 6px 10px; border-radius: var(--radius-s);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  border: 1px solid var(--line); font-size: 12px; color: var(--ink-2);
}
.map-legend span { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot-ref { background: var(--ref); }
.dot-cmp { background: #fff; border: 2.5px solid #eb6834; }
.dot-sim { background: #fff; border: 1.5px dashed var(--sim); }
.dot-small { width: 8px; height: 8px; background: #fff; border: 2px solid #4d5b67; }

.panel {
  display: flex; flex-direction: column; min-height: 0;
  border-left: 1px solid var(--line); background: var(--surface);
}
.panel-head {
  padding: 18px 20px 14px; border-bottom: 1px solid var(--line);
  display: grid; gap: 12px;
}
.brand { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.brand h1 { font-size: 17px; font-weight: 600; letter-spacing: -0.01em; }
.data-note { font-size: 12px; color: var(--muted); text-align: right; }

.search { position: relative; }
.search input {
  width: 100%; height: 40px; padding: 0 12px;
  border: 1px solid var(--line-strong); border-radius: var(--radius-s);
  background: var(--surface);
}
.search input::placeholder { color: var(--muted); }
.search-results {
  position: absolute; z-index: 20; left: 0; right: 0; top: 44px;
  margin: 0; padding: 4px; list-style: none;
  background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: var(--radius-s); box-shadow: 0 8px 24px rgba(20, 32, 43, 0.14);
  max-height: 320px; overflow: auto;
}
.search-results li {
  padding: 8px 10px; border-radius: 4px; cursor: pointer;
  display: flex; justify-content: space-between; gap: 12px;
}
.search-results li[aria-selected="true"], .search-results li:hover { background: var(--plane); }
.search-results .where { color: var(--muted); font-size: 12px; white-space: nowrap; }

.start-tabs { display: flex; gap: 0; border: 1px solid var(--line-strong); border-radius: var(--radius-s); overflow: hidden; }
.start-tab {
  flex: 1; border: 0; background: var(--surface); padding: 7px 10px; cursor: pointer;
  font-size: 13.5px; color: var(--ink-2);
}
.start-tab + .start-tab { border-left: 1px solid var(--line-strong); }
.start-tab.is-on { background: var(--ink); color: var(--surface); font-weight: 600; }
.filters label.is-off { opacity: 0.45; }
.amount-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-top: 6px; }
.amount-input { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; }
.amount-input input {
  width: 92px; height: 36px; padding: 0 10px; font-size: 16px; font-weight: 600;
  border: 1px solid var(--line-strong); border-radius: var(--radius-s); background: var(--surface);
  font-variant-numeric: tabular-nums;
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--line-strong); background: var(--surface); border-radius: 999px;
  padding: 4px 11px; font-size: 12.5px; cursor: pointer;
}
.chip.is-on { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.year-btn.compact { padding: 6px 10px; }
.price .years { grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); }
.price-rule { margin-top: 10px; font-size: 12px; color: var(--muted); }
.price-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 16px; }
.price-head h3 { font-size: 15px; font-weight: 600; }
.price-item .sim-name { text-align: left; }
.price-item .rank { font-size: 12px; }
.filters { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: end; }
.filters label { display: grid; gap: 2px; font-size: 12px; color: var(--ink-2); }
.filters select {
  height: 32px; padding: 0 8px; border: 1px solid var(--line-strong);
  border-radius: var(--radius-s); background: var(--surface); font-size: 13px;
}
.filters .check { display: flex; align-items: center; gap: 6px; height: 32px; font-size: 13px; color: var(--ink); }

.panel-body { overflow-y: auto; padding: 0 20px 24px; }
.panel-body > section, .panel-body > details { padding-top: 18px; }

.empty { padding: 32px 0; color: var(--ink-2); display: grid; gap: 8px; max-width: 36em; }
.empty-title { color: var(--ink); font-weight: 600; font-size: 15px; }

/* Selected complex */
.ref-head h2 { font-size: 22px; font-weight: 600; letter-spacing: -0.02em; line-height: 1.25; }
.ref-meta { color: var(--ink-2); font-size: 13px; margin-top: 2px; }
.step-label { margin-top: 16px; font-size: 12px; color: var(--muted); }
.years {
  margin-top: 6px; display: grid; gap: 6px;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
}
.year-btn {
  display: grid; gap: 1px; text-align: left; cursor: pointer;
  padding: 7px 10px; border-radius: var(--radius-s);
  border: 1px solid var(--line); background: var(--surface);
}
.year-btn .y { font-size: 12px; color: var(--muted); }
.year-btn .p { font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; }
.year-btn:hover { border-color: var(--line-strong); }
.year-btn[aria-checked="true"] { background: var(--ink); border-color: var(--ink); color: var(--surface); }
.year-btn[aria-checked="true"] .y { color: color-mix(in srgb, var(--surface) 70%, transparent); }
.year-btn:disabled { cursor: default; opacity: 0.45; }
.year-btn.thin .p::after { content: "*"; color: var(--muted); margin-left: 2px; font-weight: 400; }
.months {
  margin-top: 6px; display: grid; gap: 4px;
  grid-template-columns: repeat(6, minmax(0, 1fr));
}
.month-btn {
  display: grid; gap: 0; text-align: left; cursor: pointer;
  padding: 5px 7px; border-radius: var(--radius-s);
  border: 1px solid var(--line); background: var(--surface);
}
.month-btn .y { font-size: 11px; color: var(--muted); }
.month-btn .p { font-size: 12.5px; font-weight: 600; font-variant-numeric: tabular-nums; }
.month-btn:hover { border-color: var(--line-strong); }
.month-btn[aria-checked="true"] { background: var(--ref); border-color: var(--ref); color: #fff; }
.month-btn[aria-checked="true"] .y { color: rgba(255, 255, 255, 0.8); }
.month-btn:disabled { cursor: default; opacity: 0.4; }
.year-btn.in-view { border-color: var(--ink); }
.ref-price {
  margin-top: 14px; display: grid; grid-template-columns: 1fr auto; gap: 2px 12px;
  padding: 12px 14px; border-radius: var(--radius-m); background: var(--plane);
  font-size: 13px; color: var(--ink-2); font-variant-numeric: tabular-nums;
}
.ref-price strong { color: var(--ink); font-weight: 600; font-size: 15px; }
.ref-price .growth { grid-row: 1 / span 2; grid-column: 2; align-self: center; text-align: right; }
.ref-price .growth .pct { font-size: 20px; font-weight: 600; }
.ref-price .growth .lbl { font-size: 11.5px; color: var(--muted); }
.ref-price .empty-note { grid-column: 1 / -1; }
.ref-price .basis { grid-column: 1; font-size: 12px; color: var(--muted); }
.badge-thin {
  display: inline-block; font-size: 11px; font-weight: 600; padding: 0 6px; border-radius: 4px;
  background: color-mix(in srgb, var(--up) 14%, transparent); color: var(--up);
}
.sim-nums .sample { font-size: 11px; color: var(--muted); }
.ref-price .warn { grid-column: 1; font-size: 12px; color: var(--up); }

/* Chart */
.chart-head { display: flex; justify-content: space-between; align-items: center; gap: 8px 12px; flex-wrap: wrap; }
.chart-controls { display: flex; gap: 6px; flex-wrap: wrap; }
.chart-head h3, .similar-head h3 { font-size: 15px; font-weight: 600; }
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--radius-s); overflow: hidden; }
.seg-btn { border: 0; background: transparent; padding: 4px 10px; font-size: 12px; cursor: pointer; color: var(--ink-2); }
.seg-btn + .seg-btn { border-left: 1px solid var(--line-strong); }
.seg-btn.is-on { background: var(--plane); color: var(--ink); font-weight: 600; }
.chart-box { position: relative; height: 280px; margin-top: 10px; }
.chart-note { margin-top: 6px; font-size: 12px; color: var(--muted); }

/* Similar complexes: doubles as the chart legend */
.similar-head { display: grid; gap: 2px; }
.similar-hint { font-size: 12px; color: var(--muted); }
.similar-list { list-style: none; margin: 10px 0 0; padding: 0; border-top: 1px solid var(--line); }
.sim-item {
  display: grid; grid-template-columns: 26px 1fr auto; gap: 4px 8px; align-items: start;
  padding: 10px 0; border-bottom: 1px solid var(--line);
}
.sim-item input { margin: 3px 0 0; accent-color: var(--ink); }
.sim-name {
  border: 0; background: none; padding: 0; text-align: left; cursor: pointer;
  font-weight: 600; display: flex; align-items: center; gap: 7px; line-height: 1.35;
}
.sim-name:hover { text-decoration: underline; text-underline-offset: 3px; }
.swatch { flex: none; width: 14px; height: 3px; border-radius: 2px; background: transparent; }
.sim-meta { grid-column: 2; font-size: 12px; color: var(--muted); }
.band-tag {
  grid-column: 2; justify-self: start; font-size: 11.5px; font-weight: 500;
  padding: 1px 7px; border-radius: 999px; border: 1px solid var(--line-strong); color: var(--ink-2);
}
.vs { grid-column: 2 / span 2; font-size: 12.5px; color: var(--ink-2); }
.vs b { font-weight: 600; }
.band-tag.other { border-color: var(--ink-2); color: var(--ink); background: var(--plane); }
.sim-nums { grid-row: 1 / span 2; grid-column: 3; text-align: right; font-variant-numeric: tabular-nums; }
.sim-nums .now { font-weight: 600; }
.sim-nums .chg { font-size: 12px; }
.chg.up { color: var(--up); }
.chg.down { color: var(--down); }
.chg.flat { color: var(--muted); }
.sim-empty { padding: 14px 0; color: var(--ink-2); }
.sim-item.is-ref { background: color-mix(in srgb, var(--ref) 7%, transparent); }
.sim-item.is-ref .sim-name { cursor: default; }
.sim-item.is-ref .sim-name:hover { text-decoration: none; }
.ref-tag { font-size: 11px; font-weight: 500; color: var(--ref); margin-left: 2px; }
.sim-item .rank { margin: 3px 0 0; font-size: 11px; white-space: nowrap; color: var(--muted); text-align: center; font-variant-numeric: tabular-nums; }

.panel-foot { padding: 10px 20px; border-top: 1px solid var(--line); font-size: 11.5px; color: var(--muted); }

/* Trades table */
.trades summary { cursor: pointer; font-weight: 600; font-size: 15px; }
.trades-scroll { max-height: 320px; overflow: auto; margin-top: 10px; border-top: 1px solid var(--line); }
.trades table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
.trades th { position: sticky; top: 0; background: var(--surface); text-align: left; font-weight: 500; color: var(--muted); font-size: 12px; }
.trades th, .trades td { padding: 6px 4px; border-bottom: 1px solid var(--line); }
.trades td:nth-child(4) { font-weight: 600; }
.trades tr.cancelled td { color: var(--muted); text-decoration: line-through; }

/* Map labels (Kakao CustomOverlay content) */
.pin-wrap { padding-bottom: 6px; }
.pin {
  display: grid; gap: 0; padding: 3px 8px 4px; cursor: pointer;
  background: #fff; color: #14202b; white-space: nowrap;
  border: 1px solid #aab4bd; border-radius: 6px;
  box-shadow: 0 1px 3px rgba(20, 32, 43, 0.18);
  font-family: var(--font); line-height: 1.25; position: relative;
}
.pin::after {
  content: ""; position: absolute; left: 50%; bottom: -5px; transform: translateX(-50%);
  border: 5px solid transparent; border-top-color: inherit; border-bottom: 0;
}
.pin .n { font-size: 11px; color: #4d5b67; max-width: 9em; overflow: hidden; text-overflow: ellipsis; }
.pin .v { font-size: 12.5px; font-weight: 600; font-variant-numeric: tabular-nums; }
.pin .b { font-size: 10.5px; font-weight: 500; color: #4d5b67; margin-right: 4px; }
.pin.sim { border: 1.5px dashed #6c7a86; }
.pin.cmp { border: 2.5px solid var(--c); }
.pin.ref { background: #2a78d6; border-color: #2a78d6; color: #fff; z-index: 3; }
.pin.ref .n { color: rgba(255, 255, 255, 0.85); }
.dot-pin {
  width: 12px; height: 12px; padding: 0; border-radius: 50%; cursor: pointer;
  background: #fff; border: 2px solid #4d5b67; box-shadow: 0 1px 2px rgba(20, 32, 43, 0.3);
}
.dot-pin.no-band { border-color: #aab4bd; background: #eef2f5; }
.dot-pin:hover { transform: scale(1.35); }
.cluster {
  width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center;
  background: rgba(20, 32, 43, 0.82); color: #fff; font: 600 12px var(--font);
  border: 2px solid #fff;
}

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; grid-template-rows: 42dvh auto; height: auto; }
  .map-wrap { height: 42dvh; }
  .panel { border-left: 0; border-top: 1px solid var(--line); }
  .panel-body { overflow: visible; }
  .panel-head { padding: 14px 16px 12px; }
  .panel-body { padding: 0 16px 24px; }
}
@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; }
}
