/* ---- Themes (readability / contrast focused) ---- */
:root,
:root[data-theme="midnight"] {
  --bg: #0d1117; --panel: #161b22; --panel-2: #1c222b; --grid: #262b36;
  --text: #e6e8ee; --muted: #8b93a7; --accent: #58a6ff;
  --up: #3fb950; --down: #e5534b; --border: #2a313c;
  color-scheme: dark;
}

/* Maximum visibility: near-black with bright, vivid accents */
:root[data-theme="contrast"] {
  --bg: #000000; --panel: #0c0c0c; --panel-2: #161616; --grid: #383838;
  --text: #ffffff; --muted: #b8b8b8; --accent: #4cc2ff;
  --up: #2ee66e; --down: #ff5b5b; --border: #4a4a4a;
  color-scheme: dark;
}

/* Calm dark teal */
:root[data-theme="ocean"] {
  --bg: #0a1e29; --panel: #102a37; --panel-2: #143544; --grid: #1f4a5c;
  --text: #ecf6fa; --muted: #93b6c4; --accent: #38bdf8;
  --up: #34d399; --down: #fb7185; --border: #1d4557;
  color-scheme: dark;
}

/* Clean light, high contrast */
:root[data-theme="light"] {
  --bg: #f4f6f9; --panel: #ffffff; --panel-2: #eef1f5; --grid: #dde2e9;
  --text: #16191d; --muted: #586173; --accent: #0969da;
  --up: #1a7f37; --down: #cf222e; --border: #d3d9e0;
  color-scheme: light;
}

/* Warm light (solarized), low eye strain */
:root[data-theme="solarized"] {
  --bg: #fdf6e3; --panel: #fbf1d6; --panel-2: #f3ead0; --grid: #e6dcc0;
  --text: #08323d; --muted: #5d7079; --accent: #1f72b8;
  --up: #5c7a00; --down: #d33330; --border: #ddd4bd;
  color-scheme: light;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  font-size: 14px;
}

.topbar {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: baseline;
  gap: 14px;
  flex-wrap: wrap;
}
.topbar h1 { margin: 0; font-size: 18px; font-weight: 650; }
.topbar .sub { color: var(--muted); font-size: 12.5px; }
.theme-pick { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.theme-pick label { color: var(--muted); font-size: 12px; }
.theme-pick select { width: auto; padding: 6px 10px; font-size: 12.5px; }

main { padding: 18px 24px 40px; max-width: 1280px; margin: 0 auto; }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 18px;
}
.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.panel-head h2 { margin: 0; font-size: 15px; font-weight: 600; }
.panel-head .hint, .panel-head .legend { color: var(--muted); font-size: 12px; }

.controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px 16px;
  align-items: end;
}
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 11.5px; color: var(--muted); }
.field.btns { flex-direction: row; gap: 8px; align-items: stretch; }

select, input {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 7px;
  padding: 8px 9px;
  font-size: 13px;
  width: 100%;
}
input[type="date"] { color-scheme: dark; }

button {
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 9px 14px;
  font-size: 13px;
  cursor: pointer;
  background: var(--panel-2);
  color: var(--text);
  white-space: nowrap;
}
button.primary { background: var(--accent); border-color: var(--accent); color: #06121f; font-weight: 600; flex: 1; }
button.primary:disabled { opacity: 0.55; cursor: progress; }
button.ghost:hover, button.primary:hover { filter: brightness(1.08); }

.status { min-height: 0; }
.status .bar-wrap {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 16px;
  margin-bottom: 18px;
}
.status .msg { font-size: 13px; margin-bottom: 8px; color: var(--text); }
.status .track { background: var(--panel-2); border-radius: 6px; height: 8px; overflow: hidden; }
.status .fill { background: var(--accent); height: 100%; width: 0%; transition: width 0.15s ease; }
.status .err { color: var(--down); }

.table-scroll { overflow-x: auto; }
table.results { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.results th, table.results td { padding: 8px 10px; text-align: right; white-space: nowrap; }
table.results th {
  position: sticky; top: 0;
  color: var(--muted); font-weight: 600; font-size: 11.5px;
  border-bottom: 1px solid var(--border); background: var(--panel);
  text-align: right;
}
table.results th:first-child, table.results td:first-child { text-align: left; }
table.results td.params { color: var(--muted); font-family: ui-monospace, monospace; font-size: 11px; text-align: left; }
table.results tbody tr { border-bottom: 1px solid var(--grid); cursor: pointer; }
table.results tbody tr:hover { background: var(--panel-2); }
table.results tbody tr.sel { background: rgba(88,166,255,0.12); }

/* Pin # + 전략 columns so metrics map to the strategy name while scrolling */
table.results th.col-rank, table.results td.col-rank {
  position: sticky; left: 0; z-index: 2;
  background: var(--panel);
  width: 30px; min-width: 30px;
}
table.results th.col-name, table.results td.col-name {
  position: sticky; left: 30px; z-index: 2;
  background: var(--panel);
  box-shadow: 1px 0 0 var(--border);
}
table.results thead th.col-rank, table.results thead th.col-name { z-index: 4; }
table.results thead th { z-index: 3; }
/* keep hover / selection visible on the pinned cells (opaque so nothing shows through) */
table.results tbody tr:hover td.col-rank, table.results tbody tr:hover td.col-name { background: var(--panel-2); }
table.results tbody tr.sel td.col-rank, table.results tbody tr.sel td.col-name {
  background: color-mix(in srgb, var(--accent) 14%, var(--panel));
}
table.results tbody tr.bench td.col-rank, table.results tbody tr.bench td.col-name { background: var(--panel); }
table.results tbody tr.bench { color: var(--muted); font-style: italic; cursor: default; }
table.results tbody tr.bench:hover { background: transparent; }
table.results .pos { color: var(--up); }
table.results .neg { color: var(--down); }
table.results .best td { box-shadow: inset 2px 0 0 var(--accent); }
.rank { color: var(--accent); font-weight: 600; }

.metrics { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.metric {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px;
  padding: 9px 13px; min-width: 96px;
}
.metric .k { font-size: 11px; color: var(--muted); }
.metric .v { font-size: 16px; font-weight: 650; margin-top: 2px; }
.metric .v.pos { color: var(--up); }
.metric .v.neg { color: var(--down); }
.metric { cursor: pointer; transition: border-color 0.12s, background 0.12s; }
.metric:hover { border-color: var(--accent); }
.metric.active { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, var(--panel-2)); }
.qmark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 13px; height: 13px; border-radius: 50%;
  border: 1px solid var(--muted); color: var(--muted);
  font-size: 9px; line-height: 1; vertical-align: middle;
}
.metric:hover .qmark, .metric.active .qmark { border-color: var(--accent); color: var(--accent); }
th.th-info { cursor: pointer; }
th.th-info:hover { color: var(--accent); }

.metric-info {
  background: var(--panel-2);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 14px;
}
.metric-info .mi-title { font-size: 13.5px; font-weight: 650; color: var(--text); margin-bottom: 5px; }
.metric-info .mi-body { font-size: 12.5px; color: var(--text); line-height: 1.6; }
.metric-info .mi-good { font-size: 12px; color: var(--accent); margin-top: 7px; font-weight: 600; }

.chart-block { margin-bottom: 16px; }
.chart-label { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.chart-label .leg { margin-left: 10px; }
canvas.chart { width: 100%; height: 220px; display: block; background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; }
canvas.chart.small { height: 150px; }
#ddChart { height: 110px; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
/* allow grid cells to shrink below their content so wide tables/canvases
   scroll inside their card instead of stretching it past the viewport */
.grid2 > *, .chart-block { min-width: 0; }
@media (max-width: 860px) { .grid2 { grid-template-columns: 1fr; } }

.legend { display: flex; gap: 14px; }
.leg { display: inline-flex; align-items: center; gap: 6px; }
.leg i { width: 11px; height: 3px; border-radius: 2px; display: inline-block; }

.heatmap-wrap { overflow-x: auto; }
table.heatmap { border-collapse: collapse; font-size: 10.5px; width: 100%; }
table.heatmap th, table.heatmap td {
  padding: 4px 5px; text-align: right; border: 1px solid var(--bg); white-space: nowrap; min-width: 36px;
}
table.heatmap th { color: var(--muted); font-weight: 500; font-size: 10px; }
table.heatmap td.yr, table.heatmap td.yr-total { font-weight: 600; }
table.heatmap td.yr { text-align: left; color: var(--text); }

/* Pin 연도 + 연간 to the left so they stay visible while months scroll */
table.heatmap th.h-yr, table.heatmap td.yr {
  position: sticky; left: 0; z-index: 2;
  background: var(--panel);
  min-width: 46px; width: 46px;
}
table.heatmap th.h-yrt, table.heatmap td.yr-total {
  position: sticky; left: 46px; z-index: 2;
  min-width: 50px; width: 50px;
  box-shadow: 1px 0 0 var(--border);
}
table.heatmap th.h-yrt { background: var(--panel); }

.foot { padding: 16px 24px; color: var(--muted); font-size: 11.5px; border-top: 1px solid var(--border); }
.foot .warn { color: var(--down); }

/* ---- mobile ---- */
@media (max-width: 600px) {
  main { padding: 14px 12px 32px; }
  .topbar { padding: 12px 14px; gap: 8px; }
  .theme-pick { margin-left: 0; width: 100%; }
  .theme-pick select { flex: 1; }
  .panel { padding: 13px; }
  .controls { grid-template-columns: 1fr 1fr; gap: 11px 12px; }
  .controls .field.btns { grid-column: 1 / -1; }
  /* keep both buttons inside the card */
  .field.btns button { flex: 1 1 0; padding: 10px 6px; min-width: 0; }
  .metric { flex: 1 1 calc(33.333% - 7px); min-width: 0; }
  .panel-head .legend { width: 100%; }
}
@media (max-width: 360px) {
  .controls { grid-template-columns: 1fr; }
}
