:root {
  --bg: #0F172A;
  --bg-raised: #1E293B;
  --bg-muted: #272F42;
  --fg: #F8FAFC;
  --fg-dim: #94A3B8;
  --border: #334155;
  --accent: #22C55E;
  --accent-dim: #166534;
  --destructive: #EF4444;
  --ring: #22C55E;
  --radius: 12px;
  --font-ui: "Fira Sans", system-ui, sans-serif;
  --font-mono: "Fira Code", ui-monospace, monospace;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.85);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(8px);
}

.brand { display: flex; align-items: center; gap: 10px; }

.brand-mark {
  width: 14px;
  height: 22px;
  border-radius: 3px;
  background: linear-gradient(180deg, var(--accent), var(--accent-dim));
  box-shadow: 0 0 12px rgba(34, 197, 94, 0.5);
}

.brand-name { font-family: var(--font-mono); font-weight: 700; font-size: 18px; letter-spacing: 0.5px; }
.brand-accent { color: var(--accent); }

.status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--fg-dim);
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--fg-dim);
  transition: background 0.3s ease;
}
.dot.ok { background: var(--accent); box-shadow: 0 0 8px rgba(34, 197, 94, 0.6); }
.dot.err { background: var(--destructive); }

.container { max-width: 1080px; margin: 0 auto; padding: 32px 24px 64px; }

.hero h1 {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: clamp(24px, 4vw, 34px);
  margin: 0 0 8px;
  text-shadow: 0 0 24px rgba(34, 197, 94, 0.25);
}

.hero p { color: var(--fg-dim); margin: 0 0 28px; max-width: 60ch; }

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: flex-end;
  margin-bottom: 16px;
}

.search-box {
  flex: 1 1 40px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  color: var(--fg-dim);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.search-box:focus-within {
  border-color: var(--ring);
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.15);
}

.search-box input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--fg);
  font-family: var(--font-ui);
  font-size: 15px;
}

.search-box input::placeholder { color: var(--fg-dim); }

.filter-group { display: flex; flex-direction: column; gap: 6px; }

.filter-group label {
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--fg-dim);
}

select {
  appearance: none;
  background: var(--bg-raised) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394A3B8' stroke-width='2' stroke-linecap='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E") no-repeat right 12px center;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--fg);
  font-family: var(--font-ui);
  font-size: 14px;
  padding: 10px 36px 10px 14px;
  cursor: pointer;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

select:focus {
  outline: none;
  border-color: var(--ring);
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.15);
}

.result-meta {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--fg-dim);
  margin-bottom: 10px;
}

.table-wrap {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
}

table { width: 100%; border-collapse: collapse; }

thead th {
  text-align: left;
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--fg-dim);
  font-weight: 600;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-muted);
  white-space: nowrap;
}

thead th.col-num, thead th.col-score, thead th.col-avail { text-align: right; }

tbody tr {
  cursor: pointer;
  border-bottom: 1px solid rgba(51, 65, 85, 0.5);
  transition: background 0.15s ease;
}
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--bg-muted); }
tbody tr.selected { background: rgba(34, 197, 94, 0.08); box-shadow: inset 3px 0 0 var(--accent); }

td { padding: 13px 16px; font-family: var(--font-mono); font-size: 13.5px; }

td.col-num, td.col-score, td.col-avail { text-align: right; white-space: nowrap; }

td.col-gpu { font-family: var(--font-ui); font-weight: 500; }

.tier-pill {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.03em;
  color: var(--fg-dim);
  background: var(--bg-muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 8px;
  margin-left: 8px;
  vertical-align: 1px;
}

.price { font-weight: 600; }
.price.up { color: var(--destructive); }
.price.down { color: var(--accent); }
.price-flat { color: var(--fg-dim); }

.avail-0 { color: var(--destructive); }

.stars { color: var(--accent); font-size: 13px; letter-spacing: 1px; white-space: nowrap; }
.stars .off { color: var(--bg-muted); }

.empty {
  padding: 48px 24px;
  text-align: center;
  color: var(--fg-dim);
  font-family: var(--font-mono);
}

.chart-panel {
  margin-top: 24px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.chart-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.chart-head h2 {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 600;
}

.icon-btn {
  background: var(--bg-muted);
  border: 1px solid var(--border);
  color: var(--fg-dim);
  border-radius: 8px;
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: color 0.2s ease, border-color 0.2s ease;
}
.icon-btn:hover { color: var(--fg); border-color: var(--fg-dim); }

.chart-body { display: grid; grid-template-columns: 1fr 220px; gap: 20px; padding: 20px; }

#chart { width: 100%; height: 240px; position: relative; }

#trendCanvas { width: 100%; height: 100%; display: block; }

.chart-tip {
  position: absolute;
  z-index: 5;
  transform: translate(-50%, -135%);
  background: var(--bg-muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px 7px;
  font-family: var(--font-mono);
  text-align: center;
  pointer-events: none;
  white-space: nowrap;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
}
.chart-tip.flip { transform: translate(-50%, 24px); }
.chart-tip .chart-tip-date { color: var(--fg-dim); font-size: 10.5px; }
.chart-tip .chart-tip-price { color: var(--accent); font-weight: 700; font-size: 13.5px; }
.chart-tip[hidden] { display: none; }

.chart-stats { display: flex; flex-direction: column; gap: 10px; }

.stat { padding: 12px; background: var(--bg-muted); border-radius: 10px; }

.stat .k {
  font-family: var(--font-mono);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--fg-dim);
}

.stat .v { font-family: var(--font-mono); font-size: 18px; font-weight: 700; margin-top: 2px; }

.stat-hover { border: 1px solid rgba(34, 197, 94, 0.35); box-shadow: inset 3px 0 0 var(--accent); }
.stat-hover .v { color: var(--accent); }
.stat-hover[hidden] { display: none; }

.footer {
  padding: 20px 24px 32px;
  text-align: center;
  color: var(--fg-dim);
  font-size: 12.5px;
}

.footer p { margin: 0; }

@media (max-width: 860px) {
  .chart-body { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
  .container { padding: 16px 12px 40px; }
  .topbar { padding: 12px 14px; }
  .brand-name { font-size: 16px; }

  .controls { flex-direction: column; align-items: stretch; gap: 12px; }
  .filter-group { flex-direction: row; align-items: center; justify-content: space-between; gap: 10px; }
  .search-box { padding: 9px 14px; }
  select { padding: 9px 36px 9px 12px; font-size: 16px; }
  .search-box input { font-size: 16px; }

  .table-wrap { overflow: visible; background: transparent; border: none; }

  table, thead, tbody, tr, td { display: block; }
  thead { display: none; }

  table { width: 100%; min-width: 0; }
  tbody { display: flex; flex-direction: column; gap: 10px; }

  tbody tr {
    background: var(--bg-raised);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 4px 14px 8px;
    cursor: pointer;
    -webkit-tap-highlight-color: rgba(34, 197, 94, 0.15);
  }
  tbody tr:hover { background: var(--bg-muted); }
  tbody tr.selected {
    background: rgba(34, 197, 94, 0.08);
    box-shadow: inset 3px 0 0 var(--accent);
  }

  tbody tr td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 9px 0;
    font-size: 13.5px;
    text-align: right;
  }
  tbody tr td + td { border-top: 1px solid rgba(51, 65, 85, 0.4); }

  tbody tr td::before {
    content: attr(data-label);
    font-family: var(--font-mono);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--fg-dim);
    white-space: nowrap;
  }
  tbody tr td.col-gpu::before { display: none; }

  td.col-gpu {
    font-family: var(--font-ui);
    font-size: 15px;
    font-weight: 600;
    padding: 12px 0 6px;
    white-space: normal;
  }
  .tier-pill { display: inline-block; margin-left: 8px; }

  .hero p { font-size: 14px; }

  .chart-head { padding: 12px 14px; }
  .chart-body { padding: 14px; }
  #chart { height: 200px; }
  .chart-stats {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }
  .stat { padding: 10px 12px; }
  .stat .v { font-size: 16px; }

  .empty { padding: 32px 16px; }
  .footer { padding: 16px 16px 28px; }
}

@media (max-width: 380px) {
  .filter-group { flex-direction: column; align-items: stretch; gap: 4px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
