:root {
  --bg:      #0d1117;
  --bg-card: #161b22;
  --bg-row:  #0d1117;
  --bg-alt:  #111820;
  --bg-hover:#1c2128;
  --border:  #30363d;
  --text:    #e6edf3;
  --muted:   #8b949e;
  --accent:  #58a6ff;
  --green:   #3fb950;
  --purple:  #bc8cff;
  --red:     #f85149;
  --yellow:  #e3b341;
  --header-h: 65px;
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  min-height: 100vh;
  font-size: 14px;
}

/* ── HEADER ── */
header {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 20;
}
.header-left h1 { font-size: 1.25rem; font-weight: 700; letter-spacing: -.02em; }
.header-left h1 span { color: var(--accent); }
.header-left p { font-size: .72rem; color: var(--muted); margin-top: 1px; }
.header-right { display: flex; align-items: center; gap: 8px; }

/* toggle */
.toggle-wrap {
  display: flex; align-items: center; gap: 7px;
  font-size: .78rem; color: var(--muted); cursor: pointer;
  padding: 5px 11px; border: 1px solid var(--border); border-radius: 6px;
  transition: background .15s; user-select: none;
}
.toggle-wrap:hover { background: var(--bg-hover); }
.toggle-wrap.active { border-color: var(--green); color: var(--green); background: rgba(63,185,80,.08); }
.toggle-dot {
  width: 28px; height: 16px; background: var(--border); border-radius: 8px;
  position: relative; transition: background .2s; flex-shrink: 0;
}
.toggle-dot::after {
  content: ''; position: absolute; left: 2px; top: 2px;
  width: 12px; height: 12px; border-radius: 50%; background: var(--muted);
  transition: left .2s, background .2s;
}
.toggle-wrap.active .toggle-dot { background: rgba(63,185,80,.3); }
.toggle-wrap.active .toggle-dot::after { left: 14px; background: var(--green); }

button.icon-btn {
  background: transparent; border: 1px solid var(--border); color: var(--text);
  padding: 5px 12px; border-radius: 6px; cursor: pointer;
  font-size: .78rem; display: flex; align-items: center; gap: 5px;
  transition: background .15s, border-color .15s;
}
button.icon-btn:hover { background: var(--bg-hover); border-color: var(--muted); }
button.icon-btn:disabled { opacity: .4; cursor: default; }

.hdr-select {
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 5px 10px; font-size: .78rem; cursor: pointer;
  transition: border-color .15s, background .15s;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%238b949e'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 9px center;
  padding-right: 26px;
}
.hdr-select:hover { border-color: var(--muted); background-color: var(--bg-hover); }
.hdr-select:focus { outline: none; border-color: var(--accent); }

/* ── LAYOUT ── */
main { padding: 20px 24px; }
#status { font-size: .72rem; color: var(--muted); margin-bottom: 14px; min-height: 16px; }

/* ── LOADING / ERROR ── */
#loading {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; padding: 80px 0; gap: 14px;
  color: var(--muted); font-size: .88rem;
}
.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

#error-box {
  display: none;
  background: rgba(248,81,73,.1); border: 1px solid var(--red);
  border-radius: 8px; padding: 12px 16px; color: var(--red);
  font-size: .85rem; margin-bottom: 16px;
}

/* ── TABLE ── */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
}

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

/* header */
thead tr {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
}
thead th {
  padding: 10px 14px;
  text-align: left;
  font-size: .72rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  white-space: nowrap;
  position: sticky;
  /* NOTE: should be commented out always
  top: var(--header-h);
  */
  background: var(--bg-card);
  z-index: 5;
  border-bottom: 1px solid var(--border);
}
thead th.sortable {
  cursor: pointer;
  user-select: none;
}
thead th.sortable:hover { color: var(--text); }
thead th.sorted { color: var(--accent); }
.sort-arrow { margin-left: 4px; font-size: .65rem; opacity: .7; }

/* rows */
tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background .1s;
}
tbody tr:last-child { border-bottom: none; }
tbody tr:nth-child(odd)  { background: var(--bg-row); }
tbody tr:nth-child(even) { background: var(--bg-alt); }
tbody tr:hover { background: var(--bg-hover); }
tbody tr.is-new { background: rgba(63,185,80,.04); }
tbody tr.is-new:hover { background: rgba(63,185,80,.08); }
tbody tr.row-hidden { display: none; }

tbody td {
  padding: 10px 14px;
  vertical-align: middle;
  font-size: .82rem;
}

/* rank col */
.col-rank { width: 48px; text-align: center; color: var(--muted); font-weight: 600; font-size: .8rem; }

/* game col */
.col-game { min-width: 200px; }
.game-cell { display: flex; align-items: center; gap: 10px; }
.row-icon, .row-icon-ph {
  width: 38px; height: 38px; border-radius: 9px; flex-shrink: 0;
  border: 1px solid var(--border);
}
.row-icon { object-fit: cover; display: block; background: var(--bg-hover); }
.row-icon-ph {
  background: var(--bg-hover);
  display: flex; align-items: center; justify-content: center; font-size: 1.1rem;
}
.game-info { min-width: 0; }
.game-title {
  font-weight: 600; font-size: .85rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 200px;
}
.game-publisher {
  font-size: .75rem; color: var(--muted); margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 200px;
}
.game-badges { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 3px; }
.badge {
  display: inline-flex; align-items: center;
  font-size: .63rem; font-weight: 600; padding: 1px 5px; border-radius: 3px;
}
.badge-new   { background: rgba(63,185,80,.15);   color: var(--green); }
.badge-genre { background: rgba(139,148,158,.12); color: var(--muted); }

/* publisher col */
.col-publisher { display: none; }

/* category col */
.col-category { min-width: 120px; color: var(--muted); font-size: .78rem; }

/* downloads col */
.col-downloads { min-width: 120px; }
.dl-badge {
  display: inline-flex; align-items: center; gap: 3px;
  background: rgba(63,185,80,.12); color: var(--green);
  font-size: .72rem; font-weight: 600; padding: 2px 7px; border-radius: 20px;
}

/* date cols */
.col-release, .col-updated { min-width: 105px; color: var(--muted); }

/* rating col */
.col-rating { width: 80px; text-align: center; }
.rating-val    { color: var(--yellow); font-weight: 600; font-size: .82rem; }
.downloads-val { color: var(--muted);  font-size: .82rem; }

/* section headings (new-entries page) */
.section-heading {
  font-size: .82rem; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .06em;
  margin: 24px 0 8px; display: flex; align-items: center; gap: 8px;
}
.section-count {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 10px; padding: 1px 7px; font-size: .72rem; color: var(--text);
}

/* header nav */
.header-nav { display: flex; gap: 10px; margin-top: 6px; }
.nav-link {
  font-size: .75rem; color: var(--muted); text-decoration: none;
  padding: 3px 8px; border: 1px solid var(--border); border-radius: 5px;
  transition: color .15s, border-color .15s;
}
.nav-link:hover { color: var(--text); border-color: var(--muted); }
.nav-link.active { color: var(--accent); border-color: var(--accent); }

/* rank delta */
.col-rank { white-space: nowrap; }
.rank-num { font-weight: 600; }
.rank-delta { display: inline-block; margin-left: 4px; font-size: .68rem; font-weight: 600; }
.delta-up   { color: var(--green); }
.delta-down { color: var(--red); }
.delta-flat { color: var(--border); }
.delta-new  {
  color: var(--accent); background: rgba(88,166,255,.12);
  border: 1px solid rgba(88,166,255,.3); border-radius: 3px;
  padding: 1px 4px; font-size: .6rem; letter-spacing: .03em;
}

/* new chart entry row */
tbody tr.is-chart-new { background: rgba(88,166,255,.05); }
tbody tr.is-chart-new:hover { background: rgba(88,166,255,.10); }

/* similar col */
.col-similar { width: 80px; }
.similar-btn {
  color: var(--muted); border-color: var(--border);
  background: transparent; font-size: .68rem;
}
.similar-btn:hover { color: var(--text); border-color: var(--muted); background: var(--bg-hover); }

/* trend col */
.col-trend { width: 100px; }
.sparkline-wrap {
  display: flex; align-items: center; gap: 6px;
}
.sparkline {
  display: block; overflow: visible;
}
.sparkline-line {
  fill: none; stroke: var(--accent); stroke-width: 1.5;
  stroke-linecap: round; stroke-linejoin: round;
}
.sparkline-area {
  fill: url(#spark-grad); opacity: .35;
}
.spark-dot {
  fill: var(--accent);
}
.spark-no-data {
  font-size: .72rem; color: var(--border);
}

/* links col */
.col-links { min-width: 210px; }
.links-cell { display: flex; gap: 5px; flex-wrap: wrap; }
.link-btn {
  display: inline-flex; align-items: center; gap: 3px;
  text-decoration: none; font-size: .68rem; font-weight: 500;
  padding: 3px 8px; border-radius: 4px;
  transition: background .15s; border: 1px solid; white-space: nowrap;
}
.link-btn.appmagic  { color: var(--purple); border-color: rgba(188,140,255,.35); background: rgba(188,140,255,.08); }
.link-btn.appmagic:hover  { background: rgba(188,140,255,.2); }
.link-btn.playstore { color: var(--green);  border-color: rgba(63,185,80,.35);   background: rgba(63,185,80,.08); }
.link-btn.playstore:hover { background: rgba(63,185,80,.2); }
/* placeholder pulse */
.loading-val { color: var(--border); animation: pulse 1.5s ease-in-out infinite; }
@keyframes pulse { 0%,100%{opacity:.4} 50%{opacity:1} }

@media (max-width: 600px) {
  header { padding: 10px 12px; flex-wrap: wrap; }
  main { padding: 14px 8px; }
}
