/* ===========================================
   KOIEPRØVEN - Mobile-First Quiz
   =========================================== */

:root {
    --kl-green: #2EB67D;
    --kl-green-dark: #25965F;
    --kl-green-light: rgba(46, 182, 125, 0.08);
    --kl-background: #FDFBF7;
    --kl-surface: #F5F0E8;
    --kl-text: #1A1A1A;
    --kl-text-secondary: #4A4A4A;
    --kl-text-muted: #7A7A7A;
    --kl-error: #C1292E;
    --kl-error-light: rgba(193, 41, 46, 0.08);
    --kl-warning: #E9B44C;
    --kl-border: #D4CFC5;
    --kl-radius: 8px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--kl-background);
    color: var(--kl-text);
    line-height: 1.5;
    min-height: 100vh;
    padding: 24px 16px;
    -webkit-text-size-adjust: 100%;
}

.container {
    max-width: 480px;
    margin: 0 auto;
}

h1 {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--kl-text);
    margin-bottom: 4px;
}

/* Small cabin logo before the title during the quiz; tap = back home.
   Sits beside the h1 (not inside) because data-i18n rewrites h1 text. */
.home-logo-btn {
    display: none;
    width: auto; /* override the global full-width button */
    padding: 4px;
    margin: 0 6px 4px -4px;
    border: 0;
    border-radius: var(--kl-radius);
    background: none;
    cursor: pointer;
    vertical-align: middle;
}

/* Same green cabin as the flying cabins on the result screen */
.home-logo-btn svg {
    display: block;
    width: 30px;
    height: 31px;
    fill: var(--kl-green);
}

.home-logo-btn:hover {
    background: none;
}

.home-logo-btn:focus-visible {
    outline: 2px solid var(--kl-green);
}

body.kl-quiz-active .home-logo-btn {
    display: inline-block;
}

body.kl-quiz-active h1 {
    display: inline-block;
    vertical-align: middle;
}

h2 {
    font-size: 1.25rem;
    font-weight: 600;
}

.subtitle {
    color: var(--kl-text-secondary);
    font-size: 0.95rem;
    margin-bottom: 24px;
}

/* ============ Forms ============ */

.form-group {
    margin-bottom: 20px;
}

.form-group > label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
    font-size: 0.95rem;
}

input[type="text"],
input[type="email"],
input[type="tel"],
input[type="password"] {
    width: 100%;
    padding: 14px;
    border: 2px solid var(--kl-border);
    border-radius: var(--kl-radius);
    font-size: 1rem;
    transition: border-color 0.2s;
    background: #fff;
}

input[type="text"]:focus,
input[type="email"]:focus,
input[type="tel"]:focus,
input[type="password"]:focus {
    outline: none;
    border-color: var(--kl-green);
}

button {
    width: 100%;
    padding: 16px;
    background: var(--kl-green);
    color: #fff;
    border: none;
    border-radius: var(--kl-radius);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    min-height: 52px;
    -webkit-tap-highlight-color: transparent;
}

button:hover {
    background: var(--kl-green-dark);
}

button:active {
    transform: scale(0.98);
}

button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.message {
    margin-top: 12px;
    font-size: 0.9rem;
    min-height: 1.4em;
    opacity: 0;
    transition: opacity 0.3s;
}

.message.visible {
    opacity: 1;
}

.message.error {
    color: var(--kl-error);
}

.message.success {
    color: var(--kl-green-dark);
}

/* ============ Quiz: One Per Page ============ */

.quiz-progress-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.quiz-progress {
    color: var(--kl-text-muted);
    font-size: 0.85rem;
}

.quiz-section-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--kl-green);
    background: var(--kl-green-light, rgba(46, 182, 125, 0.1));
    padding: 2px 10px;
    border-radius: 12px;
}

.question-text {
    font-weight: 600;
    font-size: 1.1rem;
    margin-bottom: 16px;
}

.all-view-question {
    border-top: 2px dashed var(--kl-border);
    padding-top: 24px;
    margin-top: 24px;
}

.all-view-question:first-child {
    border-top: none;
    padding-top: 0;
    margin-top: 0;
}


.options-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 16px;
}

.option-btn {
    text-align: left;
    padding: 14px 16px;
    background: #fff;
    color: var(--kl-text);
    border: 2px solid var(--kl-border);
    font-weight: 400;
    min-height: 48px;
}

.option-btn:hover:not(:disabled) {
    border-color: var(--kl-green);
    background: var(--kl-green-light);
}

.option-btn:disabled {
    opacity: 1;
    cursor: default;
    transform: none;
}

.option-btn.selected {
    border-color: #aaa;
    background: #e8e8e8;
}

.option-btn.option-correct {
    border-color: var(--kl-green);
    background: var(--kl-green-light);
    font-weight: 600;
}

.option-btn.option-wrong {
    border-color: var(--kl-error);
    background: var(--kl-error-light);
}

/* ============ Feedback ============ */

.feedback {
    margin: 16px 0;
    padding: 12px 16px;
    border-radius: var(--kl-radius);
}

.feedback-correct {
    background: var(--kl-green-light);
}

.feedback-wrong {
    background: var(--kl-error-light);
}

.feedback-msg {
    font-weight: 700;
    font-size: 1.1rem;
    text-align: center;
}

.feedback-correct .feedback-msg {
    color: var(--kl-green-dark);
}

.feedback-wrong .feedback-msg {
    color: var(--kl-error);
}

.feedback-explanation {
    font-size: 0.85rem;
    color: var(--kl-text-secondary);
    margin-top: 8px;
    line-height: 1.4;
    text-align: left;
}

.next-btn {
    margin-top: 16px;
}

/* ============ Home Screen ============ */

.home-greeting {
    font-size: 1.1rem;
    font-weight: 500;
    color: var(--kl-text);
    margin-bottom: 24px;
}

.home-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.start-test-btn {
    background: var(--kl-green);
    font-size: 1.1rem;
}

/* ============ Categorize (drag to image zones) ============ */

.categorize-wrapper {
    display: flex;
    gap: 10px;
    margin-bottom: 12px;
}

.categorize-column {
    flex: 1;
    min-width: 0;
}

.categorize-title {
    text-align: center;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--kl-text-secondary);
    margin-bottom: 6px;
}

.categorize-dropzone {
    min-height: 120px;
    border: 2px dashed var(--kl-border);
    border-radius: var(--kl-radius);
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    background: var(--kl-surface);
    transition: border-color 0.2s, background 0.2s;
}

.categorize-dropzone.drag-over {
    border-color: var(--kl-green);
    background: var(--kl-green-light);
}

.categorize-dropzone-img {
    width: 100%;
    height: 80px;
    object-fit: contain;
    margin-bottom: 4px;
    pointer-events: none;
}

.categorize-items {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 12px;
}

.cat-chip {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 10px;
    background: #fff;
    border: 2px solid var(--kl-border);
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 500;
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
    transition: border-color 0.2s, opacity 0.2s;
}

.cat-chip-sprite {
    width: 22px;
    height: 22px;
    pointer-events: none;
    flex-shrink: 0;
}

.cat-chip.dragging {
    opacity: 0.4;
}

.cat-chip-ghost {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
    transform: scale(1.08);
}
.cat-chip.placed {
    background: #e8e8e8;
    border-color: #aaa;
    font-size: 0.7rem;
    padding: 5px 8px;
}

.cat-chip.item-correct {
    border-color: var(--kl-green);
    background: var(--kl-green-light);
}

.cat-chip.item-wrong {
    border-color: var(--kl-error);
    background: var(--kl-error-light);
}

.cat-chip.item-neutral {
    border-color: #ccc;
    background: #f0f0f0;
    opacity: 0.7;
}

/* ============ Select Items (backpack packing) ============ */

.select-counter {
    text-align: center;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--kl-text-muted);
    margin-bottom: 12px;
    transition: color 0.2s;
}

.select-counter-full {
    color: var(--kl-green-dark);
}

.select-counter-over {
    color: var(--kl-error);
}

.select-items-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 16px;
}

.select-items-grid.grid-2x2 {
    grid-template-columns: repeat(2, 1fr);
}

.select-items-grid.grid-2col {
    grid-template-columns: repeat(2, 1fr);
}

.select-item-card {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 12px 6px;
    border: 2px solid var(--kl-border);
    border-radius: var(--kl-radius);
    background: #fff;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s, transform 0.1s;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.select-item-card:active {
    transform: scale(0.96);
}

.select-item-card.selected {
    border-color: var(--kl-green);
    background: var(--kl-green-light);
}

.select-item-sprite {
    width: 36px;
    height: 36px;
}

.select-item-label {
    font-size: 0.7rem;
    text-align: center;
    color: var(--kl-text-secondary);
    font-weight: 500;
    line-height: 1.2;
}

.select-item-feedback {
    cursor: default;
    pointer-events: none;
}

.select-item-feedback.item-correct {
    border-color: var(--kl-green);
    background: var(--kl-green-light);
}

.select-item-feedback.item-correct.item-missed {
    border-style: dashed;
}

.select-item-feedback.item-wrong {
    border-color: var(--kl-error);
    background: var(--kl-error-light);
}

.select-item-feedback.item-neutral {
    border-color: #ccc;
    background: #f0f0f0;
    opacity: 0.7;
}

.item-checkmark {
    position: absolute;
    top: 4px;
    right: 6px;
    font-size: 0.85rem;
    font-weight: 700;
    line-height: 1;
}

.item-checkmark-ok { color: var(--kl-green-dark); }
.item-checkmark-wrong { color: var(--kl-error); }
.item-checkmark-missed { color: #1a1a1a; }


/* ============ Drag & Drop ============ */

.dnd-wrapper {
    margin-bottom: 16px;
}

.dnd-image-area {
    position: relative;
    border: 2px solid var(--kl-border);
    border-radius: var(--kl-radius);
    overflow: hidden;
    background: #eee;
    min-height: 200px;
    touch-action: none;
}

.dnd-image {
    width: 100%;
    height: auto;
    display: block;
    user-select: none;
    -webkit-user-drag: none;
}

.dnd-items {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    margin-top: 12px;
    margin-bottom: 12px;
    justify-content: center;
}

.dnd-item-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.dnd-item-label {
    font-size: 0.75rem;
    color: var(--kl-text-secondary);
    font-weight: 500;
    pointer-events: none;
}

.dnd-chip {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    padding: 8px;
    background: var(--kl-green);
    color: #fff;
    border-radius: 50%;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
    transition: opacity 0.2s, transform 0.1s;
}

.dnd-chip:active {
    cursor: grabbing;
    transform: scale(1.05);
}

.dnd-chip-sprite {
    width: 28px;
    height: 28px;
    pointer-events: none;
}

.dnd-chip.dragging {
    opacity: 0.5;
}

.dnd-chip.dnd-chip-placed {
    opacity: 0.4;
    cursor: grab;
}

.dnd-chip.dnd-chip-wrong {
    position: relative;
    background: var(--kl-error);
    border: 3px solid #8B1A1E;
    opacity: 1;
    cursor: default;
}

.dnd-chip-check {
    position: absolute;
    top: -4px;
    right: -4px;
    font-size: 0.7rem;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
}

.dnd-chip-ghost {
    opacity: 0.8;
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.dnd-marker {
    position: absolute;
    transform: translate(-50%, -50%);
    width: 48px;
    height: 48px;
    padding: 8px;
    background: #aaa;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
    cursor: grab;
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
    touch-action: none;
}

.dnd-marker:active {
    cursor: grabbing;
    transform: translate(-50%, -50%) scale(1.1);
    box-shadow: 0 4px 12px rgba(0,0,0,0.25);
}

.dnd-marker span {
    display: none;
}

.dnd-marker-sprite {
    width: 28px;
    height: 28px;
}

.dnd-marker-correct {
    background: var(--kl-green);
    border: 3px solid var(--kl-green-dark);
}

.dnd-marker-wrong {
    background: var(--kl-error);
    border: 3px solid #8B1A1E;
}

.dnd-marker-check {
    position: absolute;
    top: -4px;
    right: -4px;
    font-size: 0.7rem;
    font-weight: 700;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: white;
    line-height: 1;
}

/* ---- Language switcher (only on email + home screens) ---- */

.container {
    position: relative;
}

#lang-switcher-container {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 10;
}

#lang-switcher-container .lang-switcher {
    display: flex;
    gap: 6px;
}

#lang-switcher-container .lang-btn {
    background: transparent;
    border: 1.5px solid var(--kl-green, #2EB67D);
    color: var(--kl-green, #2EB67D);
    width: 44px;
    height: 33px;
    min-height: 0;
    padding: 0;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 700;
    line-height: 1;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

#lang-switcher-container .lang-btn:hover {
    background: rgba(46, 182, 125, 0.1);
}

#lang-switcher-container .lang-btn.active {
    background: var(--kl-green, #2EB67D);
    color: #fff;
    border-color: var(--kl-green, #2EB67D);
}

/* Dropdown variant: only the active chip is visible until tapped, at
   which point the alternatives unfold vertically below it. Used on
   koielappen so the chips don't overlap the centered passed-cabin
   checkmark. */
#lang-switcher-container .lang-switcher--dropdown {
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
}

#lang-switcher-container .lang-switcher--dropdown .lang-btn { display: none; }
#lang-switcher-container .lang-switcher--dropdown .lang-btn.active { display: flex; order: -1; }
#lang-switcher-container .lang-switcher--dropdown.open .lang-btn { display: flex; }

#lang-switcher-container .lang-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ============ Loading State ============ */

.loading-section {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 80px 0;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--kl-border);
    border-top-color: var(--kl-green);
    border-radius: 50%;
    animation: loadingSpin 0.8s linear infinite;
}

@keyframes loadingSpin {
    to { transform: rotate(360deg); }
}

/* Hide switcher while taking the quiz or viewing a post-attempt lockout.
   Kept visible on passed/result and on the pre-attempt lockout landing
   (body.kl-lockout-landing-active). */
body.kl-quiz-active #lang-switcher-container,
body.kl-lockout-active #lang-switcher-container {
    display: none;
}

/* During the quiz, pulling down must not reload the page (mobile
   pull-to-refresh) — progress is restored on reload, but avoid it. */
html:has(body.kl-quiz-active) {
    overscroll-behavior-y: contain;
}

/* Passed/result screen is a fixed fullscreen canvas with flying cabins;
   disable page scroll so grab-and-throw doesn't fight with viewport scroll.
   The lockout (failure) screen stays scrollable — the wrong-answers list
   can be long. */
body.kl-result-active,
html:has(body.kl-result-active) {
    overflow: hidden;
    overscroll-behavior: none;
}

/* Make the beta feedback banner + all result buttons fit within typical
   mobile viewports (~667 CSS px and up) without scrolling. Most of the
   extra room is reclaimed from the global footer (which holds only the
   tiny version string and otherwise reserves ~150 px of dead space). The
   "Koieprøven" h1 is sr-only here since the green checkmark + h2
   "Koieprøven er bestått!" already announce the page. */
body.kl-result-active h1 {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}
body.kl-result-active .checkmark-container { margin: 32px 0 12px; }
body.kl-result-active .checkmark-svg { width: 150px; height: 154px; }
body.kl-result-active .result-title { margin-bottom: 12px; }
body.kl-result-active .result-name { margin-bottom: 0; }
body.kl-result-active .result-email { margin-bottom: 12px; }
body.kl-result-active .refresh-btn { margin-top: 12px; }
body.kl-result-active #result-section .delete-btn { padding: 8px 16px; margin-top: 8px; font-size: 0.9rem; }
body.kl-result-active .logout-link { margin-top: 10px; }
/* Float the delete-confirm dialog over the bottom of the viewport instead
   of letting it push the result content past the fold. The result page is
   non-scrollable (kl-result-active overflow:hidden), so the inline
   confirmation would otherwise hide "Ja, slett" below the viewport edge. */
body.kl-result-active .delete-confirm {
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    bottom: 16px;
    width: calc(100% - 32px);
    max-width: 448px;
    z-index: 100;
    margin: 0;
    padding: 14px 16px;
    background: var(--kl-background);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
}
body.kl-result-active .delete-confirm p { margin-bottom: 8px; font-size: 0.9rem; }

/* ---- Drag-drop numbered mode (no sprites) ---- */

.dnd-items:has(.dnd-num-cell) {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px 16px;
}

.dnd-num-cell {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    min-width: 0;
}

.dnd-num-label {
    font-size: 0.7rem;
    color: var(--kl-text);
    text-align: center;
    line-height: 1.2;
    word-break: break-word;
}

.dnd-chip-num {
    width: 30px;
    height: 30px;
    padding: 0;
    background: #888;
    font-size: 1rem;
    font-weight: 700;
}

.dnd-marker-num {
    width: 30px;
    height: 30px;
    padding: 0;
    background: #888;
    font-size: 1rem;
    font-weight: 700;
    color: #fff;
}

.dnd-marker-num span {
    display: none;
}

.dnd-marker-num.dnd-marker-correct {
    background: var(--kl-green);
    border: 3px solid var(--kl-green-dark);
}

.dnd-marker-num.dnd-marker-wrong {
    background: var(--kl-error);
    border: 3px solid #8B1A1E;
}

/* ============ VIPPS Checkmark Animation ============ */

.checkmark-container {
    display: flex;
    justify-content: center;
    margin: 32px 0 24px;
}

.checkmark-svg {
    width: 200px;
    height: 205px;
    opacity: 0.55;
}

.checkmark-circle {
    transform-origin: 40px 50px;
    transform: scale(0);
    animation: popCircle 0.4s 0.3s ease-out forwards;
}

.checkmark-check {
    stroke-dasharray: 22;
    stroke-dashoffset: 22;
    animation: drawCheck 0.4s 0.5s ease-out forwards;
}

.checkmark-svg {
    animation: scaleBounce 0.3s 0.8s ease-out both;
}

@keyframes popCircle {
    0%   { transform: scale(0); }
    70%  { transform: scale(1.15); }
    100% { transform: scale(1); }
}

@keyframes drawCheck {
    to { stroke-dashoffset: 0; }
}

@keyframes scaleBounce {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

/* ============ VIPPS X-mark (Failed) Animation ============ */

.xmark-container {
    display: flex;
    justify-content: center;
    margin: 32px 0 24px;
}

.xmark-svg {
    width: 200px;
    height: 205px;
    opacity: 0.55;
    animation: scaleBounce 0.3s 0.8s ease-out both;
}

.xmark-circle {
    transform-origin: 40px 50px;
    transform: scale(0);
    animation: popCircle 0.4s 0.3s ease-out forwards;
}

.xmark-cross {
    stroke-dasharray: 18;
    stroke-dashoffset: 18;
}

.xmark-cross-1 {
    animation: drawCheck 0.25s 0.55s ease-out forwards;
}

.xmark-cross-2 {
    animation: drawCheck 0.25s 0.8s ease-out forwards;
}

/* ============ Flying Cabins Animation ============ */

.flying-cabins {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    overflow: hidden;
    z-index: 0;
}

/* Enable pointer events for cabin avoidance, but pass clicks through */
.flying-cabins.cabins-active {
    pointer-events: auto;
}

.flying-cabin {
    position: absolute;
    width: 24px;
    height: 24px;
    opacity: 0;
    will-change: transform, opacity;
    pointer-events: none;
    touch-action: none;
    cursor: grab;
    /* Koiene logo: roof + boundary with square hole + circle */
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 80 82'%3E%3Cpolygon points='40,2 0,36 80,36' fill='%232EB67D'/%3E%3Cpath d='M17,29 h46 a6,6 0 0 1 6,6 v37 a6,6 0 0 1 -6,6 h-46 a6,6 0 0 1 -6,-6 v-37 a6,6 0 0 1 6,-6 z M24,36 h32 v28 h-32 z' fill='%232EB67D' fill-rule='evenodd'/%3E%3Ccircle cx='40' cy='50' r='11' fill='%232EB67D'/%3E%3C/svg%3E") no-repeat center/contain;
}

.cabins-active .flying-cabin {
    pointer-events: auto;
}

/* Expand clickable area ~50% in each dimension without growing the visual.
   Pointer events on pseudo-elements bubble to the parent, so grab handlers
   on .flying-cabin still fire. */
.cabins-active .flying-cabin::before {
    content: '';
    position: absolute;
    inset: -25%;
}

.flying-cabin.grabbed {
    cursor: grabbing;
    opacity: calc(var(--o, 0.3) * 2) !important;
}

/* Cabins positioned randomly via JS — just define fade-in + drift */

/* Cabins: random position/size/opacity set via JS inline styles.
   Fade in with staggered delay, then gentle CSS drift. */

.cabins-active .flying-cabin {
    animation: cabinFadeIn 0.6s ease-out forwards;
}

@keyframes cabinFadeIn {
    from { opacity: 0; transform: scale(0.4) rotate(-10deg); }
    to   { opacity: var(--o, 0.3); transform: scale(1) rotate(0deg); }
}

@keyframes drift {
    0%, 100% { translate: 0 0; }
    25%  { translate: 8px -6px; }
    50%  { translate: -4px 10px; }
    75%  { translate: 6px 4px; }
}

/* Reduce motion for accessibility */
@media (prefers-reduced-motion: reduce) {
    .flying-cabin {
        animation: none !important;
        opacity: 0 !important;
    }
}

/* ============ Result Section ============ */

#result-section {
    position: relative;
    z-index: 1;
}

.result-title {
    text-align: center;
    color: var(--kl-green-dark);
    margin-bottom: 16px;
}

.result-name {
    text-align: center;
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--kl-text);
    margin-bottom: 2px;
}

.result-email {
    text-align: center;
    font-size: 0.9rem;
    color: var(--kl-text-muted);
    margin-bottom: 20px;
}

/* NTNUI-medlemskapet på bestått-kortet (docs/spec/ntnui-innlogging.md, N6) */
.result-ntnui {
    text-align: center;
    font-weight: 600;
    margin: -8px 0 20px;
}
.result-ntnui.valid { color: var(--kl-green-dark); }
.result-ntnui.expired { color: var(--kl-error); }
.result-ntnui.soon { color: #A87B12; }
/* E-postlinja med «!»: flex midtstiller knappen nøyaktig på tekstlinja, uansett font. */
.result-email.has-shared {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 0.35em;
}
.ntnui-shared-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    flex: none;
    width: 1.2em;
    height: 1.2em;
    min-height: 0;
    margin: 0;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: var(--kl-warning);
    color: #fff;
    font-size: 1em;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
}
.ntnui-shared[hidden] { display: none; }
.ntnui-shared {
    display: block;
    text-align: center;
    margin: -12px 0 20px;
    font-weight: 400;
    font-size: 0.85rem;
    color: var(--kl-warning);
}

/* NTNUI-innlogging: e-postlenka som sekundær inngang */
.ntnui-note {
    font-size: 0.8rem;
    color: var(--kl-text-muted);
    margin-top: 8px;
}
#email-login { margin-top: 16px; }
button.link-btn {
    background: none;
    border: none;
    color: var(--kl-green-dark);
    text-decoration: underline;
    width: auto;
    min-height: 0;
    padding: 8px 0;
    margin: 12px 0 4px;
    font-size: 0.9rem;
    font-weight: 400;
}
#email-login[hidden] { display: none; }

.countdown-label {
    text-align: center;
    color: var(--kl-text-muted);
    font-size: 0.85rem;
    margin-bottom: 4px;
}

.countdown {
    text-align: center;
    font-size: 2.5rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.05em;
    margin-bottom: 24px;
}

.expired-msg {
    text-align: center;
    color: var(--kl-error);
    font-weight: 500;
    margin-bottom: 16px;
}

/* ============ Lockout Section ============ */

.lockout-icon {
    text-align: center;
    font-size: 3rem;
    margin-bottom: 16px;
    margin-top: 24px;
}

.lockout-title {
    text-align: center;
    color: var(--kl-text);
    margin-bottom: 8px;
}

#lockout-section .subtitle {
    text-align: center;
}

#lockout-section .countdown {
    color: var(--kl-warning);
}

.lockout-wrong-heading {
    text-align: center;
    font-weight: 600;
    margin-top: 20px;
    margin-bottom: 8px;
    color: var(--kl-text-primary);
}

.lockout-wrong-item {
    background: var(--kl-error-light);
    border-left: 3px solid var(--kl-error);
    padding: 10px 14px;
    margin-bottom: 8px;
    border-radius: 0 var(--kl-radius) var(--kl-radius) 0;
}

.lockout-wrong-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--kl-text-primary);
}

.lockout-wrong-explanation {
    font-size: 0.85rem;
    color: var(--kl-text-secondary);
    margin-top: 4px;
}

.lockout-tip {
    text-align: center;
    margin-top: 20px;
    font-size: 0.95rem;
    color: var(--kl-text-secondary);
}

.lockout-tip a {
    color: var(--kl-green);
    font-weight: 600;
    text-decoration: none;
}

.lockout-tip a:hover {
    text-decoration: underline;
}

#lockout-section .delete-btn {
    margin-top: 24px;
}

/* ============ Section Transitions ============ */

#email-section,
#quiz-section,
#result-section,
#lockout-section {
    animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ============ Refresh & Delete ============ */

.refresh-btn {
    display: block;
    width: 100%;
    padding: 12px 16px;
    margin-top: 16px;
    background: var(--kl-green);
    color: white;
    border: none;
    border-radius: var(--kl-radius);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
}

.refresh-btn:hover { background: var(--kl-green-dark); }
.refresh-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.refresh-msg {
    text-align: center;
    font-size: 0.9rem;
    margin-top: 8px;
}
.refresh-msg.success { color: var(--kl-green-dark); }
.refresh-msg.error { color: var(--kl-error); }

.delete-btn {
    display: block;
    width: 100%;
    padding: 10px 16px;
    margin-top: 12px;
    background: transparent;
    color: var(--kl-text-muted);
    border: 1px solid var(--kl-border);
    border-radius: var(--kl-radius);
    font-size: 0.9rem;
    cursor: pointer;
}

.delete-btn:hover {
    color: var(--kl-error);
    border-color: var(--kl-error);
}

.delete-confirm {
    margin-top: 12px;
    padding: 16px;
    background: var(--kl-error-light);
    border: 1px solid var(--kl-error);
    border-radius: var(--kl-radius);
    text-align: center;
}

.delete-confirm p {
    font-size: 0.9rem;
    margin-bottom: 12px;
    color: var(--kl-text);
}

.delete-yes {
    padding: 8px 20px;
    background: var(--kl-error);
    color: white;
    border: none;
    border-radius: var(--kl-radius);
    font-weight: 600;
    cursor: pointer;
    margin-right: 8px;
}

.delete-yes:hover { opacity: 0.85; }
.delete-yes:disabled { opacity: 0.5; cursor: not-allowed; }

.delete-no {
    padding: 8px 20px;
    background: transparent;
    color: var(--kl-text-secondary);
    border: 1px solid var(--kl-border);
    border-radius: var(--kl-radius);
    cursor: pointer;
}

.delete-no:hover { background: var(--kl-surface); }

/* ============ Logout & Dev ============ */

.logout-link {
    display: block;
    text-align: center;
    margin-top: 16px;
    color: var(--kl-text-muted);
    font-size: 0.85rem;
    text-decoration: none;
}

.logout-link:hover {
    color: var(--kl-text-secondary);
    text-decoration: underline;
}

.dev-link {
    margin-top: 12px;
    padding: 10px;
    background: #f0e6ff;
    border-radius: var(--kl-radius);
    font-size: 0.85rem;
    word-break: break-all;
}

.dev-link a {
    color: #6B2D5C;
    font-weight: 500;
}

/* ============ True/False List ============ */

.tf-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 16px;
}

.tf-card {
    border: 2px solid var(--kl-border);
    border-radius: var(--kl-radius);
    background: #fff;
    padding: 14px;
    transition: border-color 0.2s, background 0.2s;
}

.tf-statement {
    font-size: 0.95rem;
    color: var(--kl-text);
    margin-bottom: 12px;
    line-height: 1.4;
}

.tf-buttons {
    display: flex;
    gap: 8px;
}

.tf-btn {
    position: relative;
    flex: 1;
    padding: 10px 0;
    border: 2px solid var(--kl-border);
    border-radius: var(--kl-radius);
    background: #fff;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--kl-text-secondary);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: border-color 0.2s, background 0.2s, color 0.2s, transform 0.1s;
}

.tf-btn:active:not(:disabled) {
    transform: scale(0.97);
}

.tf-btn:disabled {
    cursor: default;
}

.tf-btn-selected {
    border-color: var(--kl-text-secondary);
    background: var(--kl-text-secondary);
    color: #fff;
}

.tf-card-correct {
    border-color: var(--kl-green);
    background: var(--kl-green-light);
}

.tf-card-correct .tf-btn-selected {
    border-color: var(--kl-green);
    background: #fff;
    color: var(--kl-text);
    font-weight: 600;
}

.tf-card-wrong {
    border-color: var(--kl-error);
    background: var(--kl-error-light);
}

.tf-card-wrong .tf-btn-selected {
    border-color: var(--kl-error);
    background: #fff;
    color: var(--kl-text);
    font-weight: 600;
}

.tf-btn-correct-answer {
    border-color: var(--kl-green);
    border-style: dashed;
    background: #fff;
    color: var(--kl-text);
    font-weight: 600;
}

.tf-btn-mark {
    position: absolute;
    top: 4px;
    right: 6px;
    font-size: 0.85rem;
    font-weight: 700;
    line-height: 1;
}

.tf-card-correct .tf-btn-selected .tf-btn-mark {
    color: var(--kl-green-dark);
}

.tf-card-wrong .tf-btn-selected .tf-btn-mark {
    color: var(--kl-error);
}

.tf-btn-mark-missed {
    color: var(--kl-green-dark);
}

.tf-explanation {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    font-size: 0.8rem;
    color: var(--kl-text-secondary);
    line-height: 1.4;
}

.tf-error {
    margin-top: 10px;
    padding: 8px 10px;
    background: var(--kl-error-light);
    border: 1px solid var(--kl-error);
    border-radius: var(--kl-radius);
    font-size: 0.8rem;
    color: var(--kl-error);
}


/* ============ Match / Strek (two-column connect-with-lines) ============ */

.strek-stage {
    position: relative;
    display: flex;
    justify-content: space-between;
    gap: 70px;
    padding: 16px;
    margin-bottom: 16px;
    border: 2px dashed var(--kl-border);
    border-radius: var(--kl-radius);
    background: #fafafa;
    touch-action: pan-y;
    overflow: hidden;
}

.strek-svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
}

.strek-col {
    position: relative;
    z-index: 1;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-width: 0;
}

.strek-item {
    position: relative;
    /* Roomy defaults. JS fit-to-box shrinks padding then font-size
       per item so each answer uses the largest type that still fits. */
    padding: 10px 12px;
    border: 2px solid var(--kl-border);
    border-radius: var(--kl-radius);
    background: #fff;
    font-weight: 600;
    font-size: 0.82rem;
    color: var(--kl-text);
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
    /* Gest fra en boks er alltid strek; scroll skjer i midtgangen/kantene */
    touch-action: none;
    text-align: center;
    line-height: 1.3;
    /* Fixed height so every row lines up; text is shrunk to fit by JS */
    height: calc(0.82rem * 1.3 * 3 + 20px + 4px);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.strek-col.strek-left .strek-item {
    background: var(--kl-green-light);
    border-color: var(--kl-green);
}

/* Line colour per row: green, yellow, black, repeating */
.strek-col.strek-left .strek-item:nth-child(3n + 1) { --line-color: #2EB67D; }
.strek-col.strek-left .strek-item:nth-child(3n + 2) { --line-color: #f4c542; }
.strek-col.strek-left .strek-item:nth-child(3n)     { --line-color: #1a1a1a; }

.strek-item.strek-hover {
    box-shadow: 0 0 0 3px var(--kl-green);
}

.strek-item.strek-connected {
    border-color: var(--kl-green);
}

.strek-col .strek-item.strek-correct {
    border-color: var(--kl-green);
    background: var(--kl-green-light);
}

.strek-col .strek-item.strek-wrong {
    border-color: var(--kl-error);
    background: var(--kl-error-light);
}

.strek-item.strek-correct::after,
.strek-item.strek-wrong::after {
    position: absolute;
    top: 4px;
    right: 8px;
    font-size: 0.95rem;
    font-weight: 700;
    line-height: 1;
}

.strek-item.strek-correct::after {
    content: '✓';
    color: var(--kl-green-dark, var(--kl-green));
}

.strek-item.strek-wrong::after {
    content: '✗';
    color: var(--kl-error);
}

.privacy-notice {
    margin-top: 16px;
    font-size: 0.8rem;
    color: #777;
    text-align: center;
}

.privacy-notice > summary {
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 2px;
    list-style: none;
    user-select: none;
}

.privacy-notice > summary::-webkit-details-marker {
    display: none;
}

.privacy-notice[open] > summary {
    margin-bottom: 8px;
}

.privacy-notice p {
    text-align: left;
    margin: 8px 0;
    line-height: 1.5;
    color: #555;
}

/* ── Beta feedback banner + modal ─────────────────────────────────────────
   Banner is hidden by default and only revealed on result/lockout sections
   via the body classes set by showSection() in koielappen.js. */

.feedback-banner {
    display: none;
    align-items: center;
    gap: 8px;
    padding: 5px 10px;
    background: var(--kl-green-light);
    border-bottom: 1px solid var(--kl-border);
    font-size: 0.72rem;
    color: var(--kl-text);
    flex-wrap: wrap;
    justify-content: center;
    min-height: 26px;
    line-height: 1.4;
}

body.kl-result-active .feedback-banner,
body.kl-lockout-active .feedback-banner,
body.kl-lockout-landing-active .feedback-banner,
body.kl-home-active .feedback-banner {
    display: flex;
    /* Pull the banner up + out to swallow the body's 24px top / 16px side
       padding so it sits flush against the browser chrome / safe area. */
    margin: -24px -16px 0;
}

.feedback-banner__pill {
    background: var(--kl-green);
    color: #fff;
    font-size: 0.6rem;
    font-weight: 700;
    letter-spacing: 0.4px;
    padding: 1px 6px;
    border-radius: 999px;
    line-height: 1.4;
}

.feedback-banner__text {
    flex: 0 1 auto;
    text-align: center;
    min-width: 0;
    color: var(--kl-text-secondary);
}

.feedback-banner__btn {
    background: transparent;
    color: var(--kl-green);
    border: 1px solid var(--kl-green);
    border-radius: 4px;
    padding: 2px 9px;
    font-size: 0.7rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
    line-height: 1.5;
    /* Override global button { width:100%; min-height:52px; padding:16px } */
    width: auto;
    min-height: 0;
}

.feedback-banner__btn:hover,
.feedback-banner__btn:focus {
    background: var(--kl-green);
    color: #fff;
    outline: none;
}

/* "ver" toggle — replaces the old footer version line. Reveals the build
   string on click so the banner stays tidy by default. */
.feedback-banner__ver {
    background: transparent;
    border: none;
    color: var(--kl-text-muted);
    font-size: 0.65rem;
    cursor: pointer;
    padding: 0 4px;
    text-decoration: underline;
    /* Override global button { width:100%; min-height:52px; padding:16px } */
    width: auto;
    min-height: 0;
    line-height: 1.4;
}

.feedback-banner__ver:hover,
.feedback-banner__ver:focus {
    color: var(--kl-text);
    background: transparent;
    outline: none;
}

.feedback-banner__verinfo {
    flex-basis: 100%;
    order: 99;
    text-align: center;
    color: var(--kl-text-muted);
    font-size: 0.65rem;
    line-height: 1.4;
    font-family: monospace;
    padding-top: 2px;
}

.feedback-banner__verinfo[hidden] { display: none; }

/* Modal overlay */

.feedback-modal[hidden] { display: none; }

.feedback-modal {
    position: fixed;
    inset: 0;
    z-index: 9000;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 20px 12px;
    overflow-y: auto;
}

.feedback-modal__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(26, 26, 26, 0.55);
}

.feedback-modal__card {
    position: relative;
    background: var(--kl-background);
    border-radius: var(--kl-radius);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
    max-width: 520px;
    width: 100%;
    padding: 24px 22px 22px;
    margin-top: 5vh;
}

.feedback-modal__close {
    position: absolute;
    top: 6px;
    right: 8px;
    background: transparent;
    border: none;
    font-size: 1.6rem;
    line-height: 1;
    color: var(--kl-text-muted);
    cursor: pointer;
    padding: 4px 10px;
    /* Override global button { width:100%; min-height:52px; padding:16px;
       background:var(--kl-green); color:#fff } so the close stays a small
       icon-button in the corner. */
    width: auto;
    min-height: 0;
}

.feedback-modal__close:hover {
    background: transparent;
}

.feedback-modal__close:hover { color: var(--kl-text); }

.feedback-modal__title {
    margin: 0 0 4px 0;
    font-size: 1.3rem;
    color: var(--kl-text);
}

.feedback-modal__subtitle {
    margin: 0 0 16px 0;
    font-size: 0.88rem;
    color: var(--kl-text-secondary);
    line-height: 1.4;
}

/* Form */

.feedback-form__label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--kl-text);
}

.feedback-form__textarea {
    width: 100%;
    padding: 10px 12px;
    border: 2px solid var(--kl-border);
    border-radius: var(--kl-radius);
    font-family: inherit;
    font-size: 0.95rem;
    line-height: 1.5;
    color: var(--kl-text);
    background: #fff;
    resize: vertical;
    min-height: 120px;
    box-sizing: border-box;
}

.feedback-form__textarea:focus {
    outline: none;
    border-color: var(--kl-green);
}

.feedback-form__footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 10px;
    gap: 12px;
    flex-wrap: wrap;
}

.feedback-form__counter {
    font-size: 0.78rem;
    color: var(--kl-text-muted);
    font-variant-numeric: tabular-nums;
}

.feedback-form__counter.is-near-limit { color: var(--kl-warning); }
.feedback-form__counter.is-at-limit { color: var(--kl-error); }

.feedback-form__submit {
    background: var(--kl-green);
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 8px 18px;
    font-size: 0.92rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease;
}

.feedback-form__submit:hover:not(:disabled) { background: var(--kl-green-dark); }

.feedback-form__submit:disabled {
    background: var(--kl-text-muted);
    cursor: not-allowed;
}

.feedback-form__msg {
    margin: 10px 0 0 0;
    font-size: 0.85rem;
    min-height: 1.2em;
}

.feedback-form__msg.is-success { color: var(--kl-green-dark); }
.feedback-form__msg.is-error { color: var(--kl-error); }

/* History list */

.feedback-history__title {
    margin: 22px 0 8px 0;
    font-size: 1rem;
    color: var(--kl-text);
}

.feedback-history {
    list-style: none;
    padding: 0;
    margin: 0;
}

.feedback-history__item {
    border: 1px solid var(--kl-border);
    border-radius: var(--kl-radius);
    padding: 10px 12px;
    margin-bottom: 8px;
    background: #fff;
}

.feedback-history__head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
    font-size: 0.78rem;
    color: var(--kl-text-muted);
}

.feedback-history__actions {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.feedback-history__delete-btn,
.feedback-history__delete-yes,
.feedback-history__delete-no {
    font-size: 0.72rem;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: 4px;
    cursor: pointer;
    width: auto;
    min-height: 0;
    line-height: 1.4;
}

.feedback-history__delete-btn {
    background: transparent;
    color: var(--kl-error);
    border: 1px solid var(--kl-error);
}

.feedback-history__delete-btn:hover,
.feedback-history__delete-btn:focus {
    background: var(--kl-error);
    color: #fff;
    outline: none;
}

.feedback-history__delete-confirm-label {
    font-size: 0.72rem;
    color: var(--kl-text-secondary);
    margin-right: 4px;
}

.feedback-history__delete-yes {
    background: var(--kl-error);
    color: #fff;
    border: 1px solid var(--kl-error);
}

.feedback-history__delete-yes:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.feedback-history__delete-no {
    background: transparent;
    color: var(--kl-text-muted);
    border: 1px solid var(--kl-border);
}

.feedback-history__body {
    font-size: 0.9rem;
    color: var(--kl-text);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    word-break: break-word;
    line-height: 1.45;
}

.feedback-history__empty {
    color: var(--kl-text-muted);
    font-size: 0.85rem;
    font-style: italic;
    margin: 0;
}

.feedback-history__empty[hidden] { display: none; }

@media (max-width: 480px) {
    .feedback-modal__card { padding: 20px 16px 18px; margin-top: 2vh; }
    .feedback-modal__title { font-size: 1.15rem; }
    .feedback-banner { font-size: 0.8rem; padding: 8px 10px; gap: 8px; }
    .feedback-banner__text { flex-basis: 100%; order: 3; text-align: center; }
}


/* Gult kort (docs/spec/ntnui-innlogging.md, N13): bestått, men medlemskap må vises på
   annen måte. Samme kort som det grønne, bare gule farger. */
#result-section.card-yellow .checkmark-svg polygon,
#result-section.card-yellow .checkmark-svg path:not(.checkmark-check),
#result-section.card-yellow .checkmark-circle {
    fill: #E9B44C;
}
#result-section.card-yellow .result-title {
    color: #A87B12;
}
