/* ============================================================
   0. RESET DI BASE — mancava, causava overflow di padding/margini
   ============================================================ */
* {
    box-sizing: border-box;
}

/* ============================================================
   1. RESET + VARIABILI GLOBALI — PALETTE BORGO
   ============================================================ */
:root {
    --sky: #5B8FAE;
    --sea: #1B4965;

    --stone: #EFE6D3;
    --stone-dim: #DCCFAF;

    --terracotta: #C1622D;
    --terracotta-dark: #9C4C22;

    --gold: #B8873B;
    --gold-light: #D4AF6A;

    --ink: #22303B;
    --ink-soft: #465563;

    --sea-ink: #14283A;
    --cream-text: #F3ECDC;

    --shadow-strong: rgba(0, 0, 0, 0.35);
    --shadow-soft: rgba(0, 0, 0, 0.18);

    --radius: 2px;
    --transition: 0.3s ease;
}

html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    min-height: 100vh;
    font-family: "Segoe UI", system-ui, sans-serif;
    color: var(--ink);
    background: var(--stone) !important;
    overflow-x: hidden;
}

/* ============================================================
   2. DASHBOARD
   ============================================================ */
.dashboard {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    background: rgba(15, 25, 34, 0.92);
    border-bottom: 2px solid var(--gold);
    backdrop-filter: blur(18px) saturate(200%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    padding: 15px 20px;
    gap: 12px;
    z-index: 999;
    box-shadow: 0 2px 0 rgba(212, 175, 106, 0.25);
    box-sizing: border-box;
}

.logo-title {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--gold-light);
    letter-spacing: 1.5px;
}

.nav-desktop {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
}

.nav-desktop a {
    color: var(--stone);
    font-weight: 600;
    text-decoration: none;
    font-size: 0.85rem;
    letter-spacing: 0.3px;
    padding: 6px 16px;
    border-radius: 2px;
    background: rgba(239, 230, 211, 0.08);
    border: 1px solid rgba(239, 230, 211, 0.4);
    transition: all 0.3s ease;
}

.nav-desktop a:hover {
    background: rgba(193, 98, 45, 0.25);
    border-color: var(--terracotta);
    color: #fff;
}

.header-right-actions {
    display: flex;
    align-items: center;
    gap: 15px;
}

.lang-switcher {
    display: flex;
    gap: 6px;
    align-items: center;
}

.lang-switcher button {
    width: 36px;
    height: 36px;
    font-size: 0.9rem;
    font-weight: bold;
    border-radius: 2px;
    background: rgba(239, 230, 211, 0.08);
    border: 1px solid rgba(239, 230, 211, 0.4);
    color: var(--stone);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

.lang-switcher button:hover {
    background: rgba(193, 98, 45, 0.25);
}

@media screen and (max-width: 899px) {
    .header-right-actions {
        flex-wrap: wrap;
        justify-content: center;
        row-gap: 8px;
    }
    .nav-desktop {
        flex: 1 1 100%;
        justify-content: center;
    }
    .lang-switcher {
        flex: 1 1 100%;
        justify-content: center;
    }
}

/* ============================================================
   3. SEZIONE 1 — HERO (immagine castello + poesia)
   ============================================================ */
.hero {
    position: relative;
    z-index: 1;
    margin-top: 190px;
    width: 100%;
    text-align: center;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    box-sizing: border-box;
}

.hero-text {
    width: 100%;
    text-align: center;
}

.category-tag {
    font-size: 0.8rem;
    letter-spacing: 3px;
    text-transform: uppercase;
    color: var(--terracotta);
    font-weight: 700;
    margin-bottom: 5px;
    display: block;
}

.hero-text h1 {
    font-family: 'Playfair Display', serif;
    font-size: clamp(2rem, 5vw, 3.2rem);
    color: var(--sea);
    margin-bottom: 0.5rem;
}

.hero-text::after {
    content: "❧";
    display: block;
    width: auto;
    margin: 0.8rem auto 2rem;
    color: var(--gold);
    font-size: 15px;
}

.castle-hero-image {
    max-width: 620px;
    width: 100%;
    margin: 0 auto 2.5rem;
    padding: 10px;
    background: var(--stone-dim);
    border: 1px solid var(--terracotta);
    box-shadow: 0 12px 30px var(--shadow-soft);
}

.castle-hero-image img {
    display: block;
    width: 100%;
    height: auto;
}

.poesia-corpo.hero-intro {
    max-width: 640px;
    margin: 0 auto 1.5rem;
    padding: 0 1rem;
    box-sizing: border-box;
}

.poesia-corpo p {
    font-family: 'Cormorant Garamond', serif;
    font-size: clamp(1.2rem, 2.6vw, 1.45rem);
    line-height: 1.8;
    color: var(--ink);
    font-style: italic;
    margin-bottom: 0;
}

.scroll-cue {
    display: inline-block;
    margin-top: 1rem;
    color: var(--sea);
    font-size: 0.9rem;
    letter-spacing: 1px;
    text-decoration: none;
    border-bottom: 1px solid var(--gold);
    padding-bottom: 3px;
    transition: color 0.3s ease;
}

.scroll-cue:hover {
    color: var(--terracotta);
}

/* ============================================================
   4. SEZIONE 2 — PARALLASSE (contenuto storico/pratico)
   ============================================================ */
.section-parallax {
    position: relative;
    min-height: 85vh;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background: var(--sea-ink);
    -webkit-mask-image: linear-gradient(to bottom,
        transparent 0,
        black 90px,
        black calc(100% - 90px),
        transparent 100%);
    mask-image: linear-gradient(to bottom,
        transparent 0,
        black 90px,
        black calc(100% - 90px),
        transparent 100%);
}

.parallax-bg {
    position: absolute;
    inset: 0;
    background-color: var(--sea-ink);
    background-image: url('img/sfondocaccamo.jpeg');
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
    filter: brightness(0.5) contrast(1.1) saturate(1.05);
}

.parallax-overlay {
    position: absolute;
    inset: 0;
    background: linear-gradient(180deg,
        rgba(15, 25, 34, 0.80) 0%,
        rgba(15, 25, 34, 0.62) 40%,
        rgba(15, 25, 34, 0.85) 100%);
}

.parallax-content {
    position: relative;
    z-index: 2;
    width: 100%;
    max-width: 720px;
    padding: 60px 32px;
    margin: 0 auto;
    box-sizing: border-box;
    text-align: left;
}

.parallax-content p {
    font-family: 'Cormorant Garamond', serif;
    font-size: clamp(1.05rem, 2vw, 1.25rem);
    line-height: 1.85;
    color: #fff;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.6);
    margin-bottom: 1.6rem;
}

.parallax-content p:last-child {
    margin-bottom: 0;
}

.parallax-content p strong {
    color: var(--gold-light);
    font-weight: 600;
}

@media screen and (max-width: 899px) {
    .parallax-bg { background-attachment: scroll; }
    .parallax-content {
        padding: 40px 24px;
        text-align: left;
    }
    .section-parallax {
        -webkit-mask-image: linear-gradient(to bottom,
            transparent 0,
            black 50px,
            black calc(100% - 50px),
            transparent 100%);
        mask-image: linear-gradient(to bottom,
            transparent 0,
            black 50px,
            black calc(100% - 50px),
            transparent 100%);
    }
}

/* ============================================================
   5. CASTELLANA WIDGET — invariato
   ============================================================ */
.castellana-widget-area {
    position: fixed;
    right: 1.2rem;
    bottom: 1.2rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    pointer-events: auto;
}

.castellana-video-wrapper {
    width: 78px;
    height: 78px;
    border-radius: 50%;
    overflow: hidden;
    border: 3px solid var(--sea);
    background: #000;
    box-shadow: 0 4px 15px var(--shadow-strong);
    cursor: pointer;
    transition: transform 0.3s ease;
    position: relative;
}

.castellana-video-wrapper:hover {
    transform: scale(1.04);
}

.castellana-video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center 15%;
}

.castellana-tooltip {
    background: var(--sea);
    color: var(--stone);
    padding: 0.3rem 0.9rem;
    border-radius: 2px;
    font-weight: 700;
    font-size: 0.65rem;
    letter-spacing: 0.8px;
    text-transform: uppercase;
    box-shadow: 0 4px 10px var(--shadow-strong);
    pointer-events: none;
}

/* Chat: dimensioni base (mobile). Su desktop (min-width:900px) vengono
   ingrandite più sotto — prima mancava del tutto un ingrandimento
   per schermi grandi, la finestra restava sempre piccola. */
.chat-desktop {
    position: fixed;
    bottom: 150px;
    right: 3%;
    width: 320px;
    height: 350px;
    background: rgba(15, 25, 34, 0.96);
    backdrop-filter: blur(10px);
    border: 1px solid var(--gold);
    border-radius: 4px;
    padding: 16px;
    display: none;
    z-index: 99999;
    box-shadow: 0 -5px 25px rgba(0, 0, 0, 0.5);
}

.chat-desktop.active {
    display: flex;
    flex-direction: column;
    animation: fadeIn 0.3s ease forwards;
}

.chat-header {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--cream-text);
    background: var(--sea-ink);
    margin: -16px -16px 15px -16px;
    padding: 12px 15px;
    border-radius: 4px 4px 0 0;
    border-bottom: 1px solid var(--gold);
}

.chat-header span {
    flex-grow: 1;
    font-weight: 600;
    font-size: 0.9rem;
}

.avatar-status-dot {
    width: 8px;
    height: 8px;
    background: #5FD068;
    box-shadow: 0 0 6px #5FD068;
    border-radius: 50%;
    display: inline-block;
    margin-right: 6px;
}

.close-chat-btn {
    background: transparent;
    border: none;
    color: var(--cream-text);
    cursor: pointer;
    font-size: 1.1rem;
}

.close-chat-btn:hover {
    color: var(--gold-light);
}

.premium-status-bar {
    font-size: 0.72rem;
    font-weight: 600;
    text-align: center;
    padding: 4px 8px;
    margin: -6px 0 10px 0;
    border-radius: 2px;
    letter-spacing: 0.2px;
}

.premium-status-bar.premium-active {
    background: rgba(184, 135, 59, 0.18);
    color: var(--gold-light);
    border: 1px solid rgba(184, 135, 59, 0.4);
}

.premium-status-bar.premium-free {
    background: rgba(239, 230, 211, 0.08);
    color: var(--cream-text);
    border: 1px solid rgba(239, 230, 211, 0.25);
}

.chat-messages {
    flex-grow: 1;
    overflow-y: auto;
    margin-bottom: 10px;
}

.chat-messages .message {
    color: var(--ink);
    font-size: 0.9rem;
    line-height: 1.5;
    background: #fff;
    padding: 8px 12px;
    border-radius: 2px;
    margin-bottom: 8px;
    max-width: 90%;
    border-left: 2px solid var(--gold);
}

.system-msg {
    border-left: 2px solid var(--terracotta);
}

.chat-link-btn {
    display: block;
    background: var(--terracotta);
    color: #fff;
    border: none;
    padding: 8px 14px;
    border-radius: 2px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    margin: -2px 0 8px 0;
    transition: background 0.2s;
}

.chat-link-btn:hover {
    background: var(--sea);
}

.map-overlay {
    position: fixed;
    inset: 0;
    z-index: 999999;
    background: #000;
}

.map-overlay iframe {
    width: 100%;
    height: 100%;
    border: none;
    display: block;
}

.map-overlay-close {
    position: absolute;
    top: 14px;
    right: 14px;
    z-index: 2;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(15, 25, 34, 0.85);
    color: var(--cream-text);
    border: 1px solid var(--gold);
    font-size: 1.2rem;
    cursor: pointer;
}

.topic-menu {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: 2px 0 10px 0;
}

.topic-btn {
    background: #fff;
    border: 1px solid var(--gold);
    color: var(--sea);
    padding: 6px 12px;
    border-radius: 999px;
    font-size: 0.78rem;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
}

.topic-btn:hover {
    background: var(--gold);
    color: #fff;
}

.topic-group-btn {
    border-color: var(--terracotta);
    color: var(--terracotta);
    font-weight: 600;
}

.topic-group-btn:hover {
    background: var(--terracotta);
    color: #fff;
}

.topic-subitems {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    width: 100%;
    margin-top: 4px;
    padding-left: 10px;
}

.chat-input-row {
    display: flex;
    gap: 10px;
}

.chat-input-row input {
    flex-grow: 1;
    padding: 10px 14px;
    border-radius: 2px;
    border: 1px solid rgba(184, 135, 59, 0.5);
    background: #fff;
    color: var(--ink);
    outline: none;
    font-size: 0.85rem;
}

.chat-input-row input:focus {
    border-color: var(--gold);
}

.send-btn {
    background: var(--sea);
    border: none;
    border-radius: 2px;
    padding: 0 12px;
    cursor: pointer;
    color: #fff;
    font-size: 1rem;
    transition: background 0.2s;
}

.send-btn:hover {
    background: var(--terracotta);
}

.chat-messages .message.user-msg {
    background: var(--sea);
    color: #fff;
    margin-left: auto;
    border-left: none;
    border-right: 2px solid var(--gold);
    text-align: right;
}

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

/* ============================================================
   6. BOTTONE PREMIUM
   ============================================================ */
.castellana-premium-cta {
    position: relative;
    z-index: 1;
}

/* ============================================================
   7. OTTIMIZZAZIONE DESKTOP (DA 900PX IN SU)
   ============================================================ */
@media screen and (min-width: 900px) {

    .dashboard {
        height: 75px;
        flex-direction: row;
        padding: 0 40px;
        gap: 0;
    }

    .dashboard .logo-title {
        font-size: 1.55rem;
    }

    .nav-desktop {
        gap: 22px;
    }

    .nav-desktop a {
        font-size: 1rem;
        padding: 10px 18px;
    }

    .hero {
        margin-top: 110px;
    }

    .hero-text h1 {
        font-size: 3.2rem;
    }

    .castle-hero-image {
        max-width: 720px;
    }

    .poesia-corpo p {
        font-size: 1.7rem;
        line-height: 1.6;
    }

    .parallax-content {
        max-width: 820px;
        padding: 100px 40px;
    }

    .parallax-content p {
        font-size: 1.32rem;
        line-height: 1.95;
        margin-bottom: 2rem;
    }

    .castellana-widget-area {
        right: 2rem;
        bottom: 2rem;
        gap: 8px;
    }

    .castellana-video-wrapper {
        width: 110px;
        height: 110px;
        border: 3px solid var(--sea);
    }

    .castellana-tooltip {
        font-size: 0.75rem;
        padding: 0.4rem 1rem;
    }

    /* Chat più grande su desktop: prima usava sempre le stesse
       dimensioni ridotte pensate per mobile (320x350), senza alcun
       ingrandimento per schermi grandi. */
    .chat-desktop {
        width: 640px;
        max-width: 85vw;
        height: 700px;
        max-height: 78vh;
    }
}

@media screen and (min-width: 1300px) {
    .parallax-content {
        max-width: 920px;
        padding: 120px 40px;
    }

    .parallax-content p {
        font-size: 1.4rem;
        line-height: 2;
    }

    .castle-hero-image {
        max-width: 820px;
    }
}

@media (min-width: 601px) and (max-width: 899px) {
    .hero {
        margin-top: 150px;
    }
    .castellana-video-wrapper {
        width: 95px;
        height: 95px;
    }
}

/* Chat più stretta sui piccoli schermi (stessa soglia di cittadino.html) */
@media screen and (max-width: 950px) {
    .chat-desktop {
        bottom: 110px;
        left: 10px;
        right: 10px;
        width: calc(100% - 20px);
    }
}

@media screen and (max-width: 899px) {
    .header-right-actions {
        flex-wrap: wrap;
        justify-content: center;
        row-gap: 8px;
    }
    .nav-desktop {
        flex: 1 1 100%;
        justify-content: center;
    }
    .lang-switcher {
        flex: 1 1 100%;
        justify-content: center;
    }
}
