:root {
    --bg: #f7f4ef;
    --bg-subtle: #efe9e0;
    --text: #2c2825;
    --text-muted: #8c857a;
    --accent: #c9654e;
    --accent-soft: #e8b4a4;
    --border: #d8d2c8;
    --shadow: rgba(44, 40, 37, 0.08);
    --selection: #fde68a;
}

[data-theme="dark"] {
    --bg: #0f0f0f;
    --bg-subtle: #1a1a1a;
    --text: #ebebeb;
    --text-muted: #737373;
    --accent: #ff6b4a;
    --accent-soft: #2a2a2a;
    --border: #2a2a2a;
    --shadow: rgba(0, 0, 0, 0.5);
    --selection: #ff6b4a33;
}

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

html {
    font-size: 18px;
    height: 100%;
}

body {
    font-family: 'IBM Plex Mono', 'SF Mono', 'Menlo', monospace;
    background: var(--bg);
    color: var(--text);
    min-height: 100%;
    display: flex;
    flex-direction: column;
    line-height: 1.7;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
    opacity: 0.025;
    pointer-events: none;
    z-index: 0;
}

::selection {
    background: var(--selection);
    color: var(--text);
}

#editor {
    flex: 1;
    display: flex;
    flex-direction: column;
    max-width: 90ch;
    width: 100%;
    margin: 0 auto;
    padding: 4rem 2rem;
    position: relative;
    z-index: 1;
}

#content {
    flex: 1;
    width: 100%;
    min-height: calc(100vh - 8rem);
    padding: 0;
    background: transparent;
    border: none;
    outline: none;
    resize: none;
    font-family: inherit;
    font-size: 1rem;
    line-height: 1.8;
    color: var(--text);
    caret-color: var(--accent);
}

#content::placeholder {
    color: var(--text-muted);
    opacity: 0.6;
}

#content::-webkit-scrollbar {
    width: 8px;
}

#content::-webkit-scrollbar-track {
    background: transparent;
}

#content::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

#content::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

.status {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--bg-subtle);
    border: 1px solid var(--border);
    padding: 0.5rem 1.25rem;
    border-radius: 100px;
    font-size: 0.75rem;
    color: var(--text-muted);
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
    box-shadow: 0 4px 20px var(--shadow);
    z-index: 100;
}

.status.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.help-btn {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-subtle);
    border: 1px solid var(--border);
    border-radius: 50%;
    color: var(--text-muted);
    font-family: 'Newsreader', Georgia, serif;
    font-size: 1rem;
    font-style: italic;
    cursor: pointer;
    transition: all 0.2s ease;
    z-index: 100;
}

.help-btn:hover {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
    transform: scale(1.05);
}

.theme-btn {
    position: fixed;
    bottom: 2rem;
    right: 5rem;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-subtle);
    border: 1px solid var(--border);
    border-radius: 50%;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s ease;
    z-index: 100;
}

.theme-btn:hover {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
    transform: scale(1.05);
}

.theme-btn .sun-icon {
    display: none;
}

.theme-btn .moon-icon {
    display: block;
}

[data-theme="dark"] .theme-btn .sun-icon {
    display: block;
}

[data-theme="dark"] .theme-btn .moon-icon {
    display: none;
}

.help-panel {
    position: fixed;
    bottom: 5rem;
    right: 2rem;
    width: 320px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 10px 40px var(--shadow);
    z-index: 99;
    animation: slideUp 0.2s ease;
}

.help-panel.hidden {
    display: none;
}

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

.help-panel h3 {
    font-family: 'Newsreader', Georgia, serif;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text);
    margin-bottom: 0.75rem;
    letter-spacing: 0.02em;
}

.help-panel h3:not(:first-child) {
    margin-top: 1.25rem;
}

.help-panel ul {
    list-style: none;
}

.help-panel li {
    font-size: 0.75rem;
    color: var(--text-muted);
    padding: 0.35rem 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.help-panel kbd {
    display: inline-block;
    background: var(--bg-subtle);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.15rem 0.4rem;
    font-family: inherit;
    font-size: 0.65rem;
    color: var(--text);
}

.help-panel code {
    background: var(--bg-subtle);
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
    font-family: inherit;
    font-size: 0.7rem;
    color: var(--accent);
    white-space: nowrap;
}

.modal {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal.hidden {
    display: none;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
}

.modal-content {
    position: relative;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 2rem;
    text-align: center;
    box-shadow: 0 20px 60px var(--shadow);
    animation: scaleIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.modal-content h2 {
    font-family: 'Newsreader', Georgia, serif;
    font-size: 1.25rem;
    font-weight: 400;
    margin-bottom: 1.5rem;
    color: var(--text);
}

.modal-content .close-btn {
    position: absolute;
    top: 1rem;
    right: 1rem;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    border-radius: 50%;
    transition: all 0.2s ease;
}

.modal-content .close-btn:hover {
    background: var(--bg-subtle);
    color: var(--accent);
}

#qrCanvas {
    display: block;
    margin: 0 auto;
    border-radius: 8px;
    box-shadow: 0 4px 20px var(--shadow);
}

.qr-hint {
    margin-top: 1.25rem;
    font-size: 0.8rem;
    color: var(--text-muted);
}

@media (max-width: 640px) {
    html {
        font-size: 16px;
    }
    
    #editor {
        padding: 2rem 1.25rem;
    }
    
    #content {
        min-height: calc(100vh - 4rem);
    }
    
    .help-btn {
        bottom: 1.5rem;
        right: 1.5rem;
    }
    
    .theme-btn {
        bottom: 1.5rem;
        right: 4.5rem;
    }
    
    .help-panel {
        bottom: 4.5rem;
        right: 1rem;
        left: 1rem;
        width: auto;
    }
    
    .status {
        bottom: 1.5rem;
    }
}

@media print {
    body::before,
    .status,
    .help-btn,
    .help-panel,
    .modal {
        display: none !important;
    }
    
    #editor {
        padding: 0;
        max-width: 100%;
    }
    
    #content {
        min-height: auto;
    }
}

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

@media (prefers-reduced-motion: no-preference) {
    html {
        scroll-behavior: smooth;
    }
}

@media (prefers-contrast: high) {
    :root {
        --border: var(--text-muted);
    }
}
