/*
 * Blocks written with the block editor (learn/builder/): tabs, flashcards,
 * timeline, gallery, columns, download, continue button and Custom HTML.
 *
 * A block is saved in a topic's content as plain HTML that reads sensibly
 * with no style or script: titled parts, a list of front and back, a
 * numbered list, pictures with captions, parts one after another. This
 * file gives that HTML its look, and blocks.js (same folder) turns tabs and
 * flashcards into working ones. Until the script has run, or if it fails,
 * the plain form shows: every tab's content under its title, both sides of
 * every card.
 *
 * The class names are written by the block editor (src/shared/siteExport.ts
 * in the SCORM Builder project). Linked by learn/view.php and put inside
 * the page by api/export-scorm.php.
 *
 * Colours come from the site's theme values (includes/styles.css), so the
 * blocks follow light and dark with the rest of the page.
 */

.fl-tabs,
.fl-cards,
.fl-timeline,
.fl-gallery,
.fl-columns,
.fl-file,
.fl-continue,
.fl-custom,
.fl-spots,
.fl-order,
.fl-check {
    margin: 1.25rem 0;
}

/* Text for screen readers only. */
.fl-vh {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ------------------------------------------------------------------ tabs */

.fl-tabs {
    border: 1px solid var(--border-soft);
    border-radius: var(--r-md);
    background: var(--card-bg);
    overflow: hidden;
}

/* Plain form: each part is its title, then its content. */
.fl-tabs-part {
    padding: 1rem 1.25rem;
}
.fl-tabs-part + .fl-tabs-part {
    border-top: 1px solid var(--border-soft);
}
.fl-tabs-title {
    margin: 0 0 0.5rem;
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text-primary);
}
.fl-tabs-body > :first-child { margin-top: 0; }
.fl-tabs-body > :last-child { margin-bottom: 0; }

/* Working form, once blocks.js has run. */
.fl-tablist {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    padding: 0.5rem 0.5rem 0;
    background: var(--surface-2);
    border-bottom: 1px solid var(--border-soft);
}
.fl-tab {
    appearance: none;
    margin: 0;
    padding: 0.6rem 1rem;
    min-height: 44px;
    border: 1px solid transparent;
    border-bottom: 0;
    border-radius: var(--r-sm) var(--r-sm) 0 0;
    background: transparent;
    color: var(--text-secondary);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}
.fl-tab:hover {
    color: var(--text-primary);
    background: var(--card-bg);
}
.fl-tab[aria-selected="true"] {
    background: var(--card-bg);
    border-color: var(--border-soft);
    color: var(--primary-text);
    box-shadow: inset 0 3px 0 var(--primary-soft);
    /* Covers the list's bottom line, so the tab joins its panel. */
    margin-bottom: -1px;
    padding-bottom: calc(0.6rem + 1px);
}
.fl-tab:focus-visible,
.fl-tabs-body:focus-visible,
.fl-card-flip:focus-visible,
.fl-check-button:focus-visible,
.fl-order-move:focus-visible,
.fl-order-check:focus-visible,
.fl-spot-marker:focus-visible,
.fl-spot-box-close:focus-visible,
.fl-file-link:focus-visible,
.fl-continue-btn:focus-visible,
.fl-gallery-item img:focus-visible {
    outline: 3px solid var(--primary-soft);
    outline-offset: 2px;
}
.fl-tabs.fl-ready .fl-tabs-title { display: none; }
.fl-tabs.fl-ready .fl-tabs-part[hidden] { display: none; }
.fl-tabs.fl-ready .fl-tabs-part + .fl-tabs-part { border-top: 0; }

@media (max-width: 600px) {
    /* Tabs stack; blocks.js tells screen readers the list is vertical. */
    .fl-tablist {
        flex-direction: column;
        padding: 0.5rem;
    }
    .fl-tab {
        text-align: left;
        border-radius: var(--r-sm);
        border-bottom: 1px solid transparent;
    }
    .fl-tab[aria-selected="true"] {
        margin-bottom: 0;
        padding-bottom: 0.6rem;
        border-bottom-color: var(--border-soft);
        box-shadow: inset 3px 0 0 var(--primary-soft);
    }
}

/* ------------------------------------------------------------ flashcards */

.fl-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
    gap: 1rem;
    padding: 0;
    list-style: none;
}
.fl-card {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin: 0;
    padding: 0;
}
.fl-card-front,
.fl-card-back {
    padding: 1rem 1.25rem;
    border: 1px solid var(--border-medium);
    border-radius: var(--r-md);
    background: var(--card-bg);
    color: var(--text-primary);
}
.fl-card-back {
    background: var(--surface-2);
}
.fl-card-front > :first-child,
.fl-card-back > :first-child { margin-top: 0; }
.fl-card-front > :last-child,
.fl-card-back > :last-child { margin-bottom: 0; }

/* Plain form: the side's name is written by the stylesheet. */
.fl-cards:not(.fl-ready) .fl-card-front::before,
.fl-cards:not(.fl-ready) .fl-card-back::before,
.fl-card-side {
    display: block;
    margin-bottom: 0.35rem;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-muted);
}
.fl-cards:not(.fl-ready) .fl-card-front::before { content: "Front"; }
.fl-cards:not(.fl-ready) .fl-card-back::before { content: "Back"; }

/* Working form: both sides share one place; the side not showing is only hidden from sight. */
.fl-card-stage {
    display: grid;
    flex: 1;
    cursor: pointer;
}
.fl-card-stage > .fl-card-front,
.fl-card-stage > .fl-card-back {
    grid-area: 1 / 1;
    min-height: 9rem;
    display: flex;
    flex-direction: column;
    justify-content: center;
    transition: opacity 0.2s ease;
}
.fl-card-stage > .fl-card-back,
.fl-card.fl-flipped .fl-card-stage > .fl-card-front {
    opacity: 0;
    pointer-events: none;
}
.fl-card.fl-flipped .fl-card-stage > .fl-card-back {
    opacity: 1;
    pointer-events: auto;
}
.fl-card-flip {
    appearance: none;
    align-self: flex-start;
    min-height: 44px;
    padding: 0.5rem 1rem;
    border: 1px solid var(--border-strong);
    border-radius: var(--r-sm);
    background: var(--card-bg);
    color: var(--primary-text);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}
.fl-card-flip:hover {
    background: var(--surface-2);
}

@media (prefers-reduced-motion: reduce) {
    .fl-card-stage > .fl-card-front,
    .fl-card-stage > .fl-card-back { transition: none; }
}

/* -------------------------------------------------------------- timeline */

.fl-timeline {
    position: relative;
    padding: 0;
    list-style: none;
    counter-reset: fl-step;
}
.fl-timeline-item {
    position: relative;
    margin: 0;
    padding: 0 0 1.25rem 2.5rem;
    counter-increment: fl-step;
}
.fl-timeline-item:last-child { padding-bottom: 0; }
/* The line joining the items. */
.fl-timeline-item::before {
    content: "";
    position: absolute;
    left: 0.7rem;
    top: 0.4rem;
    bottom: 0;
    width: 2px;
    background: var(--border-medium);
}
.fl-timeline-item:last-child::before { display: none; }
/* The dot; a numbered circle when the block is a list of steps. */
.fl-timeline-item::after {
    content: "";
    position: absolute;
    left: 0.25rem;
    top: 0.3rem;
    width: 1rem;
    height: 1rem;
    border: 3px solid var(--primary-soft);
    border-radius: 50%;
    background: var(--card-bg);
    box-sizing: border-box;
}
.fl-timeline--steps .fl-timeline-item::after {
    content: counter(fl-step);
    left: 0;
    top: 0;
    width: 1.5rem;
    height: 1.5rem;
    border: 0;
    background: var(--primary-fill);
    color: var(--text-on-fill);
    font-size: 0.8rem;
    font-weight: 700;
    line-height: 1.5rem;
    text-align: center;
}
.fl-timeline-title {
    margin: 0 0 0.25rem;
    font-weight: 700;
    color: var(--text-primary);
}
.fl-timeline-body > :first-child { margin-top: 0; }
.fl-timeline-body > :last-child { margin-bottom: 0; }

/* --------------------------------------------------------------- gallery */

.fl-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr));
    gap: 0.75rem;
}
.fl-gallery-item {
    margin: 0;
}
/* Two classes and !important: the SCORM package limits every picture in a topic to 70% of its width. */
.fl-gallery .fl-gallery-item img {
    display: block;
    width: 100% !important;
    max-width: 100% !important;
    height: auto;
    aspect-ratio: 4 / 3;
    object-fit: cover;
    border: 1px solid var(--border-soft);
    border-radius: var(--r-sm);
    cursor: pointer;
}
.fl-gallery-item figcaption {
    margin-top: 0.35rem;
    font-size: 0.875rem;
    color: var(--text-muted);
}

/* --------------------------------------------------------------- columns */

.fl-columns {
    display: grid;
    gap: 1.5rem;
    grid-template-columns: repeat(2, minmax(0, 1fr));
}
.fl-columns--1 { grid-template-columns: minmax(0, 1fr); }
.fl-columns--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.fl-columns--4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.fl-columns-col > :first-child { margin-top: 0; }
.fl-columns-col > :last-child { margin-bottom: 0; }

@media (max-width: 900px) {
    .fl-columns--3,
    .fl-columns--4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 600px) {
    .fl-columns,
    .fl-columns--3,
    .fl-columns--4 { grid-template-columns: minmax(0, 1fr); }
}

/* --------------------------------------------------- picture with markers */

/* Plain form: the picture, then a numbered list of each marker's title and text. */
.fl-spots-stage {
    position: relative;
    display: inline-block;
    max-width: 100%;
    line-height: 0;
}
/* Two classes and !important: the SCORM package limits every picture in a topic to 70% of its width. */
.fl-spots .fl-spots-stage img {
    display: block;
    max-width: 100% !important;
    height: auto;
    border-radius: var(--r-sm);
}
/* Every picture of a topic dims a little under the mouse (section.css), to say it opens larger. On this one the
   numbers are what is pressed, and a picture that changes under them is distracting, so it stays as it is. */
.section-content-inner .fl-spots .fl-spots-stage img:hover {
    opacity: 1;
    filter: none;
    transform: none;
}
.fl-spots-list {
    margin: 0.75rem 0 0;
    padding-left: 1.5rem;
}
.fl-spot { margin-bottom: 0.5rem; }
.fl-spot-title {
    margin: 0 0 0.25rem;
    font-weight: 700;
    color: var(--text-primary);
}
.fl-spot-body > :first-child { margin-top: 0; }
.fl-spot-body > :last-child { margin-bottom: 0; }

/* Working form, once blocks.js has run: a numbered button on the picture for each item. */
.fl-spot-marker {
    appearance: none;
    position: absolute;
    width: 2rem;
    height: 2rem;
    margin: 0;
    padding: 0;
    transform: translate(-50%, -50%);
    border: 2px solid var(--text-on-fill);
    border-radius: 50%;
    background: var(--primary-fill);
    color: var(--text-on-fill);
    font: inherit;
    font-size: 0.9rem;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    box-shadow: var(--elev-1);
}
/* A bigger place to press than the circle itself. */
.fl-spot-marker::after {
    content: "";
    position: absolute;
    inset: -8px;
}
.fl-spot-marker[aria-pressed="true"] { background: var(--primary-fill-hover); transform: translate(-50%, -50%) scale(1.15); }
/* Opened already, when every marker must be opened. */
.fl-spot-marker.fl-spot-seen { background: var(--success-fill); }
/* The item of the chosen number opens in a box beside it, on the picture. */
.fl-spot-box {
    position: absolute;
    z-index: 3;
    width: max-content;
    max-width: min(20rem, 60%);
    padding: 0.75rem 2.25rem 0.75rem 1rem;
    border: 1px solid var(--border-medium);
    border-radius: var(--r-md);
    background: var(--card-bg);
    color: var(--text-primary);
    font-size: 0.95rem;
    line-height: 1.5;
    text-align: left;
    box-shadow: var(--elev-3);
}
.fl-spot-box[hidden] { display: none; }
/* 1.5rem clears the number's circle. */
.fl-spot-box--right { transform: translate(1.5rem, -1rem); }
.fl-spot-box--left { transform: translate(calc(-100% - 1.5rem), -1rem); }
.fl-spot-box--right.fl-spot-box--up { transform: translate(1.5rem, calc(-100% + 1rem)); }
.fl-spot-box--left.fl-spot-box--up { transform: translate(calc(-100% - 1.5rem), calc(-100% + 1rem)); }
.fl-spot-box-body > :last-child,
.fl-spot-box-body .fl-spot-body > :last-child { margin-bottom: 0; }
.fl-spot-box-close {
    appearance: none;
    position: absolute;
    top: 0.25rem;
    right: 0.25rem;
    width: 1.75rem;
    height: 1.75rem;
    padding: 0;
    border: 0;
    border-radius: var(--r-sm);
    background: transparent;
    color: var(--text-secondary);
    font: inherit;
    font-size: 1.25rem;
    line-height: 1;
    cursor: pointer;
}
.fl-spot-box-close:hover { background: var(--surface-2); }
/* On a narrow picture the box spans it, under the number, so it is never cut off at an edge. */
@media (max-width: 600px) {
    .fl-spot-box,
    .fl-spot-box--right,
    .fl-spot-box--left,
    .fl-spot-box--right.fl-spot-box--up,
    .fl-spot-box--left.fl-spot-box--up {
        left: 4% !important;
        width: 92%;
        max-width: 92%;
        transform: translate(0, 1.5rem);
    }
}
/* The list under the picture is the plain form; on screen its items are read in the box instead. */
@media screen {
    .fl-spots.fl-ready .fl-spots-list { display: none; }
}
.fl-spots-hint { margin: 0.5rem 0 0; color: var(--text-muted); }
.fl-spots-status {
    margin: 0 0 0.5rem;
    font-weight: 600;
    color: var(--text-secondary);
}
.fl-spots-status.fl-spots-finished { color: var(--success-text); }
/* On screen one item shows at a time; on paper all of them do. */
@media screen {
    .fl-spots.fl-ready .fl-spot.fl-spot-hidden { display: none; }
}
@media (prefers-reduced-motion: reduce) {
    .fl-spot-marker[aria-pressed="true"] { transform: translate(-50%, -50%); }
}

/* -------------------------------------------------- select all that apply */

.fl-check {
    padding: 1rem 1.25rem;
    border: 1px solid var(--border-medium);
    border-radius: var(--r-md);
    background: var(--card-bg);
}
.fl-check-prompt {
    margin: 0 0 0.5rem;
    font-weight: 700;
    color: var(--text-primary);
}
.fl-check-hint { margin: 0 0 0.75rem; font-size: 0.9rem; color: var(--text-muted); }
/* Plain form: a list of the answers. */
.fl-check-list { margin: 0; padding-left: 1.5rem; }
.fl-check-explain { margin: 0.75rem 0 0; color: var(--text-secondary); }
/* Working form, once blocks.js has run: a row with a tick box for each answer. */
.fl-check.fl-ready .fl-check-list { padding: 0; list-style: none; }
.fl-check.fl-ready .fl-check-item {
    margin: 0 0 0.5rem;
    border: 1px solid var(--border-medium);
    border-radius: var(--r-sm);
    background: var(--surface-2);
}
.fl-check-label {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    margin: 0;
    padding: 0.65rem 0.85rem;
    min-height: 44px;
    font-weight: 400;
    cursor: pointer;
}
.fl-check-box { flex: none; width: 1.15rem; height: 1.15rem; margin: 0.2rem 0 0; }
.fl-check-box:focus-visible { outline: 3px solid var(--primary-soft); outline-offset: 2px; }
.fl-check.fl-check-done .fl-check-label { cursor: default; }
/* A right answer, shown once the question has been answered rightly: an edge and a tick, not colour alone. */
.fl-check-item.fl-check-right { border-color: var(--success-text); border-left-width: 4px; }
.fl-check-item.fl-check-right .fl-check-text::after { content: " \2713"; font-weight: 700; color: var(--success-text); }
.fl-check-foot {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem 1rem;
    margin-top: 0.75rem;
}
.fl-check-button {
    appearance: none;
    min-height: 40px;
    padding: 0 1.25rem;
    border: 0;
    border-radius: var(--r-sm);
    background: var(--primary-fill);
    color: var(--text-on-fill);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}
.fl-check-button[hidden] { display: none; }
.fl-check-status { margin: 0; font-weight: 600; color: var(--text-secondary); }
.fl-check-status.fl-check-ok { color: var(--success-text); }

/* ---------------------------------------------------------- put in order */

.fl-order {
    padding: 1rem 1.25rem;
    border: 1px solid var(--border-medium);
    border-radius: var(--r-md);
    background: var(--card-bg);
}
.fl-order-prompt {
    margin: 0 0 0.75rem;
    font-weight: 700;
    color: var(--text-primary);
}
/* Plain form: a numbered list in the right order. */
.fl-order-list { margin: 0; padding-left: 1.5rem; }
.fl-order-item { margin-bottom: 0.35rem; }
.fl-order-explain { margin: 0.75rem 0 0; color: var(--text-secondary); }

/* Working form, once blocks.js has run: rows the learner moves. The numbers are their places now. */
.fl-order.fl-ready .fl-order-list {
    padding: 0;
    list-style: none;
    counter-reset: fl-order;
}
.fl-order.fl-ready .fl-order-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin: 0 0 0.5rem;
    padding: 0.5rem 0.5rem 0.5rem 0.75rem;
    border: 1px solid var(--border-medium);
    border-radius: var(--r-sm);
    background: var(--surface-2);
    counter-increment: fl-order;
    cursor: grab;
}
.fl-order.fl-ready .fl-order-item::before {
    content: counter(fl-order);
    flex: none;
    width: 1.75rem;
    height: 1.75rem;
    border-radius: 50%;
    background: var(--primary-fill);
    color: var(--text-on-fill);
    font-size: 0.85rem;
    font-weight: 700;
    line-height: 1.75rem;
    text-align: center;
}
.fl-order-text { flex: 1 1 auto; min-width: 0; }
.fl-order-tools { display: inline-flex; flex: none; gap: 0.25rem; }
.fl-order-move {
    appearance: none;
    width: 2.5rem;
    height: 2.5rem;
    padding: 0;
    border: 1px solid var(--border-medium);
    border-radius: var(--r-sm);
    background: var(--card-bg);
    color: var(--text-primary);
    font: inherit;
    font-size: 1.1rem;
    line-height: 1;
    cursor: pointer;
}
.fl-order-move:hover:not(:disabled) { border-color: var(--border-strong); }
.fl-order-move:disabled { opacity: 0.4; cursor: default; }
.fl-order-dragging { opacity: 0.5; }
.fl-order-foot {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem 1rem;
    margin-top: 0.75rem;
}
.fl-order-check {
    appearance: none;
    min-height: 40px;
    padding: 0 1.25rem;
    border: 0;
    border-radius: var(--r-sm);
    background: var(--primary-fill);
    color: var(--text-on-fill);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}
.fl-order-check[hidden] { display: none; }
.fl-order-status { margin: 0; font-weight: 600; color: var(--text-secondary); }
.fl-order-status.fl-order-right { color: var(--success-text); }
/* Solved: the rows are settled and no longer look movable. */
.fl-order.fl-order-done .fl-order-item { cursor: default; }
.fl-order.fl-order-done .fl-order-tools { display: none; }

/* -------------------------------------------------------------- download */

.fl-file {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.25rem 0.75rem;
    padding: 1rem 1.25rem;
    border: 1px solid var(--border-medium);
    border-radius: var(--r-md);
    background: var(--surface-2);
}
.fl-file-link {
    font-weight: 700;
    color: var(--primary-text);
    text-decoration: underline;
}
.fl-file-meta {
    font-size: 0.875rem;
    color: var(--text-muted);
}
.fl-file-desc {
    flex-basis: 100%;
    margin: 0;
    color: var(--text-secondary);
}

/* ------------------------------------------------------- continue button */

.fl-continue {
    display: flex;
    justify-content: center;
    padding: 0.5rem 0;
}
.fl-continue-btn {
    appearance: none;
    min-height: 44px;
    padding: 0.6rem 1.75rem;
    border: 0;
    border-radius: var(--r-sm);
    background: var(--primary-fill);
    color: var(--text-on-fill);
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}
.fl-continue-btn:hover { filter: brightness(1.08); }
/* A pressed button has done its job. */
.fl-continue.fl-continue-done { display: none; }
/* What a continue button holds back, on screen only: paper shows the whole lesson. */
@media screen {
    .fl-gated { display: none !important; }
}
/* Where reading goes on after the button is pressed. */
.fl-continue-next:focus { outline: none; }

/* ------------------------------------------------------------ Custom HTML */

.fl-custom-frame {
    display: block;
    width: 100%;
    border: 1px solid var(--border-soft);
    border-radius: var(--r-sm);
    /* A page expects to sit on white unless its author said it has its own light and dark colours. */
    background: #fff;
}
.fl-custom-frame[data-course-bg="1"] {
    border-color: transparent;
    background: transparent;
}

/* ----------------------------------------------------------------- print */

/* On paper everything is opened out: every tab under its title, both sides of every card. */
@media print {
    .fl-tablist,
    .fl-continue,
    .fl-spots-hint,
    .fl-order-tools,
    .fl-order-foot,
    .fl-check-foot,
    .fl-check-hint,
    .fl-spot-box,
    .fl-spots-status,
    .fl-card-flip { display: none !important; }
    .fl-spots.fl-ready .fl-spots-list { list-style: decimal; padding-left: 1.5rem; border: 0; }
    .fl-tabs.fl-ready .fl-tabs-title { display: block; }
    .fl-tabs.fl-ready .fl-tabs-part[hidden] { display: block !important; }
    .fl-tabs.fl-ready .fl-tabs-part + .fl-tabs-part { border-top: 1px solid var(--border-soft); }
    .fl-card-stage { display: block; }
    .fl-card-stage > .fl-card-front,
    .fl-card-stage > .fl-card-back {
        opacity: 1 !important;
        min-height: 0;
        margin-bottom: 0.5rem;
    }
    .fl-tabs,
    .fl-card,
    .fl-timeline-item,
    .fl-gallery-item { break-inside: avoid; }
}
