/* Font Size Adjuster - Accessibility Controls CSS */
/* Version: 2.3 - Mobile Optimized */

/* CSS Variables */
:root {
    --fsa-primary-color: #00008B;
    --fsa-text-color: #ffffff;
    --fsa-bg-color: rgba(0, 0, 0, 0.85);
    --fsa-border-color: #ffffff;
    --fsa-hover-color: rgba(255, 255, 255, 0.2);
    --fsa-active-color: #00008B;
    --fsa-button-size: 36px;
    --fsa-button-font-size: 16px;
    --fsa-label-font-size: 14px;
    --fsa-toggle-width: 50px;
    --fsa-toggle-height: 24px;
    --fsa-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    --fsa-border-radius: 8px;
    --fsa-focus-outline: 3px solid #0078d7;
}

/* Screen reader only text */
.screen-reader-text {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Notifications (optimized) */
.fsa-notification {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: var(--fsa-bg-color);
    color: var(--fsa-text-color);
    padding: 15px 20px;
    border-radius: var(--fsa-border-radius);
    z-index: 10000;
    box-shadow: var(--fsa-shadow);
    max-width: 300px;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.fsa-notification.fsa-visible {
    opacity: 1;
    transform: translateY(0);
}

/* Toolbar Container */
.accessibility-toolbar {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
}

/* Toolbar Positions */
.accessibility-toolbar.top-right {
    top: 20px;
    right: 20px;
    bottom: auto;
    left: auto;
}

.accessibility-toolbar.top-left {
    top: 20px;
    left: 20px;
    bottom: auto;
    right: auto;
}

.accessibility-toolbar.bottom-left {
    bottom: 20px;
    left: 20px;
    top: auto;
    right: auto;
}

/* Main Toggle Button */
.accessibility-toggle {
    background: var(--fsa-bg-color);
    color: var(--fsa-text-color);
    border: 2px solid var(--fsa-border-color);
    border-radius: 50%;
    width: 56px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: var(--fsa-shadow);
    transition: all 0.3s ease;
}

.accessibility-toggle:hover,
.accessibility-toggle:focus {
    transform: scale(1.05);
    background: #000;
}

.accessibility-toggle:focus {
    outline: var(--fsa-focus-outline);
    outline-offset: 2px;
}

.accessibility-toggle svg {
    width: 32px;
    height: 32px;
    fill: currentColor;
}

/* Accessibility Panel */
.accessibility-panel {
    position: absolute;
    bottom: 70px;
    right: 0;
    background: var(--fsa-bg-color);
    color: var(--fsa-text-color);
    border: 2px solid var(--fsa-border-color);
    border-radius: var(--fsa-border-radius);
    padding: 20px;
    width: 200px;
    max-width: 90vw;
    box-shadow: var(--fsa-shadow);
    overflow-y: auto;
    max-height: 80vh;
}

/* Panel positioning based on toolbar position */
.accessibility-toolbar.top-right .accessibility-panel,
.accessibility-toolbar.top-left .accessibility-panel {
    top: 70px;
    bottom: auto;
}

.accessibility-toolbar.bottom-left .accessibility-panel,
.accessibility-toolbar.top-left .accessibility-panel {
    left: 0;
    right: auto;
}

.panel-section {
    margin-bottom: 20px;
    padding-bottom: 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

.panel-section:last-child {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
}

.panel-section h3 {
    margin: 0 0 15px 0;
    font-size: 16px;
    color: var(--fsa-text-color);
    font-weight: 600;
}

.control-group {
    margin-bottom: 15px;
}

.control-label {
    display: block;
    margin-bottom: 8px;
    font-size: var(--fsa-label-font-size);
    color: var(--fsa-text-color);
}

.control-buttons {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

/* Control Buttons */
.control-btn {
    background: transparent;
    border: 2px solid var(--fsa-border-color);
    border-radius: 50%;
    width: var(--fsa-button-size);
    height: var(--fsa-button-size);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: var(--fsa-button-font-size);
    padding: 0;
    color: var(--fsa-text-color);
    transition: all 0.2s ease-in-out;
    position: relative;
    -webkit-tap-highlight-color: transparent;
}

.control-btn:hover,
.control-btn:focus {
    background: var(--fsa-hover-color);
    transform: scale(1.05);
}

.control-btn:focus {
    outline: var(--fsa-focus-outline);
    outline-offset: 2px;
}

.control-btn:active {
    transform: scale(0.95);
    background: rgba(255, 255, 255, 0.3);
}

.control-btn[data-active="true"] {
    background: var(--fsa-active-color);
    border-color: var(--fsa-text-color);
    color: #ffffff;
}

/* Font Size Buttons */
.font-size-btn {
    font-weight: bold;
}

.font-size-btn.normal {
    font-size: 14px;
}

/* Letter Spacing Buttons */
.letter-spacing-btn.normal::before {
    content: 'ก ข';
    font-size: 12px;
}

/* Line Height Buttons */
.line-height-btn.normal::before {
    content: '≡';
    font-size: 18px;
}

/* Theme Buttons */
.contrast-btn {
    width: 40px;
    height: 40px;
    overflow: hidden;
}

.contrast-btn.normal {
    background: linear-gradient(45deg, #ffffff 50%, #333333 50%);
    border: 2px solid var(--fsa-border-color);
}

.contrast-btn.high {
    background: #000000;
    border: 2px solid #ffff00;
}

.contrast-btn.high::after {
    content: 'A';
    color: #ffffff;
    font-weight: bold;
    font-size: 16px;
}

.contrast-btn.yellow-black {
    background: #000000;
    border: 2px solid #ffff00;
}

.contrast-btn.yellow-black::after {
    content: 'Y';
    color: #ffff00;
    font-weight: bold;
    font-size: 16px;
}

.contrast-btn.light {
    background: #ffffff;
    border: 2px solid #000000;
}

.contrast-btn.light::after {
    content: 'L';
    color: #000000;
    font-weight: bold;
    font-size: 16px;
}

.contrast-btn.dark {
    background: #222222;
    border: 2px solid #dddddd;
}

.contrast-btn.dark::after {
    content: 'D';
    color: #dddddd;
    font-weight: bold;
    font-size: 16px;
}

/* Toggle Controls */
.toggle-control {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    padding: 8px 0;
}

.toggle-label {
    font-size: var(--fsa-label-font-size);
    color: var(--fsa-text-color);
    flex: 1;
}

.toggle-control input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-switch {
    position: relative;
    display: inline-block;
    width: var(--fsa-toggle-width);
    height: var(--fsa-toggle-height);
    background-color: #666;
    border-radius: calc(var(--fsa-toggle-height) / 2);
    transition: all 0.3s;
    flex-shrink: 0;
}

.toggle-switch::after {
    content: '';
    position: absolute;
    width: calc(var(--fsa-toggle-height) - 4px);
    height: calc(var(--fsa-toggle-height) - 4px);
    border-radius: 50%;
    background-color: white;
    top: 2px;
    left: 2px;
    transition: all 0.3s;
}

.toggle-control input:checked + .toggle-label + .toggle-switch {
    background-color: var(--fsa-active-color);
}

.toggle-control input:checked + .toggle-label + .toggle-switch::after {
    transform: translateX(calc(var(--fsa-toggle-width) - var(--fsa-toggle-height)));
}

.toggle-control input:focus + .toggle-label + .toggle-switch {
    box-shadow: 0 0 0 3px rgba(0, 120, 215, 0.5);
}

/* Panel Actions */
.panel-actions {
    display: flex;
    gap: 10px;
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.2);
}

.reset-all-btn,
.save-settings-btn {
    flex: 1;
    background: transparent;
    border: 2px solid var(--fsa-border-color);
    border-radius: 6px;
    padding: 10px 16px;
    color: var(--fsa-text-color);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s;
}

.reset-all-btn:hover,
.save-settings-btn:hover,
.reset-all-btn:focus,
.save-settings-btn:focus {
    background: var(--fsa-hover-color);
}

.reset-all-btn {
    border-color: #ff4444;
    color: #ff4444;
}

.reset-all-btn:hover {
    background: rgba(255, 68, 68, 0.1);
}

.save-settings-btn {
    border-color: #44ff44;
    color: #44ff44;
}

.save-settings-btn:hover {
    background: rgba(68, 255, 68, 0.1);
}

/* Individual Controls (for shortcodes) */
.font-size-adjuster,
.contrast-adjuster,
.letter-spacing-adjuster,
.line-height-adjuster,
.dyslexia-font-control {
    display: inline-flex;
    align-items: center;
    gap: 15px;
    padding: 12px 20px;
    border-radius: var(--fsa-border-radius);
    background-color: var(--fsa-bg-color);
    box-shadow: var(--fsa-shadow);
    margin: 10px 0;
}

.font-size-adjuster .control-label,
.contrast-adjuster .contrast-label,
.letter-spacing-adjuster .control-label,
.line-height-adjuster .control-label {
    color: var(--fsa-text-color);
    font-size: var(--fsa-label-font-size);
    font-weight: 500;
    margin: 0;
}

/* ===================================
   Mobile Responsive Design
   =================================== */
   
/* Tablet and below */
@media (max-width: 768px) {
    /* Adjust toolbar position */
    .accessibility-toolbar {
        bottom: 10px !important;
        right: 10px !important;
    }
    
    .accessibility-toolbar.bottom-left {
        left: 10px !important;
        right: auto !important;
    }
    
    .accessibility-toolbar.top-right {
        top: 10px !important;
        bottom: auto !important;
    }
    
    .accessibility-toolbar.top-left {
        top: 10px !important;
        left: 10px !important;
        right: auto !important;
        bottom: auto !important;
    }
    
    /* Smaller toggle button on mobile */
    .accessibility-toggle {
        width: 48px;
        height: 48px;
    }
    
    .accessibility-toggle svg {
        width: 24px;
        height: 24px;
    }
    
    /* Panel adjustments for mobile */
    .accessibility-panel {
        width: calc(80vw - 20px);
        max-width: none;
        max-height: 70vh;
        bottom: 60px;
        left: 50%;
        right: auto;
        transform: translateX(-50%);
        padding: 15px;
        /* Enable smooth scrolling on iOS */
        -webkit-overflow-scrolling: touch;
        overflow-y: auto;
    }
    
    /* Adjust panel for top positions */
    .accessibility-toolbar.top-right .accessibility-panel,
    .accessibility-toolbar.top-left .accessibility-panel {
        top: 60px;
        bottom: auto;
    }
    
    /* Adjust panel sections */
    .panel-section {
        margin-bottom: 15px;
        padding-bottom: 15px;
    }
    
    .panel-section h3 {
        font-size: 14px;
        margin-bottom: 10px;
    }
    
    /* Smaller controls on mobile */
    .control-btn {
        width: 32px;
        height: 32px;
        font-size: 14px;
    }
    
    .contrast-btn {
        width: 36px;
        height: 36px;
    }
    
    .contrast-btn::after {
        font-size: 14px;
    }
    
    /* Adjust control groups */
    .control-group {
        margin-bottom: 12px;
    }
    
    .control-label {
        font-size: 13px;
        margin-bottom: 6px;
    }
    
    /* Optimize control buttons layout */
    .control-buttons {
        gap: 8px;
    }
    
    /* Stack panel actions on mobile */
    .panel-actions {
        flex-direction: column;
        gap: 8px;
        padding-top: 15px;
        margin-top: 15px;
    }
    
    .reset-all-btn,
    .save-settings-btn {
        width: 100%;
        padding: 12px;
    }
    
    /* Adjust toggles for mobile */
    .toggle-control {
        padding: 10px 0;
    }
    
    .toggle-label {
        font-size: 13px;
    }
    
    .toggle-switch {
        width: 44px;
        height: 22px;
    }
    
    /* Individual controls responsive */
    .font-size-adjuster,
    .contrast-adjuster,
    .letter-spacing-adjuster,
    .line-height-adjuster,
    .dyslexia-font-control {
        padding: 10px 15px;
        gap: 10px;
        flex-wrap: wrap;
    }
    
    /* Notification position on mobile */
    .fsa-notification {
        bottom: 10px;
        right: 10px;
        left: 10px;
        max-width: none;
        text-align: center;
    }
}

/* Small mobile devices */
@media (max-width: 480px) {
    /* Even smaller panel on very small screens */
    .accessibility-panel {
        width: calc(80vw - 10px);
        padding: 12px;
    }
    
    /* Reduce font sizes */
    .panel-section h3 {
        font-size: 13px;
    }
    
    .control-label {
        font-size: 12px;
    }
    
    /* Make buttons full width on very small screens */
    .control-buttons {
        flex-direction: row;
        justify-content: space-between;
    }
    
    .control-btn {
        flex: 1;
        max-width: 30%;
    }
}

/* Very small mobile devices (iPhone SE, etc.) */
@media (max-width: 375px) {
    /* Stack contrast buttons vertically */
    .contrast-adjuster .control-buttons {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 5px;
    }
    
    .contrast-btn {
        width: 100%;
        height: 40px;
    }
    
    /* Adjust toggle controls */
    .toggle-control {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .toggle-switch {
        margin-top: 5px;
    }
}

/* Landscape mode adjustments */
@media (max-height: 500px) and (orientation: landscape) {
    .accessibility-panel {
        max-height: 80vh;
        bottom: 5px;
    }
    
    .accessibility-toolbar.top-right .accessibility-panel,
    .accessibility-toolbar.top-left .accessibility-panel {
        top: 50px;
    }
    
    .panel-section {
        margin-bottom: 10px;
        padding-bottom: 10px;
    }
    
    .control-group {
        margin-bottom: 8px;
    }
}

/* Theme Specific Styles */
body[class*="fsa-theme-"] * {
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* Focus Mode Styles */
body[class*="fsa-focus-mode-"] {
    overflow-x: hidden;
}

/* Dyslexia Font */
body[class*="fsa-dyslexia-font-"] [data-fsa] {
    font-family: 'OpenDyslexic', sans-serif !important;
}

/* Hidden Panel */
.accessibility-panel[hidden] {
    display: none;
}

/* High Contrast Mode Support */
@media (prefers-contrast: high) {
    :root {
        --fsa-bg-color: #000000;
        --fsa-border-color: #ffffff;
        --fsa-hover-color: #333333;
    }
}

/* Reduced Motion Support */
@media (prefers-reduced-motion: reduce) {
    .accessibility-toggle,
    .control-btn,
    .toggle-switch,
    .toggle-switch::after,
    .fsa-notification {
        transition: none !important;
        animation: none !important;
    }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
    /* Larger touch targets */
    .control-btn {
        min-width: 44px;
        min-height: 44px;
    }
    
    .toggle-control {
        min-height: 44px;
    }
    
    /* Remove hover effects on touch devices */
    .control-btn:hover,
    .reset-all-btn:hover,
    .save-settings-btn:hover {
        background: transparent;
        transform: none;
    }
    
    /* Active state for touch */
    .control-btn:active {
        background: var(--fsa-hover-color);
        transform: scale(0.95);
    }
}

/* Mobile class specific styles */
body.fsa-mobile .accessibility-toolbar {
    /* Prevent toolbar from going off-screen */
    position: fixed !important;
}

body.fsa-mobile .accessibility-panel {
    /* Ensure panel stays within viewport */
    position: fixed !important;
    max-width: calc(100vw - 10px) !important;
}

/* Performance optimizations */
.accessibility-panel {
    /* Use GPU acceleration */
    will-change: transform, opacity;
    /* Contain layout */
    contain: layout style;
}

/* Print styles */
@media print {
    .accessibility-toolbar {
        display: none !important;
    }
}

.panel-close-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    /* วงกลมสมบูรณ์ */
}

.control-btn {
    width: 36px !important;
    height: 36px !important;
    min-width: 36px !important;
    min-height: 36px !important;
    border-radius: 50%;
    flex-shrink: 0;
    flex-grow: 0;
}