:root {
    --primary-color: #2196F3;
    --success-color: #4CAF50;
    --warning-color: #FFC107;
    --danger-color: #F44336;
    --purple-color: #9C27B0;
    --background: #ffffff;
    --surface: #f5f5f5;
    --text: #333333;
    --text-secondary: #666666;
    --border: #e0e0e0;
    --shadow: rgba(0, 0, 0, 0.1);
    --focus-highlight: rgba(33, 150, 243, 0.2);
    --focus-ring: rgba(33, 150, 243, 0.4);
}

[data-theme="dark"] {
    --background: #121212;
    --surface: #1e1e1e;
    --text: #ffffff;
    --text-secondary: #b0b0b0;
    --border: #333333;
    --shadow: rgba(255, 255, 255, 0.1);
    --focus-highlight: rgba(33, 150, 243, 0.3);
    --focus-ring: rgba(33, 150, 243, 0.5);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--background);
    color: var(--text);
    line-height: 1.6;
    padding-bottom: 80px;
    min-height: 100vh;
}

.app-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 1rem;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 4px var(--shadow);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1200px;
    margin: 0 auto;
}

.app-title {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text);
}

.header-controls {
    display: flex;
    gap: 0.5rem;
}

.btn {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.2s ease;
    text-decoration: none;
    outline: none;
    position: relative;
    overflow: hidden;
}

.btn:focus {
    box-shadow: 0 0 0 3px var(--focus-ring);
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 8px var(--shadow);
}

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

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-success {
    background: var(--success-color);
    color: white;
}

.btn-warning {
    background: var(--warning-color);
    color: #333;
}

.btn-danger {
    background: var(--danger-color);
    color: white;
}

.btn-secondary {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-small {
    padding: 0.25rem 0.5rem;
    font-size: 0.8rem;
}

.btn.active {
    background: var(--primary-color);
    color: white;
}

.app-main {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1rem;
}

.content-section {
    display: none;
    animation: fadeIn 0.3s ease;
}

.content-section.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.editor-container {
    background: var(--surface);
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 4px 12px var(--shadow);
}

.editor-toolbar {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    align-items: center;
}

.toolbar-group {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.focus-select {
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--background);
    color: var(--text);
    font-size: 0.9rem;
    outline: none;
}

.focus-select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px var(--focus-ring);
}

.editor-stats {
    display: flex;
    gap: 2rem;
    margin-bottom: 1rem;
    font-size: 0.9rem;
    color: var(--text-secondary);
    flex-wrap: wrap;
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.goal-container {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    align-items: center;
}

#wordGoal {
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--background);
    color: var(--text);
    font-size: 0.9rem;
    width: 150px;
    outline: none;
}

#wordGoal:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px var(--focus-ring);
}

.text-editor {
    width: 100%;
    min-height: 400px;
    border: none;
    outline: none;
    font-size: 16px;
    line-height: 1.8;
    font-family: inherit;
    background: transparent;
    color: var(--text);
    resize: vertical;
    padding: 1rem 0;
    transition: color 0.3s ease;
}

.text-editor:focus {
    outline: none;
}

.text-editor.focus-mode {
    color: var(--text-secondary);
}

.text-editor.focus-mode .focus-highlight {
    color: var(--text);
    background: var(--focus-highlight);
    padding: 0.25rem;
    border-radius: 4px;
}

.documents-container, .settings-container, .faq-container {
    background: var(--surface);
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 4px 12px var(--shadow);
}

.documents-list {
    display: grid;
    gap: 1rem;
    margin-top: 1rem;
}

.document-item {
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.document-item:hover {
    border-color: var(--primary-color);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--shadow);
}

.document-item:focus-within {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px var(--focus-ring);
}

.document-title {
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--text);
}

.document-meta {
    font-size: 0.85rem;
    color: var(--text-secondary);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.document-actions {
    display: flex;
    gap: 0.5rem;
}

.document-actions button {
    padding: 0.25rem 0.5rem;
    font-size: 0.8rem;
}

.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-secondary);
}

.empty-state i {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.settings-group {
    margin-bottom: 2rem;
}

.settings-group h3 {
    margin-bottom: 1rem;
    color: var(--text);
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.5rem;
}

.setting-item {
    margin-bottom: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.setting-item label {
    font-weight: 500;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.setting-item input, .setting-item select {
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--background);
    color: var(--text);
    font-size: 0.9rem;
    outline: none;
}

.setting-item input:focus, .setting-item select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px var(--focus-ring);
}

.setting-item input[type="checkbox"] {
    width: auto;
    margin-right: 0.5rem;
    accent-color: var(--primary-color);
}

.faq-item {
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 1rem;
    overflow: hidden;
}

.faq-question {
    width: 100%;
    background: var(--background);
    border: none;
    padding: 1rem;
    text-align: left;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 1rem;
    font-weight: 500;
    color: var(--text);
    transition: background-color 0.2s ease;
    outline: none;
}

.faq-question:hover {
    background: var(--surface);
}

.faq-question:focus {
    background: var(--surface);
    box-shadow: 0 0 0 2px var(--focus-ring);
}

.faq-question[aria-expanded="true"] .faq-icon {
    transform: rotate(45deg);
}

.faq-icon {
    font-size: 1.2rem;
    transition: transform 0.2s ease;
}

.faq-answer {
    padding: 1rem;
    background: var(--surface);
    border-top: 1px solid var(--border);
    animation: slideDown 0.3s ease;
}

.faq-answer[hidden] {
    display: none;
}

@keyframes slideDown {
    from {
        opacity: 0;
        max-height: 0;
        padding: 0 1rem;
    }
    to {
        opacity: 1;
        max-height: 200px;
        padding: 1rem;
    }
}

.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--surface);
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-around;
    padding: 0.5rem;
    z-index: 1000;
    box-shadow: 0 -2px 8px var(--shadow);
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0.5rem;
    text-decoration: none;
    color: var(--text-secondary);
    font-size: 0.8rem;
    transition: all 0.2s ease;
    border-radius: 8px;
    min-width: 60px;
    outline: none;
}

.nav-item i {
    font-size: 1.2rem;
    margin-bottom: 0.25rem;
}

.nav-item.active {
    color: var(--primary-color);
    background: rgba(33, 150, 243, 0.1);
}

.nav-item:hover {
    color: var(--primary-color);
}

.nav-item:focus {
    color: var(--primary-color);
    box-shadow: 0 0 0 2px var(--focus-ring);
}

.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 2000;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    backdrop-filter: blur(4px);
}

.modal.active {
    display: flex;
    animation: modalFadeIn 0.3s ease;
}

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

.modal-content {
    background: var(--background);
    border-radius: 12px;
    max-width: 500px;
    width: 100%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 8px 32px var(--shadow);
    animation: modalSlideIn 0.3s ease;
}

@keyframes modalSlideIn {
    from { transform: translateY(-20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.modal-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    margin: 0;
    color: var(--text);
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    outline: none;
    transition: all 0.2s ease;
}

.modal-close:hover {
    background: var(--surface);
    color: var(--text);
}

.modal-close:focus {
    background: var(--surface);
    color: var(--text);
    box-shadow: 0 0 0 2px var(--focus-ring);
}

.modal-body {
    padding: 1.5rem;
}

.export-options {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.export-btn {
    justify-content: flex-start;
    padding: 1rem;
    font-size: 1rem;
}

.modal-documents-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-height: 300px;
    overflow-y: auto;
}

.modal-document-item {
    padding: 1rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    background: var(--surface);
    outline: none;
}

.modal-document-item:hover {
    border-color: var(--primary-color);
    background: var(--background);
}

.modal-document-item:focus {
    border-color: var(--primary-color);
    background: var(--background);
    box-shadow: 0 0 0 2px var(--focus-ring);
}

footer {
    text-align: center;
    padding: 2rem 1rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
    border-top: 1px solid var(--border);
    margin-top: 2rem;
}

/* Font styles */
.font-system {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.font-serif {
    font-family: Georgia, 'Times New Roman', Times, serif;
}

.font-mono {
    font-family: 'Courier New', Courier, monospace;
}

/* Focus highlight overlay */
.focus-highlight-overlay {
    pointer-events: none;
    z-index: 1;
}

/* Notification styles */
#notification {
    position: fixed;
    top: 20px;
    right: 20px;
    background: var(--primary-color);
    color: white;
    padding: 1rem 1.5rem;
    border-radius: 8px;
    box-shadow: 0 4px 12px var(--shadow);
    z-index: 9999;
    transform: translateX(400px);
    transition: transform 0.3s ease;
    max-width: 300px;
    font-size: 0.9rem;
    word-wrap: break-word;
}

/* Responsive */
@media (max-width: 768px) {
    .app-main {
        padding: 0.5rem;
    }
    
    .editor-container, .documents-container, .settings-container, .faq-container {
        padding: 1rem;
    }
    
    .editor-toolbar {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
    }
    
    .toolbar-group {
        justify-content: center;
        flex-wrap: wrap;
    }
    
    .editor-stats {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .goal-container {
        flex-direction: column;
        align-items: stretch;
    }
    
    #wordGoal {
        width: 100%;
    }
    
    .text-editor {
        min-height: 300px;
        font-size: 16px;
    }
    
    .setting-item {
        flex-direction: column;
    }
    
    .modal-content {
        margin: 1rem;
        max-height: calc(100vh - 2rem);
    }
    
    .document-meta {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }
    
    .document-actions {
        width: 100%;
        justify-content: flex-end;
    }
}

@media (max-width: 480px) {
    .header-content {
        flex-direction: column;
        gap: 1rem;
    }
    
    .app-title {
        font-size: 1.25rem;
    }
    
    .bottom-nav {
        padding: 0.25rem;
    }
    
    .nav-item {
        font-size: 0.7rem;
        padding: 0.25rem;
        min-width: 50px;
    }
    
    .nav-item i {
        font-size: 1rem;
    }
    
    .btn {
        padding: 0.4rem 0.8rem;
        font-size: 0.8rem;
    }
    
    .modal {
        padding: 0.5rem;
    }
    
    .modal-content {
        margin: 0.5rem;
    }
    
    .modal-header, .modal-body {
        padding: 1rem;
    }
}

/* Print styles */
@media print {
    .app-header, .bottom-nav, .editor-toolbar, .editor-stats, .goal-container {
        display: none;
    }
    
    .text-editor {
        border: none;
        box-shadow: none;
        background: white;
        color: black;
        min-height: auto;
    }
    
    body {
        background: white;
        color: black;
        padding: 0;
    }
    
    .app-main {
        padding: 0;
        max-width: none;
    }
    
    .editor-container {
        background: white;
        box-shadow: none;
        padding: 0;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    :root {
        --border: #000000;
        --shadow: rgba(0, 0, 0, 0.3);
    }
    
    [data-theme="dark"] {
        --border: #ffffff;
        --shadow: rgba(255, 255, 255, 0.3);
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
