/*
 * Quiz patente nautica - stile
 * Mobile first: le regole base valgono per lo smartphone, i media query ampliano.
 * Nessun font esterno: si usa il carattere di sistema.
 */

:root {
    color-scheme: light dark;

    --paper: #f2f5f7;
    --surface: #ffffff;
    --surface-2: #e9eef2;
    --ink: #0c2236;
    --ink-soft: #52667a;
    --line: #d5dee6;

    --sea: #0a6c95;
    --sea-dark: #08577a;
    --sea-tint: #e3f1f7;

    --ok: #187a49;
    --ok-tint: #e1f3e9;
    --ko: #c2410c;
    --ko-tint: #fdeadf;
    --signal: #ee5a1c;

    --radius: 14px;
    --radius-sm: 10px;
    --gap: 16px;
    --bar-h: 64px;
    --shadow: 0 1px 2px rgba(12, 34, 54, 0.06), 0 6px 18px rgba(12, 34, 54, 0.05);
}

@media (prefers-color-scheme: dark) {
    :root {
        --paper: #08141f;
        --surface: #0f2233;
        --surface-2: #163048;
        --ink: #e8f0f6;
        --ink-soft: #94a9bb;
        --line: #20384e;

        --sea: #4db3dc;
        --sea-dark: #7cc8e8;
        --sea-tint: #12384d;

        --ok: #52c58a;
        --ok-tint: #11382a;
        --ko: #ff8a57;
        --ko-tint: #40200f;
        --signal: #ff7a3d;

        --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
    }
}

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

html {
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    margin: 0;
    background: var(--paper);
    color: var(--ink);
    font-family: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-size: 1rem;
    line-height: 1.5;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

img {
    max-width: 100%;
    height: auto;
}

a {
    color: var(--sea);
    text-underline-offset: 3px;
}

:focus-visible {
    outline: 3px solid var(--sea);
    outline-offset: 2px;
    border-radius: 6px;
}

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }

    * {
        transition: none !important;
        animation: none !important;
    }
}

/* ---------- Struttura ---------- */

.wrap {
    width: 100%;
    max-width: 760px;
    margin: 0 auto;
    padding: 0 var(--gap);
}

main.wrap {
    padding-bottom: calc(48px + env(safe-area-inset-bottom));
}

.topbar {
    background: var(--ink);
    color: #fff;
    padding-top: env(safe-area-inset-top);
    margin-bottom: 20px;
}

@media (prefers-color-scheme: dark) {
    .topbar {
        background: #050d14;
        border-bottom: 1px solid var(--line);
    }
}

.topbar-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 56px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #fff;
    font-weight: 800;
    letter-spacing: -0.01em;
    text-decoration: none;
}

.brand-mark {
    width: 28px;
    height: 28px;
    flex: none;
}

.nav {
    display: flex;
    gap: 4px;
}

.nav a {
    color: rgba(255, 255, 255, 0.82);
    text-decoration: none;
    padding: 10px 12px;
    border-radius: 999px;
    font-weight: 600;
    font-size: 0.95rem;
}

.nav a:hover,
.nav a[aria-current="page"] {
    background: rgba(255, 255, 255, 0.14);
    color: #fff;
}

h1 {
    font-size: 1.75rem;
    line-height: 1.15;
    letter-spacing: -0.025em;
    font-weight: 800;
    margin: 4px 0 18px;
}

h2 {
    font-size: 1.2rem;
    line-height: 1.25;
    letter-spacing: -0.015em;
    font-weight: 750;
    margin: 28px 0 10px;
}

.muted {
    color: var(--ink-soft);
    font-size: 0.94rem;
}

code {
    background: var(--surface-2);
    padding: 1px 6px;
    border-radius: 6px;
    font-size: 0.88em;
}

/* ---------- Pannelli ---------- */

.card,
.question {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 18px;
    margin-bottom: var(--gap);
    box-shadow: var(--shadow);
}

.card > h2:first-child {
    margin-top: 0;
}

.card-lead {
    border-color: var(--sea);
    background: linear-gradient(180deg, var(--sea-tint), var(--surface) 70%);
}

.notice {
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    margin-bottom: var(--gap);
    font-weight: 500;
}

.notice-ok {
    background: var(--ok-tint);
    color: var(--ok);
}

.notice-error {
    background: var(--ko-tint);
    color: var(--ko);
}

/* ---------- Pulsanti e campi ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 48px;
    padding: 0 20px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--ink);
    font: inherit;
    font-weight: 650;
    text-decoration: none;
    cursor: pointer;
    transition: background-color 0.15s, transform 0.05s;
}

.btn:hover {
    background: var(--surface-2);
}

.btn:active {
    transform: scale(0.98);
}

.btn-primary {
    background: var(--sea);
    border-color: var(--sea);
    color: #fff;
}

.btn-primary:hover {
    background: var(--sea-dark);
}

@media (prefers-color-scheme: dark) {
    .btn-primary {
        color: #04141f;
    }
}

.btn-danger {
    background: var(--ko);
    border-color: var(--ko);
    color: #fff;
}

.btn-danger:hover {
    background: var(--ko);
    filter: brightness(0.92);
}

@media (prefers-color-scheme: dark) {
    .btn-danger {
        color: #1d0b02;
    }
}

.btn-block {
    width: 100%;
}

.btn-small {
    min-height: 40px;
    padding: 0 14px;
    font-size: 0.92rem;
}

.actions-inline {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

.field {
    border: 0;
    padding: 0;
    margin: 0 0 18px;
    min-width: 0;
}

.field legend,
.field > label {
    display: block;
    font-weight: 700;
    margin-bottom: 8px;
    padding: 0;
}

.field select,
.field input[type="password"],
.field input[type="number"] {
    width: 100%;
    min-height: 48px;
    padding: 0 14px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--paper);
    color: var(--ink);
    font: inherit;
    font-size: 1rem; /* 16px: evita lo zoom automatico su iOS */
}

.field select:focus,
.field input[type="password"]:focus,
.field input[type="number"]:focus {
    border-color: var(--sea);
}

.field-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0 16px;
}

/* Scelta categorie: righe grandi, facili da toccare */
.choice-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.choice {
    position: relative;
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 56px;
    padding: 10px 14px;
    border: 1.5px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--paper);
    cursor: pointer;
}

.choice input {
    width: 22px;
    height: 22px;
    flex: none;
    accent-color: var(--sea);
}

.choice-name {
    flex: 1;
    font-weight: 600;
    line-height: 1.3;
}

.choice-count {
    color: var(--ink-soft);
    font-size: 0.88rem;
    white-space: nowrap;
}

.choice:has(input:checked) {
    border-color: var(--sea);
    background: var(--sea-tint);
}

/* ---------- Elenchi ---------- */

.row {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 12px 0;
    border-bottom: 1px solid var(--line);
}

.row:last-child {
    border-bottom: 0;
    padding-bottom: 0;
}

.row:first-of-type {
    padding-top: 0;
}

.row-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 12px;
}

.badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 0.82rem;
    font-weight: 700;
}

.badge-ok {
    background: var(--ok-tint);
    color: var(--ok);
}

.badge-ko {
    background: var(--ko-tint);
    color: var(--ko);
}

/* ---------- Test: barra fissa con timer e tacche ---------- */

.quiz-bar {
    position: sticky;
    top: 0;
    z-index: 20;
    margin: 0 calc(var(--gap) * -1) var(--gap);
    padding: 10px var(--gap) 12px;
    padding-top: calc(10px + env(safe-area-inset-top));
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    box-shadow: var(--shadow);
}

.quiz-bar-main {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.quiz-bar-title {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
    min-width: 0;
}

.quiz-bar-title strong {
    font-size: 1rem;
}

.timer {
    font-variant-numeric: tabular-nums;
    font-size: 1.6rem;
    font-weight: 800;
    letter-spacing: -0.02em;
}

.timer-low {
    color: var(--signal);
}

/* Le tacche ricordano la graduazione di una carta nautica: una per quesito */
.ticks {
    display: flex;
    gap: 3px;
    margin-top: 10px;
}

.tick {
    flex: 1 1 0;
    min-width: 0;
    height: 16px;
    border-radius: 3px;
    background: var(--surface-2);
    border: 1px solid var(--line);
    transition: background-color 0.2s;
}

.tick.is-done {
    background: var(--sea);
    border-color: var(--sea);
}

.tick.is-current {
    outline: 2px solid var(--ink);
    outline-offset: 1px;
}

/* ---------- Quesiti ---------- */

.question {
    scroll-margin-top: 110px;
}

.question-head {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 2px 12px;
    margin-bottom: 8px;
}

.question-number {
    font-weight: 800;
}

.question-text {
    font-size: 1.1rem;
    font-weight: 650;
    line-height: 1.4;
    margin: 0 0 14px;
}

.question-images {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 14px;
}

.question-images img {
    max-height: 240px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: #fff;
    padding: 4px;
}

.answers {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.answer {
    position: relative;
    display: flex;
    align-items: flex-start;
    gap: 12px;
    min-height: 56px;
    padding: 12px 14px;
    border: 1.5px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--paper);
    cursor: pointer;
    transition: border-color 0.12s, background-color 0.12s;
}

.answer:hover {
    border-color: var(--sea);
}

.answer input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.answer-key {
    flex: none;
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--surface-2);
    color: var(--ink-soft);
    font-weight: 800;
    font-size: 0.9rem;
}

.answer-text {
    flex: 1;
    min-width: 0;
    overflow-wrap: anywhere;
    padding-top: 3px;
    line-height: 1.4;
}

.answer:has(.answer-input:checked) {
    border-color: var(--sea);
    background: var(--sea-tint);
}

.answer:has(.answer-input:checked) .answer-key {
    background: var(--sea);
    color: #fff;
}

.answer:has(.answer-input:focus-visible) {
    outline: 3px solid var(--sea);
    outline-offset: 2px;
}

/* Correzione */
.answer-right {
    border-color: var(--ok);
    background: var(--ok-tint);
    cursor: default;
}

.answer-right .answer-key {
    background: var(--ok);
    color: #fff;
}

.answer-wrong {
    border-color: var(--ko);
    background: var(--ko-tint);
    cursor: default;
}

.answer-wrong .answer-key {
    background: var(--ko);
    color: #fff;
}

.answer-review {
    cursor: default;
}

.answer-review:hover {
    border-color: var(--line);
}

.answer-right:hover {
    border-color: var(--ok);
}

.answer-wrong:hover {
    border-color: var(--ko);
}

.tag {
    display: block;
    margin-top: 4px;
    font-size: 0.82rem;
    font-weight: 750;
}

.tag-ok {
    color: var(--ok);
}

.tag-ko {
    color: var(--ko);
}

.question-ok {
    border-left: 6px solid var(--ok);
}

.question-ko {
    border-left: 6px solid var(--ko);
}

/* Barra di consegna fissa in basso */
.submit-bar {
    position: sticky;
    bottom: 0;
    z-index: 15;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin: 0 calc(var(--gap) * -1);
    padding: 12px var(--gap);
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
    background: var(--surface);
    border-top: 1px solid var(--line);
    box-shadow: 0 -6px 18px rgba(12, 34, 54, 0.06);
}

.submit-note {
    margin: 4px 0 16px;
}

/* ---------- Risultato ---------- */

.summary {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.score {
    font-size: 3.6rem;
    font-weight: 850;
    letter-spacing: -0.04em;
    line-height: 1;
}

.score span {
    font-size: 1.6rem;
    color: var(--ink-soft);
    font-weight: 700;
}

.summary p {
    margin: 0 0 6px;
}

.verdict {
    display: inline-block;
    padding: 6px 14px;
    border-radius: 999px;
    font-weight: 800;
}

.verdict-ok {
    background: var(--ok-tint);
    color: var(--ok);
}

.verdict-ko {
    background: var(--ko-tint);
    color: var(--ko);
}

/* ---------- Statistiche ---------- */

.bar-row {
    margin-bottom: 16px;
}

.bar-row:last-child {
    margin-bottom: 0;
}

.bar-label {
    display: flex;
    flex-direction: column;
    gap: 0;
    margin-bottom: 6px;
}

.bar-label > span:first-child {
    font-weight: 650;
}

.bar {
    height: 12px;
    background: var(--surface-2);
    border-radius: 999px;
    overflow: hidden;
}

.bar-fill {
    height: 100%;
    background: var(--ok);
    border-radius: 999px;
}

.bar-low {
    background: var(--signal);
}

/* ---------- Schermi molto stretti (iPhone SE, 320-360px) ---------- */

@media (max-width: 360px) {
    :root {
        --gap: 12px;
    }

    .brand {
        font-size: 0.95rem;
    }

    .brand span {
        white-space: nowrap;
    }

    .nav a {
        padding: 10px 8px;
        font-size: 0.88rem;
    }

    .submit-bar .btn {
        padding: 0 8px;
        font-size: 0.88rem;
    }

    .timer {
        font-size: 1.4rem;
    }
}

/* ---------- Schermi piu' larghi ---------- */

@media (min-width: 640px) {
    :root {
        --gap: 24px;
    }

    h1 {
        font-size: 2.1rem;
    }

    .card,
    .question {
        padding: 22px 24px;
    }

    .field-row {
        grid-template-columns: 1fr 1fr;
    }

    .row {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
    }

    .summary {
        flex-direction: row;
        align-items: center;
        gap: 32px;
    }

    .bar-label {
        flex-direction: row;
        justify-content: space-between;
        align-items: baseline;
        gap: 12px;
    }

    .quiz-bar {
        border: 1px solid var(--line);
        border-radius: var(--radius);
        top: 12px;
        margin: 0 0 var(--gap);
    }

    .submit-bar {
        bottom: 12px;
        margin: 0;
        border: 1px solid var(--line);
        border-radius: var(--radius);
        grid-template-columns: 1fr auto;
    }

    .question {
        scroll-margin-top: 130px;
    }
}

/* Domande da controllare */
.doubt-note {
    margin: 12px 0;
    padding: 10px 12px;
    border-left: 4px solid var(--signal);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    color: var(--ink);
    font-size: 0.92rem;
    white-space: pre-line;
}

.doubt-note strong {
    display: block;
    margin-bottom: 4px;
}
