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

:root {
    --primary-color: #007AFF;
    --bg-color: #000000;
    --sidebar-bg: #1C1C1E;
    --text-color: #FFFFFF;
    --secondary-text: #8E8E93;
    --border-color: #38383A;
    --header-height: 44px;
    --safe-area-inset-top: env(safe-area-inset-top);
    --safe-area-inset-bottom: env(safe-area-inset-bottom);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.app-container {
    min-height: 100vh;
    padding-top: var(--safe-area-inset-top);
}

.app-header {
    position: fixed;
    top: var(--safe-area-inset-top);
    left: 0;
    right: 0;
    height: var(--header-height);
    background-color: var(--bg-color);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
    z-index: 100;
}

.hamburger-btn {
    background: none;
    border: none;
    width: 30px;
    height: 30px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    padding: 0;
}

.hamburger-btn span {
    width: 18px;
    height: 2px;
    background-color: var(--text-color);
    margin: 2px 0;
    transition: all 0.3s ease;
    border-radius: 1px;
}

.hamburger-btn.active span:nth-child(1) {
    transform: rotate(45deg) translate(4px, 4px);
}

.hamburger-btn.active span:nth-child(2) {
    opacity: 0;
}

.hamburger-btn.active span:nth-child(3) {
    transform: rotate(-45deg) translate(4px, -4px);
}

.note-title {
    font-size: 17px;
    font-weight: 600;
    flex: 1;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 0 10px;
}

.edit-btn {
    background: none;
    border: none;
    color: var(--primary-color);
    font-size: 17px;
    font-weight: 400;
    cursor: pointer;
    padding: 5px;
}

.sidebar {
    position: fixed;
    top: 0;
    left: -280px;
    width: 280px;
    height: 100vh;
    background-color: var(--sidebar-bg);
    transition: left 0.3s ease;
    z-index: 200;
    padding-top: var(--safe-area-inset-top);
}

.sidebar.active {
    left: 0;
}

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

.sidebar-header h2 {
    font-size: 22px;
    font-weight: 700;
}

.new-note-btn {
    background: none;
    border: none;
    color: var(--primary-color);
    font-size: 24px;
    cursor: pointer;
    padding: 0;
}

.notes-list {
    overflow-y: auto;
    height: calc(100vh - 80px - var(--safe-area-inset-top));
}

.note-item {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: background-color 0.2s;
}

.note-item:active {
    background-color: rgba(0, 0, 0, 0.05);
}

.note-item.active {
    background-color: rgba(0, 122, 255, 0.1);
}

.note-item-title {
    font-size: 16px;
    font-weight: 500;
    margin-bottom: 4px;
}

.note-item-preview {
    font-size: 14px;
    color: var(--secondary-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.note-item-date {
    font-size: 12px;
    color: var(--secondary-text);
    margin-top: 4px;
}

.overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.3);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
    z-index: 150;
}

.overlay.active {
    opacity: 1;
    visibility: visible;
}

.content-area {
    padding: calc(var(--header-height) + 16px) 16px 16px;
    padding-top: calc(var(--header-height) + var(--safe-area-inset-top) + 16px);
    padding-bottom: calc(16px + var(--safe-area-inset-bottom));
    min-height: 100vh;
    overflow-y: auto; /* Allow scroll if needed but try to avoid it */
}

.note-display {
    line-height: 1.4; /* Reduced from 1.8 for tighter spacing */
    width: 100%;
    /* No transition to prevent flicker */
}

.note-display h1, .note-display h2, .note-display h3,
.note-display h4, .note-display h5, .note-display h6 {
    margin-top: 20px;
    margin-bottom: 10px;
}

.note-display h1:first-child {
    margin-top: 0;
}

.note-display p {
    margin-bottom: 16px;
}

.note-display ul, .note-display ol {
    margin-left: 20px;
    margin-bottom: 16px;
}

.note-display blockquote {
    border-left: 4px solid var(--border-color);
    padding-left: 16px;
    margin: 16px 0;
    color: var(--secondary-text);
}

.note-display code {
    background-color: #1C1C1E;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'SF Mono', Monaco, 'Courier New', monospace;
    font-size: 14px;
}

.note-display pre {
    background-color: #1C1C1E;
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin-bottom: 16px;
}

.note-display pre code {
    background: none;
    padding: 0;
}

.note-display img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
}

.note-display a {
    color: var(--primary-color);
    text-decoration: none;
}

.note-display a:hover {
    text-decoration: underline;
}

.note-editor {
    display: flex;
    flex-direction: column;
    height: calc(100vh - var(--header-height) - var(--safe-area-inset-top) - 32px);
}

.note-editor.hidden {
    display: none;
}

.title-editor {
    font-size: 22px;
    font-weight: 700;
    border: none;
    border-bottom: 1px solid var(--border-color);
    padding: 12px 0;
    margin-bottom: 16px;
    outline: none;
    background: transparent;
    font-family: inherit;
}

.content-editor {
    flex: 1;
    font-size: 16px;
    line-height: 1.6;
    border: none;
    resize: none;
    outline: none;
    background: transparent;
    font-family: 'SF Mono', Monaco, 'Courier New', monospace;
}

.delete-note-btn {
    background-color: #FF3B30;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    margin-top: 8px;
    width: 100%;
}

@media (min-width: 768px) {
    .sidebar {
        width: 320px;
        left: -320px;
    }

    .content-area {
        max-width: 800px;
        margin: 0 auto;
    }
}

/* Dark mode is now the default, no media query needed */
.title-editor,
.content-editor {
    color: var(--text-color);
}