/* ==========================================================================
   Hulpmiddelen (Toerbuffel add-on): 50/50, Vraag het publiek, Wissel de vraag
   A floating dock that must never look like part of the CBR exam: own dark
   palette (--ll-* tokens in _variables.css), pill shapes and a drop shadow.
   Behaviour: js/components/lifeline-toolbar.js
   ========================================================================== */

.lifeline-toolbar {
    position: fixed;
    right: max(var(--ll-offset), env(safe-area-inset-right, 0px));
    bottom: calc(var(--displace-bottom) + var(--ll-offset));
    z-index: var(--ll-z);
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: var(--ll-gap);
    max-width: calc(100vw - 2 * var(--ll-offset));
}

.lifeline-dock {
    display: flex;
    align-items: center;
    gap: var(--ll-gap);
    padding: var(--ll-gap);
    background: var(--ll-surface);
    color: var(--ll-text);
    border: 1px solid var(--ll-border);
    border-radius: var(--ll-radius-pill);
    box-shadow: var(--ll-shadow);
}

.lifeline-tools {
    display: flex;
    gap: var(--ll-gap);
    padding-right: var(--ll-gap);
    border-right: 1px solid var(--ll-border);
}

/* Collapsed: only the lifebuoy is left, the learner rides without help */
.lifeline-toolbar.is-collapsed .lifeline-tools,
.lifeline-toolbar.is-collapsed .lifeline-panel {
    display: none;
}

.lifeline-btn,
.lifeline-toggle {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
    min-width: var(--ll-btn-size);
    min-height: var(--ll-btn-size);
    padding: 0.25rem 0.5rem;
    border: 0;
    border-radius: var(--ll-radius-pill);
    background: transparent;
    color: var(--ll-text);
    font-size: 0.6875rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    line-height: 1;
    transition: background-color var(--quiz-transition-speed) var(--quiz-transition-easing),
        transform var(--quiz-transition-speed) var(--quiz-transition-easing);
}

.lifeline-btn:hover {
    background: var(--ll-surface-raised);
}

.lifeline-btn:active,
.lifeline-toggle:active {
    transform: scale(0.94);
}

.lifeline-btn:focus-visible,
.lifeline-toggle:focus-visible {
    outline: 2px solid var(--ll-accent);
    outline-offset: 2px;
}

/* Applied to the question on screen (50/50 done, audience panel open) */
.lifeline-btn[aria-pressed="true"] {
    background: var(--ll-accent);
    color: var(--ll-accent-text);
}

/* Not for this question: stays focusable, a click explains why (aria-disabled) */
.lifeline-btn[aria-disabled="true"] {
    opacity: 0.4;
    cursor: not-allowed;
}

.lifeline-btn[aria-disabled="true"]:hover,
.lifeline-btn[aria-disabled="true"]:active {
    background: transparent;
    transform: none;
}

.lifeline-icon {
    width: 1.25rem;
    height: 1.25rem;
    fill: currentColor;
    flex-shrink: 0;
}

.lifeline-toggle {
    width: var(--ll-btn-size);
    padding: 0;
    background: var(--ll-surface-raised);
    color: var(--ll-accent);
}

.lifeline-toggle:hover {
    color: var(--ll-text);
}

.lifeline-toggle .lifeline-icon {
    width: 1.5rem;
    height: 1.5rem;
}

/* Panel above the dock: the audience vote, or why a tool is unavailable */
.lifeline-panel {
    --bs-card-bg: var(--ll-surface);
    --bs-card-color: var(--ll-text);
    --bs-card-border-color: var(--ll-border);
    --bs-card-border-radius: var(--ll-radius-panel);
    --bs-card-spacer-y: 0.875rem;
    --bs-card-spacer-x: 1rem;
    width: min(20rem, calc(100vw - 2 * var(--ll-offset)));
    max-height: 50vh;
    overflow-y: auto;
    color: var(--ll-text);
    box-shadow: var(--ll-shadow);
}

.lifeline-panel-title {
    font-size: 0.9375rem;
    font-weight: 700;
}

.lifeline-panel-meta {
    color: var(--ll-text-muted);
    font-size: 0.8125rem;
}

.lifeline-vote + .lifeline-vote {
    margin-top: 0.625rem;
}

.lifeline-vote-label {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.75rem;
    margin-bottom: 0.25rem;
    font-size: 0.875rem;
}

.lifeline-vote-text {
    display: -webkit-box;
    overflow: hidden;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.lifeline-vote-pct {
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.lifeline-vote .progress {
    --bs-progress-height: 0.5rem;
    --bs-progress-bg: var(--ll-surface-raised);
    --bs-progress-bar-bg: var(--ll-bar);
    --bs-progress-border-radius: var(--ll-radius-pill);
}

/* 50/50: the struck answers go dark and are crossed out, but stay readable,
   so you still learn why they are wrong. The box stays, so nothing jumps. */
.answer-option.lifeline-struck,
.answer-option.lifeline-struck:hover,
.answer-option.lifeline-struck:focus {
    background: var(--ll-surface);
    border-color: var(--ll-surface);
    color: var(--ll-text-muted);
    text-decoration: line-through;
    text-decoration-thickness: 2px;
    box-shadow: none;
    cursor: not-allowed;
}

/* The square in front of the answer (::before) is white by default: it goes dark too */
.answer-option.lifeline-struck::before,
.answer-option.lifeline-struck:hover::before {
    background-color: var(--ll-surface);
    box-shadow: none;
}


/* The dock floats over the content: keep the last answer reachable */
body.has-lifelines .question-content-column {
    padding-bottom: calc(var(--ll-dock-height) + 2 * var(--ll-offset));
}

/* Phone: the dock is in the flow under the answers (js/components/lifeline-toolbar.js moves it there),
   so it never covers an answer or the numeric field */
@media (max-width: 767.98px) {
    .lifeline-toolbar {
        position: static;
        z-index: auto;   /* in the flow the fixed bottom bar paints over it; a scroll brings it above the bar */
        align-items: flex-end;
        max-width: none;
        margin-top: var(--ll-offset);
    }

    body.has-lifelines .question-content-column {
        padding-bottom: var(--ll-offset);
    }
}

/* Results: which questions had help, in the add-on's own colours */
.lifeline-badge {
    background: var(--ll-surface);
    color: var(--ll-text);
}

@media (prefers-reduced-motion: reduce) {
    .lifeline-btn,
    .lifeline-toggle {
        transition: none;
    }

    .lifeline-btn:active,
    .lifeline-toggle:active {
        transform: none;
    }
}

@media print {
    .lifeline-toolbar {
        display: none;
    }
}

/* Vraag het publiek on a hotspot picture: the share on each area */
.lifeline-zone-pct {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    padding: 0.125rem 0.5rem;
    border-radius: var(--ll-radius-pill);
    background: var(--ll-surface);
    color: var(--ll-text);
    font-size: 0.875rem;
    font-weight: 700;
    pointer-events: none;
}

/* Homepage: the dock's tools in the Toerbuffel card, each with a popover that
   says what it does. The popovers live in the top layer (Popover API), so
   they never move the layout; anchor positioning puts them above their button. */
.ll-preview {
    display: flex;
    justify-content: center;
}

.ll-demo-tools {
    padding-right: 0;
    border-right: 0;
}

.ll-preview .lifeline-btn {
    min-width: var(--quiz-touch-target);
    min-height: var(--quiz-touch-target);
    padding: 0.25rem 0.375rem;
}

.lifeline-bi {
    font-size: 1.125rem;
    line-height: 1;
}

.ll-pop {
    width: min(16rem, calc(100vw - 2rem));
    padding: 0.75rem 1rem;
    border: 1px solid var(--ll-border);
    border-radius: var(--ll-radius-panel);
    background: var(--ll-surface);
    color: var(--ll-text);
    box-shadow: var(--ll-shadow);
    font-size: 0.875rem;
    text-align: left;
    opacity: 1;
    transition: opacity var(--quiz-transition-speed) var(--quiz-transition-easing),
        display var(--quiz-transition-speed) allow-discrete,
        overlay var(--quiz-transition-speed) allow-discrete;
}

.ll-pop:not(:popover-open) {
    opacity: 0;
}

@starting-style {
    .ll-pop:popover-open {
        opacity: 0;
    }
}

/* Mini examples in the popovers: show what a tool does, no explanation */
.ll-mini-q {
    margin-bottom: 0.5rem;
    font-weight: 600;
}

.ll-mini-answers {
    display: grid;
    gap: 0.375rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

.ll-mini-answers li {
    padding: 0.375rem 0.5rem;
    border-radius: var(--bs-border-radius-sm);
    background: var(--ll-text);
    color: var(--ll-accent-text);
}

/* Struck by 50/50: dark and crossed out but readable, like in the exam */
.ll-mini-answers li.is-struck {
    background: var(--ll-surface-raised);
    color: var(--ll-text-muted);
    text-decoration: line-through;
    text-decoration-thickness: 2px;
}

.ll-mini-old {
    color: var(--ll-text-muted);
    text-decoration: line-through;
}

/* Wissel demo: a tricky question swapped for an easier one */
.ll-mini-tag {
    margin-bottom: 0.25rem;
    font-size: 0.6875rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--ll-text-muted);
}

.ll-mini-tag-new {
    color: var(--ll-bar);
}

.ll-mini-arrow {
    margin: -0.25rem 0 0.25rem;
    color: var(--ll-accent);
    text-align: center;
}

.ll-w-4 { width: 4%; }
.ll-w-8 { width: 8%; }
.ll-w-15 { width: 15%; }
.ll-w-73 { width: 73%; }

/* The tool whose popover is open stays lit */
.ll-preview:has(.ll-pop-fifty:popover-open) .ll-anchor-fifty,
.ll-preview:has(.ll-pop-audience:popover-open) .ll-anchor-audience,
.ll-preview:has(.ll-pop-swap:popover-open) .ll-anchor-swap {
    background: var(--ll-accent);
    color: var(--ll-accent-text);
}

/* Where anchor positioning exists: above the button, flipped when there is no room.
   Elsewhere the popover keeps the browser default, centred on screen. */
@supports (anchor-name: --ll-a) {
    .ll-anchor-fifty { anchor-name: --ll-fifty; }
    .ll-anchor-audience { anchor-name: --ll-audience; }
    .ll-anchor-swap { anchor-name: --ll-swap; }

    .ll-pop {
        inset: auto;
        margin: 0 0 0.5rem;
        position-area: top;
        position-try-fallbacks: flip-block, flip-inline;
    }

    .ll-pop-fifty { position-anchor: --ll-fifty; }
    .ll-pop-audience { position-anchor: --ll-audience; }
    .ll-pop-swap { position-anchor: --ll-swap; }
}

@media (prefers-reduced-motion: reduce) {
    .ll-pop {
        transition: none;
    }
}
