/**
 * Exercise UI Styles
 *
 * Styles for the exercise rendering system.
 * Mobile-first, touch-friendly design for Telegram Mini App.
 */

/* ============================================
   Exercise Feedback Colors (colorblind-safe)
   ============================================ */
.exercise-container {
    /* Blue (not green) for "correct" stays colorblind-safe; use the
       palette blue instead of an off-palette Telegram blue. */
    --feedback-correct: var(--accent-blue);
    --feedback-incorrect: var(--accent-danger);
}

/* ============================================
   Call Dock
   ============================================ */
/* The call dock is the band at the bottom of the call screen that holds the
   diagonal Микрофон/Текст fabs and the agent status pill. One number owns it:
   the band itself (styles.css) and the clearance below draw from this token,
   so exercise content can never end up under the fabs. */
:root {
    --call-dock-height: calc(146px + env(safe-area-inset-bottom));
}

/* ============================================
   Exercise Container
   ============================================ */
.exercise-container {
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
    overflow-x: hidden;
    overflow-y: auto;
    flex: 1;
    animation: fadeIn 0.3s ease;
}

/* Clearance for the dock. WebKit drops the bottom padding of a scrolling flex
   column, so the reserve is a real flex item at the end of the scroll extent. */
.exercise-container::after {
    content: "";
    display: block;
    flex: 0 0 var(--call-dock-height);
}

.exercise-container.hidden {
    display: none;
}

/* ============================================
   Exercise Header
   ============================================ */
.exercise-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 16px 4px;
    background: var(--bg-primary);
}

.exercise-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}

.exercise-progress {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-primary);
    background: var(--hero-soft);
    padding: 4px 10px;
    border-radius: 10px;
    margin-inline-start: var(--spacing-sm);
    white-space: nowrap;
}

/* ============================================
   Exercise Instruction
   ============================================ */
.exercise-instruction {
    padding: 4px var(--spacing-md) var(--spacing-sm);
    font-family: ui-serif, Georgia, 'Times New Roman', serif;
    font-size: 21px;
    font-weight: 400;
    color: var(--text-primary);
    line-height: 1.35;
    margin-bottom: 8px;
}

/* ============================================
   Discussion Questions
   ============================================ */

.discussion-questions {
    list-style: decimal;
    padding-inline-start: 20px;
    margin: 0 0 24px 0;
}

.discussion-questions li {
    margin-bottom: 12px;
    font-size: 16px;
    line-height: 1.5;
    padding-inline-start: 4px;
    color: var(--text-primary);
}

.exercise-context {
    padding: var(--spacing-sm) var(--spacing-md);
    font-size: 14px;
    color: var(--text-secondary);
}

/* ============================================
   Reading Passage
   ============================================ */
.exercise-reading-passage {
    margin: 0 var(--spacing-md) var(--spacing-sm);
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-primary);
}

.passage-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: var(--spacing-sm) var(--spacing-md);
    border: none;
    background: none;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.passage-toggle-icon {
    font-size: 12px;
    color: var(--text-muted);
    transition: transform var(--transition-fast);
}

.passage-content {
    padding: 0 var(--spacing-md) var(--spacing-md);
    transition: max-height 0.3s ease, padding 0.3s ease, opacity 0.3s ease;
    opacity: 1;
}

.passage-content.collapsed {
    max-height: 0;
    padding-top: 0;
    padding-bottom: 0;
    overflow: hidden;
    opacity: 0;
}

.exercise-reading-passage .passage-heading {
    font-weight: 600;
    margin-bottom: var(--spacing-xs);
}

/* ============================================
   Exercise Content Area
   ============================================ */
.exercise-content {
    padding: 0 var(--spacing-md);
}

/* ============================================
   Exercise Actions (Check/Continue buttons)
   ============================================ */
.exercise-actions {
    padding: var(--spacing-sm) var(--spacing-md);
}

.exercise-btn {
    width: 100%;
    padding: 14px;
    border: none;
    border-radius: var(--radius-btn);
    font-size: 16px;
    font-weight: 600;
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    transition: background var(--transition-fast), opacity var(--transition-fast);
    min-height: 48px;
}

.exercise-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.exercise-btn .btn-spinner,
.exercise-btn-quiet .btn-spinner {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 2px solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    vertical-align: middle;
    margin-inline-end: 6px;
}

.exercise-check-btn {
    background: var(--accent-primary);
    color: var(--bg-surface);
}

.exercise-check-btn:not(:disabled):active {
    background: var(--accent-primary-hover);
}

.exercise-continue-btn {
    background: var(--accent-primary);
    color: var(--bg-surface);
}

.exercise-continue-btn:not(:disabled):active {
    background: var(--accent-primary-hover);
}

/* Talking exercises (discussion / present): speaking is the action, so the slot
   holds a line about what Dara is doing and, after a minute, a small "Next"
   that never competes with the exercise content. */
.exercise-actions-quiet {
    display: flex;
    justify-content: center;
}

.exercise-talk-hint {
    padding: 10px 0;
    font-size: 14px;
    line-height: 1.4;
    text-align: center;
    color: var(--text-muted);
}

.exercise-btn-quiet {
    padding: 10px 18px;
    border: none;
    border-radius: var(--radius-btn);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    background: transparent;
    color: var(--text-secondary);
    text-decoration: underline;
    min-height: 40px;
    -webkit-tap-highlight-color: transparent;
}

.exercise-btn-quiet:active {
    color: var(--text-primary);
}

.exercise-btn-quiet:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.exercise-btn-link {
    width: 100%;
    padding: 10px;
    border: none;
    border-radius: var(--radius-btn);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    background: transparent;
    color: var(--text-secondary);
    text-decoration: underline;
    min-height: 40px;
}

.exercise-btn-link:active {
    color: var(--text-primary);
}

/* ============================================
   Transition Loading
   ============================================ */
.exercise-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100%;
    gap: var(--spacing-md);
    color: var(--text-muted);
    font-size: 14px;
}

.exercise-loading .loading-spinner {
    width: 32px;
    height: 32px;
}

/* ============================================
   Question Items
   ============================================ */
.exercise-question {
    margin-bottom: var(--spacing-md);
}

.exercise-question:last-child {
    margin-bottom: 0;
}

.exercise-question-number {
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--accent-warning-text);
    margin-bottom: var(--spacing-xs);
}

.exercise-question-text {
    font-size: 16px;
    line-height: 1.5;
    color: var(--text-primary);
    margin-bottom: var(--spacing-sm);
}

/* ============================================
   Gap Fill Drag
   ============================================ */
.gap-fill-sentence {
    font-size: 16px;
    line-height: 1.8;
    margin-bottom: 20px;
}

.gap-fill-blank {
    display: inline-block;
    width: 80px;
    height: 28px;
    border-bottom: 2px dashed var(--accent-primary);
    margin: 0 4px;
    vertical-align: middle;
    background: var(--bg-surface);
    border-radius: 8px;
    box-shadow: var(--shadow-sm);
    text-align: center;
    cursor: pointer;
    transition: border-color var(--transition-fast);
    position: relative;
}

.gap-fill-blank.filled {
    border-bottom-style: solid;
    font-weight: 600;
    color: var(--accent-primary);
    line-height: 28px;
}

.gap-fill-blank .blank-chip {
    display: inline-block;
    background: var(--accent-primary);
    color: var(--bg-surface);
    padding: 2px 10px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    position: absolute;
    bottom: 2px;
    left: 50%;
    transform: translateX(-50%);
    white-space: nowrap;
}

.word-bank {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    padding-top: 16px;
    border-top: 1px solid var(--border-color);
}

/* Gap-fill word bank sticks to the bottom of the scroll area so chips stay
   reachable while the user scrolls long texts (drag distance shrinks too). */
.exercise-content > .word-bank {
    position: sticky;
    bottom: var(--spacing-sm);
    background: var(--bg-surface);
    border-top: none;
    border-radius: 16px;
    box-shadow: var(--shadow-sm);
    padding: 12px;
    margin: var(--spacing-sm) 0;
    z-index: 2;
    max-height: 35vh;
    overflow-y: auto;
}

.word-chip {
    display: inline-flex;
    align-items: center;
    padding: 8px 16px;
    background: var(--bg-surface);
    border: 1.5px solid var(--border-color);
    border-radius: 12px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    box-shadow: var(--shadow-sm);
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
    transition: background var(--transition-fast), border-color var(--transition-fast), opacity var(--transition-fast);
    min-height: 44px;
}

.word-chip:active {
    background: var(--bg-secondary);
}

.word-chip.selected {
    background: var(--accent-primary);
    color: var(--bg-surface);
    border-color: var(--accent-primary);
}

.word-chip.used {
    opacity: 0.3;
    pointer-events: none;
}

/* ============================================
   Multiple Choice
   ============================================ */
.mc-options {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

.mc-option {
    display: flex;
    align-items: center;
    padding: 14px 16px;
    background: var(--bg-surface);
    border: 1.5px solid var(--border-color);
    border-radius: 10px;
    font-size: 16px;
    color: var(--text-primary);
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    transition: border-color var(--transition-fast), background var(--transition-fast);
    min-height: 48px;
}

.mc-option:active {
    background: var(--bg-secondary);
}

.mc-option.selected {
    border-color: var(--accent-primary);
    background: var(--hero-soft);
}

.mc-option .mc-indicator {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-color);
    border-radius: 50%;
    margin-right: 12px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: border-color var(--transition-fast), background var(--transition-fast);
}

.mc-option.selected .mc-indicator {
    border-color: var(--accent-primary);
}

.mc-option.selected .mc-indicator::after {
    content: '';
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--accent-primary);
}

/* Checkbox variant for multiple select */
.mc-option .mc-indicator.checkbox {
    border-radius: 4px;
}

.mc-option.selected .mc-indicator.checkbox::after {
    content: '✓';
    width: auto;
    height: auto;
    border-radius: 0;
    background: none;
    color: var(--accent-primary);
    font-size: 14px;
    font-weight: bold;
}

/* True/false-style question: statement card with two side-by-side chips */
.mc-question.mc-question-binary {
    background: var(--bg-surface);
    border-radius: 12px;
    box-shadow: var(--shadow-sm);
    padding: 14px 16px;
}

.mc-options.mc-options-binary {
    flex-direction: row;
    gap: 8px;
}

.mc-options-binary .mc-option {
    flex: 1;
    justify-content: center;
    text-align: center;
    padding: 10px 12px;
    min-height: 44px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    background: var(--bg-primary);
    font-weight: 600;
    font-size: 15px;
}

.mc-options-binary .mc-option.selected {
    border-color: var(--accent-primary);
    background: var(--hero-soft);
}

.mc-options-binary .mc-option .mc-indicator {
    display: none;
}

/* Image option grid for picture-based multiple choice */
.mc-options.mc-options-images {
    flex-direction: row;
    flex-wrap: wrap;
    gap: var(--spacing-sm);
}

.mc-option.mc-option-image {
    flex: 1 1 calc(50% - var(--spacing-sm));
    max-width: calc(50% - var(--spacing-sm) / 2);
    padding: 6px;
    justify-content: center;
    min-height: unset;
}

.mc-option-img {
    width: 100%;
    max-height: 200px;
    object-fit: cover;
    border-radius: calc(var(--radius-md) - 4px);
    display: block;
}

.mc-option.mc-option-image.selected {
    border-color: var(--accent-primary);
    border-width: 3px;
    padding: 4px;
}

.mc-option.mc-option-image.feedback-correct {
    border-color: var(--feedback-correct) !important;
    border-width: 3px;
    padding: 4px;
}

.mc-option.mc-option-image.feedback-incorrect {
    border-color: var(--feedback-incorrect) !important;
    border-width: 3px;
    padding: 4px;
    opacity: 0.6;
}

/* ============================================
   Dropdown
   ============================================ */
.dropdown-sentence {
    font-size: 16px;
    line-height: 2.2;
    margin-bottom: var(--spacing-sm);
}

.dropdown-select {
    display: inline-block;
    padding: 9px 24px 9px 14px;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    color: var(--accent-primary);
    background: var(--bg-surface);
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='8' viewBox='0 0 12 12'%3E%3Cpath fill='%238A7261' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    outline: none;
    margin: 0 4px;
    font-family: inherit;
}

/* ============================================
   Matching
   ============================================ */
.matching-container {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.matching-pair-row {
    display: flex;
    align-items: stretch;
    gap: 12px;
    margin-bottom: 12px;
}

.matching-item {
    flex: 1;
    padding: 12px;
    background: var(--bg-surface);
    border: 1.5px solid transparent;
    border-radius: var(--radius-btn);
    box-shadow: var(--shadow-sm);
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
    text-align: start;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    transition: border-color var(--transition-fast), background var(--transition-fast);
    min-height: 44px;
    display: flex;
    align-items: center;
    position: relative;
}

.matching-item:active {
    background: var(--bg-secondary);
}

.matching-item.selected {
    border-color: var(--accent-primary);
    background: var(--accent-primary);
    color: var(--bg-surface);
}

.matching-item.selected .matching-row-number {
    background: var(--bg-surface) !important;
    color: var(--accent-primary) !important;
}

/* Right column is an unassigned pool, not a pre-linked answer:
   dashed border (no fill) breaks the "already paired" row illusion. */
.matching-item.matching-right {
    border-style: dashed;
    border-color: var(--border-color);
    background: transparent;
    box-shadow: none;
}

.matching-item.matching-right.matched,
.matching-item.matching-right.selected {
    border-style: solid;
}

.matching-item.matched {
    border-color: var(--accent-primary);
}

.matching-badge {
    position: absolute;
    top: -8px;
    inset-inline-start: -8px;
    background: var(--accent-primary);
    color: white;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
}

.matching-item.matched .matching-badge {
    background: var(--feedback-correct);
}

.matching-row-number {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--bg-secondary);
    color: var(--text-primary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    margin-inline-end: var(--spacing-sm);
    flex-shrink: 0;
}

.matching-item.matched .matching-row-number {
    display: none;
}

.matching-right-image {
    padding: 4px;
    overflow: hidden;
    min-height: 88px;
}

.matching-right-img {
    display: block;
    width: 100%;
    max-height: 96px;
    object-fit: contain;
    border-radius: var(--radius-sm);
}

.matching-connector {
    display: none;
}

/* ============================================
   Type In
   ============================================ */
.type-in-sentence {
    font-size: 16px;
    line-height: 1.8;
    margin-bottom: 0;
}

.type-in-input {
    display: inline-block;
    border: 1px solid var(--border-color);
    background: var(--bg-surface);
    box-shadow: var(--shadow-sm);
    width: 100px;
    font-size: 16px;
    font-family: inherit;
    color: var(--accent-primary);
    font-weight: 600;
    text-align: center;
    outline: none;
    border-radius: 8px;
    padding: 2px 4px;
    transition: border-color var(--transition-fast), background var(--transition-fast);
}

.type-in-input:focus {
    border-color: var(--accent-primary);
}

.type-in-input::placeholder {
    color: var(--text-muted);
}

/* ============================================
   Text Correction
   ============================================ */
.correction-sentence {
    font-size: 16px;
    line-height: 2.2;
    margin-bottom: 12px;
    padding: 12px 16px;
    background: var(--bg-primary);
    border-radius: var(--radius-md);
}

.correction-pair {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    vertical-align: baseline;
    white-space: nowrap;
}

.correction-wrong {
    font-weight: bold;
    color: var(--feedback-incorrect);
}

.correction-input {
    display: inline-block;
    border: 1.5px solid var(--border-color);
    background: var(--bg-surface);
    border-radius: 8px;
    padding: 2px 6px;
    font-size: 14px;
    color: var(--text-primary);
    outline: none;
    font-family: inherit;
    width: 100px;
    transition: border-color var(--transition-fast);
}

.correction-input:focus {
    border-color: var(--accent-primary);
}

/* ============================================
   Sequencing
   ============================================ */
.sequencing-items {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

.sequencing-slot {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

/* Position numbers are hidden: cards carry a drag-handle glyph instead. */
.sequencing-number {
    display: none;
}

.sequencing-chip::before {
    content: '\283F'; /* ⠿ grip glyph */
    color: var(--text-muted);
    font-size: 16px;
    line-height: 1;
    flex-shrink: 0;
}

.sequencing-chip {
    flex: 1;
    padding: 12px 16px;
    background: var(--bg-surface);
    border: 1px solid transparent;
    border-radius: var(--radius-btn);
    font-size: 14px;
    color: var(--text-primary);
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    transition: border-color var(--transition-fast), background var(--transition-fast), transform var(--transition-fast);
    min-height: 44px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: var(--shadow-sm);
}

.sequencing-chip:active {
    background: var(--bg-secondary);
    transform: scale(0.98);
}

.sequencing-chip.selected {
    border-color: var(--accent-primary);
    background: var(--accent-primary);
    color: #fff;
}

/* Drag handle for sequencing items */
.drag-handle {
    color: var(--text-muted);
    cursor: grab;
    display: flex;
    flex-direction: column;
    gap: 3px;
    flex-shrink: 0;
}

.drag-handle span {
    display: block;
    width: 16px;
    height: 2px;
    background: currentColor;
}

/* ============================================
   Sorting
   ============================================ */
.sorting-categories {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
}

.sorting-category {
    background: var(--bg-primary);
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-md);
    padding: 12px;
    min-height: 56px;
    overflow: hidden;
}

.sorting-category-header {
    padding: 8px var(--spacing-md);
    background: var(--hero-soft);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.08em;
    color: var(--accent-warning-text);
    text-transform: uppercase;
    margin: -12px -12px 10px -12px;
}

.sorting-category-items {
    min-height: 48px;
    display: flex;
    flex-wrap: wrap;
    gap: var(--spacing-xs);
}

.sorting-category-items .word-chip {
    padding: 6px 12px;
    font-size: 14px;
    min-height: unset;
}

/* Items tray renders ABOVE the categories (tap chip → tap category), so the
   user sees what to sort without scrolling past empty category boxes. */
.sorting-source {
    margin-bottom: var(--spacing-sm);
}

.sorting-source .word-bank {
    border-top: none;
    padding-top: 0;
}

.sorting-source-label {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: var(--spacing-sm);
}

/* ============================================
   Crossword
   ============================================ */
.crossword-section {
    margin-bottom: var(--spacing-md);
}

.crossword-section-title {
    font-size: 12px;
    font-weight: 700;
    color: var(--accent-warning-text);
    margin-bottom: var(--spacing-sm);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.crossword-clue {
    margin-bottom: 16px;
}

.crossword-clue-text {
    font-size: 14px;
    line-height: 1.4;
    color: var(--text-primary);
    margin-bottom: 6px;
    display: flex;
    gap: 8px;
}

.crossword-clue-number {
    font-weight: 700;
    color: var(--accent-primary);
}

.crossword-input {
    width: 100%;
    border: 1.5px solid var(--border-color);
    padding: 10px 12px;
    border-radius: 10px;
    font-size: 16px;
    letter-spacing: 4px;
    font-family: monospace;
    text-transform: uppercase;
    color: var(--text-primary);
    background: var(--bg-surface);
    outline: none;
    transition: border-color var(--transition-fast);
}

.crossword-input:focus {
    border-color: var(--accent-primary);
}

/* ============================================
   Marking
   ============================================ */
.marking-sentence {
    margin-bottom: var(--spacing-md);
}

.marking-tokens {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    line-height: 2;
}

.marking-token {
    padding: 4px 6px;
    border-radius: 4px;
    font-size: 16px;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    transition: background var(--transition-fast), color var(--transition-fast);
    border-bottom: 1px dotted var(--text-secondary);
    margin: 0 2px;
}

.marking-token:active {
    opacity: 0.7;
}

.marking-token.highlighted {
    background: var(--accent-primary);
    color: #fff;
    border-bottom: none;
}

/* Multi-color marking: category selector strip */
.marking-category-strip {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    overflow-x: auto;
    padding-bottom: 4px;
}

.marking-category-btn {
    padding: 6px 12px;
    border-radius: var(--radius-full);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    white-space: nowrap;
    border: 1px solid var(--border-color);
    background: transparent;
    color: var(--cat-color);
    opacity: 0.6;
    transition: background var(--transition-fast), color var(--transition-fast), opacity var(--transition-fast);
}

.marking-category-btn:active {
    opacity: 0.7;
}

.marking-category-btn.active {
    opacity: 1;
    border-color: currentColor;
    background: var(--cat-color);
    color: #fff;
}

.marking-category-btn.disabled {
    cursor: default;
    opacity: 0.6;
    pointer-events: none;
}

/* Category color classes */
.marking-category-btn.c-noun,
.marking-token.marked-noun {
    --cat-color: var(--accent-blue);
}

.marking-category-btn.c-verb,
.marking-token.marked-verb {
    --cat-color: var(--feedback-correct);
}

.marking-category-btn.c-noun {
    color: var(--accent-blue);
    background: rgba(74, 124, 153, 0.1);
}

.marking-category-btn.c-verb {
    color: var(--feedback-correct);
    background: rgba(88, 129, 87, 0.1);
}

.marking-token.marked-noun {
    background: var(--accent-blue);
    color: white;
    padding: 2px 4px;
    border-radius: 4px;
    border-bottom: none;
}

.marking-token.marked-verb {
    background: var(--feedback-correct);
    color: white;
    padding: 2px 4px;
    border-radius: 4px;
    border-bottom: none;
}

/* ============================================
   Present
   ============================================ */
.present-content {
    background: var(--bg-secondary);
    padding: 16px;
    border-radius: var(--radius-md);
    border-inline-start: 4px solid var(--accent-primary);
    font-size: 14px;
    line-height: 1.7;
    color: var(--text-secondary);
}

.present-content .present-heading {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
    margin-top: var(--spacing-md);
}

.present-content .present-heading:first-child {
    margin-top: 0;
}

.present-content .vocab-list {
    padding-inline-start: 20px;
    margin-top: 12px;
    font-size: 14px;
}

.present-content .vocab-list li {
    margin-bottom: 8px;
}

/* ============================================
   Markdown content (present, passage, instruction, hint)
   ============================================ */
.present-content p,
.passage-content p,
.exercise-instruction p,
.exercise-hint-text p {
    margin: 0 0 0.6em;
}

.present-content p:last-child,
.passage-content p:last-child,
.exercise-instruction p:last-child,
.exercise-hint-text p:last-child {
    margin-bottom: 0;
}

.present-content h1,
.present-content h2,
.present-content h3,
.passage-content h1,
.passage-content h2,
.passage-content h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    margin: var(--spacing-md) 0 8px;
}

.present-content h1:first-child,
.present-content h2:first-child,
.present-content h3:first-child,
.passage-content h1:first-child,
.passage-content h2:first-child,
.passage-content h3:first-child {
    margin-top: 0;
}

.present-content ul,
.present-content ol,
.passage-content ul,
.passage-content ol,
.exercise-hint-text ul,
.exercise-hint-text ol {
    padding-inline-start: 20px;
    margin: 8px 0;
}

.present-content li,
.passage-content li,
.exercise-hint-text li {
    margin-bottom: 4px;
}

.present-content code,
.passage-content code,
.exercise-instruction code,
.exercise-hint-text code {
    background: var(--bg-primary);
    padding: 1px 4px;
    border-radius: 3px;
    font-size: 0.9em;
}

.present-content strong,
.passage-content strong,
.exercise-instruction strong,
.exercise-hint-text strong {
    color: var(--text-primary);
}

/* ============================================
   Dialogue
   ============================================ */
.dialogue-lines {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.dialogue-bubble {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.5;
    position: relative;
}

.dialogue-bubble.speaker-a {
    background: var(--bg-secondary);
    color: var(--text-primary);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

.dialogue-bubble.speaker-b {
    background: var(--accent-primary);
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.dialogue-speaker {
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 2px;
    opacity: 0.7;
}

/* ============================================
   Free Writing
   ============================================ */
.free-writing-textarea {
    width: 100%;
    min-height: 200px;
    flex: 1;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 16px;
    font-family: inherit;
    color: var(--text-primary);
    background: var(--bg-primary);
    resize: none;
    outline: none;
    transition: border-color var(--transition-fast);
}

.free-writing-textarea:focus {
    border-color: var(--accent-primary);
}

.free-writing-notes {
    margin-bottom: var(--spacing-md);
    padding: var(--spacing-md);
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 14px;
    color: var(--text-secondary);
    white-space: pre-wrap;
}

/* ============================================
   Feedback States (after Check)
   ============================================ */
.feedback-correct {
    border-color: var(--feedback-correct) !important;
    background: rgba(88, 129, 87, 0.13) !important;
}

.feedback-incorrect {
    border-color: var(--feedback-incorrect) !important;
    background: rgba(176, 82, 82, 0.08) !important;
}

.feedback-correct-answer {
    font-size: 14px;
    color: var(--feedback-correct);
    font-weight: 500;
    margin-top: 2px;
}

.feedback-wrong-answer {
    font-size: 14px;
    color: var(--feedback-incorrect);
    margin-top: 2px;
}

.feedback-correct-text {
    font-size: 14px;
    color: var(--feedback-correct);
    font-weight: 500;
}

/* Input feedback */
.type-in-input.feedback-correct,
.correction-input.feedback-correct,
.crossword-input.feedback-correct {
    border-color: var(--feedback-correct) !important;
    color: var(--feedback-correct);
}

.type-in-input.feedback-incorrect,
.correction-input.feedback-incorrect,
.crossword-input.feedback-incorrect {
    border-color: var(--feedback-incorrect) !important;
    color: var(--feedback-incorrect);
}

.gap-fill-blank.feedback-correct {
    border-bottom-color: var(--feedback-correct) !important;
}

.gap-fill-blank.feedback-correct .blank-chip {
    background: var(--feedback-correct);
}

.gap-fill-blank.feedback-incorrect {
    border-bottom-color: var(--feedback-incorrect) !important;
}

.gap-fill-blank.feedback-incorrect .blank-chip {
    background: var(--feedback-incorrect);
}

.dropdown-select.feedback-correct {
    border-color: var(--feedback-correct) !important;
}

.dropdown-select.feedback-incorrect {
    border-color: var(--feedback-incorrect) !important;
}

.mc-option.feedback-correct {
    border-color: var(--feedback-correct) !important;
    background: rgba(88, 129, 87, 0.13) !important;
}

.mc-option.feedback-incorrect {
    border-color: var(--feedback-incorrect) !important;
    background: rgba(176, 82, 82, 0.08) !important;
}

.mc-option.feedback-correct .mc-indicator {
    border-color: var(--feedback-correct);
    background: var(--feedback-correct);
}

.mc-option.feedback-incorrect .mc-indicator {
    border-color: var(--feedback-incorrect);
    background: var(--feedback-incorrect);
}

.matching-item.feedback-correct {
    border-color: var(--feedback-correct) !important;
}

.matching-item.feedback-incorrect {
    border-color: var(--feedback-incorrect) !important;
}

.sequencing-chip.feedback-correct {
    border-color: var(--feedback-correct) !important;
    background: rgba(88, 129, 87, 0.13) !important;
}

.sequencing-chip.feedback-incorrect {
    border-color: var(--feedback-incorrect) !important;
    background: rgba(176, 82, 82, 0.08) !important;
}

.marking-token.feedback-correct {
    background: var(--feedback-correct) !important;
    color: #fff !important;
}

.marking-token.feedback-incorrect {
    background: var(--feedback-incorrect) !important;
    color: #fff !important;
}

/* ============================================
   Locked state (correct answers on retry)
   ============================================ */
.answer-locked {
    pointer-events: none !important;
    opacity: 0.7;
}

/* ============================================
   Disabled state (after submission)
   ============================================ */
.exercise-content.disabled {
    pointer-events: none;
}

.exercise-content.disabled .word-chip,
.exercise-content.disabled .mc-option,
.exercise-content.disabled .matching-item,
.exercise-content.disabled .sequencing-chip,
.exercise-content.disabled .marking-token {
    cursor: default;
}

.exercise-content.disabled .type-in-input,
.exercise-content.disabled .correction-input,
.exercise-content.disabled .crossword-input,
.exercise-content.disabled .dropdown-select,
.exercise-content.disabled .free-writing-textarea {
    pointer-events: none;
    opacity: 0.8;
}

/* ========================================
   Touch Drag-and-Drop
   ======================================== */

/* Prevent browser scroll gestures on draggable chips */
.word-chip,
.sequencing-chip,
.blank-chip {
    touch-action: none;
}

/* Ghost state for the original chip while being dragged */
.drag-source {
    opacity: 0.3;
}

/* Drop zone highlight when a dragged chip hovers over it */
.drag-over {
    background: var(--bg-secondary) !important;
    outline: 2px dashed var(--accent-primary);
    outline-offset: -2px;
}

/* ============================================
   Exercise Hint (show_hint tool)
   ============================================ */
@keyframes hintEnter {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Floating overlay so the hint always reads on top of the active screen
   (lesson exercise, level-check picture story, transcript) without being
   bound to a specific container. pointer-events:none so taps on the
   exercise behind the card still go through. */
.exercise-hint-overlay {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    /* Shift the centered hint card ~20% of viewport-height lower than
       the geometric centre. Asymmetric vertical padding moves the
       flex centre from 50vh down to ~70vh — keeps `align-items:center`
       semantics intact and respects very-tall hint content (the card
       still grows symmetrically inside the remaining cross-axis area).
       Horizontal padding stays as-is so the card hugs the viewport
       sides on phones. */
    padding: calc(var(--spacing-md) + 40vh) var(--spacing-md) var(--spacing-md);
    pointer-events: none;
    z-index: 1000;
}

.exercise-hint {
    display: flex;
    align-items: flex-start;
    gap: var(--spacing-md);
    width: 100%;
    max-width: 380px;
    padding: var(--spacing-md);
    padding-inline-start: calc(var(--spacing-md) + 3px);
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: inset 3px 0 0 var(--accent-primary), var(--shadow-md);
    pointer-events: auto;
    animation: hintEnter 250ms ease-out;
}

.exercise-hint-text {
    flex: 1;
    font-size: 16px;
    line-height: 1.5;
    color: var(--text-primary);
    min-width: 0;
}

.exercise-hint-text code {
    background: var(--bg-tertiary);
}

.exercise-hint-close-wrap {
    position: relative;
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    margin: -4px -4px 0 0;
}

.exercise-hint-close {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--text-muted);
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
    padding: 0;
    transition: background var(--transition-fast), color var(--transition-fast);
}

.exercise-hint-close:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.exercise-hint-close:active {
    background: var(--bg-tertiary);
}

/* Countdown ring drawn around the close button — drains clockwise over
   the same 45s window that the JS auto-dismiss timer uses. */
.exercise-hint-countdown {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    overflow: visible;
    transform: rotate(-90deg);
}

.exercise-hint-countdown circle {
    fill: none;
    stroke: var(--accent-primary);
    stroke-width: 2;
    stroke-linecap: round;
    stroke-dasharray: 88;
    stroke-dashoffset: 0;
    opacity: 0.55;
    animation: hintCountdown 45s linear forwards;
}

@keyframes hintCountdown {
    to { stroke-dashoffset: 88; }
}

@media (prefers-reduced-motion: reduce) {
    .exercise-hint-countdown circle { animation: none; opacity: 0.35; }
}

/* ===== Exercise how-to tutorial overlay =====
   Fullscreen dimmed backdrop with a centered card showing a short GIF
   tutorial for an exercise mechanic. Sits below the hint overlay
   (.exercise-hint-overlay, z-index 1000) so hints always win. */
.howto-overlay {
    position: fixed;
    inset: 0;
    z-index: 900;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-md);
    background: rgba(0, 0, 0, 0.55);
}

.howto-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--spacing-md);
    max-width: 420px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    padding: var(--spacing-lg);
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
}

.howto-title {
    margin: 0;
    font-family: ui-serif, Georgia, 'Times New Roman', serif;
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    text-align: center;
}

.howto-text {
    margin: 0;
    font-size: 14px;
    color: var(--text-secondary);
    text-align: center;
}

.howto-gif {
    max-width: 90%;
    height: auto;
    border-radius: var(--radius-md);
}

.howto-btn {
    width: 100%;
    padding: var(--spacing-sm) var(--spacing-md);
    border: none;
    border-radius: var(--radius-btn);
    box-shadow: var(--shadow-sm);
    background: var(--accent-primary);
    color: #fff;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
}
