/**
 * Cognitive Tests Stylesheet
 *
 * Follows jsPsych styling best practices by extending built-in classes
 * rather than creating entirely custom structures.
 *
 * Uses design tokens from design-tokens.css for consistency.
 *
 * jsPsych Built-in Classes Extended:
 * - .jspsych-btn
 * - .jspsych-btn-group-grid
 * - .jspsych-btn-group-flex
 * - #jspsych-html-button-response-stimulus
 * - #jspsych-html-button-response-btngroup
 */

/* ===================================
   GLOBAL TYPOGRAPHY
   =================================== */

/* Headings use Plus Jakarta Sans for modern SaaS aesthetic */
h1, h2, h3 {
    font-family: var(--vf-font-family-heading);
}

/* ===================================
   GLOBAL LAYOUT - Natural Content Flow
   =================================== */

/* jsPsych layout styles - scoped to visible experiment container
 * Using #jspsych-target selector to avoid interfering with display:none
 */
#jspsych-target .jspsych-display-element {
    display: flex;
    flex-direction: column;
    flex: 1;  /* Fill parent container */
    overflow-y: auto;  /* Only scroll when content overflows */
}

/* jsPsych content wrapper - follows jsPsych default flex pattern
 * Key insight: Use flex: 1 1 100% and margin: auto instead of height: 100% + justify-content
 * This prevents the overflow/scrollbar issue while still filling available space
 * Reference: https://github.com/jspsych/jsPsych/issues/515
 */
#jspsych-target .jspsych-content-wrapper {
    display: flex;
    flex-direction: column;
    flex: 1 1 100%;  /* Fill available space without forcing exact height */
    width: 100%;
    /* NO height: 100% - this causes scrollbar when combined with padding */
}

#jspsych-target .jspsych-content {
    width: 100% !important;  /* Override jsPsych inline width - required for adaptive design */
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: space-evenly;
    align-items: center;  /* Center flex items horizontally - prevents full-width stretch */
    text-align: center;
    padding: var(--vf-space-5);
    box-sizing: border-box;
}

/* ===================================
   PROGRESS BAR - Minimal & Inline
   =================================== */

/* jsPsych progress bar - slim inline design */
/* Override jsPsych's default styles (border-bottom, background-color) */
.jspsych-progressbar-container,
#jspsych-progressbar-container {
    background: transparent !important;
    background-color: transparent !important;
    border-bottom: none !important;
    height: var(--vf-progress-height);
    width: 100%;
    overflow: hidden;
    margin: 0;
    border: none;
    position: relative;
    z-index: 10000;
}

.jspsych-progressbar-inner {
    height: 100%;
    background: var(--vf-progress-fill);
    transition: width var(--vf-transition-slow);
}

/* Hide progress bar text (just show visual bar) */
#jspsych-progressbar-container span {
    display: none;
}

/* ===================================
   UNIFIED BUTTON SYSTEM

   Two categories:
   1. UI buttons (.vf-btn) - Full premium effects with movement
      Used for: navigation, results, settings, instructions
   2. Test buttons - Minimal effects, NO movement
      Used for: trial responses (Stroop, Flanker, etc.)
      Reason: Movement adds cognitive load during tests
   =================================== */

/* --------------------------------------
   UI BUTTONS - Premium with movement
   -------------------------------------- */
.vf-btn {
    border: none;
    border-radius: var(--vf-radius-md);
    padding: var(--vf-space-2) var(--vf-space-4);
    cursor: pointer;
    font-family: var(--vf-font-family);
    font-size: var(--vf-font-size-xs);
    font-weight: var(--vf-font-weight-semibold);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--vf-shadow-md), inset 0 1px 0 rgba(255, 255, 255, 0.15);
    /* Mobile: Remove 300ms double-tap delay for faster touch response */
    touch-action: manipulation;
}

.vf-btn:hover {
    transform: translateY(-2px) scale(1.02);
    box-shadow: var(--vf-shadow-lg), inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.vf-btn:active {
    transform: translateY(1px) scale(0.98);
    box-shadow: var(--vf-shadow-sm), inset 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* UI Button color variants */
.vf-btn--primary {
    background: var(--vf-color-primary);
    color: var(--vf-color-text-on-primary);
}
.vf-btn--primary:hover { background: var(--vf-color-primary-dark); }

.vf-btn--secondary {
    background: var(--vf-color-secondary);
    color: var(--vf-color-text-on-primary);
}
.vf-btn--secondary:hover { background: var(--vf-color-secondary-dark, #0e7490); }

.vf-btn--success {
    background: var(--vf-color-success);
    color: var(--vf-color-text-on-primary);
}
.vf-btn--success:hover { background: var(--vf-color-success-dark); }

.vf-btn--error {
    background: var(--vf-color-error);
    color: var(--vf-color-text-on-primary);
}
.vf-btn--error:hover { background: var(--vf-color-error-dark); }

.vf-btn--ghost {
    background: var(--vf-color-neutral-100);
    color: var(--vf-color-neutral-700);
    border: 1px solid var(--vf-color-neutral-300);
    box-shadow: var(--vf-shadow-sm), inset 0 1px 0 rgba(255, 255, 255, 0.8);
}
.vf-btn--ghost:hover {
    background: var(--vf-color-neutral-200);
    box-shadow: var(--vf-shadow-md), inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

/* Size variants */
.vf-btn--sm {
    padding: var(--vf-space-1) var(--vf-space-3);
    font-size: 10px;
}

.vf-btn--lg {
    padding: var(--vf-space-4) var(--vf-space-8);
    font-size: var(--vf-font-size-sm);
}

/* Special variants for dark backgrounds */
.vf-btn--white {
    background: var(--vf-color-bg-card);
    color: var(--vf-color-primary);
}
.vf-btn--white:hover {
    background: var(--vf-color-neutral-100);
}

.vf-btn--outline-light {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
}
.vf-btn--outline-light:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* --------------------------------------
   TEST BUTTONS - Minimal, no movement
   Applies to actual trial response buttons
   -------------------------------------- */

/* Base jsPsych button styling */
#jspsych-target .jspsych-btn {
    font-family: var(--vf-font-family);
    font-weight: var(--vf-font-weight-semibold);
    border-radius: var(--vf-btn-radius);
    /* Test buttons: subtle transition, no movement */
    transition: box-shadow 0.15s ease, background-color 0.15s ease;
    /* Mobile: Remove 300ms double-tap delay for faster touch response */
    touch-action: manipulation;
}

/* Primary action button (Start Practice, Next, etc.) - UI BUTTON
 * These are navigation buttons, NOT test response buttons
 * Full premium effects with movement are appropriate here
 */
#jspsych-target .jspsych-btn-primary,
#jspsych-target .jspsych-instructions .jspsych-btn {
    background: var(--vf-color-primary);
    color: var(--vf-color-text-on-primary);
    border: none;
    padding: var(--vf-btn-padding-y) var(--vf-btn-padding-x);
    font-size: var(--vf-font-size-xs);
    font-weight: var(--vf-font-weight-semibold);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    /* Layered shadow: outer depth + subtle inner top highlight */
    box-shadow:
        var(--vf-shadow-md),
        inset 0 1px 0 rgba(255, 255, 255, 0.15);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

#jspsych-target .jspsych-btn-primary:hover,
#jspsych-target .jspsych-instructions .jspsych-btn:hover {
    background: var(--vf-color-primary-dark);
    transform: translateY(-2px) scale(1.02);
    box-shadow:
        var(--vf-shadow-lg),
        inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

#jspsych-target .jspsych-btn-primary:active,
#jspsych-target .jspsych-instructions .jspsych-btn:active {
    transform: translateY(1px) scale(0.98);
    box-shadow:
        var(--vf-shadow-sm),
        inset 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* ===================================
   STROOP TEST STYLES
   =================================== */

/* Stroop trial container - uses css_classes parameter */
.stroop-trial #jspsych-html-button-response-stimulus {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--vf-space-8) var(--vf-space-4);
}

/* Stroop stimulus area wrapper */
.stroop-container {
    display: grid;
    grid-template-rows: auto auto auto;
    gap: var(--vf-space-6);
    align-items: center;
    justify-items: center;
    width: 100%;
    max-width: 700px;
}

.stroop-header {
    font-size: var(--vf-font-size-2xl);
    font-weight: var(--vf-font-weight-bold);
    color: var(--vf-color-neutral-800);
}

.stroop-instruction {
    font-size: var(--vf-font-size-base);
    color: var(--vf-color-neutral-600);
}

.stroop-stimulus-area {
    display: flex;
    align-items: center;
    justify-content: center;
    max-width: 600px;
    width: 100%;
    padding: var(--vf-space-12) var(--vf-space-8);
}

.stroop-stimulus {
    font-size: clamp(60px, 12vw, 120px);
    font-weight: var(--vf-font-weight-bold);
    text-transform: uppercase;
    letter-spacing: 2px;
}

/* Color buttons - TEST BUTTONS (no movement to reduce cognitive load)
 * Subtle feedback: shadow changes only, no transform
 */
.stroop-trial .jspsych-btn.color-btn {
    min-height: 80px;
    border: none;
    border-radius: var(--vf-radius-lg);
    cursor: pointer;
    transition: box-shadow 0.15s ease;
    box-shadow:
        var(--vf-shadow-md),
        inset 0 1px 0 rgba(255, 255, 255, 0.25);
}

.stroop-trial .jspsych-btn.color-btn:hover {
    /* No transform - just subtle shadow enhancement */
    box-shadow:
        var(--vf-shadow-lg),
        inset 0 1px 0 rgba(255, 255, 255, 0.35);
}

.stroop-trial .jspsych-btn.color-btn:active {
    /* Subtle press feedback via shadow only */
    box-shadow:
        var(--vf-shadow-sm),
        inset 0 2px 4px rgba(0, 0, 0, 0.15);
}

/* Individual color button styles */
.stroop-trial .jspsych-btn.yellow-btn {
    background: linear-gradient(135deg, #FFD700 0%, #FFA500 100%);
}

.stroop-trial .jspsych-btn.blue-btn {
    background: linear-gradient(135deg, #4444FF 0%, #0066FF 100%);
}

.stroop-trial .jspsych-btn.red-btn {
    background: linear-gradient(135deg, #FF4444 0%, #CC0000 100%);
}

.stroop-trial .jspsych-btn.green-btn {
    background: linear-gradient(135deg, #44AA44 0%, #228822 100%);
}

/* Button group grid spacing for Stroop */
.stroop-trial #jspsych-html-button-response-btngroup.jspsych-btn-group-grid {
    gap: var(--vf-space-5);
    max-width: 400px;
    width: 100%;
    margin: var(--vf-space-8) auto 0;
}

/* Text button styles for Stroop tests - TEST BUTTONS (no movement)
 * Base styles are inline via button_html (jsPsych recommended approach)
 * Hover/active need !important to override inline styles
 */
#jspsych-target .jspsych-btn.text-btn {
    cursor: pointer;
    transition: box-shadow 0.15s ease, background-color 0.15s ease;
    box-shadow:
        var(--vf-shadow-md),
        inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

#jspsych-target .jspsych-btn.text-btn:hover {
    /* No transform - subtle shadow + background change only */
    box-shadow: var(--vf-shadow-lg), inset 0 1px 0 rgba(255, 255, 255, 0.9) !important;
    background: var(--vf-color-neutral-100) !important;
}

#jspsych-target .jspsych-btn.text-btn:active {
    /* Subtle press feedback via shadow only */
    box-shadow: var(--vf-shadow-sm), inset 0 2px 4px rgba(0, 0, 0, 0.08) !important;
    background: var(--vf-color-neutral-200) !important;
}

/* ===================================
   FLANKER TEST STYLES
   =================================== */

.flanker-trial #jspsych-html-button-response-stimulus {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--vf-space-8) var(--vf-space-4);
}

/* Arrow buttons - TEST BUTTONS (no movement to reduce cognitive load)
 * Subtle feedback: shadow changes only, no transform
 */
.flanker-trial .jspsych-btn.arrow-btn {
    width: 160px;
    height: 80px;
    background: var(--vf-color-primary);
    border: none;
    border-radius: var(--vf-radius-lg);
    font-size: 48px;
    color: var(--vf-color-text-on-primary);
    cursor: pointer;
    box-shadow:
        var(--vf-shadow-md),
        inset 0 1px 0 rgba(255, 255, 255, 0.15);
    transition: box-shadow 0.15s ease, background-color 0.15s ease;
}

.flanker-trial .jspsych-btn.arrow-btn:hover {
    /* No transform - subtle shadow + color change only */
    box-shadow:
        var(--vf-shadow-lg),
        inset 0 1px 0 rgba(255, 255, 255, 0.2);
    background: var(--vf-color-primary-dark);
}

.flanker-trial .jspsych-btn.arrow-btn:active {
    /* Subtle press feedback via shadow only */
    box-shadow:
        var(--vf-shadow-sm),
        inset 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Button group spacing for Flanker */
.flanker-trial #jspsych-html-button-response-btngroup {
    margin-top: var(--vf-space-12);
    display: flex;
    gap: var(--vf-space-16);
    justify-content: center;
}

/* ===================================
   PRACTICE TRIAL INDICATORS
   =================================== */

.practice-trial #jspsych-html-button-response-stimulus::before {
    content: "Practice Trial";
    display: block;
    color: var(--vf-color-neutral-500);
    font-size: var(--vf-font-size-sm);
    margin-bottom: var(--vf-space-3);
    text-align: center;
}

/* ===================================
   STIMULUS CARD STYLES
   =================================== */

/* Card container for stimulus display */
.stimulus-card {
    background: var(--vf-color-bg-card);
    padding: var(--vf-space-10) var(--vf-space-12);
    border-radius: var(--vf-radius-lg);
    box-shadow: var(--vf-shadow-card);
    display: inline-block;
}

/* Instruction text above stimulus */
.instruction-text {
    font-size: var(--vf-font-size-xl);
    font-weight: var(--vf-font-weight-medium);
    color: var(--vf-color-neutral-700);
    margin-bottom: var(--vf-space-8);
    line-height: var(--vf-line-height-relaxed);
    text-align: center;
}

/* Start hint - replaces "Start Practice" button */
.start-hint {
    text-align: center;
    color: var(--vf-color-neutral-500);
    font-size: var(--vf-font-size-sm);
    margin-top: var(--vf-space-8);
    font-style: italic;
}

/* ===================================
   RESPONSIVE DESIGN
   =================================== */

/* Tablet and below */
@media (max-width: 768px) {
    .stroop-stimulus {
        font-size: clamp(40px, 10vw, 80px);
    }

    .stroop-trial #jspsych-html-button-response-btngroup.jspsych-btn-group-grid {
        max-width: 300px;
        gap: var(--vf-space-4);
    }

    .stroop-trial .jspsych-btn.color-btn {
        min-height: 60px;
    }

    .flanker-trial .jspsych-btn.arrow-btn {
        width: 120px;
        height: 60px;
        font-size: 36px;
    }

    .flanker-trial #jspsych-html-button-response-btngroup {
        gap: var(--vf-space-10);
        margin-top: var(--vf-space-16);
    }
}

/* Mobile */
@media (max-width: 480px) {
    .stroop-stimulus {
        font-size: clamp(32px, 8vw, 60px);
    }

    .stroop-trial #jspsych-html-button-response-btngroup.jspsych-btn-group-grid {
        max-width: 250px;
        gap: var(--vf-space-3);
    }

    .stroop-trial .jspsych-btn.color-btn {
        min-height: 50px;
    }

    .flanker-trial .jspsych-btn.arrow-btn {
        width: 100px;
        height: 50px;
        font-size: 28px;
    }

    .flanker-trial #jspsych-html-button-response-btngroup {
        gap: var(--vf-space-5);
        margin-top: var(--vf-space-12);
    }
}


/* ===================================
   DEMOGRAPHICS FORM - Compact Layout (Official cssClasses API)
   =================================== */

/* Survey title - our custom class via cssClasses API */
#jspsych-target .survey-title {
    margin-top: 0;
    margin-bottom: var(--vf-space-2);
    color: var(--vf-color-neutral-900);
    font-weight: var(--vf-font-weight-semibold);
}

/* Survey description - our custom class */
#jspsych-target .survey-description {
    margin-bottom: var(--vf-space-8);
    color: var(--vf-color-neutral-600);
}

/* Survey body/container - our custom class */
#jspsych-target .survey-body {
    padding: var(--vf-space-4);
}

/* Survey page - our custom class */
#jspsych-target .survey-page .survey-row {
    margin-bottom: var(--vf-space-6);
}

/* Survey question - our custom class */
#jspsych-target .survey-question {
    padding-top: var(--vf-space-2);
    padding-bottom: var(--vf-space-2);
}

/* Question title - our custom class */
#jspsych-target .survey-question-title {
    font-weight: var(--vf-font-weight-semibold);
    color: var(--vf-color-neutral-900);
    font-size: var(--vf-font-size-base);
}

/* SurveyJS library element - needs !important to override library styles */
.sd-element {
    margin-bottom: 0 !important;
}

/* ===================================
   DEMOGRAPHICS FORM - Enhanced Input Styling
   SurveyJS library has strong default styles - !important required
   =================================== */

/* Text inputs and dropdowns - modern, polished look */
.sd-input,
.sd-dropdown,
.sd-dropdown select,
.sd-selectbase,
select.sd-input,
.sd-text {
    font-family: var(--vf-font-family) !important;
    border: 2px solid var(--vf-color-neutral-300) !important;
    border-radius: var(--vf-input-radius) !important;
    padding: var(--vf-input-padding-y) var(--vf-input-padding-x) !important;
    transition: all var(--vf-transition-normal) !important;
    width: -webkit-fill-available;
}

/* Focus state - highlight when user clicks in field */
.sd-input:focus,
.sd-dropdown:focus,
.sd-dropdown select:focus,
.sd-selectbase:focus,
select.sd-input:focus,
.sd-text:focus {
    outline: none !important;
    border-color: var(--vf-color-primary) !important;
    box-shadow: 0 0 0 3px var(--vf-color-focus-ring) !important;
    background: var(--vf-color-bg-card) !important;
}

/* Hover state for inputs */
.sd-input:hover,
.sd-dropdown:hover,
.sd-dropdown select:hover,
.sd-selectbase:hover,
select.sd-input:hover,
.sd-text:hover {
    border-color: var(--vf-color-primary-light) !important;
}

/* Submit button - enhanced styling */
.sd-btn {
    font-family: var(--vf-font-family) !important;
    background: var(--vf-color-primary) !important;
    color: var(--vf-color-text-on-primary) !important;
    border: none !important;
    border-radius: var(--vf-btn-radius) !important;
    padding: var(--vf-btn-padding-y) var(--vf-btn-padding-x) !important;
    font-size: var(--vf-font-size-md) !important;
    font-weight: var(--vf-font-weight-semibold) !important;
    cursor: pointer !important;
    box-shadow: var(--vf-shadow-md) !important;
    transition: all var(--vf-transition-normal) !important;
}

.sd-btn:hover {
    background: var(--vf-color-primary-dark) !important;
    transform: translateY(-2px) !important;
    box-shadow: var(--vf-shadow-lg) !important;
}

.sd-btn:active {
    transform: translateY(0) !important;
    box-shadow: var(--vf-shadow-sm) !important;
}

/* Question title styling */
.sd-question__title {
    font-weight: var(--vf-font-weight-semibold) !important;
    color: var(--vf-color-neutral-900) !important;
    font-size: var(--vf-font-size-base) !important;
}

/* Fix dropdown rendering - hide SurveyJS wrapper and custom chevron */

/* Hide the large SVG chevron button that SurveyJS adds */
.sd-dropdown_chevron-button,
.sv-dropdown_chevron-button {
    display: none !important;
}

/* Remove wrapper styling - make it transparent */
.sv-dropdown_select-wrapper,
.sd-selectbase {
    border: none !important;
    background: transparent !important;
    padding: 0 !important;
    box-shadow: none !important;
}

/* Style the actual select element */
.sd-selectbase select,
.sd-dropdown,
select.sd-input {
    font-family: var(--vf-font-family) !important;
    border: 2px solid var(--vf-color-neutral-300) !important;
    border-radius: var(--vf-input-radius) !important;
    padding: var(--vf-input-padding-y) var(--vf-input-padding-x) !important;
    font-size: var(--vf-font-size-base) !important;
    background: var(--vf-color-bg-card) !important;
    box-shadow: var(--vf-shadow-sm) !important;
    transition: all var(--vf-transition-normal) !important;
    width: 100% !important;
}

/* ===================================
   FEEDBACK STYLES
   =================================== */

.feedback-correct {
    background: var(--vf-color-success-light);
    color: var(--vf-color-success-dark);
    padding: var(--vf-space-3) var(--vf-space-5);
    border-radius: var(--vf-radius-md);
    font-weight: var(--vf-font-weight-medium);
}

.feedback-incorrect {
    background: var(--vf-color-error-light);
    color: var(--vf-color-error-dark);
    padding: var(--vf-space-3) var(--vf-space-5);
    border-radius: var(--vf-radius-md);
    font-weight: var(--vf-font-weight-medium);
}

/* ===================================
   UTILITY CLASSES
   =================================== */

.text-center {
    text-align: center;
}

.hidden {
    display: none !important;
}

/* Hide SurveyJS chevron button (proper way via cssClasses) */
.hidden-chevron {
    display: none !important;
}

.fade-in {
    animation: fadeIn var(--vf-transition-slow);
}

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

/* ===================================
   RESULTS DASHBOARD STYLES
   =================================== */

.results-container {
    padding: var(--vf-space-5);
}

.results-content {
    margin-top: 1em;
}

.participant-section {
    background: var(--vf-color-neutral-50);
    border-radius: var(--vf-radius-md);
    margin-bottom: var(--vf-space-5);
}

.participant-section h3 {
    margin-top: 0;
    color: var(--vf-color-primary);
}

.table-wrapper {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;  /* Smooth scrolling on iOS */
    border-radius: var(--vf-radius-md);
}

.results-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--vf-color-bg-card);
    border-radius: var(--vf-radius-md);
    overflow: hidden;
}

.results-table th,
.results-table td {
    padding: var(--vf-space-3);
    text-align: left;
    border-bottom: 1px solid var(--vf-color-neutral-200);
}

/* Mobile responsive font sizing */
@media (max-width: 768px) {
    .results-table th,
    .results-table td {
        font-size: 0.625rem;  /* 10px equivalent */
        line-height: 1em;
        padding: var(--vf-space-2);
    }
}

.results-table th {
    background: var(--vf-color-primary);
    color: var(--vf-color-text-on-primary);
    font-weight: var(--vf-font-weight-semibold);
}

.results-table tr:last-child td {
    border-bottom: none;
}

.results-table tbody tr:hover {
    background: var(--vf-color-neutral-50);
}

.results-btn.danger {
    background: var(--vf-color-error);
    color: var(--vf-color-text-on-primary);
    border-color: var(--vf-color-error-dark);
}

.results-btn.danger:hover {
    background: var(--vf-color-error-dark);
}

.delete-result-btn {
    background: var(--vf-color-error);
    color: var(--vf-color-text-on-primary);
    border: none;
    padding: var(--vf-space-1) var(--vf-space-2);
    border-radius: var(--vf-radius-sm);
    cursor: pointer;
    font-size: var(--vf-font-size-base);
    transition: background var(--vf-transition-fast);
}

.delete-result-btn:hover {
    background: var(--vf-color-error-dark);
}
