:root {
  --bg: #f3f6f8;
  --surface: #ffffff;
  --surface-strong: #eef3f5;
  --ink: #1c2630;
  --muted: #66737f;
  --line: #d8e1e5;
  --teal: #0d7f72;
  --teal-soft: #d9f1ec;
  --amber: #b66b00;
  --amber-soft: #fff0d4;
  --red: #b12d3b;
  --blue: #276f9f;
  --shadow: 0 18px 50px rgba(28, 38, 48, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
  font-family:
    "Inter",
    "Pretendard",
    "Noto Sans KR",
    "Segoe UI",
    Arial,
    sans-serif;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  width: min(1480px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 44px;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--teal);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

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

h2 {
  font-size: 19px;
}

.status-stack {
  display: flex;
  align-items: flex-end;
  flex-direction: column;
  gap: 8px;
  min-width: 170px;
}

.mode-badge {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--surface-strong);
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.mode-badge.live {
  background: var(--teal-soft);
  color: var(--teal);
}

.mode-badge.static {
  background: var(--teal-soft);
  color: var(--teal);
}

.mode-badge.web {
  background: #e1edf7;
  color: var(--blue);
}

.mode-badge.demo {
  background: var(--amber-soft);
  color: var(--amber);
}

.updated-at {
  color: var(--muted);
  font-size: 13px;
  text-align: right;
}

.rank-switch,
.control-panel,
.summary-grid,
.visual-section,
.company-detail,
.table-section {
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.rank-switch {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
  padding: 8px;
  border-radius: 8px;
}

.rank-tab {
  min-height: 48px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 900;
  cursor: pointer;
}

.rank-tab:hover {
  background: #f8fbfa;
  color: var(--ink);
}

.rank-tab.active {
  border-color: rgba(13, 127, 114, 0.28);
  background: var(--teal-soft);
  color: var(--teal);
}

.control-panel {
  display: grid;
  grid-template-columns: 150px minmax(220px, 1fr) minmax(220px, 320px) auto auto;
  gap: 12px;
  align-items: end;
  padding: 16px;
  border-radius: 8px;
}

.control-panel label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.control-panel input,
.control-panel select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 0 12px;
}

.control-panel input:focus,
.control-panel select:focus,
.rank-tab:focus-visible,
#refreshButton:focus-visible {
  border-color: var(--teal);
  outline: 3px solid rgba(13, 127, 114, 0.16);
}

.range-control strong {
  color: var(--ink);
}

input[type="range"] {
  padding: 0;
  accent-color: var(--teal);
}

#refreshButton {
  min-height: 42px;
  border: 0;
  border-radius: 6px;
  background: var(--ink);
  color: #fff;
  padding: 0 18px;
  font-weight: 800;
  cursor: pointer;
}

#refreshButton:disabled {
  cursor: wait;
  opacity: 0.62;
}

.switch {
  display: inline-flex !important;
  grid-auto-flow: column;
  align-items: center;
  justify-content: center;
  gap: 8px !important;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink) !important;
  white-space: nowrap;
}

.switch input {
  width: 18px;
  min-height: 18px;
  accent-color: var(--teal);
}

.notice {
  margin-top: 14px;
  padding: 12px 14px;
  border: 1px solid #ecd39c;
  border-radius: 8px;
  background: var(--amber-soft);
  color: #6f4200;
  font-size: 14px;
}

.hidden {
  display: none;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  margin-top: 16px;
  overflow: hidden;
  border-radius: 8px;
  background: var(--line);
}

.metric {
  min-height: 128px;
  padding: 20px;
  background: var(--surface);
}

.metric span,
.metric small {
  display: block;
  color: var(--muted);
}

.metric span {
  font-size: 13px;
  font-weight: 800;
}

.metric strong {
  display: block;
  margin: 14px 0 8px;
  overflow-wrap: anywhere;
  font-size: clamp(22px, 2.5vw, 34px);
  line-height: 1.08;
}

.metric small {
  font-size: 13px;
}

.visual-section,
.company-detail,
.table-section {
  margin-top: 16px;
  overflow: hidden;
  border-radius: 8px;
}

.company-detail {
  background: #fbfdfd;
}

.detail-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 68px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}

.detail-heading h2 {
  margin-bottom: 6px;
}

.detail-heading span {
  color: var(--muted);
  font-size: 13px;
}

#detailClose {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}

.history-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  background: var(--line);
}

.history-chart {
  min-width: 0;
  padding: 16px;
  background: #fff;
}

.line-chart-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.line-chart-head strong {
  font-size: 14px;
}

.line-chart-head span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  text-align: right;
}

.line-chart-svg {
  display: block;
  width: 100%;
  height: auto;
}

.line-chart-svg .axis {
  stroke: var(--line);
  stroke-width: 1;
}

.line-chart-svg .axis-label {
  fill: var(--muted);
  font-size: 12px;
}

.line-chart-svg .axis-label.end {
  text-anchor: end;
}

.line-chart-svg .line {
  fill: none;
  stroke: var(--teal);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 4;
}

.line-chart-svg.profit .line {
  stroke: var(--blue);
}

.line-chart-svg.market .line {
  stroke: #7a5a00;
}

.line-chart-svg.price .line {
  stroke: #6b5fb5;
}

.line-chart-svg .dot {
  fill: #fff;
  stroke: var(--teal);
  stroke-width: 3;
}

.line-chart-svg.profit .dot {
  stroke: var(--blue);
}

.line-chart-svg.market .dot {
  stroke: #7a5a00;
}

.line-chart-svg.price .dot {
  stroke: #6b5fb5;
}

@media (max-width: 1280px) {
  .history-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.empty-chart {
  min-height: 180px;
  display: grid;
  place-items: center;
  color: var(--muted);
  background: var(--surface-strong);
  border-radius: 6px;
  font-size: 13px;
}

.detail-table-wrap {
  border-top: 1px solid var(--line);
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 58px;
  padding: 0 18px;
  border-bottom: 1px solid var(--line);
}

.section-heading span {
  color: var(--muted);
  font-size: 13px;
}

.bar-chart {
  display: grid;
  gap: 12px;
  padding: 18px;
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(120px, 210px) minmax(120px, 1fr) minmax(118px, 170px);
  align-items: center;
  gap: 14px;
}

.bar-name {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.bar-name strong {
  overflow: hidden;
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar-name span,
.bar-value {
  color: var(--muted);
  font-size: 12px;
}

.bar-track {
  position: relative;
  height: 16px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-strong);
}

.bar-fill {
  height: 100%;
  min-width: 3px;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--teal), var(--blue));
}

.bar-fill.loss {
  background: var(--red);
}

.bar-value {
  text-align: right;
}

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

table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
}

th,
td {
  padding: 15px 18px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  background: #f8fafb;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

td {
  font-size: 14px;
}

tbody tr:hover {
  background: #f7fbfa;
}

.clickable-row {
  cursor: pointer;
}

.clickable-row.selected-row,
.clickable-row.selected-row:hover {
  background: var(--teal-soft);
}

.company-detail-row,
.company-detail-row:hover {
  background: #fbfdfd;
}

.company-detail-row > td {
  padding: 0;
  border-bottom: 1px solid var(--line);
}

.company-detail-row .company-detail {
  margin-top: 0;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

.rank {
  color: var(--teal);
  font-weight: 900;
}

.company-cell {
  display: grid;
  gap: 4px;
}

.company-cell strong {
  font-size: 15px;
}

.company-cell span,
.basis-cell,
.muted {
  color: var(--muted);
  font-size: 12px;
}

.numeric {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.payout {
  color: var(--teal);
  font-weight: 900;
}

.loss-text {
  color: var(--red);
}

.source-link {
  color: var(--blue);
  font-weight: 800;
  text-decoration: none;
}

.source-link:hover {
  text-decoration: underline;
}

.empty-row td {
  padding: 34px 18px;
  color: var(--muted);
  text-align: center;
}

.site-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-top: 18px;
  color: var(--muted);
  font-size: 13px;
}

.footer-copy {
  display: grid;
  gap: 6px;
}

.site-footer nav {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: flex-end;
}

.site-footer a,
.legal-page a {
  color: var(--blue);
  font-weight: 800;
  text-decoration: none;
}

.site-footer a:hover,
.legal-page a:hover {
  text-decoration: underline;
}

.legal-page {
  max-width: 860px;
  padding-top: 44px;
}

.legal-page h1 {
  margin: 22px 0 18px;
  font-size: clamp(30px, 5vw, 44px);
}

.legal-page h2 {
  margin: 26px 0 10px;
  color: var(--ink);
  font-size: 20px;
}

.legal-page p {
  margin: 0 0 16px;
  color: #34424f;
  font-size: 16px;
  line-height: 1.75;
}

.legal-page code {
  padding: 2px 6px;
  border-radius: 6px;
  background: #edf4f6;
  color: var(--ink);
  font-size: 0.92em;
}

.legal-list {
  display: grid;
  gap: 9px;
  margin: 0 0 18px 20px;
  padding: 0;
  color: #34424f;
  font-size: 16px;
  line-height: 1.65;
}

.contact-list {
  display: grid;
  gap: 12px;
  margin: 8px 0 22px;
}

.contact-list div {
  display: grid;
  gap: 4px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.contact-list dt {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.contact-list dd {
  margin: 0;
  font-size: 17px;
}

.back-link {
  display: inline-flex;
  margin-bottom: 10px;
}

@media (max-width: 1080px) {
  .control-panel {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

@media (max-width: 720px) {
  .app-shell {
    width: min(100% - 20px, 1480px);
    padding-top: 18px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .status-stack {
    align-items: flex-start;
  }

  .rank-switch,
  .control-panel,
  .summary-grid {
    grid-template-columns: 1fr;
  }

  .metric {
    min-height: 112px;
  }

  .section-heading {
    align-items: flex-start;
    flex-direction: column;
    justify-content: center;
    padding: 12px 14px;
  }

  .bar-row {
    grid-template-columns: 1fr;
    gap: 7px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--line);
  }

  .history-grid {
    grid-template-columns: 1fr;
  }

  .company-detail-row .company-detail {
    width: min(100%, calc(100vw - 20px));
  }

  .detail-heading {
    align-items: flex-start;
    padding: 12px 14px;
  }

  .detail-heading h2 {
    font-size: 18px;
  }

  .history-chart {
    padding: 14px;
  }

  .bar-value {
    text-align: left;
  }

  .site-footer {
    align-items: flex-start;
    flex-direction: column;
  }

  .site-footer nav {
    justify-content: flex-start;
  }
}
