/* =========================================================
   DESIGN TOKENS (light/dark via data-theme)
   - stessi nomi del progetto precedente
   - aggiunti i token per i puntini (doping / clean)
   ========================================================= */
:root {
    --bg: radial-gradient(circle at top, #f1f5f9 0%, #cbd5e1 70%);
    --panel: rgba(255, 255, 255, 0.35);
    --text: #0f172a;
    --muted: #475569;
    --border: rgba(148, 163, 184, 0.4);
    --shadow: 0 20px 40px rgba(15, 23, 42, 0.25);
    --accent: #0f766e;
    --axis: rgba(15, 23, 42, 0.35);
    --svg-bg: radial-gradient(circle, #e2e8f0 0%, #cbd5e1 60%, #94a3b8 90%);
    --dot-clean: #0ea5e9;
    --dot-doping: #e11d48;
    --dot-hover: #fbbf24;
}

/* =========================================================
   TEMA SCURO
   ========================================================= */
body[data-theme="dark"] {
    --bg: radial-gradient(circle at top, #1f2937 0%, #020617 70%);
    --panel: rgba(2, 6, 23, 0.4);
    --text: #e2e8f0;
    --muted: #94a3b8;
    --border: rgba(148, 163, 184, 0.2);
    --shadow: 0 20px 40px rgba(0, 0, 0, 0.35);
    --accent: #38bdf8;
    --axis: rgba(203, 213, 225, 0.25);
    --svg-bg: radial-gradient(circle, #020617 0%, #020617 60%, #000 90%);
    --dot-clean: #38bdf8;
    --dot-doping: #f43f5e;
}

/* =========================================================
   BASE LAYOUT
   - rimuove scroll
   - centra la card
   ========================================================= */
* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    height: 100%;
    overflow: hidden;
}

body {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
        sans-serif;
    color: var(--text);
    transition: background 0.25s ease, color 0.25s ease;
    min-height: 100vh;
}

/* =========================================================
   TOGGLE TEMA
   - fisso in alto a destra
   - feedback hover
   ========================================================= */
.theme-icon {
    position: fixed;
    top: 14px;
    right: 18px;
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
    user-select: none;
    color: var(--text);
    opacity: 0.75;
    z-index: 50;
    transition: transform 0.1s ease, opacity 0.2s ease;
}

.theme-icon:hover {
    opacity: 1;
    transform: scale(1.1);
}

/* =========================================================
   CONTAINER PRINCIPALE
   - effetto glass
   - width max
   ========================================================= */
#container {
    background: var(--panel);
    backdrop-filter: blur(14px);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 1rem 1.5rem 0.8rem;
    box-shadow: var(--shadow);
    max-width: 1150px;
    width: 100%;
    margin: 1.2rem;
    position: relative;
}

#title {
    text-align: center;
    font-size: 1.45rem;
    margin-bottom: 0.4rem;
    letter-spacing: 0.02em;
}

#subtitle {
    text-align: center;
    font-size: 0.8rem;
    color: var(--muted);
    margin-bottom: 1rem;
}

/* =========================================================
   AREA SVG
   ========================================================= */
svg {
    background: var(--svg-bg);
    border-radius: 16px;
    width: 100%;
    height: auto;
}

/* =========================================================
   ASSI D3
   ========================================================= */
.axis text {
    fill: var(--text);
    opacity: 0.7;
    font-size: 0.6rem;
}

.axis path,
.axis line {
    stroke: var(--axis);
}

/* Label verticale asse Y */
.y-label {
    fill: var(--text);
    opacity: 0.8;
    font-size: 0.8rem;
    letter-spacing: 0.02em;
}

/* =========================================================
   PUNTI DELLO SCATTER
   ========================================================= */
.dot {
    stroke: rgba(15, 23, 42, 0.35);
    stroke-width: 1px;
    opacity: 0.9;
    cursor: pointer;
    transition: 0.12s ease-out;
}

.dot:hover {
    stroke: rgba(15, 23, 42, 0.9);
    stroke-width: 1.8px;
}

/* =========================================================
   TOOLTIP ASSOLUTO
   - posizionato via JS
   - contrastato per leggibilità
   ========================================================= */
#tooltip {
    position: absolute;
    background: rgba(15, 23, 42, 0.92);
    color: #e2e8f0;
    padding: 0.5rem 0.65rem 0.4rem;
    border-radius: 8px;
    pointer-events: none;
    font-size: 0.7rem;
    line-height: 1.2;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.04);
    opacity: 0;
    transition: opacity 0.1s ease-out;
    z-index: 9999;
    min-width: 150px;
}

#tooltip strong {
    display: block;
    margin-bottom: 2px;
}

/* =========================================================
   LEGENDA
   - due item affiancati
   - usa i colori dei token
   ========================================================= */
#legend {
    position: absolute;
    top: 48px;
    right: 28px;
    background: rgba(15, 23, 42, 0.04);
    border: 1px solid rgba(148, 163, 184, 0.25);
    border-radius: 12px;
    padding: 0.35rem 0.5rem;
    font-size: 0.65rem;
    backdrop-filter: blur(6px);
    display: flex;
    gap: 0.45rem;
    align-items: center;
    color: var(--text);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.legend-swatch {
    width: 10px;
    height: 10px;
    border-radius: 999px;
}

/* =========================================================
   RESPONSIVE
   ========================================================= */
@media (max-width: 950px) {
    #container {
        width: 100%;
        margin: 0.4rem;
        border-radius: 16px;
    }

    /* legenda va sotto al grafico */
    #legend {
        position: static;
        margin-top: 0.6rem;
    }
}

@media (max-width: 540px) {
    #container {
        padding: 0.7rem 0.6rem 0.6rem;
    }
}