/* ==========================================================================
   TOKENS
   ========================================================================== */

:root {
  color-scheme: light;
  --bg: #f4f4f1;
  --surface-1: #fcfcfb;
  --surface-2: #f0efeb;
  --border: #e2e1dc;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #7a7974;
  --accent: #2a78d6;
  --accent-soft: #e3eefb;
  --accent-ink: #ffffff;
  --series-1: #2a78d6;
  --grid: #e9e8e3;
  --good: #1a7f37;
  --warning: #9a6700;
  --critical: #cf222e;
  --gold: #d4a72c;
  --silver: #a3acb6;
  --bronze: #c07a45;
  --shadow: 0 1px 2px rgb(0 0 0 / .04), 0 4px 16px rgb(0 0 0 / .05);
  --ticker-bg: #0b0b0b;
  --ticker-text: #f0efec;
  --ticker-muted: #9a998f;
  --ticker-tag-bg: #2e2e2b;
  --radius: 14px;
  --font: "Inter", system-ui, -apple-system, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111110;
    --surface-1: #1a1a19;
    --surface-2: #232321;
    --border: #2e2e2b;
    --text-primary: #f0efec;
    --text-secondary: #c3c2b7;
    --text-muted: #8f8e86;
    --accent: #3987e5;
    --accent-soft: #1b2a3d;
    --series-1: #3987e5;
    --grid: #2a2a27;
    --good: #3fb950;
    --warning: #d29922;
    --critical: #f85149;
    --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 6px 20px rgb(0 0 0 / .25);
    --ticker-bg: #0a0a09;
    --ticker-tag-bg: #262624;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111110;
  --surface-1: #1a1a19;
  --surface-2: #232321;
  --border: #2e2e2b;
  --text-primary: #f0efec;
  --text-secondary: #c3c2b7;
  --text-muted: #8f8e86;
  --accent: #3987e5;
  --accent-soft: #1b2a3d;
  --series-1: #3987e5;
  --grid: #2a2a27;
  --good: #3fb950;
  --warning: #d29922;
  --critical: #f85149;
  --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 6px 20px rgb(0 0 0 / .25);
  --ticker-bg: #0a0a09;
  --ticker-tag-bg: #262624;
}

/* ==========================================================================
   BASE
   ========================================================================== */

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text-primary);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ==========================================================================
   TOPBAR
   ========================================================================== */

.masthead { position: sticky; top: 0; z-index: 10; }

.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 10px 28px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 10px; color: var(--accent); }
.brand h1 { font-size: 16px; color: var(--text-primary); letter-spacing: -0.02em; }

.segmented {
  display: inline-flex; padding: 2px; gap: 2px;
  background: var(--surface-2); border-radius: 9px;
  margin-left: auto;
}
.segmented button {
  border: 0; background: transparent; padding: 5px 12px; border-radius: 7px;
  color: var(--text-muted); font-size: 13px; font-weight: 500; transition: background .15s, color .15s;
}
.segmented button:hover { color: var(--text-primary); }
.segmented button[aria-selected="true"] { background: var(--surface-1); color: var(--text-primary); }

.actions { display: flex; align-items: center; gap: 4px; }

.icon-btn {
  display: inline-grid; place-items: center; width: 32px; height: 32px;
  border: 0; background: transparent; border-radius: 8px;
  color: var(--text-muted);
}
.icon-btn:hover { color: var(--text-primary); background: var(--surface-2); }

.ghost-btn {
  padding: 6px 12px; border-radius: 8px; border: 1px solid var(--border);
  background: transparent; color: var(--text-secondary); font-size: 12px; font-weight: 500;
}
.ghost-btn:hover { color: var(--text-primary); border-color: var(--text-muted); }

.btn-primary {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 8px 14px; border: 0; border-radius: 9px;
  background: var(--accent); color: var(--accent-ink); font-weight: 600;
  text-decoration: none; transition: filter .15s;
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-block { width: 100%; padding: 11px; margin-top: 8px; }

/* ==========================================================================
   TICKER NOTIZIE
   ========================================================================== */

.ticker {
  display: flex; align-items: stretch; height: 34px; overflow: hidden;
  background: var(--ticker-bg); color: var(--ticker-text);
  font-size: 13px;
}
.ticker-label {
  display: inline-flex; align-items: center; gap: 7px; flex: none;
  padding: 0 22px 0 28px; font-weight: 700; letter-spacing: .08em; font-size: 11px;
  background: var(--critical); color: #fff;
  clip-path: polygon(0 0, 100% 0, calc(100% - 10px) 100%, 0 100%);
}
.live-dot { width: 7px; height: 7px; border-radius: 50%; background: #fff; animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .3; } }

.ticker-track {
  position: relative; flex: 1; overflow: hidden; display: flex; align-items: center;
  mask-image: linear-gradient(90deg, transparent, #000 32px, #000 calc(100% - 32px), transparent);
}
.ticker-content {
  display: flex; align-items: center; white-space: nowrap; width: max-content;
  animation: ticker var(--ticker-duration, 60s) linear infinite;
}
.ticker:hover .ticker-content, .ticker:focus-within .ticker-content { animation-play-state: paused; }
@keyframes ticker { to { transform: translateX(-50%); } }

.ticker-item {
  display: inline-flex; align-items: center; gap: 8px; padding: 0 22px;
  text-decoration: none; color: inherit; position: relative;
}
.ticker-item + .ticker-item::before {
  content: ""; position: absolute; left: 0; width: 4px; height: 4px; border-radius: 50%;
  background: var(--ticker-muted);
}
a.ticker-item:hover .ticker-title { text-decoration: underline; }
.ticker-tag {
  font-size: 10px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  padding: 2px 6px; border-radius: 4px; background: var(--ticker-tag-bg); color: var(--ticker-text);
}
.ticker-meta { color: var(--ticker-muted); font-family: var(--mono); font-size: 12px; }
.ticker-item--muted { color: var(--ticker-muted); }

/* ==========================================================================
   LAYOUT
   ========================================================================== */

.container { max-width: 1320px; margin: 0 auto; padding: 28px 28px 64px; }

.intro { margin-bottom: 28px; }
.intro-text { margin: 0 0 10px; color: var(--text-secondary); font-size: 15px; line-height: 1.6; text-wrap: pretty; }
.intro-text strong { color: var(--text-primary); }
.intro-facts {
  display: flex; flex-wrap: wrap; gap: 6px 20px; margin: 0; padding: 0; list-style: none;
  font-size: 12px; color: var(--text-muted);
}
.intro-facts li { display: inline-flex; align-items: center; gap: 7px; }
.intro-facts li::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: var(--accent); }

.overview {
  display: flex; align-items: baseline; justify-content: space-between; gap: 8px 24px; flex-wrap: wrap;
  margin-bottom: 18px; padding-top: 18px; border-top: 1px solid var(--border);
}
.overview-text { margin: 0; color: var(--text-secondary); font-size: 14px; }
.overview-text strong { color: var(--text-primary); font-weight: 600; font-variant-numeric: tabular-nums; }
.overview-text a { color: var(--text-primary); font-weight: 500; text-decoration: none; border-bottom: 1px solid var(--border); }
.overview-text a:hover { border-color: var(--accent); }
.muted { color: var(--text-muted); font-family: var(--mono); font-size: 12px; }

.status-line {
  display: inline-flex; align-items: center; gap: 6px; margin: 0;
  color: var(--text-muted); font-size: 12px; white-space: nowrap;
}
.status-line:empty { display: none; }
.status-line::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--text-muted); }
.status-line[data-source="database"]::before { background: var(--good); }
.status-line[data-source="live"]::before { background: var(--accent); }
.status-line[data-source="snapshot"]::before { background: var(--warning); }
.status-line[data-source="none"]::before { background: var(--critical); }

.layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 36px; align-items: start; }
.side { display: flex; flex-direction: column; gap: 24px; position: sticky; top: 108px; }

.chart-box { position: relative; height: 220px; }

/* ==========================================================================
   TOOLBAR & FILTRI
   ========================================================================== */

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }

.search {
  flex: 1 1 260px; display: flex; align-items: center; gap: 8px;
  padding: 0 12px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 10px; color: var(--text-muted);
}
.search:focus-within { border-color: var(--accent); }
.search input { flex: 1; min-width: 0; border: 0; background: transparent; padding: 9px 0; outline: none; color: var(--text-primary); }

select {
  padding: 8px 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface-2);
}

.view-toggle { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.view-toggle button { border: 0; background: var(--surface-2); padding: 0 12px; color: var(--text-muted); font-size: 16px; }
.view-toggle button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 500;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text-secondary);
  transition: border-color .15s, background .15s;
}
.chip:hover { border-color: var(--text-muted); }
.chip[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--text-primary); }
.chip .count { color: var(--text-muted); font-family: var(--mono); font-size: 11px; }

.lang-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; box-shadow: 0 0 0 1px rgb(0 0 0 / .12) inset; }

/* ==========================================================================
   CARD REPOSITORY
   ========================================================================== */

.repo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }

.repo-card {
  position: relative; display: flex; flex-direction: column; gap: 10px;
  padding: 16px; text-align: left; width: 100%;
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px;
  transition: border-color .15s;
}
.repo-card:hover { border-color: var(--text-muted); }

.repo-head { display: flex; align-items: center; gap: 10px; min-width: 0; }
.repo-head img { width: 32px; height: 32px; border-radius: 8px; background: var(--surface-2); flex: none; }
.repo-title { min-width: 0; }
.repo-owner { font-size: 12px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.repo-name { font-weight: 600; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank { margin-left: auto; font-family: var(--mono); font-size: 12px; color: var(--text-muted); }
.out-tag {
  margin-left: auto; flex: none; padding: 1px 7px; border-radius: 999px;
  font-size: 11px; color: var(--text-muted); border: 1px solid var(--border);
}
td .out-tag { margin-left: 6px; }

.repo-desc {
  margin: 0; color: var(--text-secondary); font-size: 13px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  min-height: 2.9em;
}

.gain { display: flex; align-items: baseline; gap: 6px; }
.gain strong { font-family: var(--mono); font-size: 22px; font-weight: 500; }
.gain span { font-size: 12px; color: var(--text-muted); }

.repo-meta { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12px; color: var(--text-secondary); }
.repo-meta span { display: inline-flex; align-items: center; gap: 5px; }
.repo-meta svg { color: var(--text-muted); }

/* ==========================================================================
   TABELLA
   ========================================================================== */

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { font-size: 12px; font-weight: 500; color: var(--text-muted); }
td.num, th.num { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--surface-2); }

/* ==========================================================================
   HALL OF FAME
   ========================================================================== */

.hof-card {
  padding: 18px 16px 12px; border-radius: var(--radius);
  background:
    radial-gradient(120% 70% at 50% 0%, color-mix(in srgb, var(--gold) 16%, transparent), transparent 70%),
    var(--surface-1);
  border: 1px solid var(--border);
}
.hof-head { text-align: center; margin-bottom: 16px; }
.hof-head h2 { font-size: 15px; }
.hof-head p { margin: 2px 0 0; font-size: 12px; color: var(--text-muted); }

.podium { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: end; gap: 6px; }
.podium-step {
  --c: var(--bronze);
  display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 0;
  padding: 0; border: 0; background: none; text-align: center;
}
.podium-step--1 { --c: var(--gold); }
.podium-step--2 { --c: var(--silver); }
.podium-avatar { position: relative; display: block; }
.podium-avatar img {
  display: block; width: 48px; height: 48px; border-radius: 50%;
  background: var(--surface-2); box-shadow: 0 0 0 3px var(--c);
  transition: transform .2s;
}
.podium-step--1 .podium-avatar img { width: 62px; height: 62px; }
.podium-step:hover .podium-avatar img { transform: translateY(-3px) scale(1.04); }
.podium-medal { position: absolute; right: -6px; bottom: -4px; font-size: 18px; line-height: 1; }
.podium-name {
  max-width: 100%; margin-top: 6px; font-size: 12px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.podium-days { font-size: 11px; color: var(--text-muted); }
.podium-days strong { color: var(--text-primary); font-family: var(--mono); font-weight: 500; }
.podium-block {
  display: grid; place-items: center; width: 100%; margin-top: 6px;
  border-radius: 8px 8px 0 0; font-family: var(--mono); font-size: 18px; font-weight: 500;
  color: var(--c);
  background: linear-gradient(180deg, color-mix(in srgb, var(--c) 28%, transparent), color-mix(in srgb, var(--c) 6%, transparent));
}
.podium-step--1 .podium-block { height: 64px; }
.podium-step--2 .podium-block { height: 46px; }
.podium-step--3 .podium-block { height: 34px; }

.hof { list-style: none; margin: 12px 0 0; padding: 8px 0 0; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 2px; }
.hof li {
  display: grid; grid-template-columns: 16px 26px minmax(0, 1fr) auto; align-items: center; gap: 10px;
  padding: 6px; border-radius: 8px; cursor: pointer;
}
.hof li:hover { background: var(--surface-2); }
.hof .pos { font-family: var(--mono); font-size: 12px; color: var(--text-muted); text-align: right; }
.hof img { width: 26px; height: 26px; border-radius: 50%; background: var(--surface-2); }
.hof .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; font-size: 13px; line-height: 1.25; }
.hof .name small { display: block; font-weight: 400; font-size: 11px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; }
.hof .days { font-family: var(--mono); font-size: 12px; color: var(--text-secondary); }

.empty { color: var(--text-muted); font-size: 13px; text-align: center; padding: 24px 8px; margin: 0; }

/* ==========================================================================
   GRAFICO DI CRESCITA
   ========================================================================== */

.growth { margin-top: 56px; padding-top: 28px; border-top: 1px solid var(--border); }
.growth-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.growth-head h2 { font-size: 18px; }
.growth-sub { margin: 2px 0 0; font-size: 13px; color: var(--text-muted); }
.growth-chart { position: relative; height: 380px; }

.growth-legend {
  display: flex; flex-wrap: wrap; gap: 8px; margin: 18px 0 0; padding: 0; list-style: none;
}
.growth-legend button {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 4px 10px 4px 4px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface-1); font-size: 12px;
}
.growth-legend button:hover { border-color: var(--c); }
.growth-legend img { width: 22px; height: 22px; border-radius: 50%; box-shadow: 0 0 0 2px var(--c); background: var(--surface-2); }
.growth-name { font-weight: 500; }
.growth-gain { font-family: var(--mono); color: var(--text-muted); }

/* ==========================================================================
   SKELETON
   ========================================================================== */

.skeleton {
  height: 160px; border-radius: 12px;
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--border) 50%, var(--surface-2) 75%);
  background-size: 200% 100%; animation: shimmer 1.2s infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* ==========================================================================
   DRAWER
   ========================================================================== */

.drawer {
  margin: 0 0 0 auto; height: 100vh; max-height: 100vh; width: min(480px, 100vw);
  padding: 0; border: 0; border-left: 1px solid var(--border);
  background: var(--surface-1); color: var(--text-primary);
}
.drawer[open] { animation: slide .25s ease; }
.drawer::backdrop { background: rgb(0 0 0 / .35); backdrop-filter: blur(2px); }
@keyframes slide { from { transform: translateX(40px); opacity: 0; } }

.drawer-inner { position: relative; padding: 28px 24px; display: flex; flex-direction: column; gap: 18px; }
.drawer-close { position: absolute; top: 16px; right: 16px; }
.drawer-head { display: flex; gap: 14px; align-items: center; padding-right: 40px; }
.drawer-head img { border-radius: 12px; background: var(--surface-2); }
.drawer-head h2 { font-size: 20px; word-break: break-word; }
.drawer-owner { margin: 0; color: var(--text-muted); font-size: 13px; }
.drawer-desc { margin: 0; color: var(--text-secondary); }
.drawer-stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.drawer-stats div { padding: 12px; background: var(--surface-2); border-radius: 10px; }
.drawer-stats span { display: block; font-size: 12px; color: var(--text-muted); }
.drawer-stats strong { font-family: var(--mono); font-size: 18px; font-weight: 500; }
.drawer-section h3 { font-size: 13px; color: var(--text-secondary); margin-bottom: 10px; }

/* ==========================================================================
   SPAZIO SPONSOR
   ========================================================================== */

.ad-slot:empty { display: none; }

.ad {
  position: relative; display: flex; flex-direction: column; gap: 4px;
  padding: 0 4px; color: var(--text-muted); font-size: 12px;
}
.ad-label { font-size: 10px; letter-spacing: .06em; text-transform: uppercase; }
.ad-close {
  position: absolute; top: -4px; right: 0; width: 20px; height: 20px;
  border: 0; border-radius: 5px; background: transparent; color: var(--text-muted); font-size: 11px;
  opacity: 0; transition: opacity .15s;
}
.ad:hover .ad-close, .ad-close:focus-visible { opacity: 1; }
.ad-close:hover { background: var(--surface-2); color: var(--text-primary); }
.ad img { width: 40px; height: 40px; border-radius: 8px; object-fit: cover; }
.ad-title { display: block; font-weight: 500; font-size: 13px; color: var(--text-secondary); text-decoration: none; }
.ad-title:hover { color: var(--text-primary); }
.ad-text { display: block; }
.ad-cta { color: var(--accent); text-decoration: none; font-weight: 500; }

/* ==========================================================================
   RIASSUNTO README
   ========================================================================== */

.summary { padding: 16px; border-radius: 12px; background: var(--accent-soft); }
.summary-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.summary-head h3 { font-size: 13px; }
.summary-badge { font-size: 11px; font-weight: 600; color: var(--accent); white-space: nowrap; }
.summary p { margin: 0 0 10px; color: var(--text-secondary); }
.summary ul { margin: 0 0 10px; padding-left: 18px; color: var(--text-secondary); }
.summary li { margin-bottom: 4px; }
.summary-foot { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; font-size: 12px; color: var(--text-muted); }
.summary-foot a { color: var(--accent); text-decoration: none; font-weight: 500; }
.summary-line {
  height: 12px; margin-bottom: 8px; border-radius: 6px;
  background: linear-gradient(90deg, var(--surface-1) 25%, var(--border) 50%, var(--surface-1) 75%);
  background-size: 200% 100%; animation: shimmer 1.2s infinite;
}

/* ==========================================================================
   TOAST
   ========================================================================== */

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px);
  padding: 10px 16px; border-radius: 10px; max-width: calc(100vw - 32px);
  background: var(--text-primary); color: var(--surface-1); font-weight: 500;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ==========================================================================
   RESPONSIVE
   ========================================================================== */

@media (max-width: 1000px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .side { position: static; max-width: 420px; }
}

@media (max-width: 720px) {
  .ticker-label { padding-left: 16px; }
  .topbar { padding: 10px 16px; gap: 8px; flex-wrap: wrap; }
  .segmented { margin-left: 0; order: 3; width: 100%; }
  .segmented button { flex: 1; }
  .actions { margin-left: auto; }
  .container { padding: 20px 16px 48px; }
  .intro-text { font-size: 14px; }
  .repo-grid { grid-template-columns: minmax(0, 1fr); }
  .side { max-width: none; }
  .growth-head { flex-direction: column; align-items: flex-start; }
  .growth-chart { height: 300px; }
}

@media (prefers-reduced-motion: reduce) {
  .ticker-track { overflow-x: auto; mask-image: none; }
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
