/* Base styles */
html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

html,
body {
    max-width: 100%;
    overflow-x: hidden;
}

body {
    font-family: 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

/* Per-note typography. The note page sets data-font on its container. */
[data-font] {
    min-width: 0;
    max-width: 100%;
}
[data-font="ibm-plex"] {
    font-family: 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

[data-font="source-sans-3"] {
    font-family: 'Source Sans 3', 'Source Sans Pro', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

[data-font="newsreader"] {
    font-family: 'Newsreader', Georgia, 'Times New Roman', serif;
}

[data-font="source-serif-4"] {
    font-family: 'Source Serif 4', 'Source Serif Pro', Georgia, 'Times New Roman', serif;
}

[data-font="eb-garamond"] {
    font-family: 'EB Garamond', Garamond, Georgia, serif;
}

/* Markdown content styles */
.markdown-content h1 {
    font-size: 2em;
    font-weight: bold;
    margin: 1em 0;
}

.markdown-content h2 {
    font-size: 1.5em;
    font-weight: bold;
    margin: 0.83em 0;
}

.markdown-content h3 {
    font-size: 1.17em;
    font-weight: bold;
    margin: 1em 0;
}

.markdown-content h4 {
    font-size: 1em;
    font-weight: bold;
    margin: 1em 0;
}

.markdown-content p {
    margin: 1em 0;
}

.markdown-content pre {
    background-color: #f5f5f5;
    padding: 1em;
    border-radius: 0.5em;
    overflow-x: auto;
}

/* Code stays monospace regardless of the note's chosen reading font */
.markdown-content code,
.markdown-content pre {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, 'Liberation Mono', monospace;
}

.markdown-content a {
    color: #000;
    text-decoration: underline;
}

.markdown-content img {
    max-width: 100%;
    height: auto;
}

.markdown-content blockquote {
    border-left: 4px solid #ccc;
    padding-left: 1em;
    margin: 1em 0;
    color: #555;
}

.markdown-content ol {
    list-style-type: decimal;
    list-style-position: outside;
    margin-left: 0;
    padding-left: 3em;
}

.markdown-content ul {
    list-style-type: disc;
    list-style-position: outside;
    margin-left: 0;
    padding-left: 2em;
}

.markdown-content li {
    margin: 0.5em 0;
}

.markdown-content strong {
    font-weight: bold;
}

.markdown-content em {
    font-style: italic;
}

.markdown-content del {
    text-decoration: line-through;
}

.markdown-content hr {
    border: 0;
    border-top: 1px solid #ccc;
    margin: 1.5em 0;
}

.markdown-content table {
    border-collapse: collapse;
    width: 100%;
    margin: 1em 0;
}

.markdown-content th,
.markdown-content td {
    border: 1px solid #ccc;
    padding: 0.5em;
}

/* ---------------------------------------------------------------------------
   Long words, pasted URLs, links and media must never widen the page.
   Everything wraps inside the reading column instead.
   --------------------------------------------------------------------------- */

.markdown-content {
    min-width: 0;
    max-width: 100%;
    overflow-wrap: break-word;
}

.markdown-content p,
.markdown-content li,
.markdown-content blockquote,
.markdown-content h1,
.markdown-content h2,
.markdown-content h3,
.markdown-content h4,
.markdown-content h5,
.markdown-content h6,
.markdown-content th,
.markdown-content td {
    overflow-wrap: break-word;
}

/* URLs have no natural break points, so allow them to split anywhere. */
.markdown-content a,
.markdown-content a * {
    overflow-wrap: anywhere;
}

/* The note title/byline sit outside .markdown-content. */
[data-font] header,
[data-font] header h1,
[data-font] header a,
[data-font] header span,
[data-font-preview-pane] header,
[data-font-preview-pane] header h1,
[data-font-preview-pane] header a,
[data-font-preview-pane] header span {
    min-width: 0;
    overflow-wrap: anywhere;
}

/* Inline code can contain one very long token; let it break when needed. */
.markdown-content :not(pre) > code {
    overflow-wrap: anywhere;
}

.markdown-content img,
.markdown-content iframe,
.markdown-content video {
    max-width: 100%;
}

.markdown-content img,
.markdown-content video {
    height: auto;
}

.markdown-content iframe {
    width: 100%;
    height: auto;
    aspect-ratio: 16 / 9;
    border: 0;
}

/* ---------------------------------------------------------------------------
   Small screens: wrap code and tables too, so a note never needs sideways
   scrolling just to read it.
   --------------------------------------------------------------------------- */

@media (max-width: 640px) {
    .markdown-content pre {
        white-space: pre-wrap;
        overflow-x: hidden;
        overflow-wrap: anywhere;
        word-break: break-word;
    }

    .markdown-content pre code {
        white-space: pre-wrap;
        overflow-wrap: anywhere;
    }

    .markdown-content :not(pre) > code {
        white-space: pre-wrap;
    }

    .markdown-content table {
        table-layout: fixed;
    }

    .markdown-content th,
    .markdown-content td {
        overflow-wrap: anywhere;
    }
}

/* ---------------------------------------------------------------------------
   Dark mode
   --------------------------------------------------------------------------- */

:root {
    --na-panel-bg: #f7f7f7;
    --na-list-bg: #f7f7f7;
    --na-card-bg: #ffffff;
    --na-text: #333333;
    --na-body-text: #444444;
    --na-meta: #999999;
    --na-action: #666666;
    --na-icon: #aaaaaa;
    --na-reply-text: #555555;
    --na-border: #dbdbdb;
    --na-subtle-border: #eeeeee;
    --na-input-bg: #ffffff;
    --na-input-border: #dddddd;
    --na-placeholder: #999999;
    --na-hover-bg: #f0f0f0;
    --na-empty-bg: #ffffff;
    --na-badge-bg: #eeeeee;
    --na-badge-text: #666666;
    --na-quote-bg: #f9f9f9;
    --na-quote-text: #777777;
    --na-reply-box-bg: #f9f9f9;
    --na-secondary-bg: #ffffff;
    --na-secondary-border: #dddddd;
    --na-like-hover: #fff0f0;
    --na-para-hover: rgba(0, 0, 0, 0.02);
    --na-card-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    --na-card-hover-shadow: 0 4px 8px rgba(0, 0, 0, 0.08);
    --na-avatar-border: rgba(0, 0, 0, 0.05);
    --na-sidebar-shadow-mobile: 0 -4px 20px rgba(0, 0, 0, 0.15);
    --na-sidebar-shadow-desktop: -2px 0 12px rgba(0, 0, 0, 0.05);
    --na-primary: #bd1c2b;
    --na-count-bg: #ffffff;
    --na-count-border: #e0e0e0;
    --na-count-text: #999999;
}

html.dark {
    color-scheme: dark;
    --na-panel-bg: #111111;
    --na-list-bg: #0b0b0b;
    --na-card-bg: #1a1a1a;
    --na-text: #f5f5f5;
    --na-body-text: #d4d4d4;
    --na-meta: #9ca3af;
    --na-action: #b3b3b3;
    --na-icon: #9ca3af;
    --na-reply-text: #d4d4d4;
    --na-border: #333333;
    --na-subtle-border: #2a2a2a;
    --na-input-bg: #111111;
    --na-input-border: #444444;
    --na-placeholder: #6b7280;
    --na-hover-bg: #262626;
    --na-empty-bg: #111111;
    --na-badge-bg: #262626;
    --na-badge-text: #d4d4d4;
    --na-quote-bg: #1f1f1f;
    --na-quote-text: #b3b3b3;
    --na-reply-box-bg: #202020;
    --na-secondary-bg: #1a1a1a;
    --na-secondary-border: #444444;
    --na-like-hover: rgba(189, 28, 43, 0.18);
    --na-para-hover: rgba(255, 255, 255, 0.04);
    --na-card-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
    --na-card-hover-shadow: 0 4px 8px rgba(0, 0, 0, 0.5);
    --na-avatar-border: rgba(255, 255, 255, 0.12);
    --na-sidebar-shadow-mobile: 0 -4px 20px rgba(0, 0, 0, 0.6);
    --na-sidebar-shadow-desktop: -2px 0 12px rgba(0, 0, 0, 0.5);
    --na-count-bg: #111111;
    --na-count-border: #333333;
    --na-count-text: #9ca3af;
}

.na-sidebar textarea::placeholder {
    color: var(--na-placeholder);
}

body {
    transition: background-color 0.2s ease, color 0.2s ease;
}

html.dark .markdown-content a {
    color: #fff;
}

html.dark .markdown-content pre {
    background-color: #171717;
}

html.dark .markdown-content blockquote {
    border-left-color: #444;
    color: #b3b3b3;
}

html.dark .markdown-content hr {
    border-top-color: #333;
}

html.dark .markdown-content th,
html.dark .markdown-content td {
    border-color: #333;
}

/* The theme button shows the mode it will switch to. */
[data-theme-label-light] {
    display: none;
}

html.dark [data-theme-label-dark] {
    display: none;
}

html.dark [data-theme-label-light] {
    display: inline;
}
