:root {
  --bg: #0d1117;
  --bg-soft: #161b22;
  --bg-card: #1a2029;
  --border: #2a3441;
  --text: #e6edf3;
  --text-dim: #97a3b4;
  --accent: #2f81f7;
  --accent-soft: rgba(47, 129, 247, .14);
  --up: #ef4444;     /* 한국식: 상승=빨강 */
  --down: #3b82f6;   /* 하락=파랑 */
  --green: #16c784;
  --shadow: 0 8px 30px rgba(0,0,0,.35);
  --radius: 14px;
}
[data-theme="light"] {
  --bg: #f4f6fb;
  --bg-soft: #ffffff;
  --bg-card: #ffffff;
  --border: #e3e8ef;
  --text: #1a2230;
  --text-dim: #5b6677;
  --accent: #2563eb;
  --accent-soft: rgba(37, 99, 235, .10);
  --shadow: 0 6px 24px rgba(20,40,80,.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: "Pretendard", -apple-system, BlinkMacSystemFont, "Segoe UI",
               "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  transition: background .25s, color .25s;
}

/* ---------- Topbar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px; background: var(--bg-soft);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20;
  backdrop-filter: blur(8px);
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo { width: 30px; height: 30px; color: var(--accent); }
.brand h1 { font-size: 20px; font-weight: 800; letter-spacing: -.4px; }
.tagline { font-size: 12px; color: var(--text-dim); }
.icon-btn {
  width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg-card); cursor: pointer; display: grid; place-items: center;
  color: var(--text); transition: .2s;
}
.icon-btn:hover { border-color: var(--accent); }
.theme-icon::before { content: "🌙"; font-size: 18px; }
[data-theme="light"] .theme-icon::before { content: "☀️"; }

/* ---------- Layout ---------- */
.container { max-width: 1280px; margin: 0 auto; padding: 24px 20px 60px; }

/* ---------- Search ---------- */
.search-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow);
}
.search-row { display: flex; gap: 12px; }
#symbolInput {
  flex: 1; padding: 14px 18px; font-size: 16px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--bg-soft); color: var(--text);
  outline: none; transition: .2s;
}
#symbolInput:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.primary-btn {
  padding: 14px 26px; font-size: 15px; font-weight: 700; border: none;
  border-radius: 10px; background: var(--accent); color: #fff; cursor: pointer;
  white-space: nowrap; transition: .2s;
}
.primary-btn:hover { filter: brightness(1.08); }
.primary-btn:disabled { opacity: .6; cursor: wait; }
.examples { margin-top: 14px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.examples > span { font-size: 13px; color: var(--text-dim); }
.chip {
  padding: 6px 13px; font-size: 13px; border-radius: 20px; cursor: pointer;
  border: 1px solid var(--border); background: var(--bg-soft); color: var(--text-dim);
  transition: .15s;
}
.chip:hover { border-color: var(--accent); color: var(--text); }

/* ---------- Guide ---------- */
.guide-section { margin-top: 22px; }
.guide {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}
.guide > summary {
  list-style: none; cursor: pointer; padding: 18px 22px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  font-weight: 700; user-select: none;
}
.guide > summary::-webkit-details-marker { display: none; }
.guide-summary-title { font-size: 16px; }
.guide-summary-hint { font-size: 12px; color: var(--text-dim); font-weight: 500; }
.guide[open] .guide-summary-hint::after { content: " ▲"; }
.guide:not([open]) .guide-summary-hint::after { content: " ▼"; }
.guide-body { padding: 4px 22px 24px; border-top: 1px solid var(--border); }
.guide-intro { font-size: 14px; color: var(--text-dim); margin: 16px 0 6px; }
.guide-h { font-size: 15px; margin: 22px 0 12px; color: var(--text); }
.guide-note { font-size: 13.5px; color: var(--text-dim); margin: 6px 0 10px; }

.legend-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.legend-item { display: flex; gap: 12px; align-items: flex-start; font-size: 13.5px; }
.legend-item > div > span { color: var(--text-dim); }
.lg-swatch {
  flex: 0 0 16px; width: 16px; height: 16px; border-radius: 4px; margin-top: 3px;
}
.lg-cloud { background: linear-gradient(180deg, rgba(22,199,132,.5), rgba(239,68,68,.4)); }

.target-guide { list-style: none; display: grid; gap: 10px; margin: 6px 0; }
.target-guide li { font-size: 13.5px; color: var(--text-dim); padding-left: 2px; }
.target-guide b { color: var(--text); }
.tkey {
  display: inline-grid; place-items: center; min-width: 22px; height: 22px;
  border-radius: 6px; color: #fff; font-weight: 800; font-size: 12px;
  margin-right: 8px; padding: 0 5px; vertical-align: middle;
}
.algo-steps { margin: 6px 0 6px 18px; font-size: 13.5px; color: var(--text-dim); display: grid; gap: 7px; }
.algo-steps b { color: var(--text); }

.accuracy-box {
  margin-top: 20px; padding: 16px 18px; border-radius: 12px;
  background: var(--accent-soft); border: 1px solid var(--border); font-size: 13.5px;
}
.acc-stats { display: flex; flex-wrap: wrap; gap: 22px; margin: 14px 0 6px; }
.acc-stats > div { display: flex; flex-direction: column; }
.acc-num { font-size: 24px; font-weight: 800; color: var(--accent); line-height: 1.1; }
.acc-lbl { font-size: 12px; color: var(--text-dim); }
.acc-note { font-size: 12px; color: var(--text-dim); }

@media (max-width: 720px) {
  .legend-grid { grid-template-columns: 1fr; }
}

/* ---------- Result ---------- */
.result-area { margin-top: 22px; }
.hidden { display: none !important; }
.result-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  flex-wrap: wrap; gap: 14px; margin-bottom: 14px;
}
.title-block h2 { font-size: 24px; font-weight: 800; }
.title-block .sub { font-size: 13px; color: var(--text-dim); margin-top: 2px; }
.toolbar { display: flex; align-items: center; gap: 12px; }
.tabs { display: inline-flex; background: var(--bg-soft); border: 1px solid var(--border); border-radius: 10px; padding: 3px; }
.tab {
  padding: 8px 16px; font-size: 14px; font-weight: 600; border: none; cursor: pointer;
  background: transparent; color: var(--text-dim); border-radius: 8px; transition: .15s;
}
.tab.active { background: var(--accent); color: #fff; }
.ghost-btn {
  padding: 9px 15px; font-size: 14px; font-weight: 600; cursor: pointer;
  border: 1px solid var(--border); background: var(--bg-card); color: var(--text);
  border-radius: 10px; transition: .15s;
}
.ghost-btn:hover { border-color: var(--accent); }

.chart-wrap {
  position: relative; background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px; box-shadow: var(--shadow);
}
#chart { width: 100%; height: 560px; }

.loader { position: absolute; inset: 0; display: grid; place-items: center;
  background: color-mix(in srgb, var(--bg-card) 70%, transparent); border-radius: var(--radius); }
.spinner {
  width: 46px; height: 46px; border: 4px solid var(--border);
  border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Insights ---------- */
.insight-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-top: 18px;
}
.insight-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px;
}
.insight-card h3 { font-size: 15px; margin-bottom: 14px; font-weight: 700; }
.gauge-bar {
  height: 12px; border-radius: 8px; overflow: hidden;
  background: linear-gradient(90deg, var(--down), #888 50%, var(--up));
  position: relative;
}
.gauge-fill {
  position: absolute; top: -3px; width: 4px; height: 18px; background: #fff;
  border-radius: 2px; box-shadow: 0 0 6px rgba(0,0,0,.6); transition: left .4s; left: 50%;
}
.gauge-labels { display: flex; justify-content: space-between; margin-top: 8px;
  font-size: 12px; color: var(--text-dim); }
#biasLabel { font-weight: 800; color: var(--text); }
.reason-list { list-style: none; margin-top: 12px; display: flex; flex-direction: column; gap: 6px; }
.reason-list li { font-size: 13px; color: var(--text-dim); padding-left: 16px; position: relative; }
.reason-list li::before { content: "•"; position: absolute; left: 2px; color: var(--accent); }

.target-table, .meta-table { width: 100%; border-collapse: collapse; }
.target-table td, .meta-table td { padding: 7px 4px; font-size: 13.5px; border-bottom: 1px solid var(--border); }
.target-table td:first-child { color: var(--text-dim); width: 38%; }
.target-table td:last-child, .meta-table td:last-child { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.meta-table td:first-child { color: var(--text-dim); }
.tkey { display: inline-block; width: 22px; height: 22px; line-height: 22px; text-align: center;
  border-radius: 6px; font-weight: 800; font-size: 12px; color: #fff; margin-right: 6px; }
.ret-line { margin-top: 12px; font-size: 13px; color: var(--text-dim); }
.ret-line b { color: var(--text); }
.pos { color: var(--up); } .neg { color: var(--down); }

.disclaimer {
  margin-top: 20px; font-size: 12.5px; color: var(--text-dim); text-align: center;
  background: var(--bg-soft); border: 1px solid var(--border); border-radius: 10px; padding: 14px;
}

/* ---------- Empty ---------- */
.empty-state { text-align: center; padding: 70px 20px; color: var(--text-dim); }
.es-icon { font-size: 56px; margin-bottom: 14px; }
.empty-state h2 { color: var(--text); font-size: 22px; margin-bottom: 10px; }

/* ---------- Footer ---------- */
.footer {
  display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px;
  max-width: 1280px; margin: 0 auto; padding: 20px; font-size: 12px; color: var(--text-dim);
  border-top: 1px solid var(--border);
}

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%);
  background: #d33; color: #fff; padding: 12px 22px; border-radius: 10px;
  font-size: 14px; font-weight: 600; box-shadow: var(--shadow); z-index: 50;
  transition: opacity .3s, transform .3s;
}

@media (max-width: 820px) {
  .insight-grid { grid-template-columns: 1fr; }
  #chart { height: 460px; }
  .search-row { flex-direction: column; }
}
