/* Newsprint-inspired stylesheet for Markdown-to-HTML content */
/* Compatible with any HTML converted from Markdown */

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

/* CSS Variables for easy theming */
:root {
    --bg-color: #f5f5dc;
    --text-color: #1f0909;
    --link-color: #065588;
    --code-bg: #dadada;
    --border-color: #c5c5c5;
    --blockquote-color: #656565;
    --blockquote-border: #bababa;
    --table-stripe: #e8e7e7;
    --table-header: #dadada;
    --max-width: 50em;
    --font-family: "PT Serif", 'Times New Roman', Times, Georgia, serif;
    --code-font: Menlo, 'Ubuntu Mono', Consolas, 'Courier New', monospace;
}

/* Reset and base styles */
*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    background-color: var(--bg-color);
    font-family: var(--font-family);
    color: var(--text-color);
    line-height: 1.6;
    margin: 0;
    padding: 2rem 1rem;
}

/* Main content container - works with article, main, or .content class */
article,
main,
.content,
.markdown-body,
#content,
#write {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0 1rem;
}

@media (min-width: 1400px) {

    article,
    main,
    .content,
    .markdown-body,
    #content,
    #write {
        max-width: 914px;
    }
}

/* Headings */
h1,
h2,
h3,
h4,
h5,
h6 {
    font-weight: bold;
    margin-top: 1.5em;
    margin-bottom: 0.75em;
    line-height: 1.3;
}

h1 {
    font-size: 1.875em;
    font-weight: normal;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.5em;
    margin-bottom: 1em;
    margin-top: 0;
}

h2 {
    font-size: 1.5em;
    margin-top: 2em;
}

h3 {
    font-size: 1.3125em;
    font-weight: normal;
}

h4 {
    font-size: 1.125em;
    margin-top: 1.5em;
}

h5,
h6 {
    font-size: 1em;
}

/* Paragraphs and text */
p {
    margin: 0 0 1.5em 0;
}

/* Links */
a {
    color: var(--link-color);
    text-decoration: none;
}

a:hover,
a:active {
    text-decoration: underline;
}

/* Lists */
ul,
ol {
    margin: 0 0 1.5em 1.5em;
    padding: 0;
}

ul li {
    list-style-type: disc;
    list-style-position: outside;
}

ol li {
    list-style-type: decimal;
    list-style-position: outside;
}

li {
    margin-bottom: 0.5em;
}

li>ul,
li>ol {
    margin-top: 0.5em;
    margin-bottom: 0;
}

li ol>li {
    list-style-type: lower-alpha;
}

li li ol>li {
    list-style-type: lower-roman;
}

/* Nested list spacing */
p+ul,
p+ol {
    margin-top: -0.5em;
}

h3+ul,
h4+ul,
h5+ul,
h6+ul,
h3+ol,
h4+ol,
h5+ol,
h6+ol {
    margin-top: 0.5em;
}

/* Blockquotes */
blockquote {
    font-style: italic;
    border-left: 5px solid var(--blockquote-border);
    margin: 0 0 1.5em 2em;
    padding: 0.5em 0 0.5em 1em;
    color: var(--blockquote-color);
}

blockquote p:last-child {
    margin-bottom: 0;
}

blockquote ul,
blockquote ol {
    margin-left: 0;
}

/* Code - inline */
code {
    background-color: var(--code-bg);
    padding: 0.15em 0.4em;
    border-radius: 3px;
    font-size: 0.875em;
    font-family: var(--code-font);
}

/* Code blocks */
pre {
    background-color: var(--code-bg);
    padding: 1em;
    margin: 0 0 1.5em 2em;
    overflow-x: auto;
    border-radius: 4px;
    font-size: 0.875em;
    line-height: 1.6;
}

pre code {
    background-color: transparent;
    padding: 0;
    border-radius: 0;
    font-size: inherit;
}

/* Tables */
table {
    border-collapse: collapse;
    border-spacing: 0;
    margin-bottom: 1.5em;
    width: 100%;
    font-size: 1em;
}

thead {
    background-color: var(--table-header);
}

thead th,
tfoot th {
    padding: 0.5em;
    text-transform: uppercase;
    text-align: left;
    font-weight: bold;
}

th {
    text-align: left;
    font-weight: bold;
}

td {
    vertical-align: top;
    padding: 0.5em;
    border-bottom: 1px solid var(--border-color);
}

tr:nth-child(even) {
    background: var(--table-stripe);
}

/* Horizontal rules */
hr {
    border: none;
    border-bottom: 1px solid var(--border-color);
    margin: 2em 0;
}

/* Images */
img {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 1em 0;
}

/* Strong and emphasis */
strong,
b {
    font-weight: bold;
}

em,
i {
    font-style: italic;
}

/* Task lists (GitHub-style) */
.task-list,
ul.contains-task-list {
    list-style: none;
    padding-left: 1rem;
}

.task-list-item,
li.task-list-item {
    list-style-type: none;
    padding-left: 1.5rem;
    position: relative;
}

.task-list-item input[type="checkbox"] {
    position: absolute;
    left: 0;
    margin-top: 0.25em;
}

/* Definition lists */
dl {
    margin: 0 0 1.5em 0;
}

dt {
    font-weight: bold;
    margin-top: 1em;
}

dd {
    margin-left: 2em;
    margin-bottom: 0.5em;
}

/* Abbreviations */
abbr[title] {
    border-bottom: 1px dotted var(--text-color);
    cursor: help;
    text-decoration: none;
}

/* Keyboard input */
kbd {
    background-color: var(--code-bg);
    border: 1px solid var(--border-color);
    border-radius: 3px;
    padding: 0.15em 0.4em;
    font-size: 0.875em;
    font-family: var(--code-font);
}

/* Mark/highlight */
mark {
    background-color: #fff176;
    padding: 0.1em 0.2em;
}

/* Subscript and superscript */
sub,
sup {
    font-size: 0.75em;
    line-height: 0;
    position: relative;
    vertical-align: baseline;
}

sup {
    top: -0.5em;
}

sub {
    bottom: -0.25em;
}

/* Details/Summary (collapsible) */
details {
    margin-bottom: 1.5em;
}

summary {
    cursor: pointer;
    font-weight: bold;
    padding: 0.5em 0;
}

details[open] summary {
    margin-bottom: 0.5em;
}

/* Footnotes (common in markdown processors) */
.footnotes {
    border-top: 1px solid var(--border-color);
    margin-top: 2em;
    padding-top: 1em;
    font-size: 0.9em;
}

.footnote-ref {
    font-size: 0.8em;
    vertical-align: super;
}

/* Print styles */
@media print {
    body {
        background-color: white;
        color: black;
        padding: 0;
    }

    article,
    main,
    .content,
    .markdown-body,
    #content,
    #write {
        max-width: none;
    }

    a {
        color: black;
        text-decoration: underline;
    }

    pre,
    code {
        background-color: #f5f5f5;
    }

    h1,
    h2,
    h3,
    h4,
    h5,
    h6 {
        page-break-after: avoid;
    }

    pre,
    blockquote,
    table {
        page-break-inside: avoid;
    }
}

/* Responsive adjustments */
@media (max-width: 768px) {
    body {
        padding: 1rem 0.5rem;
    }

    article,
    main,
    .content,
    .markdown-body,
    #content,
    #write {
        padding: 0 0.5rem;
    }

    pre {
        margin-left: 0;
        border-radius: 0;
    }

    blockquote {
        margin-left: 0;
    }
}