/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Open Sans', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 10px;
    overflow-x: hidden;
}

.app-container {
    max-width: 1200px;
    margin: 0 auto;
    background: white;
    border-radius: 20px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    min-height: calc(100vh - 20px);
    display: flex;
    flex-direction: column;
}

/* Header */
.app-header {
    background: linear-gradient(135deg, #4CAF50, #45a049);
    color: white;
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.header-left {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* User Info */
.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.9rem;
    opacity: 0.9;
}

.user-email {
    background: rgba(255, 255, 255, 0.2);
    padding: 4px 12px;
    border-radius: 15px;
    font-weight: 500;
}

.save-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    padding: 6px 12px;
    border-radius: 15px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
}

.save-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: translateY(-1px);
}

.save-btn.saving {
    background: #FF9800;
    animation: pulse 1s infinite;
}

.save-btn.saved {
    background: #4CAF50;
    animation: saved 2s ease;
}

/* Save button states for device-based storage */
.save-btn.unsaved {
    background: rgba(255, 152, 0, 0.8) !important;
    animation: pulse 2s infinite;
}

.save-btn.saved {
    background: rgba(76, 175, 80, 0.8) !important;
}

@keyframes pulse {
    0% { opacity: 1; }
    50% { opacity: 0.7; }
    100% { opacity: 1; }
}

@keyframes saved {
    0% { transform: scale(1); }
    20% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

.header-controls {
    display: flex;
    gap: 20px;
    align-items: center;
}

/* Mode Toggle Switch */
.mode-toggle {
    display: flex;
    align-items: center;
    gap: 15px;
    background: rgba(255, 255, 255, 0.1);
    padding: 10px 15px;
    border-radius: 25px;
    backdrop-filter: blur(10px);
}

.toggle-label {
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9rem;
    margin: 0;
}

.mode-text {
    color: rgba(255, 255, 255, 0.8);
    transition: color 0.3s ease;
    white-space: nowrap;
}

.toggle-switch {
    position: relative;
    width: 50px;
    height: 24px;
}

.toggle-input {
    position: absolute;
    opacity: 0;
    width: 100%;
    height: 100%;
    cursor: pointer;
    z-index: 2;
}

.toggle-slider {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 24px;
    transition: all 0.3s ease;
    cursor: pointer;
}

.toggle-slider::before {
    content: '';
    position: absolute;
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background: white;
    border-radius: 50%;
    transition: all 0.3s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.toggle-input:checked + .toggle-slider {
    background: #FF6B6B;
}

.toggle-input:checked + .toggle-slider::before {
    transform: translateX(26px);
}

/* Mode text highlighting */
.toggle-input:not(:checked) ~ .mode-text:first-of-type,
.toggle-input:checked ~ .mode-text:last-of-type {
    color: white;
    text-shadow: 0 0 8px rgba(255, 255, 255, 0.5);
}

/* Message Display */
.message-display {
    background: #f8f9fa;
    padding: 12px 20px;
    min-height: 60px;
    border-bottom: 2px solid #e9ecef;
    display: flex;
    align-items: center;
}

.message-text {
    font-size: 1.5rem;
    font-weight: 600;
    color: #333;
    line-height: 1.4;
    word-wrap: break-word;
    min-height: 40px;
    width: 100%;
}

/* Category Tabs */
.category-tabs {
    display: flex;
    background: #f8f9fa;
    border-bottom: 2px solid #e9ecef;
    overflow-x: auto;
    padding: 0 20px;
}

.tab-btn {
    padding: 12px 20px;
    border: none;
    background: transparent;
    color: #666;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    border-bottom: 3px solid transparent;
    white-space: nowrap;
}

.tab-btn:hover,
.tab-btn.active {
    color: #4CAF50;
    border-bottom-color: #4CAF50;
    background: rgba(76, 175, 80, 0.1);
}

/* Buttons Container */
.buttons-container {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
}

.buttons-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 15px;
    margin-bottom: 20px;
}

.comm-btn {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    border: none;
    padding: 20px;
    border-radius: 15px;
    font-size: 1.2rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    min-height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    position: relative;
    overflow: hidden;
}

.comm-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
}

.comm-btn:active {
    transform: translateY(-1px);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.comm-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: left 0.5s;
}

.comm-btn:hover::before {
    left: 100%;
}

/* Quick Phrases */
.quick-phrases {
    background: #f8f9fa;
    padding: 20px;
    border-top: 2px solid #e9ecef;
}

.quick-phrases h3 {
    color: #333;
    margin-bottom: 15px;
    font-size: 1.3rem;
}

.phrases-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 10px;
}

.phrase-btn {
    background: #28a745;
    color: white;
    border: none;
    padding: 15px 10px;
    border-radius: 10px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.phrase-btn:hover {
    background: #218838;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* Mode-specific styles */
.speak-mode .comm-btn:hover,
.speak-mode .phrase-btn:hover {
    background: linear-gradient(135deg, #FF6B6B, #ff5252);
    transform: translateY(-3px) scale(1.02);
}

.speak-mode .comm-btn::after,
.speak-mode .phrase-btn::after {
    content: '🔊';
    position: absolute;
    top: 5px;
    right: 5px;
    font-size: 0.8rem;
    opacity: 0.7;
}

/* Mode indicator */
.mode-indicator {
    animation: slideDown 0.3s ease;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Toggle switch focus styles */
.toggle-input:focus + .toggle-slider {
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.3);
}

/* Responsive Design */
@media (max-width: 768px) {
    body {
        padding: 2px;
    }
    
    .app-container {
        border-radius: 0;
        min-height: 100vh;
        margin: 0;
    }
    
    .app-header {
        padding: 12px;
        flex-direction: column;
        gap: 12px;
        text-align: center;
    }
    
    .header-left {
        align-items: center;
    }
    
    .header-controls {
        flex-wrap: wrap;
        gap: 8px;
        width: 100%;
        justify-content: center;
    }
    
    .control-btn {
        min-width: 80px;
        padding: 12px 16px;
        font-size: 0.9rem;
        flex: 1;
        max-width: 120px;
    }
    
    .mode-toggle {
        order: -1;
        width: 100%;
        justify-content: center;
        padding: 8px 12px;
    }
    
    .toggle-label {
        font-size: 0.8rem;
        gap: 8px;
    }
    
    .app-header h1 {
        font-size: 1.3rem;
    }
    
    .user-info {
        flex-direction: column;
        gap: 6px;
    }
    
    .message-display {
        padding: 10px 15px;
        min-height: 50px;
    }
    
    .message-text {
        font-size: 1.2rem;
    }
    
    .buttons-grid {
        grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
        gap: 8px;
    }
    
    .comm-btn {
        padding: 12px 8px;
        font-size: 0.9rem;
        min-height: 65px;
    }
    
    .category-tabs {
        padding: 0 8px;
        gap: 2px;
    }
    
    .tab-btn {
        padding: 8px 12px;
        font-size: 0.8rem;
        min-width: 70px;
    }
    
    .phrases-grid {
        grid-template-columns: repeat(auto-fit, minmax(90px, 1fr));
        gap: 8px;
    }
    
    .phrase-btn {
        padding: 10px 6px;
        font-size: 0.8rem;
    }
    
    .quick-phrases {
        padding: 15px;
    }
    
    .quick-phrases h3 {
        font-size: 1.1rem;
        margin-bottom: 10px;
    }
    
    .buttons-container {
        padding: 15px;
    }
}

@media (max-width: 480px) {
    body {
        padding: 0;
    }
    
    .app-header {
        padding: 8px 10px;
        gap: 8px;
    }
    
    .control-btn {
        min-width: 60px;
        padding: 10px 12px;
        font-size: 0.8rem;
        max-width: 100px;
    }
    
    .message-display {
        padding: 8px 12px;
        min-height: 40px;
    }
    
    .message-text {
        font-size: 1rem;
    }
    
    .tab-btn {
        padding: 6px 10px;
        font-size: 0.7rem;
        min-width: 60px;
    }
    
    .category-tabs {
        padding: 0 6px;
    }
    
    .buttons-container {
        padding: 12px;
    }
}

/* Mobile-specific large buttons enhancement */
@media (max-width: 768px) {
    .large-buttons .comm-btn,
    .large-buttons .phrase-btn {
        min-height: 80px;
        font-size: 1.1rem;
        padding: 18px 12px;
    }
    
    .large-buttons .comm-btn span:first-child {
        font-size: 2rem !important;
    }
    
    .large-buttons .control-btn {
        min-height: 48px;
        padding: 14px 18px;
        font-size: 1rem;
    }
    
    .large-buttons .tab-btn {
        min-height: 44px;
        padding: 14px 16px;
        font-size: 0.9rem;
    }
}

@media (max-width: 480px) {
    .large-buttons .comm-btn,
    .large-buttons .phrase-btn {
        min-height: 70px;
        font-size: 1rem;
        padding: 16px 10px;
    }
    
    .large-buttons .comm-btn span:first-child {
        font-size: 1.8rem !important;
    }
}

/* Landscape orientation adjustments */
@media (max-width: 768px) and (orientation: landscape) {
    .app-header {
        padding: 6px 8px;
        flex-direction: row;
        gap: 8px;
        align-items: center;
    }
    
    .header-left {
        flex: 0 0 auto;
        min-width: 0;
    }
    
    .user-info {
        display: none !important; /* Hide user info in landscape to save space */
    }
    
    .header-controls {
        flex: 1;
        flex-direction: row;
        flex-wrap: nowrap;
        gap: 4px;
        justify-content: flex-end;
        min-width: 0;
    }
    
    .mode-toggle {
        order: 1;
        padding: 4px 8px;
        flex: 0 0 auto;
    }
    
    .toggle-label {
        font-size: 0.65rem;
        gap: 6px;
    }
    
    .mode-text {
        display: none; /* Hide mode text in landscape */
    }
    
    .toggle-switch {
        width: 40px;
        height: 20px;
    }
    
    .toggle-slider::before {
        height: 14px;
        width: 14px;
        left: 3px;
        bottom: 3px;
    }
    
    .toggle-input:checked + .toggle-slider::before {
        transform: translateX(20px);
    }
    
    .control-btn {
        padding: 6px 8px;
        font-size: 0.7rem;
        min-width: 40px;
        flex: 0 0 auto;
        border-radius: 15px;
    }
    
    .message-display {
        padding: 8px;
        min-height: 35px;
    }
    
    .message-text {
        font-size: 0.9rem;
    }
    
    .buttons-grid {
        grid-template-columns: repeat(auto-fit, minmax(70px, 1fr));
        gap: 4px;
    }
    
    .comm-btn {
        min-height: 40px;
        padding: 6px 4px;
        font-size: 0.7rem;
    }
    
    .quick-phrases {
        padding: 8px;
    }
    
    .quick-phrases h3 {
        font-size: 0.9rem;
        margin-bottom: 6px;
    }
    
    .phrase-btn {
        padding: 6px 4px;
        font-size: 0.7rem;
    }
}

/* Extra narrow landscape (very small phones) */
@media (max-width: 640px) and (orientation: landscape) {
    .control-btn {
        padding: 4px 6px;
        font-size: 0.65rem;
        min-width: 35px;
    }
    
    .mode-toggle {
        padding: 2px 6px;
    }
    
    .toggle-switch {
        width: 35px;
        height: 18px;
    }
    
    .toggle-slider::before {
        height: 12px;
        width: 12px;
    }
    
    .toggle-input:checked + .toggle-slider::before {
        transform: translateX(17px);
    }
}

/* High DPI display support */
@media (min-resolution: 192dpi) {
    .comm-btn,
    .phrase-btn,
    .control-btn {
        border-width: 0.5px;
    }
}

/* Dark mode support for mobile */
@media (prefers-color-scheme: dark) and (max-width: 768px) {
    .app-container {
        background: #1a1a1a;
        color: #ffffff;
    }
    
    .message-display {
        background: #2d2d2d;
        color: #ffffff;
    }
    
    .category-tabs {
        background: #2d2d2d;
    }
    
    .tab-btn {
        color: #cccccc;
    }
    
    .tab-btn.active {
        color: #4CAF50;
    }
    
    .quick-phrases {
        background: #2d2d2d;
    }
    
    .quick-phrases h3 {
        color: #ffffff;
    }
}

/* Animation for button press feedback */
@keyframes buttonPress {
    0% { transform: scale(1); }
    50% { transform: scale(0.95); }
    100% { transform: scale(1); }
}

.comm-btn.pressed,
.phrase-btn.pressed {
    animation: buttonPress 0.2s ease;
}

/* Accessibility */
.comm-btn:focus,
.phrase-btn:focus,
.control-btn:focus,
.tab-btn:focus {
    outline: 3px solid #FFD700;
    outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .comm-btn {
        background: #000;
        color: #fff;
        border: 2px solid #fff;
    }
    
    .phrase-btn {
        background: #006600;
        border: 2px solid #fff;
    }
}

/* Custom page styles */
.add-btn, .remove-btn {
    position: absolute;
    top: -5px;
    right: -5px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #4CAF50;
    color: white;
    font-size: 16px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 2;
}

.remove-btn {
    background: #FF6B6B;
    font-size: 20px;
    line-height: 1;
}

.comm-btn:hover .add-btn,
.comm-btn:hover .remove-btn,
.comm-btn.removable .remove-btn {
    opacity: 1;
    transform: scale(1);
}

.add-btn:hover {
    background: #45a049;
    transform: scale(1.1);
}

.remove-btn:hover {
    background: #ff5252;
    transform: scale(1.1);
}

/* Custom page edit mode */
.comm-btn.removable {
    position: relative;
    border: 2px dashed #FF6B6B;
    background: linear-gradient(135deg, #ffebee, #ffcdd2);
    color: #c62828;
}

.comm-btn.removable:hover {
    border-color: #ff5252;
    transform: translateY(-2px);
}

/* Empty state */
.empty-state {
    grid-column: 1 / -1;
    margin: 20px 0;
}

/* Message popup animations */
@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(100%);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes slideOutRight {
    from {
        opacity: 1;
        transform: translateX(0);
    }
    to {
        opacity: 0;
        transform: translateX(100%);
    }
}

/* Custom tab highlighting */
.tab-btn[data-category="custom"] {
    position: relative;
}

.tab-btn[data-category="custom"]::after {
    content: '⭐';
    font-size: 0.8rem;
    margin-left: 5px;
}

/* Long press visual feedback */
.comm-btn.long-pressing {
    animation: longPressEffect 0.8s ease-in-out;
}

@keyframes longPressEffect {
    0%, 100% { 
        transform: scale(1); 
        box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    }
    50% { 
        transform: scale(1.05); 
        box-shadow: 0 8px 25px rgba(76, 175, 80, 0.3);
    }
}

/* Settings Modal */
.settings-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    animation: fadeIn 0.3s ease;
}

.settings-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(5px);
}

.settings-content {
    position: relative;
    background: white;
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    margin: 5vh auto;
    border-radius: 20px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.settings-header {
    background: linear-gradient(135deg, #4CAF50, #45a049);
    color: white;
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.settings-header h2 {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 700;
}

.close-btn {
    background: none;
    border: none;
    color: white;
    font-size: 2rem;
    cursor: pointer;
    padding: 0;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.3s ease;
}

.close-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.settings-body {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
}

.settings-section {
    margin-bottom: 30px;
}

.settings-section h3 {
    color: #333;
    font-size: 1.2rem;
    margin-bottom: 15px;
    padding-bottom: 8px;
    border-bottom: 2px solid #e9ecef;
}

.setting-item {
    margin-bottom: 20px;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 10px;
    border: 1px solid #e9ecef;
}

.setting-label {
    display: block;
    cursor: pointer;
    font-weight: 500;
}

.setting-checkbox {
    margin-right: 12px;
    transform: scale(1.2);
}

.setting-text {
    font-size: 1rem;
    color: #333;
    margin-bottom: 5px;
    display: block;
}

.setting-description {
    font-size: 0.9rem;
    color: #666;
    font-weight: normal;
    display: block;
    margin-top: 5px;
    line-height: 1.4;
}

.setting-range {
    width: 100%;
    margin: 10px 0;
    height: 6px;
    border-radius: 3px;
    background: #ddd;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

.setting-range::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #4CAF50;
    cursor: pointer;
    border: 2px solid white;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

.setting-range::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #4CAF50;
    cursor: pointer;
    border: 2px solid white;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

.setting-value {
    display: inline-block;
    background: #4CAF50;
    color: white;
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 600;
    min-width: 40px;
    text-align: center;
    margin-left: 10px;
}

.settings-footer {
    background: #f8f9fa;
    padding: 20px;
    border-top: 1px solid #e9ecef;
    display: flex;
    justify-content: space-between;
    gap: 15px;
}

.reset-btn, .apply-btn {
    padding: 12px 20px;
    border: none;
    border-radius: 25px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    flex: 1;
}

.reset-btn {
    background: #f44336;
    color: white;
}

.reset-btn:hover {
    background: #d32f2f;
    transform: translateY(-2px);
}

.apply-btn {
    background: #4CAF50;
    color: white;
}

.apply-btn:hover {
    background: #45a049;
    transform: translateY(-2px);
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Settings modal responsive */
@media (max-width: 768px) {
    .settings-content {
        width: 95%;
        margin: 1vh auto;
        max-height: 95vh;
        border-radius: 15px;
    }
    
    .settings-header {
        padding: 15px;
    }
    
    .settings-header h2 {
        font-size: 1.2rem;
    }
    
    .settings-body {
        padding: 15px;
    }
    
    .setting-item {
        padding: 12px;
        margin-bottom: 15px;
    }
    
    .setting-text {
        font-size: 0.9rem;
    }
    
    .setting-description {
        font-size: 0.8rem;
    }
    
    .settings-footer {
        padding: 15px;
        flex-direction: column;
        gap: 10px;
    }
    
    .reset-btn, .apply-btn {
        margin-bottom: 0;
        padding: 14px 20px;
        font-size: 0.9rem;
    }
}

@media (max-width: 480px) {
    .settings-content {
        width: 98%;
        margin: 0.5vh auto;
        max-height: 98vh;
        border-radius: 10px;
    }
    
    .settings-header {
        padding: 12px;
    }
    
    .settings-header h2 {
        font-size: 1.1rem;
    }
    
    .close-btn {
        width: 35px;
        height: 35px;
        font-size: 1.5rem;
    }
    
    .settings-body {
        padding: 12px;
    }
    
    .setting-item {
        padding: 10px;
        margin-bottom: 12px;
    }
    
    .setting-text {
        font-size: 0.85rem;
    }
    
    .setting-description {
        font-size: 0.75rem;
    }
    
    .settings-section h3 {
        font-size: 1rem;
        margin-bottom: 12px;
    }
    
    .settings-footer {
        padding: 12px;
    }
    
    .reset-btn, .apply-btn {
        padding: 12px 16px;
        font-size: 0.85rem;
    }
}

/* UI Settings Classes */
.large-buttons .comm-btn,
.large-buttons .phrase-btn {
    min-height: 100px;
    font-size: 1.4rem;
    padding: 25px;
}

.large-buttons .comm-btn span:first-child {
    font-size: 2.5rem !important;
}

.high-contrast .comm-btn {
    background: #000000;
    color: #ffffff;
    border: 3px solid #ffffff;
}

.high-contrast .phrase-btn {
    background: #003300;
    color: #ffffff;
    border: 2px solid #ffffff;
}

.high-contrast .app-header {
    background: #000000;
    border-bottom: 3px solid #ffffff;
}

.high-contrast .message-display {
    background: #ffffff;
    color: #000000;
    border: 3px solid #000000;
}

.high-contrast .category-tabs {
    background: #000000;
}

.high-contrast .tab-btn {
    color: #ffffff;
    border: 2px solid #ffffff;
    margin: 2px;
}

.high-contrast .tab-btn.active {
    background: #ffffff;
    color: #000000;
}

.reduced-motion *,
.reduced-motion *::before,
.reduced-motion *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
}

.reduced-motion .comm-btn:hover,
.reduced-motion .phrase-btn:hover {
    transform: none;
}

/* Settings applied indicator */
.settings-applied {
    animation: settingsApplied 2s ease;
}

@keyframes settingsApplied {
    0% { background-color: rgba(76, 175, 80, 0.2); }
    100% { background-color: transparent; }
}

/* Control Buttons - Enhanced */
.control-btn {
    padding: 16px 28px;
    border: none;
    border-radius: 25px;
    font-size: 1.3rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s ease;
    background: rgba(255, 255, 255, 0.25);
    color: white;
    backdrop-filter: blur(10px);
    min-width: 140px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
    border: 2px solid rgba(255, 255, 255, 0.2);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.control-btn:hover {
    background: rgba(255, 255, 255, 0.35);
    transform: translateY(-3px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
    border-color: rgba(255, 255, 255, 0.4);
}

.control-btn:active {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.control-btn.primary {
    background: linear-gradient(135deg, #FF6B6B, #ff5252);
    border-color: rgba(255, 255, 255, 0.3);
}

.control-btn.primary:hover {
    background: linear-gradient(135deg, #ff5252, #e53935);
    transform: translateY(-3px) scale(1.02);
}

/* Button icons enhancement */
.control-btn::before {
    font-size: 1.4rem;
    margin-right: 4px;
}

#settingsBtn {
    background: linear-gradient(135deg, #9C27B0, #7B1FA2);
}

#settingsBtn:hover {
    background: linear-gradient(135deg, #7B1FA2, #6A1B9A);
}

#clearBtn {
    background: linear-gradient(135deg, #FF9800, #F57C00);
}

#clearBtn:hover {
    background: linear-gradient(135deg, #F57C00, #EF6C00);
}

/* Touch-friendly mobile enhancements */
@media (hover: none) and (pointer: coarse) {
    /* Mobile touch devices */
    .comm-btn,
    .phrase-btn,
    .control-btn,
    .tab-btn {
        min-height: 44px; /* Apple's recommended touch target size */
        min-width: 44px;
    }
    
    .comm-btn:hover,
    .phrase-btn:hover,
    .control-btn:hover,
    .tab-btn:hover {
        transform: none; /* Disable hover transforms on touch devices */
    }
    
    .comm-btn:active,
    .phrase-btn:active,
    .control-btn:active,
    .tab-btn:active {
        transform: scale(0.95);
        transition: transform 0.1s ease;
    }
}

/* Improved scrolling for mobile */
.category-tabs {
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.category-tabs::-webkit-scrollbar {
    display: none;
}

.buttons-container {
    -webkit-overflow-scrolling: touch;
}

.settings-body {
    -webkit-overflow-scrolling: touch;
}

/* Prevent text selection on buttons for better mobile experience */
.comm-btn,
.phrase-btn,
.control-btn,
.tab-btn {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

/* Mobile-specific focus styles */
@media (max-width: 768px) {
    .comm-btn:focus,
    .phrase-btn:focus,
    .control-btn:focus,
    .tab-btn:focus {
        outline: 2px solid #FFD700;
        outline-offset: 1px;
    }
}

/* Safe area support for notched devices */
@supports (padding: max(0px)) {
    .app-container {
        padding-left: max(0px, env(safe-area-inset-left));
        padding-right: max(0px, env(safe-area-inset-right));
    }
    
    .app-header {
        padding-top: max(10px, env(safe-area-inset-top));
    }
    
    .quick-phrases {
        padding-bottom: max(15px, env(safe-area-inset-bottom));
    }
}

/* Mobile-optimized animations */
@media (max-width: 768px) {
    /* Disable expensive animations on mobile for better performance */
    .reduced-motion-mobile *,
    .reduced-motion-mobile *::before,
    .reduced-motion-mobile *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.1s !important;
    }
    
    /* Optimized button press animation for mobile */
    .comm-btn:active,
    .phrase-btn:active {
        transform: scale(0.95);
        transition: transform 0.1s ease-out;
    }
    
    /* Smooth scrolling for category tabs */
    .category-tabs {
        scroll-behavior: smooth;
    }
    
    /* Optimize tab switching animation */
    .tab-btn.active {
        transition: all 0.2s ease-out;
    }
    
    /* Quick feedback for touch interactions */
    .comm-btn:focus,
    .phrase-btn:focus {
        background: linear-gradient(135deg, #667eea, #764ba2);
        outline: 2px solid rgba(255, 215, 0, 0.8);
        outline-offset: 1px;
    }
}

/* Mobile-specific utility classes */
.mobile-hidden {
    display: none !important;
}

@media (max-width: 768px) {
    .mobile-visible {
        display: block !important;
    }
    
    .desktop-only {
        display: none !important;
    }
}

@media (min-width: 769px) {
    .mobile-only {
        display: none !important;
    }
    
    .desktop-visible {
        display: block !important;
    }
}

/* Mobile keyboard support */
@media (max-width: 768px) {
    /* Adjust layout when virtual keyboard is open */
    .keyboard-open .app-container {
        height: 100vh;
        overflow: hidden;
    }
    
    .keyboard-open .buttons-container {
        max-height: 40vh;
        overflow-y: auto;
    }
    
    .keyboard-open .quick-phrases {
        display: none;
    }
}

/* Performance optimizations for mobile */
@media (max-width: 768px) {
    /* Use hardware acceleration for animations */
    .comm-btn,
    .phrase-btn,
    .control-btn,
    .tab-btn {
        will-change: transform;
        transform: translateZ(0);
    }
    
    /* Optimize repaints */
    .buttons-grid {
        contain: layout style paint;
    }
    
    .category-tabs {
        contain: layout style;
    }
}

.setting-select {
    width: 100%;
    padding: 8px 12px;
    margin: 10px 0;
    border: 2px solid #ddd;
    border-radius: 8px;
    background: white;
    font-size: 1rem;
    color: #333;
    cursor: pointer;
    transition: border-color 0.3s ease;
}

.setting-select:focus {
    outline: none;
    border-color: #4CAF50;
    box-shadow: 0 0 0 3px rgba(76, 175, 80, 0.2);
}

.setting-select option {
    padding: 8px;
    background: white;
    color: #333;
}

.setting-checkbox {
    margin-right: 12px;
    transform: scale(1.2);
}

/* Mobile styles for select dropdown */
@media (max-width: 768px) {
    .setting-select {
        padding: 10px 12px;
        font-size: 0.9rem;
    }
}

@media (max-width: 480px) {
    .setting-select {
        padding: 8px 10px;
        font-size: 0.85rem;
    }
}

.setting-text {
    font-size: 1rem;
    color: #333;
    margin-bottom: 5px;
    display: block;
}

.setting-description {
    font-size: 0.9rem;
    color: #666;
    font-weight: normal;
    display: block;
    margin-top: 5px;
    line-height: 1.4;
}

.setting-range {
    width: 100%;
    margin: 10px 0;
    height: 6px;
    border-radius: 3px;
    background: #ddd;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

.setting-range::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #4CAF50;
    cursor: pointer;
    border: 2px solid white;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

.setting-range::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #4CAF50;
    cursor: pointer;
    border: 2px solid white;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

.setting-value {
    display: inline-block;
    background: #4CAF50;
    color: white;
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 600;
    min-width: 40px;
    text-align: center;
    margin-left: 10px;
}

.settings-footer {
    background: #f8f9fa;
    padding: 20px;
    border-top: 1px solid #e9ecef;
    display: flex;
    justify-content: space-between;
    gap: 15px;
}

.reset-btn, .apply-btn {
    padding: 12px 20px;
    border: none;
    border-radius: 25px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    flex: 1;
}

.reset-btn {
    background: #f44336;
    color: white;
}

.reset-btn:hover {
    background: #d32f2f;
    transform: translateY(-2px);
}

.apply-btn {
    background: #4CAF50;
    color: white;
}

.apply-btn:hover {
    background: #45a049;
    transform: translateY(-2px);
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Settings modal responsive */
@media (max-width: 768px) {
    .settings-content {
        width: 95%;
        margin: 1vh auto;
        max-height: 95vh;
        border-radius: 15px;
    }
    
    .settings-header {
        padding: 15px;
    }
    
    .settings-header h2 {
        font-size: 1.2rem;
    }
    
    .settings-body {
        padding: 15px;
    }
    
    .setting-item {
        padding: 12px;
        margin-bottom: 15px;
    }
    
    .setting-text {
        font-size: 0.9rem;
    }
    
    .setting-description {
        font-size: 0.8rem;
    }
    
    .settings-footer {
        padding: 15px;
        flex-direction: column;
        gap: 10px;
    }
    
    .reset-btn, .apply-btn {
        margin-bottom: 0;
        padding: 14px 20px;
        font-size: 0.9rem;
    }
}

@media (max-width: 480px) {
    .settings-content {
        width: 98%;
        margin: 0.5vh auto;
        max-height: 98vh;
        border-radius: 10px;
    }
    
    .settings-header {
        padding: 12px;
    }
    
    .settings-header h2 {
        font-size: 1.1rem;
    }
    
    .close-btn {
        width: 35px;
        height: 35px;
        font-size: 1.5rem;
    }
    
    .settings-body {
        padding: 12px;
    }
    
    .setting-item {
        padding: 10px;
        margin-bottom: 12px;
    }
    
    .setting-text {
        font-size: 0.85rem;
    }
    
    .setting-description {
        font-size: 0.75rem;
    }
    
    .settings-section h3 {
        font-size: 1rem;
        margin-bottom: 12px;
    }
    
    .settings-footer {
        padding: 12px;
    }
    
    .reset-btn, .apply-btn {
        padding: 12px 16px;
        font-size: 0.85rem;
    }
}

/* Compact control buttons override */
.control-btn {
    padding: 10px 16px !important;
    border-radius: 20px !important;
    font-size: 1.1rem !important;
    min-width: 100px !important;
    gap: 6px !important;
}

/* Hide Clear and Speak buttons in speak mode */
.speak-mode #clearBtn,
.speak-mode #speakBtn {
    display: none !important;
}

/* Show only Settings button in speak mode */
.speak-mode .header-controls {
    gap: 8px;
}

/* Speak mode indicator styles */
.speak-mode .mode-toggle {
    order: -1;
}

/* Device info styling */
.user-info .user-email {
    font-size: 0.8em;
    color: rgba(255, 255, 255, 0.8);
    margin-right: 10px;
}

@media (max-width: 768px) {
    .user-info .user-email {
        font-size: 0.7em;
        margin-right: 5px;
    }
    
    .save-btn.unsaved,
    .save-btn.saved {
        font-size: 0.9em;
        padding: 6px 12px !important;
    }
}
