/* ============================================================
   Calcolatore RAEE — Frontend Styles
   ============================================================ */

/* ---------- Variabili colore ---------- */
:root {
    --craee-teal-light:  #6ecfcf;
    --craee-teal-mid:    #3aacac;
    --craee-teal-dark:   #1a6e7e;
    --craee-teal-deep:   #0d4a5c;
    --craee-dot-color:   #0d4a5c;
    --craee-box-border:  #c8e8ec;
    --craee-text:        #2a2a2a;
    --craee-text-light:  #7a9faa;
    --craee-circle-size: 260px;
    --craee-arc-size:    900px;  /* cerchio molto più grande → curva gentile */
    --craee-card-size:   80px;
    --craee-radius:      540px;   /* raggio posizionamento card sull'arco */
}

/* ---------- Wrapper generale ---------- */
.craee-wrapper {
    font-family: inherit;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
    width: 100%;
    max-width: 860px;
    margin: 0 auto;
    box-sizing: border-box;
    user-select: none;
    -webkit-user-select: none;
}

/* Reset globale pulsanti: impedisce al tema di sovrascrivere hover/background/border */
.craee-wrapper button {
    -webkit-appearance: none;
    appearance: none;
    font-family: inherit;
    box-sizing: border-box;
    text-decoration: none;
}
.craee-wrapper button:hover,
.craee-wrapper button:active {
    text-decoration: none;
    
    box-shadow: none;   /* verrà ridefinito da regole specifiche */
}
.craee-wrapper button:focus {
    outline: none;  /* accessibilità gestita via :focus-visible nei selettori specifici */
}

/* ---------- Stage (cerchio + box laterali) — 3 colonne uguali ---------- */
.craee-stage {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 20px;
    width: 100%;
}

/* Colonna sinistra: spacer vuoto che bilancia i box a destra */
.craee-spacer {
    /* nessun contenuto, esiste solo per simmetria */
}

/* Cerchio: centrato nella colonna centrale */
.craee-orbit-wrap {
    justify-self: center;
}

/* Box: allineati a sinistra nella colonna destra */
.craee-boxes {
    justify-self: start;
}

/* ---------- Orbit wrap (contiene cerchio + SVG lines) ---------- */
.craee-orbit-wrap {
    position: relative;
    width: var(--craee-circle-size);
    height: var(--craee-circle-size);
    justify-self: center;
}

/* ---------- SVG linee (nascosto finché non è selecting/active) ---------- */
.craee-lines {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: visible;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.4s ease;
}

.craee-dot {
    fill: var(--craee-dot-color);
}

.craee-line {
    stroke: var(--craee-dot-color);
    stroke-width: 1.5;
}

/* ---------- Cerchio principale ---------- */
.craee-circle {
    width: var(--craee-circle-size);
    height: var(--craee-circle-size);
    border-radius: 50%;
    background:
        radial-gradient(circle at 50% 50%, #ffffff 0%, #f0f9fb 60%, #d6f0f4 100%);
    border: none;
    cursor: pointer;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow:
        0 0 0 10px rgba(62, 186, 186, 0.18),
        0 0 0 18px rgba(26, 110, 126, 0.10),
        0 4px 24px rgba(26, 110, 126, 0.15);
    transition: box-shadow 0.3s ease, transform 0.2s ease;
    outline: none;
}

/* Anello teal esterno */
.craee-circle::before {
    content: '';
    position: absolute;
    inset: -12px;
    border-radius: 50%;
    border: 3.5px solid transparent;
    background:
        linear-gradient(white, white) padding-box,
        linear-gradient(135deg, var(--craee-teal-light), var(--craee-teal-dark)) border-box;
}

/* Secondo anello interno sottile */
.craee-circle::after {
    content: '';
    position: absolute;
    inset: 8px;
    border-radius: 50%;
    border: 1.5px solid rgba(110, 207, 207, 0.4);
    pointer-events: none;
}

.craee-circle:hover {
    transform: scale(1.02);
    box-shadow:
        0 0 0 10px rgba(62, 186, 186, 0.25),
        0 0 0 18px rgba(26, 110, 126, 0.14),
        0 6px 30px rgba(26, 110, 126, 0.20);
}

/* Focus ring tastiera (solo keyboard navigation, non su click) */
.craee-circle:focus-visible {
    outline: 3px solid var(--craee-teal-mid);
    outline-offset: 16px;
    border-radius: 50%;
}

/* ---------- Contenuti interni al cerchio ---------- */
.craee-circle-idle,
.craee-circle-selecting,
.craee-circle-active {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
    text-align: center;
    transition: opacity 0.35s ease, transform 0.35s ease;
}

/* Stato idle visibile di default */
.craee-circle-idle       { opacity: 1;  transform: scale(1);    pointer-events: auto; }
.craee-circle-selecting  { opacity: 0;  transform: scale(0.85); pointer-events: none; }
.craee-circle-active     { opacity: 0;  transform: scale(0.85); pointer-events: none; }

[data-phase="selecting"] .craee-circle-idle      { opacity: 0;  transform: scale(0.85); pointer-events: none; }
[data-phase="selecting"] .craee-circle-selecting { opacity: 1;  transform: scale(1);    pointer-events: auto; }
[data-phase="selecting"] .craee-circle-active    { opacity: 0;  transform: scale(0.85); pointer-events: none; }

[data-phase="active"] .craee-circle-idle         { opacity: 0;  transform: scale(0.85); pointer-events: none; }
[data-phase="active"] .craee-circle-selecting    { opacity: 0;  transform: scale(0.85); pointer-events: none; }
[data-phase="active"] .craee-circle-active       { opacity: 1;  transform: scale(1);    pointer-events: auto; }

/* Logo impronta */
.craee-circle-idle img {
    width: 90px;
    height: 90px;
    object-fit: contain;
    border-radius: 50%;
}

/* Testo "Inserisci i tuoi elettrodomestici" */
.craee-circle-selecting span {
    font-size: 1rem;
    color: var(--craee-teal-dark);
    line-height: 1.4;
    font-weight: 500;
}

/* Icona e nome elemento attivo */
.craee-circle-active img {
    padding: 5px;
    border-radius: 12px;
    background: #327C7C;
    width: 72px;
    height: 72px;
    object-fit: contain;
}

.craee-circle-active span {
    font-size: 0.85rem;
    color: var(--craee-teal-dark);
    font-weight: 600;
    margin-top: 4px;
}

/* Pulsanti quantità */
.craee-qty-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
    background: rgba(255,255,255,0.85);
    border: 1.5px solid var(--craee-teal-light);
    border-radius: 30px;
    padding: 3px 12px;
}

.craee-qty-btn {
    background: none;
    border: none;
    font-size: 1.3rem;
    line-height: 1;
    color: var(--craee-teal-dark);
    cursor: pointer;
    padding: 0 2px;
    transition: color 0.2s;
}

.craee-qty-btn:hover         { color: var(--craee-teal-mid); background: none; }
.craee-qty-btn:active        { color: var(--craee-teal-deep); transform: scale(0.88); }
.craee-qty-btn:focus-visible { outline: 2px solid var(--craee-teal-mid); outline-offset: 2px; border-radius: 4px; }

#craee-qty-value {
    font-size: 1rem;
    font-weight: 700;
    min-width: 22px;
    text-align: center;
    color: var(--craee-teal-deep);
}

/* ---------- SVG lines visibili in selecting/active ---------- */
[data-phase="selecting"] .craee-lines,
[data-phase="active"]    .craee-lines {
    opacity: 1;
}

/* ---------- Tre box laterali ---------- */
.craee-boxes {
    display: flex;
    flex-direction: column;
    gap: 14px;
    opacity: 0;
    transition: opacity 0.4s ease 0.1s;
    pointer-events: none;
    min-width: 160px;
}

[data-phase="selecting"] .craee-boxes,
[data-phase="active"]    .craee-boxes {
    opacity: 1;
    pointer-events: auto;
}

.craee-box {
    border: 1.5px solid var(--craee-box-border);
    border-radius: 14px;
    padding: 10px 18px;
    background: #ffffff;
    box-shadow: 0 2px 10px rgba(26, 110, 126, 0.07);
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 130px;
    gap: 2px;
}

.craee-box-label {
    font-size: 0.72rem;
    color: var(--craee-text-light);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    text-align: center;
}

.craee-box-value {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--craee-teal-deep);
    line-height: 1.1;
}

.craee-box-unit {
    font-size: 0.75rem;
    color: var(--craee-text-light);
}

/* ---------- Arc wrapper (mezzaluna) ---------- */
.craee-arc-wrapper {
    position: relative;
    width: 100%;                 /* si adatta alla larghezza del widget */
    overflow: hidden;            /* nasconde i lati del grande cerchio */
    /*
     * Mostra circa 1/3 del cerchio (arco ~120°) invece della mezzaluna.
     * Formula: R*(1-cos(55°)) + card_half + buffer
     *        = 540*0.426    + 40       + 60   ≈ 330px → arrotondato a 360px
     * Usando la variabile: arc_size/4 ≈ R/2 → leggermente generoso per includere le card
     */
    height: calc( var(--craee-arc-size) / 4 + 60px );
    margin-top: 30px;           /* lieve sovrapposizione con il cerchio principale */
    display: flex;
    align-items: flex-start;
    justify-content: center;
    /* Fade ai bordi sinistro e destro: le card entrano/escono dall'arco in dissolvenza */
    -webkit-mask-image: linear-gradient(to right, transparent 0%, black 10%, black 90%, transparent 100%);
    mask-image:         linear-gradient(to right, transparent 0%, black 10%, black 90%, transparent 100%);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease 0.2s;
}

[data-phase="selecting"] .craee-arc-wrapper,
[data-phase="active"]    .craee-arc-wrapper {
    opacity: 1;
    pointer-events: auto;
}

/* Il tracciato circolare su cui vengono posizionati gli item */
.craee-arc-track {
    position: absolute;
    width: var(--craee-arc-size);
    height: var(--craee-arc-size);
    top: 50%;
    left: 50%;
    transform: translateX(-50%);
    /* Bordo mezzaluna teal */
    border-radius: 50%;
    border: 2.5px solid transparent;
    background:
        linear-gradient(white, white) padding-box,
        linear-gradient(180deg, var(--craee-teal-light) 0%, var(--craee-teal-dark) 100%) border-box;
    box-shadow: 0 -4px 20px rgba(26, 110, 126, 0.10);
    /* La rotazione del tracciato anima tutte le card lungo la curvatura del cerchio */
    transition: none;
    cursor: grab;
    user-select: none;
}
.craee-arc-track.is-dragging {
    cursor: grabbing;
}

/* ---------- Card elemento (generate da JS) ---------- */
.craee-item-card {
    position: absolute;
    width: var(--craee-card-size);
    height: var(--craee-card-size);
    border-radius: 18px;
    background: #327C7C;
    border: 1.5px solid var(--craee-box-border);
    box-shadow: 0 2px 10px rgba(26,110,126,0.10);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    will-change: transform, opacity;   /* mantiene il layer GPU anche quando opacity=0 */
    transition:
        scale      0.25s ease,          /* selezione item: gestita da CSS */
        opacity    0.35s ease,
        box-shadow 0.2s ease,
        border-color 0.2s ease;
    /* transform viene impostato da JS (animazione angolare) */
    top: 50%;
    left: 50%;
    margin-top: calc( var(--craee-card-size) / -2 );
    margin-left: calc( var(--craee-card-size) / -2 );
}

.craee-item-card img {
    width: 48px;
    height: 48px;
    object-fit: contain;
    pointer-events: none;
}

.craee-card-label {
    position: absolute;
    top: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    white-space: nowrap;
    max-width: calc(var(--craee-card-size) + 24px);
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 10px;
    font-weight: 600;
    line-height: 1.2;
    color: var(--craee-teal-dark);
    text-align: center;
    pointer-events: none;
    user-select: none;
}

.craee-item-card:focus, .craee-item-card:focus-visible {
    box-shadow: 0 4px 18px rgba(26,110,126,0.20);
    border-color: var(--craee-teal-mid);
    background: #327C7C;        /* blocca eventuale background hover del tema */
    text-decoration: none;
}
.craee-item-card:hover {
    box-shadow: 0 4px 18px rgba(26,110,126,0.20);
    border-color: var(--craee-teal-mid);
    background: #327C7C;        /* blocca eventuale background hover del tema */
    text-decoration: none;
}
.craee-item-card:active {
    box-shadow: 0 1px 6px rgba(26,110,126,0.15);
    border-color: var(--craee-teal-dark);
    background: #327C7C;
}
.craee-item-card:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px var(--craee-teal-mid), 0 2px 10px rgba(26,110,126,0.10);
}

.craee-item-card.is-selected {
    border-color: var(--craee-teal-dark);
    box-shadow: 0 4px 20px rgba(26,110,126,0.28);
    background: linear-gradient(135deg, #96cdcd, #327C7C);
    /* scale: 1.12;   CSS scale property — non interferisce con il transform JS */
    /* Il transform (posizione sull'arco) è gestito interamente da JS */
}

.craee-item-card.is-out-of-view {
    opacity: 0;
    pointer-events: none;
}

/* Teletrasporto circolare: nessuna transizione durante il riposizionamento invisibile */
.craee-item-card.craee-teleport {
    transition: none !important;
}

/* Cloni per scroll infinito: non interattivi, visivi solo */
.craee-item-card.craee-arc-clone {
    pointer-events: none;
}

/* ---------- Frecce navigazione arc ---------- */
.craee-arc-nav {
    position: absolute;
    bottom: 8px;
    background: none;
    border: none;
    font-size: 2rem;
    color: var(--craee-teal-dark);
    cursor: pointer;
    line-height: 1;
    padding: 4px 12px;
    z-index: 10;
    transition: color 0.2s, transform 0.15s;
}

.craee-arc-nav:hover         { color: var(--craee-teal-mid); transform: scale(1.15); background: rgba(255,255,255,0.95); }
.craee-arc-nav:active        { color: var(--craee-teal-dark); transform: scale(0.93); background: rgba(110,207,207,0.15); }
.craee-arc-nav:focus-visible { outline: 2px solid var(--craee-teal-mid); outline-offset: 3px; border-radius: 50%; }
.craee-arc-prev { left: calc(50% - 80px); }
.craee-arc-next { right: calc(50% - 80px); }

/* ---------- Responsive mobile ---------- */
@media (max-width: 767px) {
    :root {
        --craee-circle-size: 200px;
        --craee-arc-size:    700px;  /* cerchio grande ridotto per mobile */
        --craee-radius:      315px;
        --craee-card-size:   64px;
    }

    .craee-stage {
        grid-template-columns: 1fr;
        justify-items: center;
    }

    /* Nasconde lo spacer: su mobile non serve la simmetria */
    .craee-spacer { display: none; }

    .craee-boxes {
        justify-self: center;
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
        min-width: unset;
    }

    /* Rende i box in riga su mobile */
    .craee-boxes {
        display: flex;
    }

    .craee-box {
        min-width: 100px;
    }

    /* Nasconde SVG lines su mobile (non hanno senso senza i box a lato) */
    .craee-lines { display: none; }
}
