:root {
    color-scheme: light dark;
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
    --accent: #3157d5;
    --surface: color-mix(in srgb, Canvas 94%, transparent);
    --border: color-mix(in srgb, CanvasText 16%, transparent);
    --shadow: 0 12px 35px rgb(0 0 0 / 18%);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0;
    background: color-mix(in srgb, Canvas 96%, var(--accent) 4%);
    color: CanvasText;
    overflow: hidden;
}

button, .button { font: inherit; }
button, .button {
    border: 0;
    border-radius: 11px;
    background: var(--accent);
    color: white;
    cursor: pointer;
    font-weight: 650;
    padding: .7rem 1rem;
    text-decoration: none;
}
button:disabled { cursor: default; opacity: .45; }
button.secondary { background: color-mix(in srgb, CanvasText 10%, transparent); color: CanvasText; }
.button.secondary { background: color-mix(in srgb, CanvasText 10%, transparent); color: CanvasText; }
.button.large { display: inline-block; padding: .85rem 1.25rem; }

.app-bar {
    align-items: center;
    backdrop-filter: blur(20px);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    min-height: 76px;
    padding: max(.75rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) .75rem max(1rem, env(safe-area-inset-left));
    position: relative;
    z-index: 10;
}
.app-bar h1 { font-size: 1.25rem; margin: .1rem 0 0; }
.eyebrow { color: var(--accent); font-size: .75rem; font-weight: 750; letter-spacing: .08em; margin: 0; text-transform: uppercase; }
.app-version {
    background: color-mix(in srgb, var(--accent) 14%, transparent);
    border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
    border-radius: 999px;
    color: var(--accent);
    display: inline-block;
    font-weight: 750;
    letter-spacing: normal;
    margin-left: .4rem;
    padding: .15rem .45rem;
    text-transform: none;
}
.actions { align-items: center; display: flex; gap: .55rem; }
button.close-timeline {
    background: #ffffff;
    border: 1.5px solid #111111;
    color: #111111;
    margin-left: .45rem;
}
#file-input { height: 1px; opacity: 0; position: absolute; width: 1px; }

main { height: calc(100% - 76px); }
.welcome {
    left: 50%;
    max-width: 560px;
    padding: 2rem;
    position: absolute;
    text-align: center;
    top: 50%;
    transform: translate(-50%, -50%);
    width: min(100%, 560px);
}
.welcome h2 { font-size: clamp(1.6rem, 4vw, 2.35rem); margin: .8rem 0; }
.welcome p { color: color-mix(in srgb, CanvasText 70%, transparent); line-height: 1.55; }
.welcome-icon {
    border-radius: 24%;
    box-shadow: 0 12px 30px rgb(0 0 0 / 20%);
    display: block;
    height: clamp(96px, 14vw, 132px);
    margin: 0 auto;
    object-fit: cover;
    width: clamp(96px, 14vw, 132px);
}
.hint { font-size: .85rem; }
.code-form { align-items: center; display: flex; flex-direction: column; gap: .8rem; margin: 1.4rem auto 0; }
.code-form label { font-size: .85rem; font-weight: 700; }
.code-form input {
    background: Canvas;
    border: 2px solid var(--border);
    border-radius: 14px;
    color: CanvasText;
    font: 700 2rem/1 -apple-system, BlinkMacSystemFont, "SF Pro Rounded", sans-serif;
    letter-spacing: .3em;
    max-width: 280px;
    padding: .8rem .7rem .8rem 1rem;
    text-align: center;
    width: 100%;
}
.code-form input:focus { border-color: var(--accent); outline: 3px solid color-mix(in srgb, var(--accent) 25%, transparent); }
.manual-import { margin-top: 1.5rem; }
.manual-import summary { color: color-mix(in srgb, CanvasText 68%, transparent); cursor: pointer; font-size: .85rem; margin-bottom: 1rem; }
.code-error { color: #d52b35 !important; font-size: .9rem; font-weight: 650; margin: .8rem 0 0 !important; }
.reader, .viewport { height: 100%; width: 100%; }
.language-picker { align-items: center; display: flex; gap: .5rem; font-size: .9rem; font-weight: 650; }
.language-picker select {
    background: Canvas;
    border: 1px solid color-mix(in srgb, CanvasText 25%, transparent);
    border-radius: 10px;
    color: CanvasText;
    font: inherit;
    padding: .55rem .7rem;
}
.viewport { cursor: grab; overflow: auto; overscroll-behavior: contain; padding: 24px; }
.viewport.is-panning { cursor: grabbing; user-select: none; }
.timeline-canvas {
    cursor: grab;
    touch-action: pan-y;
    position: relative;
    transform-origin: top left;
    transition: transform 180ms ease;
}
.timeline-canvas-title {
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Rounded", "Segoe UI", sans-serif;
    font-size: 52px;
    font-weight: 700;
    left: 32px;
    line-height: 1.1;
    max-height: 128px;
    max-width: min(900px, calc(100% - 64px));
    overflow: hidden;
    position: absolute;
    top: 24px;
}
.timeline-item, .timeline-item * { cursor: auto; }
.timeline-item {
    border: 1px solid rgb(0 0 0 / 12%);
    border-radius: 14px;
    box-shadow: var(--shadow);
    color: #151515;
    overflow: hidden;
    position: absolute;
}
.timeline-item.text { background: white; overflow: auto; padding: 16px; white-space: pre-wrap; }
.timeline-item.text .text-content { padding-right: 42px; }
.speech-button {
    align-items: center;
    background: rgb(255 255 255 / 92%);
    border: 1px solid rgb(0 0 0 / 16%);
    border-radius: 999px;
    box-shadow: 0 2px 8px rgb(0 0 0 / 14%);
    color: #111111;
    display: flex;
    height: 34px;
    justify-content: center;
    padding: 0;
    position: absolute;
    right: 8px;
    top: 8px;
    width: 34px;
}
.speech-button svg {
    fill: none;
    height: 20px;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 2.2;
    width: 20px;
}
.timeline-item.image {
    background: transparent;
    border: 0;
    box-shadow: none;
    cursor: grab;
    touch-action: none;
}
.timeline-item.image.is-moving { cursor: grabbing; user-select: none; }
.timeline-item.image img { cursor: inherit; height: 100%; object-fit: contain; pointer-events: none; width: 100%; }
.media-title {
    background: rgb(0 0 0 / 68%);
    bottom: 0;
    color: white;
    left: 0;
    padding: .55rem .75rem;
    position: absolute;
    right: 0;
}
.timeline-item.video iframe,
.timeline-item.video video,
.timeline-item.web iframe { border: 0; height: 100%; width: 100%; }
.timeline-item.video video { background: #000; object-fit: contain; }
.timeline-item.sound { align-items: center; background: white; display: flex; flex-direction: column; gap: .7rem; justify-content: center; padding: 16px; }
.timeline-item.sound audio { max-width: 100%; }
.timeline-item.date {
    align-items: center;
    background: #3157d5;
    color: white;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 14px;
    text-align: center;
}
.timeline-item.date strong { font-size: 1.15rem; }
.timeline-item.quiz { align-items: center; background: white; display: flex; flex-direction: column; gap: 12px; justify-content: center; padding: 18px; text-align: center; }

.message { border-radius: 14px; left: 50%; max-width: 540px; padding: 1.5rem; position: absolute; top: 50%; transform: translate(-50%, -50%); width: calc(100% - 2rem); }
.error { background: #8d1b22; color: white; }
.hidden { display: none !important; }

dialog { border: 0; border-radius: 18px; box-shadow: var(--shadow); max-height: min(780px, 90vh); max-width: 720px; padding: 0; width: calc(100% - 2rem); }
dialog::backdrop { backdrop-filter: blur(6px); background: rgb(0 0 0 / 45%); }
.quiz-shell { display: flex; flex-direction: column; max-height: 90vh; }
.quiz-shell > header, .quiz-shell > footer { align-items: center; display: flex; justify-content: space-between; padding: 1rem 1.25rem; }
.quiz-shell > header { border-bottom: 1px solid var(--border); }
.quiz-shell > footer { border-top: 1px solid var(--border); gap: 1rem; }
.quiz-footer-actions { align-items: center; display: flex; gap: .65rem; margin-left: auto; }
#quiz-close {
    background: #ffffff;
    border: 1.5px solid #111111;
    color: #111111;
}
.quiz-shell h2 { margin: .15rem 0 0; }
.quiz-submission { border-top: 1px solid var(--border); padding: 1rem 1.25rem; text-align: center; }
.student-name-fields { display: grid; gap: .75rem; grid-template-columns: 1fr 1fr; margin: 1rem 0; text-align: left; }
.student-name-fields label { display: grid; font-weight: 650; gap: .35rem; }
.student-name-fields input { border: 1px solid var(--border); border-radius: 10px; font: inherit; padding: .65rem .75rem; }
.quiz-send-status { min-height: 1.25rem; }
.icon-button { background: transparent; color: CanvasText; font-size: 1.8rem; padding: .2rem .6rem; }
#quiz-content { overflow: auto; padding: 1.25rem; }
.question { border-bottom: 1px solid var(--border); padding: 0 0 1rem; }
.question:last-child { border: 0; }
.answer {
    align-items: center;
    border: 2px solid transparent;
    border-radius: 11px;
    display: flex;
    gap: .6rem;
    margin: .45rem 0;
    padding: .55rem .7rem;
    transition: background-color 160ms ease, border-color 160ms ease;
}
.answer::after { font-size: 1.15rem; font-weight: 800; margin-left: auto; }
.answer.correct-answer {
    background: color-mix(in srgb, #2eaf57 16%, Canvas);
    border-color: #2eaf57;
    color: color-mix(in srgb, #167236 88%, CanvasText);
}
.answer.correct-answer::after { content: "✓"; color: #16823b; }
.answer.wrong-answer {
    background: color-mix(in srgb, #dc3545 14%, Canvas);
    border-color: #dc3545;
    color: color-mix(in srgb, #a61f2c 88%, CanvasText);
}
.answer.wrong-answer::after { content: "✕"; color: #c32635; }
.answer input:disabled { opacity: 1; }

body.dragging::after {
    align-items: center;
    background: rgb(49 87 213 / 90%);
    color: white;
    content: "Rilascia il file Timeline";
    display: flex;
    font-size: 1.5rem;
    font-weight: 700;
    inset: 0;
    justify-content: center;
    position: fixed;
    z-index: 100;
}

@media (max-width: 620px) {
    .app-bar { align-items: flex-start; gap: .75rem; }
    .actions { flex-direction: column-reverse; }
    .actions button, .actions .button { font-size: .85rem; padding: .55rem .7rem; }
    .viewport { padding: 10px; }
    .student-name-fields { grid-template-columns: 1fr; }
}
