/* ========================================
   LIXORIUM — Configuratore Pozioni
   Mobile-first, zero dependencies
   ======================================== */

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    /* Brand palette */
    --sfondo: #F4F0E8;
    --testo: #1A2332;
    --testo-primario: #4A4438;
    --testo-titolo: #2A2520;
    --testo-secondario: #8A7F6E;
    --linea: #D8D0C0;
    --linea-leggera: #C8C0AE;

    /* Serie */
    --arcana: #5A7A4A;
    --ludibria: #8A7040;
    --fabulae: #6A5E8A;

    /* State (updated by JS) */
    --base-colore: #AAAAAA;
    --riflesso-colore: transparent;

    /* Typography */
    --font-display: 'Cinzel Decorative', serif;
    --font-heading: 'Cinzel', serif;
    --font-body: 'Crimson Pro', serif;

    /* Layout */
    --padding: 1.25rem;
    --max-width: 480px;
    --radius: 8px;
    --transition: 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font-body);
    background-color: var(--sfondo);
    color: var(--testo-primario);
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ========================================
   TYPOGRAPHY
   ======================================== */

h1 {
    font-family: var(--font-display);
    font-weight: 700;
    color: var(--testo);
    font-size: 2rem;
    line-height: 1.25;
    letter-spacing: 0.02em;
}

h2 {
    font-family: var(--font-display);
    font-weight: 400;
    color: var(--testo);
    font-size: 1.2rem;
    letter-spacing: 0.02em;
}

/* ========================================
   HEADER
   ======================================== */

#header {
    padding: 0.9rem var(--padding);
    text-align: center;
    border-bottom: 1px solid var(--linea);
    background: var(--sfondo);
    position: sticky;
    top: 0;
    z-index: 50;
}

.brand {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.brand-fox {
    width: 28px;
    height: 28px;
    object-fit: contain;
}

.brand-text {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.brand-name {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1rem;
    color: var(--testo);
    letter-spacing: 0.18em;
}

.brand-sub {
    font-family: var(--font-heading);
    font-size: 0.58rem;
    color: var(--testo-secondario);
    letter-spacing: 0.22em;
    text-transform: uppercase;
    margin-top: 0.1rem;
}

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

main {
    flex: 1;
    display: flex;
    flex-direction: column;
    max-width: var(--max-width);
    margin: 0 auto;
    width: 100%;
}

/* ========================================
   SCREENS
   ======================================== */

.screen {
    display: none;
    flex-direction: column;
    padding: var(--padding);
    animation: fadeIn 0.5s ease;
}

.screen.active {
    display: flex;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ========================================
   INTRO
   ======================================== */

#intro {
    justify-content: center;
    align-items: center;
    text-align: center;
    min-height: 75vh;
}

.intro-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.8rem;
}

/* Ornament divider */
.ornament {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    padding: 0.3rem 0;
}

.ornament::before,
.ornament::after {
    content: '';
    width: 32px;
    height: 1px;
    background: var(--linea);
}

.ornament span {
    display: block;
    width: 5px;
    height: 5px;
    background: var(--linea);
    transform: rotate(45deg);
}

.tagline {
    font-family: var(--font-body);
    font-style: italic;
    font-size: 1.05rem;
    color: var(--testo-secondario);
    font-weight: 300;
}

.intro-desc {
    font-size: 0.95rem;
    color: var(--testo-primario);
    line-height: 1.65;
    max-width: 280px;
}

/* ========================================
   BUTTONS
   ======================================== */

.btn-primary {
    font-family: var(--font-heading);
    font-size: 0.8rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    padding: 0.85rem 2.2rem;
    background: var(--testo);
    color: var(--sfondo);
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.3s ease;
    -webkit-tap-highlight-color: transparent;
}

.btn-primary:hover {
    background: var(--testo-primario);
}

.btn-primary:active {
    transform: scale(0.97);
}

.btn-primary:disabled {
    opacity: 0.35;
    cursor: not-allowed;
    transform: none;
}

.btn-secondary {
    font-family: var(--font-heading);
    font-size: 0.75rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    padding: 0.7rem 1.5rem;
    background: transparent;
    color: var(--testo);
    border: 1.5px solid var(--linea);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.3s ease;
    -webkit-tap-highlight-color: transparent;
}

.btn-secondary:hover {
    border-color: var(--testo-secondario);
}

.btn-secondary:active {
    transform: scale(0.97);
}

.btn-secondary:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.btn-small {
    padding: 0.65rem 1.1rem;
    font-size: 0.7rem;
}

/* ========================================
   PROGRESS INDICATOR
   ======================================== */

#progress {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.5rem 0 0.2rem;
    flex-shrink: 0;
}

.progress-step {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
}

.step-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    border: 1.5px solid var(--linea);
    background: transparent;
    transition: all var(--transition);
}

.progress-step.active .step-dot {
    background: var(--testo);
    border-color: var(--testo);
}

.progress-step.completed .step-dot {
    background: var(--arcana);
    border-color: var(--arcana);
}

.step-label {
    font-family: var(--font-heading);
    font-size: 0.55rem;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--testo-secondario);
    transition: color var(--transition);
}

.progress-step.active .step-label,
.progress-step.completed .step-label {
    color: var(--testo);
}

.progress-line {
    width: 36px;
    height: 1px;
    background: var(--linea);
    margin-bottom: 1rem;
    transition: background var(--transition);
}

.progress-line.filled {
    background: var(--arcana);
}

/* ========================================
   CONFIGURATOR LAYOUT (viewport-locked)
   ======================================== */

#configurator {
    height: calc(100dvh - 55px);
    overflow: hidden;
    padding-bottom: 0;
}

#steps-container {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    min-height: 0;
    padding-bottom: 0.5rem;
}

/* ========================================
   BOTTLE PREVIEW
   ======================================== */

#bottle-preview {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 140px;
    margin: 0 0 0.3rem;
    transition: opacity 0.3s ease;
    flex-shrink: 0;
}

#bottle-preview svg,
#result-bottle-preview svg {
    transition: opacity 0.35s ease;
}

#bottle-preview svg {
    width: 90px;
    height: 140px;
}

/* ========================================
   STEPS
   ======================================== */

.step {
    display: none;
    animation: slideIn 0.35s ease;
}

.step.active {
    display: block;
}

@keyframes slideIn {
    from { opacity: 0; transform: translateX(16px); }
    to   { opacity: 1; transform: translateX(0); }
}

.step h2 {
    text-align: center;
    margin-bottom: 0.2rem;
}

.step-desc {
    text-align: center;
    font-size: 0.88rem;
    color: var(--testo-secondario);
    margin-bottom: 1rem;
    font-style: italic;
    font-weight: 300;
}

/* ========================================
   OPTIONS GRID
   ======================================== */

.options-grid-wrap {
    position: relative;
}

/* Fade hint at bottom when content overflows */
.options-grid-wrap::after {
    content: '';
    position: sticky;
    bottom: 0;
    display: block;
    height: 32px;
    background: linear-gradient(to bottom, transparent, var(--sfondo));
    pointer-events: none;
    margin-top: -32px;
    opacity: 1;
    transition: opacity 0.3s;
}

.options-grid-wrap.scrolled-bottom::after {
    opacity: 0;
}

.options-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
}

.option-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    padding: 0.55rem 0.3rem 0.5rem;
    border: 1.5px solid var(--linea-leggera);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.25s ease;
    background: transparent;
    -webkit-tap-highlight-color: transparent;
    min-height: 0;
}

.option-card:active {
    transform: scale(0.96);
}

.option-card.selected {
    border-color: var(--testo);
    background: rgba(26, 35, 50, 0.035);
}

/* Multi-select badge (for 2-base selection) */
.option-card {
    position: relative;
}

.select-badge {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--testo);
    color: var(--sfondo);
    font-family: var(--font-heading);
    font-size: 0.55rem;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    animation: badgePop 0.25s ease;
}

@keyframes badgePop {
    from { transform: scale(0); }
    to   { transform: scale(1); }
}

/* Color swatch */
.option-swatch {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: 2px solid rgba(0, 0, 0, 0.08);
    transition: all 0.3s ease;
    flex-shrink: 0;
}

.option-card.selected .option-swatch {
    transform: scale(1.1);
    box-shadow: 0 0 0 3px rgba(26, 35, 50, 0.12);
}

/* "Nessuno" shimmer swatch */
.option-swatch-none {
    background: transparent !important;
    border: 2px dashed var(--linea) !important;
    display: flex;
    align-items: center;
    justify-content: center;
}

.option-swatch-none::after {
    content: '';
    width: 18px;
    height: 1.5px;
    background: var(--linea);
    transform: rotate(-45deg);
}

/* Bottle icon */
.option-bottle-icon {
    width: 32px;
    height: 48px;
    flex-shrink: 0;
}

.option-bottle-icon svg {
    width: 100%;
    height: 100%;
}

/* Option text */
.option-name {
    font-family: var(--font-heading);
    font-size: 0.65rem;
    letter-spacing: 0.04em;
    color: var(--testo);
    text-align: center;
    line-height: 1.2;
}

/* Ingredient name - revealed on selection */
.option-ingredient {
    font-family: var(--font-body);
    font-size: 0.65rem;
    color: var(--testo-secondario);
    text-align: center;
    line-height: 1.25;
    font-style: italic;
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    transition: all 0.3s ease;
}

.option-card.selected .option-ingredient {
    max-height: 2.5rem;
    opacity: 1;
    margin-top: 0.1rem;
}

/* ========================================
   NAVIGATION BUTTONS
   ======================================== */

#nav-buttons {
    display: flex;
    justify-content: space-between;
    padding: 0.7rem 0;
    gap: 0.8rem;
    flex-shrink: 0;
    border-top: 1px solid var(--linea);
    background: var(--sfondo);
}

#nav-buttons button {
    flex: 1;
}

/* ========================================
   RESULT SCREEN
   ======================================== */

#result {
    align-items: center;
    padding-top: 1.5rem;
}

.result-content {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.2rem;
}

.result-card {
    width: 100%;
    background: #FFFDF8;
    border-radius: 12px;
    padding: 1.4rem 1.2rem;
    box-shadow: 0 2px 24px rgba(0, 0, 0, 0.06);
    text-align: center;
    animation: cardReveal 0.6s cubic-bezier(0.2, 0, 0.2, 1);
}

@keyframes cardReveal {
    from { opacity: 0; transform: translateY(20px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.result-header {
    margin-bottom: 0.4rem;
}

.result-label {
    font-family: var(--font-heading);
    font-size: 0.6rem;
    letter-spacing: 0.22em;
    color: var(--testo-secondario);
    text-transform: uppercase;
}

.result-line {
    width: 36px;
    height: 1.5px;
    background: var(--linea);
    margin: 0.5rem auto;
}

.result-name {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1.2rem;
    color: var(--testo);
    margin-bottom: 0.3rem;
    letter-spacing: 0.02em;
    line-height: 1.3;
}

#result-bottle-preview {
    display: flex;
    justify-content: center;
    margin: 0.6rem 0 0.8rem;
}

#result-bottle-preview svg {
    width: 150px;
    height: 250px;
}

/* Ingredients */
#result-ingredients {
    text-align: left;
    margin-top: 0.5rem;
}

.ingredient-section {
    padding: 0.5rem 0;
    border-top: 1px solid #EDE8DF;
}

.ingredient-section:last-child {
    border-bottom: 1px solid #EDE8DF;
}

.ingredient-label {
    font-family: var(--font-heading);
    font-size: 0.55rem;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--testo-secondario);
    margin-bottom: 0.25rem;
}

.ingredient-name {
    font-family: var(--font-heading);
    font-size: 0.9rem;
    color: var(--testo);
    margin-bottom: 0.1rem;
}

.ingredient-desc {
    font-family: var(--font-body);
    font-size: 0.82rem;
    color: var(--testo-secondario);
    font-style: italic;
    font-weight: 300;
    line-height: 1.4;
}

/* Result stamp */
.result-stamp {
    margin-top: 0.8rem;
    padding-top: 0.7rem;
    border-top: 1px solid #EDE8DF;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.15rem;
}

.result-stamp span {
    font-family: var(--font-body);
    font-size: 0.7rem;
    color: var(--linea-leggera);
    font-style: italic;
    font-weight: 300;
}

.result-stamp strong {
    font-family: var(--font-display);
    font-size: 0.7rem;
    color: var(--linea);
    letter-spacing: 0.18em;
    font-weight: 700;
}

/* Result actions */
.result-actions {
    display: flex;
    gap: 0.65rem;
    width: 100%;
}

.result-actions button {
    flex: 1;
}

.btn-save {
    width: 100%;
    padding: 0.9rem 1.5rem;
}

/* ========================================
   CTA SECTION
   ======================================== */

.cta-section {
    text-align: center;
    padding: 1rem 0 0.5rem;
    width: 100%;
}

.cta-text {
    font-family: var(--font-body);
    font-size: 1rem;
    color: var(--testo-primario);
    margin-bottom: 0.8rem;
    font-style: italic;
    font-weight: 300;
}

.btn-instagram {
    display: inline-block;
    font-family: var(--font-heading);
    font-size: 0.75rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    padding: 0.85rem 2rem;
    background: linear-gradient(135deg, #833AB4, #E1306C, #F77737);
    color: white;
    border: none;
    border-radius: var(--radius);
    text-decoration: none;
    transition: all 0.3s ease;
    -webkit-tap-highlight-color: transparent;
}

.btn-instagram:active {
    transform: scale(0.97);
}

/* Hide footer when configurator/result is showing (JS adds class to body) */
body.no-footer footer {
    display: none;
}

.hidden {
    display: none !important;
}

/* ========================================
   FOOTER
   ======================================== */

footer {
    padding: 1.3rem var(--padding);
    text-align: center;
    border-top: 1px solid var(--linea);
    margin-top: auto;
}

.brand-name-small {
    font-family: var(--font-display);
    font-size: 0.65rem;
    color: var(--testo-secondario);
    letter-spacing: 0.15em;
}

.footer-dot {
    color: var(--linea);
    margin: 0 0.4rem;
}

.footer-text {
    font-family: var(--font-heading);
    font-size: 0.55rem;
    color: var(--testo-secondario);
    letter-spacing: 0.15em;
    text-transform: uppercase;
}

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

.toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%) translateY(80px);
    background: var(--testo);
    color: var(--sfondo);
    font-family: var(--font-body);
    font-size: 0.85rem;
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius);
    transition: transform 0.35s cubic-bezier(0.2, 0, 0.2, 1);
    z-index: 200;
    pointer-events: none;
    white-space: nowrap;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
}

/* ========================================
   MICA GALAXY PARTICLES (SVG)
   ======================================== */

/* Multiple drift patterns for organic movement */
@keyframes drift1 {
    0%   { transform: translate(0, 0); opacity: 0; }
    12%  { opacity: var(--op, 0.6); }
    88%  { opacity: calc(var(--op, 0.6) * 0.6); }
    100% { transform: translate(7px, -38px); opacity: 0; }
}

@keyframes drift2 {
    0%   { transform: translate(0, 0); opacity: 0; }
    15%  { opacity: var(--op, 0.6); }
    85%  { opacity: calc(var(--op, 0.6) * 0.5); }
    100% { transform: translate(-9px, -28px); opacity: 0; }
}

@keyframes drift3 {
    0%   { transform: translate(0, 0) scale(1); opacity: 0; }
    10%  { opacity: var(--op, 0.7); }
    50%  { transform: translate(5px, -18px) scale(0.9); }
    90%  { opacity: calc(var(--op, 0.7) * 0.4); }
    100% { transform: translate(3px, -42px) scale(0.5); opacity: 0; }
}

@keyframes drift4 {
    0%   { transform: translate(0, 0); opacity: 0; }
    18%  { opacity: var(--op, 0.5); transform: translate(5px, -6px); }
    50%  { transform: translate(-5px, -18px); }
    82%  { opacity: calc(var(--op, 0.5) * 0.5); transform: translate(4px, -30px); }
    100% { transform: translate(-3px, -40px); opacity: 0; }
}

@keyframes drift5 {
    0%   { transform: translate(0, 0); opacity: 0; }
    14%  { opacity: var(--op, 0.6); }
    40%  { transform: translate(-7px, -12px); }
    70%  { transform: translate(4px, -25px); }
    100% { transform: translate(-2px, -36px); opacity: 0; }
}

@keyframes drift6 {
    0%   { transform: translate(0, 0) scale(1); opacity: 0; }
    20%  { opacity: var(--op, 0.5); transform: translate(3px, -5px) scale(1.1); }
    60%  { transform: translate(-6px, -15px) scale(0.8); }
    100% { transform: translate(2px, -32px) scale(0.4); opacity: 0; }
}

/* Subtle twinkle overlay */
@keyframes twinkle {
    0%, 100% { opacity: var(--op, 0.4); }
    50%      { opacity: calc(var(--op, 0.4) + 0.3); }
}

/* Main particle class - dual animation: drift + twinkle */
.mica-particle {
    animation:
        var(--drift, drift1) var(--dur, 4s) var(--del, 0s) infinite ease-in-out,
        twinkle var(--tw, 2.5s) var(--twd, 0s) infinite ease-in-out;
}

/* Glow particles (larger accent particles) */
.mica-glow {
    animation:
        var(--drift, drift1) var(--dur, 5s) var(--del, 0s) infinite ease-in-out,
        twinkle var(--tw, 3s) var(--twd, 0s) infinite ease-in-out;
    filter: url(#mica-glow-filter);
}

/* ========================================
   RESPONSIVE — larger screens
   ======================================== */

@media (min-width: 520px) {
    :root {
        --padding: 2rem;
    }

    h1 {
        font-size: 2.4rem;
    }

    h2 {
        font-size: 1.35rem;
    }

    .options-grid {
        gap: 0.85rem;
    }

    .option-swatch {
        width: 40px;
        height: 40px;
    }

    .option-name {
        font-size: 0.72rem;
    }

    #bottle-preview {
        height: 180px;
    }

    #bottle-preview svg {
        width: 110px;
        height: 180px;
    }

    #result-bottle-preview svg {
        width: 180px;
        height: 290px;
    }
}

/* Prefers reduced motion */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}
