/* =========================================================
   DESIGN TOKENS (light/dark via data-theme)
   - stesso schema degli altri progetti
   ========================================================= */
: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);
    --axis: rgba(15, 23, 42, 0.35);
    --svg-bg: radial-gradient(circle, #e2e8f0 0%, #cbd5e1 60%, #94a3b8 90%);
    --tooltip-bg: rgba(15, 23, 42, 0.92);
}

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);
    --axis: rgba(203, 213, 225, 0.25);
    --svg-bg: radial-gradient(circle, #020617 0%, #020617 60%, #000 90%);
    --tooltip-bg: rgba(15, 23, 42, 0.92);
}

/* =========================================================
   BASE LAYOUT
   ========================================================= */
* {
    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
   ========================================================= */
.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
   ========================================================= */
#container {
    background: var(--panel);
    backdrop-filter: blur(14px);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 1rem 1.5rem 1rem;
    box-shadow: var(--shadow);
    max-width: 1250px;
    width: 100%;
    margin: 1.2rem;
    position: relative;
}

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

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

/* =========================================================
   SVG / CHART
   ========================================================= */
svg {
    border-radius: 16px;
    width: 100%;
    height: auto;
}

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

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

/* =========================================================
   CELLE HEATMAP
   ========================================================= */
.cell {
    stroke: rgba(15, 23, 42, 0.04);
    stroke-width: 0.5px;
    transition: 0.1s ease-out;
    cursor: pointer;
}

.cell:hover {
    stroke: rgba(15, 23, 42, 0.7);
    stroke-width: 1.1px;
}

/* =========================================================
   TOOLTIP
   ========================================================= */
#tooltip {
    position: absolute;
    background: var(--tooltip-bg);
    color: #e2e8f0;
    padding: 0.55rem 0.7rem 0.45rem;
    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: 140px;
}

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

/* =========================================================
   LEGENDA
   ========================================================= */
#legend {
    width: 100%;
    display: block;
    color: var(--text);
}

#legend svg {
    width: 100%;
    height: 60px;
    display: block;
}

.legend-title {
    font-weight: 600;
    margin-right: 0.8rem;
}

.legend-scale {
    display: flex;
    gap: 0.55rem;
    flex-wrap: wrap;
}

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

.legend-swatch {
    width: 16px;
    height: 12px;
    border-radius: 3px;
    border: 1px solid rgba(15, 23, 42, 0.15);
}

/* =========================================================
   RESPONSIVE
   ========================================================= */
@media (max-width: 1050px) {
    #container {
        margin: 0.4rem;
    }
}

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

    #description {
        font-size: 0.7rem;
    }

    #legend {
        width: 100%;
    }
}