:root {
  /* desert southwest: night-adobe ground, sunset terracotta, sand gold */
  --bg: #191009;
  --bg-2: #1f140b;
  --panel: #241710;
  --panel-2: #2c1c12;
  --line: #43301f;
  --line-soft: #362619;
  --ink: #f4ead9;
  --ink-soft: #b39a80;
  --ink-dim: #83685a;
  --accent: #e07a3f;
  --accent-dim: #8a4522;
  --accent-soft: #2a1a10;
  --gold: #e6b866;
  --warn: #e6b866;
  --neg: #c94f38;
  --shadow: 0 1px 0 rgba(255,255,255,.02), 0 10px 30px rgba(0,0,0,.45);
  --radius: 16px;
  color-scheme: dark;
  font-synthesis: none;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(224,122,63,.11), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(230,184,102,.06), transparent 55%),
    var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
  letter-spacing: .01em;
}
h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
a { color: var(--accent); text-decoration: none; }

/* ---- top bar ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
  padding: 16px 28px;
  background: linear-gradient(180deg, rgba(36,23,16,.9), rgba(25,16,9,.65));
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand h1 { font-size: 18px; font-weight: 620; }
.brand .tag { margin: 3px 0 0; font-size: 12.5px; color: var(--ink-soft); max-width: 56ch; }
.mark {
  width: 38px; height: 38px; flex: none; border-radius: 8px; object-fit: contain;
}
.guide-link {
  display: inline-flex; align-items: center; gap: 6px; font-size: 13px;
  padding: 7px 13px; border: 1px solid var(--line); border-radius: 10px;
  color: var(--ink); background: var(--panel);
}
.guide-link:hover { border-color: var(--accent); color: var(--accent); }

/* ---- layout ---- */
.layout {
  display: grid;
  grid-template-columns: 268px minmax(0, 1fr);
  gap: 20px;
  padding: 20px 28px 64px;
  align-items: start;
  max-width: 1480px;
  margin: 0 auto;
}
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .controls { position: static; }
  .topbar { position: static; }
}

.controls {
  position: sticky;
  top: 88px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.ctl label {
  display: block; font-size: 10.5px; text-transform: uppercase;
  letter-spacing: .11em; color: var(--ink-dim); margin-bottom: 10px; font-weight: 600;
}
.btns { display: flex; flex-wrap: wrap; gap: 6px; }
.btns button {
  font: inherit; font-size: 12.5px; border: 1px solid var(--line);
  background: var(--bg-2); color: var(--ink-soft); border-radius: 9px;
  padding: 6px 11px; cursor: pointer; text-align: left; transition: .12s;
}
.btns button:hover { border-color: var(--accent); color: var(--ink); }
.btns button.on {
  background: var(--accent); border-color: var(--accent);
  color: #1f1008; font-weight: 600;
}
select {
  width: 100%; font: inherit; font-size: 13px; padding: 8px 10px;
  border: 1px solid var(--line); border-radius: 9px;
  background: var(--bg-2); color: var(--ink); letter-spacing: normal;
}
select:focus { outline: none; border-color: var(--accent); }
.note {
  font-size: 12px; line-height: 1.55; color: var(--ink-soft);
  border-top: 1px solid var(--line-soft); padding-top: 14px;
}

/* ---- stage ---- */
.stage { display: flex; flex-direction: column; gap: 20px; min-width: 0; }

.badge { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.badge .cell {
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line); border-radius: 14px;
  padding: 13px 15px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; justify-content: flex-start;
}
.badge .k {
  font-size: 10px; text-transform: uppercase; letter-spacing: .09em;
  color: var(--ink-dim); line-height: 1.4; min-height: 28px; font-weight: 600;
}
.badge .v { font-size: 24px; font-weight: 640; letter-spacing: -.01em; color: var(--ink); margin-top: 3px; }
.badge .v.up { color: var(--accent); }
.badge .v.dn { color: var(--neg); }
.badge .u { font-size: 11px; color: var(--ink-dim); margin-top: 2px; }

.chart-card {
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px 14px;
  box-shadow: var(--shadow);
}
.figtitle { font-size: 15px; font-weight: 600; }
.figsub { font-size: 12px; color: var(--ink-soft); margin: 3px 0 10px; }
#main-chart { width: 100%; }

/* ---- table ---- */
.tablewrap { max-height: 420px; overflow: auto; margin-top: 10px; border-radius: 10px; }
table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
th {
  position: sticky; top: 0; background: var(--panel-2);
  font-size: 10px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--ink-dim); text-align: right; padding: 8px 11px;
  border-bottom: 1px solid var(--line);
}
th:first-child, td:first-child { text-align: left; }
td { padding: 6px 11px; border-bottom: 1px solid var(--line-soft); text-align: right; color: var(--ink); }
tbody tr:hover td { background: rgba(224,122,63,.06); }
td.note-td { text-align: left; color: var(--ink-soft); font-size: 11.5px; max-width: 340px; }

/* ---- tooltip ---- */
.tip {
  position: absolute; pointer-events: none; z-index: 30; opacity: 0;
  background: #140c06; color: var(--ink); padding: 9px 11px; border-radius: 9px;
  border: 1px solid var(--line); font-size: 12px; line-height: 1.5; max-width: 280px;
  box-shadow: 0 8px 24px rgba(0,0,0,.6); transition: opacity .08s;
}
.tip b { color: var(--gold); }
.tip i { color: var(--ink-soft); }

footer {
  border-top: 1px solid var(--line);
  margin-top: 8px; padding: 20px 28px 26px;
  font-size: 12px; color: var(--ink-dim); line-height: 1.6;
}
footer a { color: var(--ink-soft); }
footer a:hover { color: var(--accent); }
