/* === VARIABLES & RESET === */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

@import url('https://fonts.googleapis.com/css2?family=Crimson+Pro:ital,wght@0,400;0,600;1,400&display=swap');

:root {
    --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --serif: "Crimson Pro", "Crimson Text", Georgia, serif;
    --mono: "SF Mono", Monaco, Consolas, monospace;
    --text: #0d1b33;
    --muted: #6e6e6e;
    --border: #e5e5e5;
    --bg: #fffbe9;
    --hover: #f7f7f7;
}

body[data-theme=dark] {
    --text: #fffbe9;
    --muted: #999;
    --border: #2a2a2a;
    --bg: #0d1b33;
    --hover: #252525;
}

/* === LAYOUT === */
body {
    font-family: var(--sans);
    height: 100vh;
    display: flex;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
}

body.serif #preview {
    font-family: var(--serif);
}

.container {
    display: flex;
    width: 100%;
    height: 100vh;
    animation: fadeIn .3s ease-out;
}

.editor-pane {
    width: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    min-width: 200px;
}

.divider {
    width: 1px;
    background: var(--border);
    cursor: col-resize;
    position: relative;
    transition: .2s;
}

.divider::before {
    content: '';
    position: absolute;
    left: -4px;
    right: -4px;
    top: 0;
    bottom: 0;
}

.divider:hover,
.divider.drag {
    background: var(--muted);
}

.divider.drag {
    background: var(--text);
    opacity: .3;
}

.preview-pane {
    flex: 1;
    overflow-y: scroll;
    padding: 80px 0;
    min-width: 200px;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.preview-pane::-webkit-scrollbar {
    display: none;
}

/* === COMPONENTS === */
.btn {
    position: fixed;
    width: 40px;
    height: 40px;
    border: 1.5px solid var(--border);
    background: var(--bg);
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    transition: .2s;
}

.btn:hover {
    background: var(--hover);
    transform: scale(1.05);
}

.btn svg {
    width: 20px;
    height: 20px;
    stroke: var(--text);
    fill: none;
}

#share {
    top: 24px;
    right: 74px;
}

#theme {
    top: 24px;
    right: 24px;
}

#menu {
    top: 24px;
    left: 24px;
}

.moon,
[data-theme=dark] .sun,
.close,
#menu.active .bars {
    display: none;
}

[data-theme=dark] .moon,
#menu.active .close {
    display: block;
}

.float-menu {
    position: fixed;
    top: 76px;
    left: 24px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 8px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, .08);
    opacity: 0;
    transform: translateY(-10px) scale(.95);
    pointer-events: none;
    transition: .2s;
    z-index: 999;
    width: 280px;
}

.float-menu.active {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
}

.context-menu {
    position: fixed;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 8px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, .08);
    opacity: 0;
    transform: translateY(-10px) scale(.95);
    pointer-events: none;
    transition: .2s;
    z-index: 1001;
    width: 200px;
}

.context-menu.active {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
}

.context-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 12px;
    border: none;
    background: 0;
    color: var(--text);
    font: 500 14px var(--sans);
    cursor: pointer;
    border-radius: 8px;
    transition: .15s;
    width: 100%;
    text-align: left;
}

.context-item:hover {
    background: var(--hover);
}

.context-item svg {
    width: 18px;
    height: 18px;
    stroke: var(--muted);
    flex-shrink: 0;
}

.menu-group {
    padding: 4px 0;
    border-bottom: 1px solid var(--border);
}

.menu-group:last-child {
    border-bottom: none;
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 12px;
    border: none;
    background: 0;
    color: var(--text);
    font: 500 14px var(--sans);
    cursor: pointer;
    border-radius: 8px;
    transition: .15s;
    width: 100%;
    text-align: left;
}

.menu-item:hover {
    background: var(--hover);
}

.menu-item svg {
    width: 18px;
    height: 18px;
    stroke: var(--muted);
    flex-shrink: 0;
}

.menu-label {
    color: var(--muted);
    font: 600 11px var(--sans);
    text-transform: uppercase;
    letter-spacing: .5px;
    padding: 8px 12px 4px;
}

/* === EDITOR === */
#editor {
    width: 100%;
    max-width: 680px;
    padding: 80px 40px;
    font: 400 15px/1.8 var(--mono);
    letter-spacing: -.01em;
    border: none;
    outline: none;
    resize: none;
    color: var(--text);
    background: 0;
    height: 100%;
    overflow-y: scroll;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

#editor::-webkit-scrollbar {
    display: none;
}

#editor::placeholder {
    color: var(--muted);
}

/* === PREVIEW === */
#preview {
    width: 100%;
    max-width: 680px;
    margin: 0 auto;
    padding: 0 40px;
    font: 400 16px/1.5 var(--sans);
    letter-spacing: -.011em;
}

#preview h1,
#preview h2,
#preview h3,
#preview h4,
#preview h5,
#preview h6 {
    font-weight: 600;
    letter-spacing: -.02em;
    margin: 2em 0 .5em;
}

#preview h1 {
    font-size: 2.25em;
    font-weight: 700;
    letter-spacing: -.03em;
    margin-top: 0;
}

#preview h2 {
    font-size: 1.75em;
}

#preview h3 {
    font-size: 1.375em;
}

#preview h4 {
    font-size: 1.125em;
}

#preview h5 {
    font-size: 1em;
}

#preview h6 {
    font-size: 0.875em;
}

#preview p {
    margin: 1.5em 0;
    text-align: justify;
}

#preview a {
    color: var(--text);
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 2px;
    text-decoration-color: var(--muted);
    transition: .2s;
}

#preview a:hover {
    text-decoration-color: var(--text);
}

#preview code {
    font: 87.5% var(--mono);
    background: var(--hover);
    padding: 3px 6px;
    border-radius: 4px;
}

#preview pre {
    background: #2d2d2d;
    color: #ccc;
    padding: 20px 24px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 2em 0;
    font-size: .875em;
    line-height: 1.6;
}

[data-theme=dark] #preview pre {
    background: #0d0d0d;
}

#preview pre code {
    background: 0;
    padding: 0;
    color: inherit;
    font-size: inherit;
}

#preview blockquote {
    border-left: 3px solid var(--border);
    margin: 2em 0;
    padding-left: 20px;
    color: var(--muted);
    font-style: italic;
}

#preview ul,
#preview ol {
    margin: 1.5em 0;
    padding-left: 1.5em;
}

#preview li {
    margin: .5em 0;
}

#preview hr {
    border: none;
    height: 1px;
    background: var(--border);
    margin: 3em 0;
}

#preview img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin: 2em 0;
}

#preview table {
    width: 100%;
    border-collapse: collapse;
    margin: 2em 0;
    font-size: .9375em;
}

#preview th,
#preview td {
    text-align: left;
    padding: 12px;
    border-bottom: 1px solid var(--border);
}

#preview th {
    font-weight: 600;
    font-size: .875em;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--muted);
}

/* === RESPONSIVE === */
@media (max-width: 768px) {
    .container {
        flex-direction: column;
    }
    
    .editor-pane {
        width: 100% !important;
        border-bottom: 1px solid var(--border);
    }
    
    .divider {
        display: none;
    }
    
    #editor,
    #preview {
        padding: 60px 20px 40px;
    }
    
    .preview-pane {
        padding: 60px 0 40px;
    }
    
    .btn {
        top: 16px;
    }
    
    .float-menu {
        top: 68px;
        left: 16px;
        right: 16px;
        width: auto;
    }
    
}


/* === ANIMATIONS === */
@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}