* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: Arial, Helvetica, sans-serif;
    background:
        radial-gradient(circle at top left, rgba(74, 116, 255, 0.12), transparent 30%),
        #f4f6fb;
    color: #182033;
}

.page {
    width: min(1240px, 92%);
    margin: 0 auto;
    padding: 48px 0;
}

.hero {
    text-align: center;
    margin-bottom: 32px;
}

.hero.small {
    margin-bottom: 28px;
}

.eyebrow {
    margin: 0 0 8px;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    font-size: 13px;
    color: #52627a;
    font-weight: bold;
}

h1 {
    margin: 0;
    font-size: clamp(36px, 6vw, 66px);
    line-height: 1;
}

h2 {
    margin: 0 0 14px;
    font-size: 24px;
}

.subtitle {
    max-width: 840px;
    margin: 18px auto 0;
    font-size: 19px;
    line-height: 1.6;
    color: #52627a;
}

.card {
    background: #ffffff;
    border-radius: 24px;
    padding: 28px;
    box-shadow: 0 18px 50px rgba(20, 35, 70, 0.10);
}

form {
    display: grid;
    gap: 16px;
}

label {
    font-weight: bold;
}

select,
textarea {
    width: 100%;
    border: 1px solid #d5dbea;
    border-radius: 14px;
    padding: 14px;
    font-size: 16px;
    font-family: inherit;
    background: white;
}

textarea {
    resize: vertical;
}

button {
    border: 0;
    border-radius: 16px;
    padding: 16px 20px;
    font-size: 17px;
    font-weight: bold;
    cursor: pointer;
    background: #182033;
    color: white;
}

button:hover {
    opacity: 0.92;
}

.layout {
    display: grid;
    grid-template-columns: minmax(0, 1.35fr) minmax(340px, 0.95fr);
    gap: 24px;
    align-items: start;
}

.result {
    display: grid;
    gap: 26px;
}

.study-section {
    border-bottom: 1px solid #e8ecf5;
    padding-bottom: 22px;
}

.study-section:last-of-type {
    border-bottom: 0;
}

.study-section p,
.study-section li {
    font-size: 18px;
    line-height: 1.8;
}

.study-section ul {
    margin: 0;
    padding-left: 22px;
}

.map-card {
    position: sticky;
    top: 24px;
    overflow: hidden;
}

.map-image-wrap {
    background: #f8faff;
    border: 1px solid #e2e8f7;
    border-radius: 18px;
    padding: 14px;
}

.mindmap-image {
    display: block;
    width: 100%;
    height: auto;
    border-radius: 14px;
}

.back-link {
    display: inline-block;
    margin-top: 8px;
    color: #182033;
    font-weight: bold;
    text-decoration: none;
}

@media (max-width: 900px) {
    .layout {
        grid-template-columns: 1fr;
    }

    .map-card {
        position: static;
    }
}

input {
    width: 100%;
    border: 1px solid #d5dbea;
    border-radius: 14px;
    padding: 14px;
    font-size: 16px;
    font-family: inherit;
    background: white;
}

.optional,
.form-note {
    color: #66758e;
    font-weight: normal;
    font-size: 14px;
}

.form-note {
    margin: -4px 0 0;
    line-height: 1.5;
}

.loading-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgba(244, 246, 251, 0.88);
    backdrop-filter: blur(10px);
}

.loading-overlay.is-visible {
    display: flex;
}

.loader-card {
    width: min(460px, 100%);
    text-align: center;
    background: #fff;
    border-radius: 28px;
    padding: 34px;
    box-shadow: 0 24px 70px rgba(20, 35, 70, 0.18);
}

.loader-spinner {
    width: 72px;
    height: 72px;
    margin: 0 auto 18px;
    border-radius: 50%;
    border: 7px solid #e8eefb;
    border-top-color: #4a74ff;
    animation: spin 0.9s linear infinite;
}

.loader-card h2 {
    margin-bottom: 8px;
}

.loader-card p {
    color: #52627a;
    line-height: 1.6;
}

.loader-steps {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    margin-top: 18px;
}

.loader-steps span {
    border-radius: 999px;
    padding: 9px 12px;
    background: #f0f5ff;
    color: #254bd6;
    font-weight: bold;
    font-size: 13px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.maps-stack {
    display: grid;
    gap: 22px;
}

.single-map h3 {
    margin: 0 0 12px;
    font-size: 18px;
}

.exercise-list {
    display: grid;
    gap: 14px;
}

.exercise-card {
    border: 1px solid #e2e8f7;
    background: #f8faff;
    border-radius: 18px;
    padding: 18px;
}

.exercise-top {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-bottom: 10px;
}

.exercise-top span {
    display: inline-grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #182033;
    color: #fff;
    font-weight: bold;
}

.exercise-top strong {
    color: #182033;
}

.exercise-card p {
    margin: 8px 0;
}

.exercise-card details {
    margin-top: 10px;
    border-top: 1px solid #e2e8f7;
    padding-top: 10px;
}

.exercise-card summary {
    cursor: pointer;
    font-weight: bold;
    color: #254bd6;
}


/* ===== ESEMPI PRATICI ===== */
.example-list {
    display: grid;
    gap: 14px;
}

.example-card {
    border: 1px solid #dbe8fb;
    background: linear-gradient(135deg, #ffffff, #f2f8ff);
    border-radius: 18px;
    padding: 18px;
}

.example-top {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-bottom: 10px;
}

.example-top span {
    display: inline-grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #254bd6;
    color: #fff;
    font-weight: bold;
}

.example-top strong {
    color: #182033;
}

.example-card p {
    margin: 8px 0 0;
}

/* ===== ZOOM MAPPE ===== */
.zoom-map {
    display: block;
    width: 100%;
    padding: 0;
    border: 0;
    background: transparent;
    color: inherit;
    cursor: zoom-in;
    text-align: left;
}

.zoom-map span {
    display: inline-flex;
    margin-top: 10px;
    border-radius: 999px;
    padding: 8px 12px;
    background: #eef5ff;
    color: #254bd6;
    font-size: 13px;
    font-weight: bold;
}

.map-lightbox {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 26px;
    background: rgba(10, 18, 32, 0.82);
    backdrop-filter: blur(8px);
}

.map-lightbox.is-visible {
    display: flex;
}

.map-lightbox img {
    max-width: min(1500px, 96vw);
    max-height: 90vh;
    width: auto;
    height: auto;
    border-radius: 24px;
    box-shadow: 0 28px 90px rgba(0, 0, 0, 0.38);
    background: #fff;
}

.map-lightbox-close {
    position: fixed;
    top: 18px;
    right: 22px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    padding: 0;
    background: #ffffff;
    color: #182033;
    font-size: 32px;
    line-height: 1;
}

/* ===== ATTESA GENERAZIONE ===== */
button .button-wait {
    display: none;
}

button.is-loading .button-text {
    display: none;
}

button.is-loading .button-wait {
    display: inline;
}

button:disabled {
    opacity: 0.72;
    cursor: wait;
}

.loading-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgba(244, 246, 251, 0.86);
    backdrop-filter: blur(10px);
}

.loading-overlay.is-visible {
    display: flex;
}

.loader-card {
    width: min(460px, 94vw);
    text-align: center;
    background: #ffffff;
    border: 1px solid #dfe7f7;
    border-radius: 30px;
    padding: 34px;
    box-shadow: 0 28px 90px rgba(20, 35, 70, 0.20);
}

.loader-card h2 {
    margin-top: 18px;
    font-size: 28px;
}

.loader-card p {
    color: #52627a;
    font-size: 16px;
    line-height: 1.6;
}

.loader-orbit {
    position: relative;
    width: 94px;
    height: 94px;
    margin: 0 auto;
    border-radius: 50%;
    background: radial-gradient(circle, #ffffff 35%, #eaf2ff 36%, #effcff 100%);
}

.loader-orbit span {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 3px solid transparent;
    border-top-color: #254bd6;
    animation: spin 1.1s linear infinite;
}

.loader-orbit span:nth-child(2) {
    inset: 9px;
    border-top-color: #06b6d4;
    animation-duration: 1.45s;
    animation-direction: reverse;
}

.loader-orbit span:nth-child(3) {
    inset: 18px;
    border-top-color: #10b981;
    animation-duration: 1.8s;
}

.loader-book {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    font-size: 30px;
}

.loader-progress {
    height: 10px;
    overflow: hidden;
    border-radius: 999px;
    background: #e8eef8;
    margin: 22px 0 18px;
}

.loader-progress i {
    display: block;
    width: 45%;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, #254bd6, #06b6d4, #10b981);
    animation: loadingBar 1.35s ease-in-out infinite;
}

.loader-steps {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
}

.loader-steps span {
    border-radius: 999px;
    padding: 8px 11px;
    background: #eef5ff;
    color: #254bd6;
    font-size: 13px;
    font-weight: bold;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

@keyframes loadingBar {
    0% { transform: translateX(-110%); }
    50% { transform: translateX(60%); }
    100% { transform: translateX(240%); }
}

/* ===== PDF / STAMPA ===== */
.result-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: center;
    margin-top: 22px;
}

.print-button,
.print-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    padding: 13px 18px;
    font-size: 15px;
    font-weight: bold;
    text-decoration: none;
}

.print-button {
    background: linear-gradient(135deg, #254bd6, #06b6d4);
    color: #fff;
    box-shadow: 0 14px 34px rgba(37, 75, 214, 0.22);
}

.print-link {
    background: #ffffff;
    color: #182033;
    border: 1px solid #d5dbea;
}

.print-hint {
    margin: 12px auto 0;
    color: #52627a;
    font-size: 14px;
}

@media print {
    @page {
        size: A4;
        margin: 14mm;
    }

    * {
        box-shadow: none !important;
        text-shadow: none !important;
    }

    html,
    body {
        background: #ffffff !important;
        color: #111827 !important;
    }

    body {
        font-family: Arial, Helvetica, sans-serif;
        font-size: 11.5pt;
        line-height: 1.45;
    }

    body::after {
        content: "Calia Software · Spazio Studenti";
        position: fixed;
        left: 50%;
        top: 48%;
        transform: translate(-50%, -50%) rotate(-28deg);
        font-size: 42pt;
        font-weight: 800;
        letter-spacing: 0.04em;
        color: rgba(37, 75, 214, 0.055);
        white-space: nowrap;
        pointer-events: none;
        z-index: 9999;
    }

    .no-print,
    .map-lightbox,
    .loading-overlay,
    .back-link,
    script {
        display: none !important;
    }

    .page {
        width: 100%;
        padding: 0;
        margin: 0;
    }

    .hero,
    .hero.small {
        text-align: left;
        margin: 0 0 12mm;
        padding: 0 0 6mm;
        border-bottom: 2px solid #e5e7eb;
    }

    .eyebrow {
        color: #334155 !important;
        font-size: 9pt;
        letter-spacing: 0.08em;
    }

    h1 {
        font-size: 25pt;
        line-height: 1.05;
        margin: 0 0 4mm;
        page-break-after: avoid;
    }

    h2 {
        font-size: 16pt;
        margin: 0 0 4mm;
        page-break-after: avoid;
    }

    h3 {
        page-break-after: avoid;
    }

    .subtitle {
        max-width: none;
        margin: 0;
        font-size: 11pt;
        color: #475569 !important;
    }

    .layout {
        display: block;
    }

    .card {
        border-radius: 0;
        padding: 0;
        background: transparent !important;
        border: 0;
    }

    .result {
        display: block;
    }

    .study-section {
        break-inside: avoid;
        page-break-inside: avoid;
        border-bottom: 1px solid #e5e7eb;
        padding-bottom: 7mm;
        margin-bottom: 7mm;
    }

    .study-section p,
    .study-section li {
        font-size: 11.5pt;
        line-height: 1.5;
    }

    .map-card {
        position: static;
        margin-top: 8mm;
        break-before: page;
        page-break-before: always;
    }

    .maps-stack,
    .single-map {
        display: block;
    }

    .single-map {
        break-inside: avoid;
        page-break-inside: avoid;
        margin-bottom: 9mm;
    }

    .map-image-wrap {
        border: 1px solid #d1d5db;
        border-radius: 0;
        padding: 3mm;
        background: #ffffff !important;
        overflow: visible;
    }

    .zoom-map {
        cursor: default;
    }

    .zoom-map span {
        display: none !important;
    }

    .mindmap-image {
        max-width: 100%;
        border-radius: 0;
    }

    .exercise-card,
    .example-card {
        border: 1px solid #d1d5db;
        background: #ffffff !important;
        break-inside: avoid;
        page-break-inside: avoid;
    }

    details > summary {
        list-style: none;
    }

    details[open],
    details {
        display: block;
    }
}
