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

:root {
    /* Light mode colors */
    --bg-primary: #f5f5f5;
    --bg-secondary: white;
    --bg-tertiary: #f8f9fa;
    --bg-header: #2c3e50;
    --bg-pane-header: #34495e;
    --text-primary: #333;
    --text-secondary: #666;
    --text-header: white;
    --border-color: #e0e0e0;
    --border-color-dark: #d0d0d0;
    --code-bg: #f4f4f4;
    --code-block-bg: #2d2d2d;
    --code-text: #e83e8c;
    --shadow: rgba(0,0,0,0.1);
}

body.dark-mode {
    /* Dark mode colors */
    --bg-primary: #1a1a1a;
    --bg-secondary: #2d2d2d;
    --bg-tertiary: #252525;
    --bg-header: #1a1a1a;
    --bg-pane-header: #252525;
    --text-primary: #e0e0e0;
    --text-secondary: #b0b0b0;
    --text-header: #e0e0e0;
    --border-color: #404040;
    --border-color-dark: #505050;
    --code-bg: #3a3a3a;
    --code-block-bg: #1e1e1e;
    --code-text: #ff6b9d;
    --shadow: rgba(0,0,0,0.3);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
    transition: background-color 0.3s, color 0.3s;
}

/* Smooth scrolling */
* {
    scroll-behavior: smooth;
}

/* Better focus states for accessibility */
button:focus-visible,
textarea:focus-visible {
    outline: 2px solid #3498db;
    outline-offset: 2px;
}

.container {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

header {
    background-color: var(--bg-header);
    color: var(--text-header);
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 4px var(--shadow);
}

header h1 {
    font-size: 1.5rem;
    font-weight: 600;
}

.header-info {
    display: flex;
    gap: 1rem;
    align-items: center;
}

.theme-toggle {
    padding: 0.5rem;
    background-color: rgba(255, 255, 255, 0.1);
    color: var(--text-header);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.2rem;
    transition: all 0.3s;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.theme-toggle:hover {
    background-color: rgba(255, 255, 255, 0.2);
    transform: rotate(20deg);
}

.theme-toggle:active {
    transform: rotate(20deg) scale(0.95);
}

.export-buttons {
    display: flex;
    gap: 0.5rem;
}

.export-btn {
    padding: 0.4rem 0.75rem;
    background-color: #3498db;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s;
    font-weight: 500;
}

.export-btn:hover {
    background-color: #2980b9;
    transform: translateY(-1px);
}

.export-btn:active {
    background-color: #21618c;
    transform: translateY(0);
}

.export-btn.success {
    background-color: #27ae60;
}

.autosave-status {
    font-size: 0.85rem;
    opacity: 0.8;
    padding: 0.3rem 0.6rem;
    background-color: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    transition: all 0.3s;
}

.autosave-status.saving {
    opacity: 1;
    background-color: rgba(52, 152, 219, 0.2);
}

.autosave-status.saved {
    opacity: 1;
    background-color: rgba(39, 174, 96, 0.2);
}

.word-count {
    font-size: 0.9rem;
    opacity: 0.9;
}

.editor-container {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.editor-pane,
.preview-pane {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: var(--bg-secondary);
    overflow: hidden;
}

.editor-pane {
    border-right: 2px solid var(--border-color);
}

.pane-header {
    background-color: var(--bg-pane-header);
    color: var(--text-header);
    padding: 0.75rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.pane-header h2 {
    font-size: 1rem;
    font-weight: 500;
}

/* Toolbar styles */
.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    padding: 0.75rem 1rem;
    background-color: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
    align-items: center;
}

.toolbar-btn {
    padding: 0.4rem 0.75rem;
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color-dark);
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.875rem;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    height: 32px;
    color: var(--text-primary);
}

.toolbar-btn:hover {
    background-color: var(--bg-tertiary);
    border-color: var(--border-color-dark);
}

.toolbar-btn:active {
    transform: translateY(1px);
}

.toolbar-btn.active {
    background-color: #3498db;
    color: white;
    border-color: #2980b9;
}

.toolbar-btn.active:hover {
    background-color: #2980b9;
}

.toolbar-divider {
    width: 1px;
    height: 24px;
    background-color: var(--border-color-dark);
    margin: 0 0.25rem;
}

/* Toolbar Tooltip */
.toolbar-tooltip {
    position: fixed;
    background-color: var(--bg-secondary);
    border: 2px solid #3498db;
    border-radius: 8px;
    padding: 0.75rem;
    box-shadow: 0 4px 12px var(--shadow);
    z-index: 1000;
    min-width: 200px;
    max-width: 300px;
    pointer-events: none;
    transition: opacity 0.2s, transform 0.2s;
}

.toolbar-tooltip.hidden {
    opacity: 0;
    transform: translateY(-5px);
    display: none;
}

.toolbar-tooltip .tooltip-markdown {
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.85rem;
    background-color: var(--code-bg);
    padding: 0.5rem;
    border-radius: 4px;
    margin-bottom: 0.5rem;
    color: var(--code-text);
    border: 1px solid var(--border-color);
}

.toolbar-tooltip .tooltip-arrow {
    position: absolute;
    top: -6px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-bottom: 6px solid #3498db;
}

.toolbar-tooltip .tooltip-preview {
    font-size: 0.85rem;
    color: var(--text-primary);
    padding: 0.25rem 0;
}

.toolbar-tooltip .tooltip-preview strong {
    font-weight: 600;
}

.toolbar-tooltip .tooltip-preview em {
    font-style: italic;
}

.toolbar-tooltip .tooltip-preview s {
    text-decoration: line-through;
}

.toolbar-tooltip .tooltip-preview code {
    background-color: var(--code-bg);
    padding: 0.2rem 0.4rem;
    border-radius: 3px;
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.9em;
}

/* Cheat Sheet Panel */
.cheatsheet-panel {
    background-color: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
    max-height: 300px;
    overflow-y: auto;
    transition: all 0.3s ease;
}

.cheatsheet-panel.hidden {
    max-height: 0;
    overflow: hidden;
    border-bottom: none;
}

.cheatsheet-content {
    padding: 1rem 1.5rem;
}

.cheatsheet-content h3 {
    margin: 0 0 1rem 0;
    font-size: 1.1rem;
    color: var(--text-primary);
}

.cheatsheet-section {
    margin-bottom: 1rem;
}

.cheatsheet-section h4 {
    margin: 0 0 0.5rem 0;
    font-size: 0.9rem;
    color: var(--text-primary);
    font-weight: 600;
}

.cheatsheet-section code {
    display: inline-block;
    background-color: var(--bg-secondary);
    padding: 0.3rem 0.6rem;
    margin: 0.2rem 0.3rem 0.2rem 0;
    border-radius: 3px;
    font-size: 0.85rem;
    border: 1px solid var(--border-color);
    font-family: 'Courier New', Courier, monospace;
    line-height: 1.4;
    color: var(--text-primary);
}

.cheatsheet-section strong {
    display: inline-block;
    background-color: #3498db;
    color: white;
    padding: 0.2rem 0.5rem;
    margin: 0.2rem 0.3rem 0.2rem 0;
    border-radius: 3px;
    font-size: 0.85rem;
    font-weight: 600;
}

#markdown-input {
    flex: 1;
    padding: 1.5rem;
    border: none;
    resize: none;
    font-family: 'Courier New', Courier, monospace;
    font-size: 14px;
    line-height: 1.6;
    outline: none;
    background-color: var(--bg-secondary);
    color: var(--text-primary);
}

#preview-output {
    flex: 1;
    padding: 1.5rem;
    overflow-y: auto;
    line-height: 1.6;
}

/* Basic markdown preview styling */
#preview-output h1 {
    font-size: 2rem;
    margin: 1rem 0;
    border-bottom: 2px solid #e0e0e0;
    padding-bottom: 0.5rem;
}

#preview-output h2 {
    font-size: 1.5rem;
    margin: 0.875rem 0;
    border-bottom: 1px solid #e0e0e0;
    padding-bottom: 0.25rem;
}

#preview-output h3 {
    font-size: 1.25rem;
    margin: 0.75rem 0;
}

#preview-output p {
    margin: 0.75rem 0;
}

#preview-output code {
    background-color: #f4f4f4;
    padding: 0.2rem 0.4rem;
    border-radius: 3px;
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.9em;
}

#preview-output pre {
    background-color: #f4f4f4;
    padding: 1rem;
    border-radius: 5px;
    overflow-x: auto;
    margin: 1rem 0;
}

#preview-output pre code {
    background-color: transparent;
    padding: 0;
}

#preview-output ul, 
#preview-output ol {
    margin: 0.75rem 0;
    padding-left: 2rem;
}

#preview-output li {
    margin: 0.25rem 0;
}

#preview-output blockquote {
    border-left: 4px solid #3498db;
    padding-left: 1rem;
    margin: 1rem 0;
    color: #666;
    font-style: italic;
}

#preview-output a {
    color: #3498db;
    text-decoration: none;
}

#preview-output a:hover {
    text-decoration: underline;
}

#preview-output img {
    max-width: 100%;
    height: auto;
    margin: 1rem 0;
}

/* Table of Contents styling */
#preview-output .toc {
    background-color: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 5px;
    padding: 1.5rem;
    margin: 1.5rem 0;
}

#preview-output .toc h2 {
    margin-top: 0;
    font-size: 1.25rem;
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 0.5rem;
}

#preview-output .toc ul {
    list-style: none;
    padding-left: 0;
}

#preview-output .toc ul ul {
    padding-left: 1.5rem;
}

#preview-output .toc li {
    margin: 0.5rem 0;
}

#preview-output .toc a {
    color: #3498db;
    text-decoration: none;
    transition: all 0.2s;
}

#preview-output .toc a:hover {
    color: #2980b9;
    text-decoration: underline;
}

#preview-output table {
    border-collapse: collapse;
    width: 100%;
    margin: 1rem 0;
}

#preview-output th,
#preview-output td {
    border: 1px solid #ddd;
    padding: 0.75rem;
    text-align: left;
}

#preview-output th {
    background-color: #f4f4f4;
    font-weight: 600;
}

/* Task lists (GitHub-flavored markdown) */
#preview-output ul {
    list-style-type: disc;
}

#preview-output input[type="checkbox"] {
    margin-right: 0.5rem;
}

#preview-output li input[type="checkbox"] {
    pointer-events: none; /* Prevent interaction in preview */
}

/* Strikethrough */
#preview-output del {
    text-decoration: line-through;
    opacity: 0.7;
}

/* Horizontal rule */
#preview-output hr {
    border: none;
    border-top: 2px solid #e0e0e0;
    margin: 2rem 0;
}

/* Enhanced code block styling */
#preview-output pre {
    background-color: var(--code-block-bg);
    padding: 1rem;
    border-radius: 5px;
    overflow-x: auto;
    margin: 1rem 0;
}

#preview-output pre code {
    background-color: transparent;
    padding: 0;
    color: #f8f8f2;
    font-size: 0.9em;
}

/* Inline code */
#preview-output code {
    background-color: var(--code-bg);
    padding: 0.2rem 0.4rem;
    border-radius: 3px;
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.9em;
    color: var(--code-text);
}

/* Better table styling */
#preview-output .markdown-table {
    border: 1px solid var(--border-color);
}

#preview-output .markdown-table th {
    background-color: var(--bg-tertiary);
    border-bottom: 2px solid var(--border-color);
}

#preview-output .markdown-table tr:nth-child(even) {
    background-color: var(--bg-tertiary);
}

#preview-output .markdown-table tr:hover {
    background-color: var(--code-bg);
}

body.dark-mode #preview-output .markdown-table tr:hover {
    background-color: #3a3a3a;
}

/* Better text selection */
::selection {
    background-color: #3498db;
    color: white;
}

body.dark-mode ::selection {
    background-color: #2980b9;
    color: white;
}

/* Responsive design */
@media (max-width: 768px) {
    .editor-container {
        flex-direction: column;
    }

    .editor-pane {
        border-right: none;
        border-bottom: 2px solid #e0e0e0;
    }

    .editor-pane,
    .preview-pane {
        min-height: 50vh;
    }

    header {
        padding: 0.75rem 1rem;
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    header h1 {
        font-size: 1.25rem;
    }
    
    .header-info {
        width: 100%;
        justify-content: space-between;
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    
    .export-buttons {
        gap: 0.25rem;
    }
    
    .export-btn {
        padding: 0.3rem 0.6rem;
        font-size: 0.75rem;
    }
    
    .autosave-status {
        font-size: 0.75rem;
        padding: 0.2rem 0.4rem;
    }

    .word-count {
        font-size: 0.8rem;
    }

    .toolbar {
        padding: 0.5rem;
        gap: 0.2rem;
    }

    .toolbar-btn {
        padding: 0.3rem 0.6rem;
        font-size: 0.8rem;
        min-width: 28px;
        height: 28px;
    }
    
    .cheatsheet-panel {
        max-height: 250px;
        font-size: 0.85rem;
    }
    
    .cheatsheet-content {
        padding: 0.75rem 1rem;
    }
    
    .cheatsheet-section code {
        font-size: 0.75rem;
        padding: 0.2rem 0.4rem;
    }
}
