/* ==========================================================================
   Writing practice — Writing SWT task screen
   All values mirror Reading's design tokens and patterns exactly.
   ========================================================================== */

/* Workspace wrapper */
.writing-workspace {
    display: flex;
    flex-direction: column;
    gap: var(--space-10);
}

/* Task surface — mirrors Reading's .workspace-stage { padding: space-20 space-32 0 } */
#writingTaskSurface {
    padding: var(--space-20) var(--space-32) 0;
}

/* ---- Context strip ---- */
.writing-context-strip {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-12);
    padding: var(--space-10) var(--space-32);
    border-bottom: var(--border-width-default) solid var(--border-subtle);
}

.writing-context-main {
    display: flex;
    align-items: center;
    gap: var(--space-10);
    min-width: 0;
    flex: 1;
}

/* Filter picker — reuses Reading's mode-picker classes directly */
.writing-mode-picker {
    position: relative;
    display: inline-flex;
    align-items: center;
}

/* ---- Prompt service row (instruction + bookmark) ---- */
.writing-prompt-service-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-16);
    padding: 0 0 var(--space-14);
    border-bottom: var(--border-width-default) solid var(--border-subtle);
}

/* ---- Source block ---- */
.writing-source-block {
    padding: var(--space-10) 0 var(--space-16);
}

.writing-response-input {
    width: 100%;
    /* iOS Safari gives <textarea> an intrinsic UA width from its default `cols`; as a flex
       item its default min-width:auto refuses to shrink below that, so it overflows the
       container to the right on narrow screens. min-width:0 + max-width:100% pins it to the
       container width. (Not reproducible in headless Chromium — verified on device.) */
    min-width: 0;
    max-width: 100%;
    min-height: 110px;
    resize: vertical;
    border: 1px solid var(--input-border-default);
    border-radius: var(--radius-input, 8px);
    padding: 10px 12px;
    font-family: inherit;
    font-size: 0.9375rem;
    color: var(--text-primary);
    background: var(--bg-page);
    box-sizing: border-box;
    line-height: 1.5;
    transition: border-color var(--motion-duration-fast) var(--motion-ease-standard);
}

/* Essay answers are full 200–300 word texts — give the input far more room than SWT's one sentence. */
.writing-response-input--roomy {
    min-height: 320px;
}

.writing-response-input:focus {
    outline: none;
    border-color: var(--input-border-focus);
}

/* Read-only while reviewing feedback (just-submitted or a past attempt) — shows the
   submitted text but can't be edited/cleared; resize off, no focus accent, muted bg. */
.writing-response-input.is-readonly,
.writing-response-input[readonly] {
    background: var(--warm-gray-soft);
    color: var(--text-secondary);
    cursor: default;
    resize: none;
}

.writing-response-input.is-readonly:focus,
.writing-response-input[readonly]:focus {
    border-color: var(--input-border-default);
}

.writing-response-input::placeholder {
    color: var(--text-faint);
}

/* Word count row — status left, count right */
.writing-count-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-8);
}

.writing-count-status {
    font-size: 0.8125rem;
    font-weight: var(--font-weight-regular);
    color: var(--text-muted);
}

.writing-count-status--under  { color: var(--text-muted); }
.writing-count-status--within { color: var(--accent-success); }
.writing-count-status--approaching { color: var(--warning-accent); }
.writing-count-status--over   { color: var(--accent-danger); }

.writing-word-count {
    font-size: 0.8125rem;
    font-weight: var(--font-weight-regular);
    color: var(--text-muted);
}

/* ---- Action row ---- */
.writing-actions {
    /* Cluster Previous + Check answer + Next together on the right (mirrors Reading's
       .question-actions); .question-action-guidance keeps margin-right:auto so the hint
       stays on the left. (Was space-between, which floated Previous to the middle.) */
    justify-content: flex-end;
    flex-wrap: nowrap;
    /* Breathing room above (off the word-count meter) and below (off the divider). */
    margin-top: var(--space-16);
    margin-bottom: var(--space-16);
}

/* The base .question-primary-actions has margin-left:auto; combined with the guidance hint's
   margin-right:auto that put TWO auto margins around Previous, floating it to the middle.
   Drop it here so Previous sits immediately left of Check answer (the guidance hint's
   margin-right:auto still keeps the hint on the far left). */
.writing-actions .question-primary-actions {
    margin-left: 0;
}

#writingNextButton .question-nav-arrow {
    font-size: 0.8125rem;
    transition: transform var(--motion-duration-fast) var(--motion-ease-micro);
}

#writingNextButton:hover .question-nav-arrow {
    transform: translateX(var(--space-2));
}

/* ---- Attempt count + error ---- */

.writing-error-text {
    margin: var(--space-10) 0 0;
    font-size: 0.875rem;
    color: var(--danger-text);
}

.writing-error-text[hidden] {
    display: none;
}

/* ---- Loading prompt ---- */
.writing-loading-prompt {
    margin: var(--space-20) 0;
    font-size: 0.9375rem;
    color: var(--text-muted);
}

.writing-loading-prompt[hidden] {
    display: none;
}

/* ---- Attempts panel — uses .question-attempts-panel classes from reading-practice.css.
   Only positional/margin override needed. ---- */
.writing-attempts-panel {
    margin: 0;
    padding: var(--space-14) 0 0;
    border-top: var(--border-width-default) solid var(--border-subtle);
}

/* Keyboard hints are desktop-only affordances. The shared .question-next-hint-row
   and .kbd-hint-chip are already hidden on touch by reading-practice.css; this hides
   Writing's inline keyboard hint too, mirroring Reading. */
@media (pointer: coarse), (max-width: 767px) {
    .writing-actions .question-keyboard-hint {
        display: none !important;
    }
}

/* Mobile */
@media (max-width: 767px) {
    .writing-context-strip {
        padding: var(--space-8) 0;
    }

    /* Match Reading's mobile rule (.workspace-stage { padding: 0 }) — the card already
       supplies the horizontal gutter. The desktop space-32 side padding here squeezed the
       content into a narrow column and added overflow pressure. */
    #writingTaskSurface {
        padding-left: 0;
        padding-right: 0;
    }

    /* Let the flex column shrink so the textarea can't push past the card edge on iOS. */
    .writing-response-block {
        min-width: 0;
    }

    .writing-response-input {
        min-height: 90px;
        /* iOS Safari auto-zooms (and stays zoomed) when focusing a control with font-size
           < 16px. The desktop size is 0.9375rem (15px); bump to 16px on phones. */
        font-size: 16px;
    }

    /* Keep the essay input roomy on phones too (still shorter than desktop). */
    .writing-response-input--roomy {
        min-height: 220px;
    }

    .writing-primary-actions {
        flex-direction: column;
        align-items: stretch;
        width: 100%;
    }

    .writing-primary-actions .btn-primary {
        width: 100%;
        justify-content: center;
    }
}

/* Completion screen vertical centering. Reading centers via its tall
   .workspace-stage--completion parent; Writing's #writingCompletion has no such
   parent, so it gets the height itself — the shared .completion (justify-center)
   then centers the content. */
#writingCompletion {
    min-height: calc(100dvh - (var(--space-32) * 7));
}

/* ── Writing task-type picker (landing) ───────────────────────────────────
   Reuses Reading's welcome grid + card visuals (.reading-home-task-*). Reading's
   own .reading-task-picker-hero is display:none outside its mobile task-picker-mode,
   so the writing picker carries its own always-visible header here. */
.writing-welcome-state .reading-task-picker-hero {
    display: block;
    padding: var(--space-8) var(--space-4) var(--space-4);
}

.writing-welcome-state .reading-task-picker-title {
    margin: 0 0 var(--space-2);
    font-size: 28px;
    font-weight: var(--font-weight-medium);
    line-height: 1.2;
    color: var(--text-primary);
}

.writing-welcome-state .reading-task-picker-sub-row {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.writing-welcome-state .reading-task-picker-sub {
    margin: 0;
    color: var(--text-subtle);
}

/* Two task types → two balanced columns on desktop. */
@media (min-width: 768px) {
    .writing-home-task-grid.reading-home-task-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

/* Mobile: with only two task types, Reading's flat list-rows look sparse. Present them as large
   cards instead — icon, title, description (stats row to be added later). Each card is ~30% of the
   viewport and sits at the top; the remaining space falls to the bottom by design. */
@media (max-width: 767px) {
    .writing-welcome-state .reading-home-task-card,
    .writing-welcome-state .reading-home-task-card:hover {
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        justify-content: center;
        gap: var(--space-12);
        min-height: 30vh;
        padding: var(--space-24);
        border: var(--border-default-width) solid var(--border-default);
        border-radius: var(--radius-card);
        background: var(--bg-surface-muted);
        box-shadow: none;
    }

    .writing-welcome-state .writing-home-task-grid {
        display: flex;
        flex-direction: column;
        gap: var(--space-16);
    }

    /* Larger icon to anchor the bigger card. */
    .writing-welcome-state .reading-home-task-icon {
        width: var(--space-48);
        height: var(--space-48);
    }

    .writing-welcome-state .reading-home-task-icon .reading-task-icon-svg {
        width: var(--space-24);
        height: var(--space-24);
    }

    .writing-welcome-state .reading-home-task-title {
        font-size: var(--font-size-100);
    }
}

/* Read-only annotated answer shown in review mode (post-submit / history) in place of the
   textarea, so spelling highlights can be rendered. Mirrors the read-only input's look. */
.writing-response-annotated {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    min-height: 110px;
    box-sizing: border-box;
    border: 1px solid var(--input-border-default);
    border-radius: var(--radius-input, 8px);
    padding: 10px 12px;
    font-family: inherit;
    font-size: 0.9375rem;
    line-height: 1.5;
    color: var(--text-secondary);
    background: var(--warm-gray-soft);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.writing-response-annotated--roomy {
    min-height: 320px;
}
