:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", sans-serif;
  --map-bg: #151c25;
  --map-surface: #1d2631;
  --map-surface-2: #202c39;
  --map-line: #3c4b5c;
  --map-text: #edf3f9;
  --map-muted: #9aa9b8;
  --map-blue: #2588f4;
  --map-blue-soft: #75b8ff;
  --map-magenta: #d226c4;
  --map-good: #55d6a4;
  --map-bad: #ff8a8a;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  background: var(--map-bg);
  color: var(--map-text);
}

button,
input,
select {
  font: inherit;
}

a {
  color: inherit;
}

.map-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 22px clamp(18px, 4vw, 56px);
  border-bottom: 1px solid var(--map-line);
  background: rgba(21, 28, 37, 0.94);
  backdrop-filter: blur(12px);
}

.map-brand {
  color: var(--map-blue-soft);
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 0.01em;
  text-decoration: none;
}

.map-topbar p {
  margin: 5px 0 0;
  color: var(--map-muted);
  font-size: 13px;
}

.map-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  color: var(--map-muted);
  font-size: 13px;
}

.map-nav a:hover {
  color: var(--map-text);
}

.map-main {
  display: grid;
  gap: 16px;
  width: min(1500px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 48px;
}

.map-intro {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 28px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--map-blue-soft);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.16em;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(26px, 4vw, 42px);
  line-height: 1.08;
}

h2 {
  font-size: 18px;
}

.intro-copy {
  max-width: 760px;
  margin-top: 10px;
  color: var(--map-muted);
  font-size: 14px;
  line-height: 1.55;
}

.map-note {
  display: grid;
  gap: 5px;
  min-width: min(100%, 390px);
  padding: 13px 15px;
  border: 1px solid var(--map-line);
  border-radius: 10px;
  background: var(--map-surface);
  color: var(--map-muted);
  font-size: 12px;
  line-height: 1.45;
}

.map-note strong {
  color: var(--map-text);
  font-size: 13px;
}

.map-controls {
  display: flex;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 12px;
  padding: 13px;
  border: 1px solid var(--map-line);
  border-radius: 10px;
  background: var(--map-surface);
}

.map-controls label {
  display: grid;
  gap: 5px;
  color: var(--map-muted);
  font-size: 12px;
}

.map-controls .ticker-control {
  flex: 1 1 280px;
}

.map-controls .growth-mode-control {
  flex: 1 1 430px;
}

.map-controls .growth-mode-control select {
  width: 100%;
}

.map-controls .label-mode-control {
  flex: 0 1 205px;
}

.map-controls .label-mode-control select {
  width: 100%;
}

.map-controls .label-limit-control { flex: 0 0 110px; }
.map-controls .label-limit-control input { min-width: 0; width: 110px; }
.label-limit-note { flex: 1 1 100%; color: var(--map-muted); font-size: 12px; line-height: 1.5; }
.label-limit-control input:disabled { opacity: 0.45; }
.point-label-leader { stroke: var(--map-muted); stroke-width: 0.8; opacity: 0.55; pointer-events: none; }

.map-controls select,
.map-controls input,
.map-controls button {
  height: 38px;
  border: 1px solid #536477;
  border-radius: 7px;
  background: #18212b;
  color: var(--map-text);
}

.map-controls select,
.map-controls input {
  min-width: 180px;
  padding: 0 10px;
}

.map-controls input {
  width: 100%;
}

.map-controls button {
  padding: 0 15px;
  cursor: pointer;
  font-weight: 700;
}

.map-controls button:hover {
  border-color: var(--map-blue-soft);
}

.quality-filter {
  flex: 1 1 100%;
  border-top: 1px solid rgba(83, 97, 113, 0.55);
}

.quality-filter summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-top: 10px;
  cursor: pointer;
  color: var(--map-blue-soft);
  font-size: 12px;
  font-weight: 800;
}

.quality-filter summary strong {
  color: #ffd166;
  font-size: 11px;
}

.quality-filter-body {
  display: grid;
  gap: 8px;
  padding-top: 10px;
  color: var(--map-muted);
  font-size: 12px;
}

.quality-filter-body p {
  margin: 0;
}

.quality-proxy-note {
  color: #ffd166;
}

.quality-rule-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px 16px;
}

.map-controls .quality-rule-grid label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  color: var(--map-text);
}

.map-controls .quality-rule-grid input {
  width: 16px;
  min-width: 16px;
  height: 16px;
  margin: 0;
  padding: 0;
}

.quality-rule-grid small {
  margin-left: auto;
  color: var(--map-muted);
  font-variant-numeric: tabular-nums;
}

.quality-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.quality-actions #qualityResult {
  color: var(--map-muted);
}

.ticker-basket {
  display: grid;
  gap: 10px;
  padding: 13px;
  border: 1px solid var(--map-line);
  border-radius: 10px;
  background: var(--map-surface);
}

.ticker-basket-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 14px;
}

.ticker-basket-head > div {
  display: grid;
  gap: 3px;
}

.ticker-basket-head strong {
  color: var(--map-text);
  font-size: 13px;
}

.ticker-basket-head span,
.ticker-basket-summary {
  color: var(--map-muted);
  font-size: 11px;
}

.ticker-add-form {
  display: flex;
  gap: 7px;
}

.ticker-add-form input,
.ticker-add-form button {
  height: 34px;
  border: 1px solid #536477;
  border-radius: 7px;
  background: #18212b;
  color: var(--map-text);
}

.ticker-add-form input {
  width: 210px;
  padding: 0 10px;
}

.ticker-add-form button {
  padding: 0 13px;
  cursor: pointer;
  font-weight: 800;
}

.ticker-initial-form {
  display: grid;
  grid-template-columns: minmax(210px, 0.42fr) minmax(280px, 1fr) auto;
  align-items: end;
  gap: 9px;
  padding: 10px;
  border: 1px solid rgba(117, 184, 255, 0.22);
  border-radius: 8px;
  background: rgba(14, 21, 29, 0.34);
}

.ticker-initial-form label {
  display: grid;
  gap: 3px;
}

.ticker-initial-form label strong {
  color: var(--map-text);
  font-size: 12px;
}

.ticker-initial-form label span {
  color: var(--map-muted);
  font-size: 10px;
  line-height: 1.35;
}

.ticker-initial-form input,
.ticker-initial-form button {
  height: 36px;
  border: 1px solid #536477;
  border-radius: 7px;
  background: #18212b;
  color: var(--map-text);
}

.ticker-initial-form input {
  min-width: 0;
  padding: 0 10px;
}

.ticker-initial-form button {
  padding: 0 14px;
  cursor: pointer;
  font-weight: 800;
  white-space: nowrap;
}

.ticker-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  max-height: 122px;
  overflow-y: auto;
}

.ticker-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 27px;
  padding: 3px 5px 3px 9px;
  border: 1px solid rgba(85, 168, 255, 0.62);
  border-radius: 999px;
  background: rgba(64, 137, 213, 0.14);
  color: var(--map-blue-soft);
  font-size: 11px;
  font-weight: 800;
}

.ticker-chip.is-excluded,
.ticker-chip.is-unavailable {
  border-color: rgba(255, 209, 102, 0.55);
  color: #ffd166;
  opacity: 0.78;
}

.ticker-chip.is-error {
  border-color: rgba(255, 113, 113, 0.6);
  color: var(--map-bad);
}

.ticker-chip button {
  display: grid;
  place-items: center;
  width: 19px;
  height: 19px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: currentColor;
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
}

.ticker-chip button:hover {
  background: rgba(255, 255, 255, 0.1);
}

.ticker-basket-summary {
  margin: 0;
}

.model-list {
  display: grid;
  gap: 18px;
}

.load-status {
  min-height: 38px;
  align-content: center;
  color: var(--map-muted);
  font-size: 12px;
}

.map-card {
  overflow: hidden;
  border: 1px solid var(--map-line);
  border-radius: 12px;
  background: var(--map-surface);
  box-shadow: 0 18px 45px rgba(0, 0, 0, 0.14);
}

.map-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  padding: 17px 18px 10px;
}

.map-card-head.compact {
  padding-bottom: 15px;
}

.map-card-head p {
  margin-top: 5px;
  color: var(--map-muted);
  font-size: 12px;
  line-height: 1.45;
}

.fit-result-stack {
  display: grid;
  justify-items: end;
  gap: 6px;
  flex: 0 0 auto;
  max-width: min(100%, 620px);
}

.fit-summary {
  color: var(--map-blue-soft);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.5;
  text-align: right;
}

.fit-summary.p-significant,
.regression-details .technical-values.p-significant {
  color: var(--map-good);
}

.fit-summary.p-moderate,
.regression-details .technical-values.p-moderate {
  color: #ffd166;
}

.fit-summary.p-none,
.regression-details .technical-values.p-none {
  color: var(--map-muted);
}

.fit-summary.is-blocked {
  color: var(--map-bad);
}

.regression-details {
  max-width: 620px;
  color: var(--map-muted);
  font-size: 11px;
  text-align: left;
}

.regression-details summary {
  cursor: pointer;
  color: var(--map-blue-soft);
  font-weight: 700;
  text-align: right;
}

.regression-details-body {
  display: grid;
  gap: 4px;
  margin-top: 7px;
  padding: 9px 11px;
  border: 1px solid rgba(83, 97, 113, 0.7);
  border-radius: 7px;
  background: rgba(17, 24, 32, 0.78);
  line-height: 1.45;
}

.regression-details-body p {
  margin: 0;
}

.chart-viewport {
  position: relative;
  width: 100%;
  min-height: 420px;
  padding: 0 10px 8px;
}

.scatter-chart {
  display: block;
  width: 100%;
  height: clamp(470px, 58vw, 720px);
  overflow: visible;
}

.scatter-chart .chart-bg {
  fill: #1d2631;
}

.scatter-chart .grid-line {
  stroke: #536171;
  stroke-width: 1;
  stroke-dasharray: 3 8;
  opacity: 0.64;
}

.scatter-chart .axis-line {
  stroke: #dce5ee;
  stroke-width: 1.25;
}

.scatter-chart .tick-text,
.scatter-chart .axis-title,
.scatter-chart .fit-label {
  fill: #dce5ee;
  font-size: 13px;
}

.scatter-chart .axis-title {
  font-size: 16px;
  font-weight: 700;
}

.scatter-chart .point {
  fill: var(--map-blue);
  stroke: #8dc3ff;
  stroke-width: 1.3;
  cursor: pointer;
  opacity: 0.92;
  transition: r 120ms ease, fill 120ms ease;
}

.scatter-chart .point:hover,
.scatter-chart .point.is-focus {
  fill: #49a0ff;
  stroke: #e4f2ff;
  stroke-width: 2;
}

.scatter-chart .point-label {
  fill: #55a8ff;
  font-size: 13px;
  font-weight: 650;
  pointer-events: none;
  paint-order: stroke;
  stroke: #1d2631;
  stroke-width: 4px;
  stroke-linejoin: round;
}

.scatter-chart .point-label.is-focus {
  fill: #b9d9ff;
  font-weight: 800;
}

.scatter-chart .point-label.is-dense {
  font-size: 12px;
}

.scatter-chart .fit-line {
  stroke: var(--map-magenta);
  stroke-width: 7;
  stroke-linecap: round;
  opacity: 0.88;
}

.model-theil .fit-line,
.model-theil .legend-line {
  stroke: #2dd4bf;
  background: #2dd4bf;
}

.model-huber .fit-line,
.model-huber .legend-line {
  stroke: #f59e0b;
  background: #f59e0b;
}

.scatter-chart .fit-label {
  fill: #f09de9;
  font-weight: 700;
}

.scatter-chart .empty-message {
  fill: var(--map-muted);
  font-size: 16px;
}

.chart-legend {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 18px;
  padding: 10px 18px 15px;
  border-top: 1px solid rgba(83, 97, 113, 0.6);
  color: var(--map-muted);
  font-size: 12px;
}

.regression-interpretation {
  display: grid;
  gap: 6px;
  margin: 0 18px 15px;
  padding: 11px 13px;
  border: 1px solid rgba(83, 97, 113, 0.75);
  border-radius: 8px;
  background: rgba(24, 33, 43, 0.72);
  color: var(--map-muted);
  font-size: 12px;
  line-height: 1.5;
}

.regression-interpretation .n-warning.blocked,
.regression-interpretation .n-warning.red,
.regression-interpretation .loo-instability {
  color: var(--map-bad);
  font-weight: 700;
}

.regression-interpretation .n-warning.yellow {
  color: #ffd166;
  font-weight: 700;
}

.regression-interpretation .regression-caution {
  color: var(--map-muted);
}

.regression-interpretation .loo-stable {
  color: var(--map-good);
  font-weight: 700;
}

.regression-interpretation .filter-change-warning,
.filter-history-notice {
  display: grid;
  gap: 2px;
  color: #ffd166;
}

.filter-history {
  margin: 0 18px 16px;
  border-top: 1px solid rgba(83, 97, 113, 0.6);
  color: var(--map-muted);
  font-size: 12px;
}

.filter-history summary {
  padding: 12px 0 2px;
  cursor: pointer;
  color: var(--map-blue-soft);
  font-weight: 700;
}

.filter-history-notice {
  margin: 8px 0;
  line-height: 1.5;
}

.filter-history-table-wrap {
  overflow-x: auto;
  margin-top: 8px;
}

.filter-history table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.filter-history th,
.filter-history td {
  padding: 8px 10px;
  border-top: 1px solid rgba(83, 97, 113, 0.45);
  text-align: left;
  white-space: nowrap;
}

.filter-history th {
  color: var(--map-muted);
  font-size: 11px;
}

.filter-history th.number,
.filter-history td.number {
  text-align: right;
}

.filter-history .history-p-significant {
  color: var(--map-good);
}

.filter-history .history-p-moderate {
  color: #ffd166;
}

.chart-legend span {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.legend-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border: 1px solid #8dc3ff;
  border-radius: 50%;
  background: var(--map-blue);
}

.legend-line {
  display: inline-block;
  width: 24px;
  height: 4px;
  border-radius: 99px;
  background: var(--map-magenta);
}

.legend-help {
  flex: 1 1 300px;
  justify-content: flex-end;
}

.map-tooltip {
  position: absolute;
  z-index: 3;
  min-width: 205px;
  max-width: 280px;
  padding: 10px 12px;
  border: 1px solid #66798e;
  border-radius: 8px;
  background: rgba(20, 28, 37, 0.97);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
  color: var(--map-text);
  font-size: 12px;
  line-height: 1.55;
  pointer-events: none;
}

.map-tooltip strong {
  display: block;
  margin-bottom: 3px;
  color: var(--map-blue-soft);
  font-size: 14px;
}

.map-tooltip span {
  display: block;
  color: var(--map-muted);
}

.map-tooltip b {
  color: var(--map-text);
}

.map-insights {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
}

.insight-card {
  display: grid;
  gap: 5px;
  padding: 13px 14px;
  border: 1px solid var(--map-line);
  border-radius: 10px;
  background: var(--map-surface);
}

.insight-card span {
  color: var(--map-muted);
  font-size: 12px;
}

.insight-card strong {
  color: var(--map-text);
  font-size: 19px;
}

.r2-card {
  cursor: help;
}

.map-table-wrap {
  overflow-x: auto;
}

.map-table-wrap table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.map-table-wrap th,
.map-table-wrap td {
  padding: 10px 13px;
  border-top: 1px solid rgba(83, 97, 113, 0.58);
  text-align: left;
  white-space: nowrap;
}

.map-table-wrap th {
  color: var(--map-muted);
  font-size: 11px;
  font-weight: 700;
}

.map-table-wrap td.number,
.map-table-wrap th.number {
  text-align: right;
}

.map-table-wrap tbody tr:hover {
  background: rgba(64, 137, 213, 0.1);
}

.map-table-wrap a {
  color: var(--map-blue-soft);
  font-weight: 800;
  text-decoration: none;
}

.map-table-wrap a:hover {
  text-decoration: underline;
}

.relative-expensive {
  color: var(--map-bad);
}

.relative-cheap {
  color: var(--map-good);
}

.empty-cell {
  padding: 24px 13px !important;
  color: var(--map-muted);
  text-align: center !important;
}

@media (max-width: 900px) {
  .map-intro {
    display: grid;
    align-items: start;
  }

  .map-note {
    min-width: 0;
  }

  .map-insights {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .quality-rule-grid {
    grid-template-columns: 1fr;
  }

  .legend-help {
    justify-content: flex-start;
  }
}

@media (max-width: 560px) {
  .map-topbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 12px;
  }

  .map-main {
    width: min(100% - 18px, 1500px);
    padding-top: 18px;
  }

  .map-card-head {
    display: grid;
  }

  .fit-summary {
    text-align: left;
  }

  .fit-result-stack {
    justify-items: start;
  }

  .regression-details summary {
    text-align: left;
  }

  .scatter-chart {
    height: 460px;
  }

  .ticker-basket-head {
    align-items: stretch;
    flex-direction: column;
  }

  .ticker-initial-form {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .ticker-add-form input {
    min-width: 0;
    width: 100%;
  }
}
