:root {
    color-scheme: dark;
    --bg: #101522;
    --panel: #1a2234;
    --border: #303b53;
    --text: #f2f5fc;
    --muted: #a7b2c8;
    --accent: #70e1c1;
    --gold: #ffd166;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, sans-serif;
    line-height: 1.6;
}

a {
    color: var(--accent);
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 18px max(22px, calc((100% - 1080px) / 2));
    border-bottom: 1px solid var(--border);
    background: #151c2b;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--text);
    font-weight: 800;
    letter-spacing: 2px;
    text-decoration: none;
}

.brand-icon {
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: var(--accent);
    color: #10201d;
    font-size: 22px;
}

.topbar-caption,
.muted {
    color: var(--muted);
    font-size: 14px;
}

.container {
    width: min(1080px, calc(100% - 32px));
    margin: 36px auto;
}

.hero {
    margin-bottom: 26px;
}

.eyebrow {
    color: var(--accent);
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 2px;
    text-transform: uppercase;
}

h1 {
    margin: 8px 0;
    font-size: clamp(28px, 5vw, 42px);
    line-height: 1.2;
}

h2 {
    font-size: 20px;
}

.panel,
.module-card {
    padding: 24px;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: var(--panel);
}

.stats {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
    margin: 24px 0 36px;
}

.stat-label {
    color: var(--muted);
    font-size: 14px;
}

.stat-value {
    margin-top: 5px;
    font-size: 28px;
    font-weight: 800;
}

.xp-track {
    height: 12px;
    overflow: hidden;
    border-radius: 20px;
    background: #30394b;
}

.xp-fill {
    height: 100%;
    border-radius: inherit;
    background: var(--accent);
}

.module-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
}

.module-number {
    color: var(--gold);
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 1px;
    text-transform: uppercase;
}

.module-card h3 {
    margin-bottom: 8px;
}

.button {
    display: inline-block;
    margin-top: 14px;
    padding: 10px 16px;
    border: 0;
    border-radius: 9px;
    background: var(--accent);
    color: #10201d;
    font: inherit;
    font-weight: 800;
    text-decoration: none;
    cursor: pointer;
}

.button-secondary {
    background: #303b53;
    color: var(--text);
}

.footer {
    padding: 24px 16px;
    color: var(--muted);
    text-align: center;
    font-size: 13px;
}

@media (max-width: 650px) {
    .topbar-caption {
        display: none;
    }

    .stats,
    .module-grid {
        grid-template-columns: 1fr;
    }

    .container {
        margin-top: 24px;
    }
}

/* ===== LOGIN PHP QUEST ===== */

.login-page {
    min-height: 100vh;
    background:
        radial-gradient(
            ellipse at 50% 35%,
            rgba(112, 225, 193, 0.09),
            transparent 48%
        ),
        var(--bg);
}

.login-container {
    width: min(100% - 32px, 480px);
    min-height: calc(100vh - 76px);
    margin: 0 auto;
    padding: 52px 0 24px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.login-card {
    width: 100%;
    padding: 38px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: rgba(26, 34, 52, 0.96);
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.28);
    text-align: center;
}

.login-emblem {
    width: 64px;
    height: 64px;
    margin: 0 auto 24px;
    display: grid;
    place-items: center;
    border: 1px solid rgba(112, 225, 193, 0.45);
    border-radius: 18px;
    background: rgba(112, 225, 193, 0.1);
    color: var(--accent);
    font-size: 30px;
    box-shadow: 0 0 30px rgba(112, 225, 193, 0.08);
}

.login-card .eyebrow {
    font-size: 11px;
    letter-spacing: 1.7px;
}

.login-card h1 {
    margin: 14px 0 12px;
    font-size: clamp(26px, 5vw, 34px);
}

.login-intro {
    margin: 0 auto 28px;
    max-width: 340px;
    font-size: 14px;
}

.login-form {
    text-align: left;
}

.login-field {
    margin-bottom: 20px;
}

.login-field label {
    display: block;
    margin-bottom: 8px;
    font-size: 14px;
    font-weight: 700;
}

.login-field input {
    width: 100%;
    min-height: 48px;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 10px;
    outline: none;
    background: #111827;
    color: var(--text);
    font: inherit;
    font-size: 14px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.login-field input::placeholder {
    color: #77839a;
}

.login-field input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(112, 225, 193, 0.12);
}

.login-button {
    width: 100%;
    min-height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-top: 8px;
    font-size: 14px;
    transition: transform 0.2s, filter 0.2s;
}

.login-button:hover {
    filter: brightness(1.08);
    transform: translateY(-1px);
}

.login-error {
    margin-bottom: 22px;
    padding: 12px 14px;
    border: 1px solid #a74e5c;
    border-radius: 10px;
    background: rgba(167, 78, 92, 0.12);
    color: #ffb8c1;
    font-size: 14px;
    text-align: left;
}

.login-hint {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 9px;
    margin-top: 28px;
    padding-top: 22px;
    border-top: 1px solid var(--border);
    color: var(--muted);
    font-size: 12px;
}

.login-hint-icon {
    color: var(--gold);
}

.login-footer {
    margin: 26px 0 0;
    color: #77839a;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 1.5px;
    text-align: center;
}

.login-footer span {
    padding: 0 5px;
    color: var(--accent);
}

@media (max-width: 480px) {
    .login-container {
        padding-top: 28px;
    }

    .login-card {
        padding: 28px 22px;
    }

    .login-emblem {
        width: 56px;
        height: 56px;
        margin-bottom: 20px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .login-field input,
    .login-button {
        transition: none;
    }
}

/* ===== LAYOUT APPLICAZIONE ===== */

html,
body.app-layout {
    height: 100%;
}

body.app-layout {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Header sempre visibile */

body.app-layout .topbar {
    position: relative;
    z-index: 100;
    flex: 0 0 auto;
    width: 100%;
    background: #151c2b;
    border-bottom: 1px solid var(--border);
}

/* Pulsanti dell'header */

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

.header-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
    padding: 7px 13px;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: transparent;
    color: var(--text);
    font: inherit;
    font-size: 14px;
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
}

.header-action:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.logout-form {
    margin: 0;
}

.logout-button {
    background: var(--accent);
    border-color: var(--accent);
    color: #10201d;
}

.logout-button:hover {
    background: #8aebd0;
    color: #10201d;
}

body.app-layout .header-action {
    white-space: nowrap;
}

/* Solo il contenuto centrale scorre */

body.app-layout .app-content {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior-y: contain;
    scrollbar-gutter: stable;
    margin-top: 0;
    margin-bottom: 0;
    padding-top: 36px;
    padding-bottom: 36px;
}

/* Footer sempre visibile */

body.app-layout .app-footer {
    position: relative;
    z-index: 100;
    flex: 0 0 auto;
    width: 100%;
    padding: 14px 16px;
    background: #151c2b;
    border-top: 1px solid var(--border);
}

/* Adattamento per schermi piccoli */

@media (max-width: 480px) {
    body.app-layout .topbar {
        padding: 12px 14px;
        gap: 8px;
    }

    body.app-layout .brand {
        gap: 7px;
        font-size: 12px;
        letter-spacing: 1px;
    }

    body.app-layout .brand-icon {
        width: 32px;
        height: 32px;
        font-size: 18px;
    }

    .header-actions {
        gap: 6px;
    }

    .header-action {
        min-height: 34px;
        padding: 5px 8px;
        font-size: 12px;
    }

    body.app-layout .app-content {
        padding-top: 24px;
        padding-bottom: 24px;
    }

    body.app-layout .app-footer {
        padding: 10px 8px;
        font-size: 11px;
    }
}

/* ===== CORREZIONE LAYOUT DESKTOP ===== */

@media (min-width: 651px) {

    /* Header esteso da bordo a bordo */
    body.app-layout .topbar {
        width: 100%;
        padding-left: 24px;
        padding-right: 24px;
    }

    /* Contenuto centrale a tutta larghezza */
    body.app-layout .app-content {
        width: 100%;
        max-width: none;
        margin: 0;
        padding-left: 32px;
        padding-right: 32px;
        flex: 1 1 0;
        min-height: 0;
        overflow-y: auto;
    }

    /* Footer esteso da bordo a bordo */
    body.app-layout .app-footer {
        width: 100%;
    }
}

/* ===== PAGINA MODULO ===== */

.module-hero {
    margin-bottom: 38px;
}

.back-link {
    display: inline-block;
    margin-bottom: 28px;
    color: var(--muted);
    font-size: 14px;
    text-decoration: none;
}

.back-link:hover {
    color: var(--accent);
}

.module-description {
    max-width: 720px;
    font-size: 16px;
}

.module-summary {
    display: flex;
    flex-wrap: wrap;
    gap: 32px;
    margin: 28px 0 18px;
}

.module-summary > div {
    display: flex;
    flex-direction: column;
}

.summary-number {
    font-size: 26px;
    font-weight: 800;
}

.summary-label {
    color: var(--muted);
    font-size: 13px;
}

.lessons-section {
    margin-bottom: 24px;
}

.lesson-list {
    display: grid;
    gap: 14px;
    margin-top: 22px;
}

.lesson-card {
    display: flex;
    align-items: center;
    gap: 18px;
    padding: 22px;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: var(--panel);
}

.lesson-icon {
    display: grid;
    place-items: center;
    flex: 0 0 46px;
    width: 46px;
    height: 46px;
    border-radius: 13px;
    font-size: 22px;
    font-weight: 800;
}

.lesson-icon.not-started {
    background: #30394b;
    color: var(--muted);
}

.lesson-icon.in-progress {
    background: rgba(255, 209, 102, 0.12);
    color: var(--gold);
}

.lesson-icon.completed {
    background: rgba(112, 225, 193, 0.12);
    color: var(--accent);
}

.lesson-info {
    flex: 1;
    min-width: 0;
}

.lesson-position {
    color: var(--muted);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 1.5px;
}

.lesson-info h3 {
    margin: 5px 0 10px;
    font-size: 17px;
}

.lesson-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    font-size: 12px;
}

.lesson-status {
    font-weight: 700;
}

.lesson-status.not-started {
    color: var(--muted);
}

.lesson-status.in-progress {
    color: var(--gold);
}

.lesson-status.completed {
    color: var(--accent);
}

.lesson-xp {
    color: var(--gold);
    font-weight: 700;
}

.lesson-button {
    flex: 0 0 auto;
    margin-top: 0;
}

@media (max-width: 650px) {
    .lesson-card {
        align-items: flex-start;
        flex-wrap: wrap;
        gap: 12px;
        padding: 16px;
    }

    .lesson-icon {
        flex-basis: 38px;
        width: 38px;
        height: 38px;
        font-size: 18px;
    }

    .lesson-info {
        flex-basis: calc(100% - 50px);
    }

    .lesson-button {
        margin-left: 50px;
    }

    .module-summary {
        gap: 24px;
    }
}


/* ===== PAGINA LEZIONE ===== */

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

.lesson-hero h1 {
    max-width: 900px;
}

.lesson-hero-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 18px;
    margin-top: 20px;
    font-size: 13px;
    font-weight: 700;
}

.lesson-content {
    max-width: 1000px;
    padding: clamp(22px, 4vw, 38px);
}

.lesson-text {
    margin-top: 22px;
    font-size: 17px;
    line-height: 1.9;
    overflow-wrap: anywhere;
}

.lesson-challenge {
    display: flex;
    gap: 16px;
    margin-top: 32px;
    padding: 22px;
    border: 1px solid rgba(255, 209, 102, 0.25);
    border-radius: 14px;
    background: rgba(255, 209, 102, 0.06);
}

.challenge-icon {
    flex: 0 0 38px;
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: rgba(255, 209, 102, 0.12);
    color: var(--gold);
    font-size: 20px;
}

.lesson-challenge h2 {
    margin-top: 0;
}

.lesson-challenge p {
    margin-bottom: 0;
    color: var(--muted);
}

.complete-lesson-button {
    min-height: 48px;
    margin-top: 28px;
}

.lesson-disclaimer {
    margin-top: 12px;
    font-size: 12px;
}

.lesson-notice {
    max-width: 1000px;
    margin-bottom: 20px;
    padding: 15px 18px;
    border: 1px solid var(--border);
    border-radius: 12px;
}

.lesson-notice.success {
    border-color: rgba(112, 225, 193, 0.4);
    background: rgba(112, 225, 193, 0.08);
    color: var(--accent);
}

.lesson-notice.error {
    border-color: #a74e5c;
    background: rgba(167, 78, 92, 0.12);
    color: #ffb8c1;
}

.lesson-completed {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-top: 28px;
    padding: 18px;
    border: 1px solid rgba(112, 225, 193, 0.3);
    border-radius: 12px;
    background: rgba(112, 225, 193, 0.06);
}

.completed-symbol {
    display: grid;
    place-items: center;
    flex: 0 0 40px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(112, 225, 193, 0.14);
    color: var(--accent);
    font-size: 22px;
    font-weight: 800;
}

.lesson-completed p {
    margin: 4px 0 0;
}

.lesson-bottom-nav {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    max-width: 1000px;
    margin-top: 24px;
}

.lesson-bottom-nav .back-link {
    margin-bottom: 0;
}

@media (max-width: 650px) {
    .lesson-text {
        font-size: 15px;
        line-height: 1.8;
    }

    .lesson-challenge {
        gap: 12px;
        padding: 16px;
    }

    .lesson-bottom-nav {
        align-items: flex-start;
    }
}
