/**
 * Texting Practice Widget Styles
 *
 * Per-exchange scaffolded loop with iMessage-style chat bubbles.
 * Mobile-first, zero layout shift.
 *
 * @package Aphasia_Exercises
 * @since 1.5.72
 */

/* ========================================
   LAYOUT COMPATIBILITY
   ======================================== */

.exercise-layout-wrapper .texting-practice-root,
.exercise-layout-wrapper .texting-practice-container {
    max-width: 100%;
}

/* ========================================
   CONTAINER & THEME
   ======================================== */

.texting-practice-root {
    --ex-primary: #3b82f6;
    --ex-primary-dark: #2563eb;
    --ex-primary-light: #eff6ff;
    --ex-primary-ring: #60a5fa;
    --ex-success: #22c55e;
    --ex-success-light: #f0fdf4;
    --ex-success-dark: #16a34a;
    --ex-error: #ef4444;
    --ex-error-light: #fef2f2;
    --ex-error-dark: #dc2626;
    --ex-neutral-50: #f9fafb;
    --ex-neutral-100: #f3f4f6;
    --ex-neutral-200: #e5e7eb;
    --ex-neutral-500: #6b7280;
    --ex-neutral-700: #374151;
    --ex-neutral-800: #1f2937;
    --ex-radius-sm: 6px;
    --ex-radius-md: 8px;
    --ex-radius-lg: 12px;
    --ex-radius-full: 9999px;
    --ex-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --ex-transition: 0.2s ease;
    --ex-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;

    --tp-purple: #5B6ABB;
    --tp-purple-dark: #4a59a8;
    --tp-purple-light: #7B68EE;

    font-family: var(--ex-font);
    max-width: 500px;
    margin: 0 auto;
    background: #f5f5f5;
    border-radius: 20px;
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

.texting-practice-root *,
.texting-practice-root *::before,
.texting-practice-root *::after {
    box-sizing: border-box;
}

.texting-practice-container {
    display: flex;
    flex-direction: column;
    min-height: 400px;
}

.texting-practice-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 300px;
    color: #666;
    font-size: 1rem;
}

.texting-practice-error,
.texting-error {
    padding: 2rem;
    text-align: center;
    color: #d32f2f;
    background: #ffebee;
    border-radius: 12px;
    margin: 1rem;
}

/* ========================================
   ELEMENTOR PREVIEW
   ======================================== */

.texting-preview-placeholder {
    padding: 2rem;
    text-align: center;
    background: linear-gradient(135deg, #f8f9fa, #e9ecef);
    border-radius: 12px;
    min-height: 300px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.texting-preview-placeholder .preview-icon {
    font-size: 3rem;
    margin-bottom: 0.75rem;
}

.texting-preview-placeholder .preview-title {
    font-size: 1.25rem;
    font-weight: 600;
    margin: 0 0 0.5rem;
}

/* ========================================
   SCENARIO NAV BAR (prev / title / next)
   ======================================== */

.tp-scenario-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 8px;
    background: var(--ex-neutral-50);
    border-bottom: 1px solid var(--ex-neutral-200);
    gap: 6px;
}

.tp-nav-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--ex-neutral-700);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: center;
    flex: 1;
    min-width: 0;
}

.tp-nav-btn {
    font-size: 12px;
    font-weight: 600;
    color: var(--tp-purple);
    background: none;
    border: 1.5px solid var(--tp-purple);
    border-radius: 14px;
    padding: 5px 12px;
    cursor: pointer;
    transition: all 0.15s;
    flex-shrink: 0;
    min-height: 32px;
    white-space: nowrap;
}

.tp-nav-btn:hover:not(:disabled) {
    background: var(--ex-primary-light);
    color: var(--tp-purple);
}

.tp-nav-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.tp-nav-btn:focus-visible {
    outline: 3px solid var(--tp-purple);
    outline-offset: 2px;
}

/* ========================================
   CHAT AREA (scrollable)
   ======================================== */

.tp-chat-area {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 180px;
    max-height: 320px;
    scroll-behavior: smooth;
}

/* ========================================
   CHAT BUBBLES
   ======================================== */

.chat-bubble-container {
    display: flex;
    flex-direction: column;
    max-width: 80%;
    animation: popIn 0.3s ease-out;
}

.chat-bubble-container.other {
    align-self: flex-start;
}

.chat-bubble-container.user {
    align-self: flex-end;
}

.chat-bubble {
    padding: 10px 14px;
    border-radius: 18px;
    font-size: 15px;
    line-height: 1.4;
    word-wrap: break-word;
}

.other-bubble {
    background: #fff;
    color: #333;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.user-bubble {
    background: linear-gradient(135deg, var(--tp-purple), var(--tp-purple-light));
    color: #fff;
    border-bottom-right-radius: 4px;
}

.user-bubble.sent-flash {
    animation: sentFlash 0.8s ease;
}

.chat-speaker {
    font-size: 11px;
    color: #999;
    margin-top: 2px;
    padding: 0 8px;
}

@keyframes popIn {
    0% { opacity: 0; transform: scale(0.85) translateY(10px); }
    60% { transform: scale(1.02) translateY(-2px); }
    100% { opacity: 1; transform: scale(1) translateY(0); }
}

@keyframes sentFlash {
    0% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.6); }
    50% { box-shadow: 0 0 0 8px rgba(34, 197, 94, 0); }
    100% { box-shadow: none; }
}

/* ========================================
   GHOST PREVIEW (model response)
   ======================================== */

.ghost-preview {
    opacity: 0;
    animation: ghostAppear 1.5s ease-out forwards;
}

.ghost-bubble {
    opacity: 0.45;
    border: 2px dashed rgba(255, 255, 255, 0.5);
}

.ghost-label {
    color: var(--tp-purple);
    font-style: italic;
    font-size: 11px;
}

@keyframes ghostAppear {
    0% { opacity: 0; }
    20% { opacity: 0.7; }
    80% { opacity: 0.5; }
    100% { opacity: 0.15; }
}

/* ========================================
   TYPING INDICATOR (3 bouncing dots)
   ======================================== */

.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 10px 16px;
    align-items: center;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #ccc;
    animation: typingBounce 1.4s infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); background: #ccc; }
    30% { transform: translateY(-6px); background: var(--tp-purple); }
}

/* ========================================
   RESPONSE AREA (anchored at bottom)
   ======================================== */

.tp-response-area {
    padding: 10px 12px;
    border-top: 1px solid var(--ex-neutral-200);
    background: #fff;
    min-height: 70px;
}

.tp-response-content {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* --- Your Turn pulse --- */

.tp-your-turn {
    text-align: center;
    color: var(--tp-purple);
    font-weight: 600;
    font-size: 14px;
    padding: 6px 0;
}

.tp-your-turn.pulse {
    animation: yourTurnPulse 1.5s ease-in-out infinite;
}

@keyframes yourTurnPulse {
    0%, 100% { opacity: 0.5; transform: scale(1); }
    50% { opacity: 1; transform: scale(1.03); }
}

/* --- Inline feedback --- */

.tp-inline-feedback {
    text-align: center;
    padding: 10px;
    border-radius: 10px;
    font-weight: 600;
    font-size: 15px;
    animation: fadeIn 0.2s ease;
}

.tp-inline-feedback.success {
    background: var(--ex-success-light);
    color: var(--ex-success-dark);
    border: 1.5px solid var(--ex-success);
}

.tp-inline-feedback.hint {
    background: #fff3e0;
    color: #e65100;
    border: 1.5px solid #ffcc80;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ========================================
   CHOICE BUTTONS (tap to select)
   ======================================== */

.tp-choice-buttons {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.tp-choice-btn {
    background: linear-gradient(135deg, #e8eaf6, #c5cae9);
    border: none;
    padding: 12px 16px;
    border-radius: 14px;
    font-size: 15px;
    font-weight: 500;
    color: #333;
    cursor: pointer;
    text-align: left;
    transition: transform 0.15s, box-shadow 0.15s;
    min-height: 44px;
}

.tp-choice-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(91, 106, 187, 0.2);
    color: #333;
}

.tp-choice-btn:active {
    transform: translateY(0);
}

.tp-choice-btn:focus-visible {
    outline: 3px solid var(--tp-purple);
    outline-offset: 2px;
}

/* ========================================
   TEXT INPUT AREA (iMessage style)
   ======================================== */

.text-input-area {
    display: flex;
    gap: 8px;
    align-items: center;
    background: var(--ex-neutral-50);
    padding: 8px;
    border-radius: 22px;
    border: 1px solid var(--ex-neutral-200);
}

.texting-input {
    flex: 1;
    border: none;
    outline: none;
    font-size: 15px;
    padding: 8px 12px;
    background: transparent;
    color: var(--ex-neutral-800);
    font-family: var(--ex-font);
}

.texting-input::placeholder {
    color: var(--ex-neutral-500);
}

.texting-input:disabled {
    background: var(--ex-neutral-100);
    color: #999;
}

.send-button {
    background: linear-gradient(135deg, var(--tp-purple), var(--tp-purple-light));
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s, opacity 0.15s;
}

.send-button:hover:not(:disabled) {
    transform: scale(1.05);
    color: #fff;
}

.send-button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.send-button:focus-visible {
    outline: 3px solid var(--tp-purple);
    outline-offset: 2px;
}

/* ========================================
   HINT BUTTON & WORD BANK
   ======================================== */

.tp-hint-btn {
    align-self: center;
    background: transparent;
    border: 1.5px solid #ca8a04;
    color: #ca8a04;
    padding: 6px 14px;
    border-radius: 16px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
}

.tp-hint-btn:hover {
    background: #fffbeb;
    color: #a16207;
}

.tp-hint-btn:focus-visible {
    outline: 3px solid #ca8a04;
    outline-offset: 2px;
}

.tp-word-bank {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px;
    background: #fffbeb;
    border-radius: 10px;
    border: 1px solid #fde68a;
}

.word-chip {
    background: #fef3c7;
    color: #92400e;
    padding: 6px 12px;
    border-radius: 16px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
}

.word-chip:hover {
    background: #fde68a;
    color: #78350f;
}

/* --- Building response (word bank mode) --- */

.tp-building-response {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: #fff;
    border: 1.5px solid var(--tp-purple);
    border-radius: 12px;
    min-height: 40px;
}

.tp-building-text {
    flex: 1;
    font-size: 15px;
    font-weight: 500;
    color: var(--ex-neutral-800);
}

.tp-clear-btn {
    background: none;
    border: none;
    color: var(--ex-neutral-500);
    font-size: 16px;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 50%;
    transition: all 0.15s;
    flex-shrink: 0;
    min-width: 28px;
    min-height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tp-clear-btn:hover {
    background: var(--ex-neutral-100);
    color: var(--ex-error);
}

.tp-send-built {
    background: linear-gradient(135deg, var(--tp-purple), var(--tp-purple-light));
    color: #fff;
    border: none;
    padding: 10px 20px;
    border-radius: 14px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    min-height: 44px;
    width: 100%;
    transition: transform 0.15s, box-shadow 0.15s;
}

.tp-send-built:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(91, 106, 187, 0.3);
    color: #fff;
}

.tp-send-built:focus-visible {
    outline: 3px solid var(--tp-purple);
    outline-offset: 2px;
}

/* ========================================
   PROGRESS PIPS
   ======================================== */

.tp-progress-pips {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: 8px 12px;
    border-top: 1px solid var(--ex-neutral-200);
}

.tp-pip {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--ex-neutral-200);
    transition: all 0.3s;
    flex-shrink: 0;
}

.tp-pip.current {
    width: 10px;
    height: 10px;
    background: var(--tp-purple);
}

.tp-pip.correct {
    background: var(--ex-success);
    animation: pipPop 0.3s ease-out;
}

.tp-pip.incorrect {
    background: #fca5a5;
    animation: pipPop 0.3s ease-out;
}

@keyframes pipPop {
    0% { transform: scale(0.5); }
    60% { transform: scale(1.3); }
    100% { transform: scale(1); }
}

.tp-pip-counter {
    font-size: 12px;
    font-weight: 600;
    color: var(--ex-neutral-500);
    margin-left: 6px;
    white-space: nowrap;
}

/* ========================================
   COMPLETE SCREEN
   ======================================== */

.complete-screen {
    text-align: center;
    padding: 24px 16px;
}

.complete-screen h2 {
    margin: 0 0 0.5rem;
    color: #333;
}

.complete-screen > p {
    color: #666;
    margin-bottom: 1rem;
}

/* ========================================
   BUTTONS (general)
   ======================================== */

.primary-button {
    background: linear-gradient(135deg, var(--tp-purple), var(--tp-purple-light));
    color: #fff;
    border: none;
    padding: 12px 24px;
    border-radius: 20px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    width: 100%;
    margin-top: 0.75rem;
    transition: transform 0.15s, box-shadow 0.15s;
    min-height: 44px;
}

.primary-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(91, 106, 187, 0.4);
    color: #fff;
}

.restart-button {
    background: var(--ex-neutral-100);
    border: 1.5px solid var(--ex-neutral-200);
    color: var(--ex-neutral-700);
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    width: 100%;
    min-height: 38px;
    transition: all 0.15s;
}

.restart-button:hover {
    background: var(--ex-neutral-200);
    color: var(--ex-neutral-800);
}

/* ========================================
   SETTINGS PANEL
   ======================================== */

.tp-settings-panel {
    padding: 12px 16px;
    background: var(--ex-neutral-50);
    border: 1px solid var(--ex-neutral-200);
    border-radius: 10px;
}

.tp-setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.tp-setting-row label {
    font-size: 12px;
    font-weight: 500;
    color: var(--ex-neutral-500);
    white-space: nowrap;
}

.tp-setting-select {
    padding: 6px 10px;
    border: 1px solid var(--ex-neutral-200);
    border-radius: 8px;
    font-size: 13px;
    background: #fff;
    color: var(--ex-neutral-700);
    cursor: pointer;
    flex: 1;
    min-width: 0;
}

.tp-setting-select:focus {
    outline: 3px solid var(--tp-purple);
    outline-offset: 2px;
    border-color: var(--tp-purple);
}

.settings-actions {
    display: flex;
    gap: 8px;
}

/* ========================================
   SCENARIO SELECTOR
   ======================================== */

.scenario-selector {
    padding: 20px 16px;
}

.selector-header {
    text-align: center;
    margin-bottom: 16px;
}

.selector-header h3 {
    font-size: 1.25rem;
    margin: 0 0 4px;
    color: #333;
}

.selector-subtitle {
    color: #666;
    font-size: 14px;
    margin: 0;
}

.scenario-cards {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 16px;
    max-height: 350px;
    overflow-y: auto;
}

.scenario-card {
    background: #fff;
    border: 2px solid var(--ex-neutral-200);
    border-radius: 12px;
    padding: 12px;
    cursor: pointer;
    transition: all 0.15s;
}

.scenario-card:hover {
    border-color: var(--tp-purple);
    box-shadow: 0 2px 8px rgba(91, 106, 187, 0.15);
}

.scenario-card.selected {
    border-color: var(--tp-purple);
    background: linear-gradient(135deg, #f5f7ff, #eef1ff);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}

.difficulty-badge {
    font-size: 11px;
    font-weight: 600;
    color: #fff;
    padding: 2px 8px;
    border-radius: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.selected-badge {
    background: var(--tp-purple);
    color: #fff;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
}

.scenario-card .scenario-title {
    font-size: 15px;
    font-weight: 600;
    color: #333;
    margin: 0 0 4px;
}

.scenario-preview {
    font-size: 13px;
    color: #666;
    margin: 0 0 6px;
    line-height: 1.4;
}

.scenario-meta {
    display: flex;
    gap: 12px;
}

.meta-item {
    font-size: 12px;
    color: #999;
}

.start-selected-btn {
    margin-top: 8px;
}

/* ========================================
   ACCESSIBILITY
   ======================================== */

@media (prefers-reduced-motion: reduce) {
    .texting-practice-root *,
    .texting-practice-root *::before,
    .texting-practice-root *::after {
        animation-duration: 0.01ms;
        transition-duration: 0.01ms;
    }
    .tp-your-turn.pulse { animation: none; opacity: 1; }
    .ghost-preview { animation: none; opacity: 0.3; }
    .tp-pip.correct, .tp-pip.incorrect { animation: none; }
}

/* ========================================
   RESPONSIVE — MOBILE (480px)
   ======================================== */

@media (max-width: 480px) {
    .texting-practice-root {
        border-radius: 0;
        max-width: 100%;
    }

    .chat-bubble-container {
        max-width: 85%;
    }

    .tp-chat-area {
        padding: 8px;
        min-height: 160px;
        max-height: 280px;
    }

    .tp-response-area {
        padding: 8px 10px;
    }

    .tp-choice-btn {
        padding: 10px 14px;
        font-size: 14px;
    }

    .chat-bubble {
        font-size: 14px;
        padding: 8px 12px;
    }

    .scenario-selector {
        padding: 16px 12px;
    }
}

/* ========================================
   RESPONSIVE — SMALL PHONES (360px)
   ======================================== */

@media (max-width: 360px) {
    .tp-chat-area {
        max-height: 240px;
    }

    .chat-bubble {
        font-size: 13px;
    }

    .tp-choice-btn {
        font-size: 13px;
        padding: 10px 12px;
    }
}
