/*
 * Surveys, micro-feedback probes and the feedback note (CLAUDE.md §12).
 *
 * This is the instrument the whole test rests on, so it is built to be easy to
 * answer honestly on a phone: big targets, one question per row, and the
 * anonymity promise repeated where the student can see it.
 */

/* --- The blocking overlay (§12.2) --- */

.survey-overlay {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: grid;
    place-items: center;
    padding: 24px 16px calc(24px + env(safe-area-inset-bottom));
    overflow-y: auto;
    /* The map stays visible behind it, blurred — they should see what they get
       access to (§12.2). */
    background: rgba(18, 26, 32, 0.55);
    backdrop-filter: blur(7px);
    -webkit-backdrop-filter: blur(7px);
}

.survey-overlay__panel {
    width: 100%;
    max-width: 640px;
    max-height: 100%;
    overflow-y: auto;
    border-radius: 20px;
    background: var(--surface);
    box-shadow: 0 30px 70px -30px rgba(8, 20, 14, 0.7);
}

/* --- Survey --- */

.survey {
    display: flex;
    flex-direction: column;
    gap: 18px;
    padding: 28px 26px;
}

.survey__head {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.survey__eyebrow {
    margin: 0;
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--accent);
}

.survey__title {
    margin: 0;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 27px;
    line-height: 1.15;
    letter-spacing: -0.025em;
}

.survey__intro {
    margin: 0;
    max-width: 52ch;
    font-size: 14.5px;
    line-height: 1.55;
    color: var(--text-2);
    text-wrap: pretty;
}

.survey__progress {
    margin: 0;
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-3);
}

.survey__progress[data-state="complete"] {
    color: #3f7d3a;
}

.survey__list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.survey__item {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--surface);
}

.survey__item[data-answered="true"] {
    border-color: color-mix(in oklab, var(--accent) 35%, var(--border));
    background: color-mix(in oklab, var(--accent) 3%, #fffffe);
}

.survey__question {
    display: flex;
    align-items: baseline;
    gap: 10px;
    font-size: 15.5px;
    line-height: 1.45;
}

.survey__number {
    flex: none;
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-4);
}

.survey__optional {
    color: var(--text-4);
    font-size: 13px;
}

/* A heading above a run of questions that share a `group` (CLAUDE.md §12.7).
   It sits in the <ol> as a bare list item, without the card the questions get. */
.survey__group {
    margin: 10px 0 -4px;
}

.survey__group-title {
    margin: 0;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    color: var(--text-3);
}

.survey__scale {
    display: flex;
    align-items: center;
    gap: 10px;
}

.survey__anchor {
    flex: none;
    max-width: 8ch;
    font-family: var(--font-mono);
    font-size: 10px;
    line-height: 1.3;
    color: var(--text-4);
}

.survey__options {
    display: flex;
    flex: 1;
    gap: 5px;
}

.survey__choice {
    flex: 1;
    display: grid;
    place-items: center;
    min-height: 44px;
    border: 1.5px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    cursor: pointer;
    touch-action: manipulation;
}

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

.survey__value {
    font-family: var(--font-mono);
    font-size: 14px;
    color: var(--text-2);
}

/* Word options (`choice`) instead of numbers: they set their own width and wrap
   onto a second line rather than squeezing five words into five equal columns. */
.survey__options[data-words] {
    flex-wrap: wrap;
    gap: 6px;
}

.survey__options[data-words] .survey__choice {
    flex: 1 1 auto;
    padding: 0 12px;
}

.survey__options[data-words] .survey__value {
    font-family: inherit;
    font-size: 13.5px;
    text-align: center;
}

.survey__choice:hover {
    border-color: var(--accent);
}

.survey__choice:has(input:checked) {
    border-color: var(--accent);
    background: var(--accent);
}

.survey__choice:has(input:checked) .survey__value {
    color: #fffffe;
    font-weight: 600;
}

.survey__choice:has(input:focus-visible) {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.survey__textarea {
    width: 100%;
    padding: 12px;
    border: 1.5px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    color: var(--text-1);
    font-family: inherit;
    /* 16px keeps iOS Safari from zooming on focus. */
    font-size: 16px;
    line-height: 1.55;
    resize: vertical;
}

.survey__error {
    margin: 0;
    color: var(--danger);
    font-size: 14px;
    min-height: 1em;
}

.survey__actions {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
}

.survey__submit {
    flex: 1;
    min-width: 200px;
    min-height: 50px;
    padding: 14px 22px;
    border: 0;
    border-radius: 12px;
    background: var(--accent);
    color: #fffffe;
    font-family: inherit;
    font-size: 15px;
    font-weight: 700;
    text-align: center;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    touch-action: manipulation;
}

.survey__submit:disabled {
    opacity: 0.55;
    cursor: default;
}

.survey__anonymous {
    font-family: var(--font-mono);
    font-size: 10.5px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-4);
}

.survey--thanks {
    text-align: center;
    align-items: center;
}

.survey__points {
    margin: 0;
    font-family: var(--font-mono);
    font-size: 13px;
    color: var(--accent);
}

/* The debriefing from §16 rides in the final survey's outro. */
.survey__outro {
    max-width: 54ch;
    margin: 6px 0;
    padding: 18px;
    border-radius: 12px;
    background: var(--page);
    border: 1px solid var(--border);
    text-align: left;
    font-size: 14.5px;
    line-height: 1.6;
    color: var(--text-1);
}

.survey__outro h2,
.survey__outro h3 {
    margin: 0 0 8px;
    font-family: var(--font-display);
    font-size: 17px;
    letter-spacing: -0.02em;
}

.survey__outro p { margin: 0 0 10px; }
.survey__outro p:last-child { margin-bottom: 0; }

.survey-page__main {
    flex: 1;
    width: 100%;
    max-width: 680px;
    margin: 0 auto;
    padding: 24px 16px calc(40px + env(safe-area-inset-bottom));
}

/* --- Micro-feedback probe (§12.4) --- */

.module-probe,
.module-survey {
    margin-top: 8px;
}

.probe {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 16px 18px;
    border: 1px dashed color-mix(in oklab, var(--module, var(--accent)) 40%, var(--border));
    border-radius: 14px;
    background: color-mix(in oklab, var(--module, var(--accent)) 4%, #fffffe);
}

.probe__prompt {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
}

.probe__options {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.probe__button {
    min-height: 44px;
    padding: 10px 16px;
    border: 1.5px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    font-family: inherit;
    font-size: 15px;
    cursor: pointer;
    touch-action: manipulation;
}

.probe__button[data-chosen="true"] {
    border-color: var(--module, var(--accent));
    background: var(--module, var(--accent));
    color: #fffffe;
}

.probe__anchor {
    font-family: var(--font-mono);
    font-size: 10.5px;
    color: var(--text-4);
}

.probe__comment {
    width: 100%;
    padding: 10px;
    border: 1.5px solid var(--border);
    border-radius: 10px;
    font-family: inherit;
    font-size: 16px;
    line-height: 1.5;
    resize: vertical;
}

.probe__send {
    align-self: flex-start;
    min-height: 44px;
    padding: 10px 20px;
    border: 0;
    border-radius: 10px;
    background: var(--module, var(--accent));
    color: #fffffe;
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}

.probe__send:disabled {
    opacity: 0.45;
    cursor: default;
}

.probe__anonymous,
.probe__thanks {
    margin: 0;
    font-family: var(--font-mono);
    font-size: 10.5px;
    color: var(--text-4);
}

.probe__thanks {
    padding: 14px 18px;
    border-radius: 14px;
    background: color-mix(in oklab, #3f7d3a 10%, #fffffe);
    color: #2c5828;
    font-size: 13px;
}

/* --- The feedback note button (§12.1) --- */

.note-button {
    position: fixed;
    right: 14px;
    /* Pages with their own sticky footer raise this so the button never covers
       the primary action. */
    bottom: calc(var(--note-offset, 14px) + env(safe-area-inset-bottom));
    z-index: 40;
    min-height: 40px;
    padding: 9px 15px;
    border: 1px solid rgba(255, 255, 254, 0.18);
    border-radius: 20px;
    background: rgba(22, 23, 26, 0.82);
    color: rgba(255, 255, 254, 0.92);
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: 0.06em;
    cursor: pointer;
    backdrop-filter: blur(4px);
    touch-action: manipulation;
}

.note-button:hover {
    background: rgba(22, 23, 26, 0.94);
}

/* A teacher's preview (§15.9) has the way back where the feedback button sits. */
.preview-pill {
    display: inline-flex;
    align-items: center;
    border-color: transparent;
    background: color-mix(in oklab, var(--staff) 88%, #16171a);
    color: #fff;
    text-decoration: none;
}

.preview-pill:hover {
    background: var(--staff);
}

/* The module player's footer is sticky; clear it. */
.page--module {
    --note-offset: 84px;
}

/* On a phone the module panel is a full-width bottom sheet, and the button
   lands straight on top of "Start modul". Get out of the way — the student is
   opening a module, not writing feedback, and the button comes back on close. */
@media (max-width: 767px) {
    body:has(.gm-panel:not([hidden])) .note-button {
        opacity: 0;
        pointer-events: none;
    }
}

.note-dialog {
    width: min(460px, calc(100vw - 32px));
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: var(--surface);
}

.note-dialog::backdrop {
    background: rgba(18, 26, 32, 0.5);
}

.note-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 22px;
}

.note-form__title {
    margin: 0;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 20px;
    letter-spacing: -0.02em;
}

.note-form__body {
    margin: 0;
    font-size: 14px;
    line-height: 1.55;
    color: var(--text-2);
}

.note-form__textarea {
    width: 100%;
    padding: 12px;
    border: 1.5px solid var(--border);
    border-radius: 10px;
    font-family: inherit;
    font-size: 16px;
    line-height: 1.55;
    resize: vertical;
}

.note-form__status {
    margin: 0;
    min-height: 1em;
    font-size: 13px;
    color: var(--text-2);
}

.note-form__actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

.note-form__cancel,
.note-form__send {
    min-height: 44px;
    padding: 11px 18px;
    border-radius: 10px;
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}

.note-form__cancel {
    border: 1.5px solid var(--border);
    background: var(--surface);
    color: var(--text-2);
}

.note-form__send {
    border: 0;
    background: var(--accent);
    color: #fffffe;
}

@media (max-width: 600px) {
    .survey {
        padding: 22px 16px;
        gap: 14px;
    }

    .survey__title {
        font-size: 22px;
    }

    /* The 1-7 row needs the full width on a phone, so the anchor words move
       above and below it. */
    .survey__scale {
        flex-direction: column;
        align-items: stretch;
        gap: 6px;
    }

    .survey__anchor {
        max-width: none;
    }

    .survey__anchor:last-child {
        text-align: right;
    }

    .survey__options {
        gap: 4px;
    }

    /* Ten steps across a 390px phone leaves ~32px per target. Two rows of five
       keeps every one of them past the 44px touch minimum (CLAUDE.md §3). */
    .survey__options[data-steps="10"] {
        display: grid;
        grid-template-columns: repeat(5, 1fr);
    }

    /* Word options wrap on a phone. In a grid the second row lines up under the
       first instead of stretching two buttons across the full width. */
    .survey__options[data-words] {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
    }

    .survey__value {
        font-size: 13px;
    }
}
