/* Tidi DarkLight Mode — switcher (blocco, shortcode, menu, pulsante flottante) */

/* Schema attivo → controlli di sistema (scrollbar, campi) coerenti */
html[data-theme="dark"]  { color-scheme: dark; }
html[data-theme="light"] { color-scheme: light; }

/* Reset deciso: i temi stilano spesso <button> in modo aggressivo */
button.tdl-switch.tdl-switch {
    all: unset;
    box-sizing: border-box;
    display: block;
    cursor: pointer;
    color: inherit;
    font: inherit;
    line-height: 1;
    font-size: var(--tdl-size, 22px);
    -webkit-tap-highlight-color: transparent;
}
button.tdl-switch.tdl-switch:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: 3px;
    border-radius: 999px;
}

/* —— Variante pulsante —— */
button.tdl-switch.tdl-switch.tdl-switch--button {
    transition: background-color .15s ease, border-color .15s ease;
}

/* Icone ed etichette: se ne vede una sola, in base allo schema attivo */
.tdl-switch .tdl-ico,
.tdl-switch .tdl-label { display: none; }
.tdl-switch .tdl-ico { width: 1em; height: 1em; line-height: 1; }
.tdl-switch .tdl-ico svg,
.tdl-switch .tdl-ico img { display: block; width: 1em; height: 1em; }
.tdl-switch .tdl-emoji { font-size: .85em; line-height: 1; }
.tdl-switch .tdl-label { font-size: max(.6em, 14px); font-weight: 500; white-space: nowrap; }

/* "target": icona/etichetta della modalità a cui si passa — "current": di quella attuale */
html[data-theme="light"] .tdl-switch[data-tdl-icons="target"] .tdl-ico--dark,
html[data-theme="dark"]  .tdl-switch[data-tdl-icons="target"] .tdl-ico--light,
html[data-theme="light"] .tdl-switch[data-tdl-icons="current"] .tdl-ico--light,
html[data-theme="dark"]  .tdl-switch[data-tdl-icons="current"] .tdl-ico--dark,
html[data-theme="light"] .tdl-switch[data-tdl-icons="target"] .tdl-label--dark,
html[data-theme="dark"]  .tdl-switch[data-tdl-icons="target"] .tdl-label--light,
html[data-theme="light"] .tdl-switch[data-tdl-icons="current"] .tdl-label--light,
html[data-theme="dark"]  .tdl-switch[data-tdl-icons="current"] .tdl-label--dark { display: inline-block; }
/* prima che lo schema sia noto (nessun JS) */
html:not([data-theme]) .tdl-switch .tdl-ico--dark,
html:not([data-theme]) .tdl-switch .tdl-label--dark { display: inline-block; }

/* —— Variante interruttore (pill) —— */
button.tdl-switch.tdl-switch.tdl-switch--pill { font-size: var(--tdl-size, 22px); }
.tdl-switch--pill .tdl-track {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: space-between;
    box-sizing: border-box;
    width: calc(var(--tdl-size, 22px) * 2.5);
    height: calc(var(--tdl-size, 22px) * 1.3);
    padding: 0 calc(var(--tdl-size, 22px) * .22);
    border-radius: 999px;
    border: 1px solid rgba(127, 127, 127, .4);
    background: rgba(127, 127, 127, .14);
    font-size: calc(var(--tdl-size, 22px) * .68);
}
.tdl-switch--pill .tdl-ico { display: inline-flex; position: relative; z-index: 1; }
.tdl-switch--pill .tdl-thumb {
    position: absolute;
    top: 50%;
    left: calc(var(--tdl-size, 22px) * .1);
    width: calc(var(--tdl-size, 22px) * 1.02);
    height: calc(var(--tdl-size, 22px) * 1.02);
    margin-top: calc(var(--tdl-size, 22px) * -.51);
    border-radius: 50%;
    background: currentColor;
    opacity: .2;
    transition: transform .2s ease;
}
html[data-theme="dark"] .tdl-switch--pill .tdl-thumb {
    transform: translateX(calc(var(--tdl-size, 22px) * 1.28));
}

/* —— Blocco —— */
.tdl-block { display: flex; }
.tdl-block--left   { justify-content: flex-start; }
.tdl-block--center { justify-content: center; }
.tdl-block--right  { justify-content: flex-end; }

/* —— Voce di menu —— */
.menu-item-tdl-switch { display: inline-flex; align-items: center; list-style: none; }

/* —— Pulsante flottante —— */
.tdl-float { position: fixed; z-index: 99990; }
.tdl-float--bottom-right { right: var(--tdl-offset, 20px); bottom: var(--tdl-offset, 20px); }
.tdl-float--bottom-left  { left: var(--tdl-offset, 20px);  bottom: var(--tdl-offset, 20px); }
.tdl-float--top-right    { right: var(--tdl-offset, 20px); top: var(--tdl-offset, 20px); }
.tdl-float--top-left     { left: var(--tdl-offset, 20px);  top: var(--tdl-offset, 20px); }
.tdl-float button.tdl-switch.tdl-switch {
    background: Canvas;
    color: CanvasText;
    border: 1px solid rgba(127, 127, 127, .45);
    box-shadow: 0 2px 10px rgba(0, 0, 0, .18);
}
.tdl-float button.tdl-switch.tdl-switch--pill { padding: .25em; border-radius: 999px; }

@media print { .tdl-float, .tdl-switch { display: none !important; } }
@media (prefers-reduced-motion: reduce) {
    .tdl-switch--pill .tdl-thumb, button.tdl-switch.tdl-switch.tdl-switch--button { transition: none; }
    html.tdl-fade, html.tdl-fade * { transition: none !important; }
}
