:root {
    --dark-bg:  #F0E4DC;
    --bg:       #FDF7F4;
    --text:     #24211D;
    --heading:  #1A2B1E;
    --link:     #A8371C;
    --accent:   #E2684A;
    --muted:    #665D54;
    --danger:   #9E1B32;
    --on-accent: #FBF3EE;
    --btn:      #A8371C;

    --font-body: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --font-heading: var(--font-body);
    --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

    --body-width: 1248px;
    --content-width: 816px;
    --radius: 6px;
    --radius-sm: 4px;
    --transition: 0.2s ease;
}
@media (prefers-color-scheme: dark) {
    :root {

        --dark-bg:  #0D140F;
        --bg:       #17241C;
        --border:   #223328;
        --text:     #E8E2DA;
        --heading:  #F4EDE6;
        --link:     #F0906F;
        --accent:   #E2684A;
        --muted:    #A79C90;
        --danger:   #F0728A;
        --btn:      #A8371C;
    }
}

*, *::before, *::after {
    box-sizing: border-box;
}

html {
    font-size: 100%;
    -webkit-text-size-adjust: 100%;
    text-rendering: optimizeLegibility;
}

body {
    background-color: var(--dark-bg);
    color: var(--text);
    line-height: 1.6;
    margin: 0;

    font-family: var(--font-body);
    font-size: 1rem;
    font-feature-settings: "kern", "liga";
}

img {
    max-width: 100%;
}

p {
    margin: 0 0 1em;
    padding: 0;
    text-wrap: pretty;
    hyphens: auto;
}

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

a {
    text-decoration: none;
    color: var(--link);
    font-weight: 500;
}

a:hover {
    text-decoration: underline;
}

strong, b { font-weight: 600; }
em, i    { font-style: italic; }

small {
    font-size: 0.875em;
    color: var(--muted);
}

/* ── Lists ───────────────────────────────────────────── */
ul, ol {
    margin: 0 0 1em;
    padding-left: 1.5em;
}

li {
    margin-bottom: 0.25em;
}

li > ul,
li > ol {
    margin: 0.25em 0 0.5em;
}

/* ── Blockquote, code, hr ───────────────────────────────────────────── */
blockquote {
    margin: 1.25em 0;
    padding: 0 0 0 1em;
    border-left: 3px solid var(--muted);
    font-style: italic;
}

code {
    font-family: var(--font-mono);
    font-size: 0.9em;
    padding: 0.1em 0.35em;
    background: var(--dark-bg);
    border-radius: 3px;
}

pre {
    margin: 1em 0;
    padding: 1em 1.25em;
    background: var(--dark-bg);
    border-radius: 6px;
    overflow-x: auto;
    line-height: 1.5;
}

pre code {
    padding: 0;
    background: none;
    font-size: 0.875em;
}


h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-heading);
    font-weight: 600;
    line-height: 1.2;
    text-wrap: balance;       /* keeps headlines from leaving orphans */
    padding: 0;
}

h1 {
    font-size: 2.25rem;
    line-height: 1.1;
    letter-spacing: -0.02em;
    margin: 0 0 0.5em;        /* no top margin: usually first in flow */
}

h2 {
    font-size: 1.75rem;
    line-height: 1.2;
    letter-spacing: -0.015em;
    margin: 1.75em 0 0.5em;
}

h3 {
    font-size: 1.35rem;
    line-height: 1.25;
    letter-spacing: -0.01em;
    margin: 1.5em 0 0.4em;
}

h4 {
    font-size: 1.125rem;
    line-height: 1.3;
    margin: 1.25em 0 0.4em;
}

h5 {
    font-size: 1rem;
    line-height: 1.4;
    margin: 1.25em 0 0.3em;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

h6 {
    font-size: 0.875rem;
    line-height: 1.4;
    margin: 1.25em 0 0.3em;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

/* When a heading immediately follows another heading, collapse the gap */
h1 + h2, h2 + h3, h3 + h4, h4 + h5, h5 + h6 {
    margin-top: 0.5em;
}
hr + h2, hr + h3, hr + h4, hr + h5, hr + h6 {
    margin-top: 0.5em;
}

/* ── Tables ───────────────────────────────────────────────── */
/* Opt-in table styling. Add class "styled-table" to a <table> to apply. */
.styled-table {
    width: 100%;
    border-collapse: collapse;
    margin: 1rem 0;
}

.styled-table th,
.styled-table td {
    padding: 0.5rem 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--muted);
}

.styled-table thead th {
    font-weight: 600;
    color: var(--heading);
    background-color: color-mix(in srgb, var(--accent) 15%, transparent);
    border-bottom: 2px solid var(--accent);
}

.styled-table tbody tr:hover {
    background-color: color-mix(in srgb, var(--muted) 15%, transparent);
}

.styled-table tbody tr:last-child td {
    border-bottom: none;
}

/* ── Details / Summary ────────────────────────────────────── */
details {
    margin: 0.75rem 0;
    border: 1px solid color-mix(in srgb, var(--muted) 35%, transparent);
    border-radius: var(--radius-sm);
    background: color-mix(in srgb, var(--muted) 6%, transparent);
    overflow: hidden;
    transition: background var(--transition);
}

details[open] > *:not(summary) {
    padding: 0.5rem 1rem 0.9rem;
}

summary {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.7rem 1rem;
    cursor: pointer;
    font-weight: 600;
    font-size: 1rem;
    user-select: none;
    list-style: none;
}

summary::-webkit-details-marker {
    display: none;
}

summary::before {
    content: "";
    width: 0.55em;
    height: 0.55em;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(-45deg);
    transition: transform var(--transition);
    margin-right: 0.1em;
}

details[open] summary::before {
    transform: rotate(45deg);
}

summary:hover {
    background: color-mix(in srgb, var(--muted) 12%, transparent);
}

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

/* ── Forms ─────────────────────────────────────────────────── */
label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 0.25rem;
}

input,
textarea,
select {
    width: 100%;
    padding: 0.5rem 0.65rem;
    font-size: 0.875rem;
    font-family: inherit;
    color: var(--text);
    background-color: var(--dark-bg);
    border: 1px solid color-mix(in srgb, var(--muted) 40%, var(--dark-bg));
    border-radius: var(--radius-sm);
    transition: border-color var(--transition);
}

input:focus,
textarea:focus,
select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 15%, transparent);
}

input[type="checkbox"] {
    width: auto;
    margin-left: 0.5rem;
    vertical-align: middle;
}

/* Inline label next to checkbox */
:has(> input[type="checkbox"]) label {
    display: inline;
}

button {
    background-color: var(--btn);
    color: var(--on-accent);
    border: none;
    padding: 0.45rem 1.25rem;
    border-radius: var(--radius);
    font-weight: 600;
    font-size: 0.875rem;
    cursor: pointer;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    transition: background-color var(--transition);
}

button:hover {
    background-color: color-mix(in srgb, var(--btn) 88%, #000);
}

button.danger {
    background-color: var(--danger);
}

/* Secondary button */
button.secondary,
.editor-control {
    background-color: transparent;
    color: var(--text);
    border: 1px solid color-mix(in srgb, var(--muted) 55%, transparent);
}

button.secondary:hover,
.editor-control:hover {
    opacity: 1;
    background-color: color-mix(in srgb, var(--muted) 14%, transparent);
    border-color: var(--accent);
}

.form-controls {
    margin-bottom: 0.75rem;
}

/* ── Asset upload ─────────────────────────────────────────── */
.asset-upload .form-controls:last-of-type {
    margin-bottom: 0.75rem;
}

.asset-upload button {
    width: 100%;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.file-picker {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.4rem 0.4rem 0.4rem 0.5rem;
    margin-bottom: 0.75rem;
    cursor: pointer;
    border: 1px solid color-mix(in srgb, var(--muted) 40%, var(--dark-bg));
    border-radius: var(--radius-sm);
    background-color: var(--dark-bg);
    transition: border-color var(--transition);
}

.file-picker:hover {
    border-color: var(--accent);
}

.file-picker:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 15%, transparent);
}

.file-picker-action {
    flex: 0 0 auto;
    margin-left: auto;
    padding: 0.3rem 0.75rem;
    font-size: 0.8rem;
    font-weight: 600;
    border-radius: var(--radius-sm);
    background-color: color-mix(in srgb, var(--muted) 18%, transparent);
}

.asset-preview-img {
    flex: 0 0 auto;
    width: 48px;
    height: 48px;
    max-width: none;
    object-fit: cover;
    border-radius: var(--radius-sm);
    border: 1px solid color-mix(in srgb, var(--muted) 25%, transparent);
}

.asset-preview-icon {
    flex: 0 0 auto;
    width: 40px;
    height: 40px;
    color: var(--muted);
}

.asset-preview-img[hidden],
.asset-preview-icon[hidden] {
    display: none;
}

.asset-preview-name {
    flex: 1 1 auto;
    min-width: 0;
    word-break: break-all;
}

/* ── Assets list ──────────────────────────────────────────── */
.asset-list {}

.asset-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0;
    border-bottom: 1px solid color-mix(in srgb, var(--muted) 25%, transparent);
}

.asset-item:last-child {
    border-bottom: none;
}

.asset-item .asset-name {
    flex: 1 1 auto;
    min-width: 0;
    word-break: break-all;
}

.asset-item .secondary {
    flex: 0 0 auto;
}

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.4rem;
    line-height: 0;
}

.icon-btn svg {
    width: 1.1rem;
    height: 1.1rem;
}

.asset-img {
    flex: 0 0 auto;
    display: block;
    width: 48px;
    height: 48px;
    max-width: none;
    object-fit: cover;
    border-radius: var(--radius-sm);
    border: 1px solid color-mix(in srgb, var(--muted) 25%, transparent);
}

.asset-upload input[type="file"] {
    padding: 0.4rem 0.5rem;
    line-height: 1.4;
}

/* ── Header ───────────────────────────────────────────────── */
#blog-title {
    /*font-family: 'Courgette', var(--font-heading);*/
    margin-bottom: 0.25rem;
}

header {
    background-color: var(--bg);
    max-width: var(--body-width);
    padding: 1.5rem 1rem 1rem;
    margin: 10px auto 0;
}

header h2 {
    font-size: 1.75rem;
}

header ul {
    margin: 0;
    padding: 0;
    display: flex;
    flex-wrap: wrap;
    column-gap: 1rem;
    list-style: none;
}

header ul li {
    margin: 0;
    padding: 0;
}

header ul li a {
    font-weight: 500;
    font-size: 1.1rem;
    color: var(--link);
}

/* ── Main content area ────────────────────────────────────── */
#main-content {
    background-color: var(--bg);
    margin: 0 auto;
    padding: 1rem;
    max-width: var(--body-width);
}

#main-content h1:first-of-type {
    margin-top: 0;
}

#main-content h1:has(~ p.blog-file-date) {
    margin-bottom: 0;
}

/* ── Content + sidebar layout ─────────────────────────────── */
.content-layout {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.main-content {
    width: 100%;
}

.sidebar {
    width: 100%;
}

@media (min-width: 768px) {
    body:not(.admin):not(:has(.sidebar)) {
        --body-width: calc(var(--content-width) + 2rem);
    }

    .content-layout {
        flex-direction: row;
    }

    .main-content {
        flex: 0 1 var(--content-width);
        width: auto;
        min-width: 0;
    }

    .sidebar {
        flex: 1 1 0;
        width: auto;
        min-width: 14rem;
    }
}

/* ── Blog post list ───────────────────────────────────────── */
.blog-posts {
    list-style-type: none;
    padding: unset;
}

.blog-posts li {
    display: flex;
}

.blog-posts li span {
    flex: 0 0 130px;
    font-style: italic;
}

/* Blog post header */
h1.blog-file-title {
}

p.blog-file-date {
    font-style: italic;
    margin-bottom: 2rem;
}

/* Posts table header row */
.posts-table .table-title {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 0.5rem;
}

/* ── Widgets ──────────────────────────────────────────────── */
.widget-container {
    background-color: color-mix(in srgb, var(--bg) 60%, var(--dark-bg));
    border: 1px solid color-mix(in srgb, var(--muted) 30%, transparent);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 1.25rem;
}

.widget-container:hover {
    border-color: color-mix(in srgb, var(--muted) 50%, transparent);
}

.widget-title {
    font-size: 1.1rem;
    font-weight: 500;
    color: var(--heading);
    margin: 0 0 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
    letter-spacing: -0.02em;
}

.widget-body {
    color: var(--text);
}

/* Media list inside widgets (thumbnail + title + meta, optional trailing note) */
.media-list {
    list-style: none;
    margin: 0 0 0.75rem;
    padding: 0;
    max-height: 12rem;
    overflow-y: auto;
}

.media-list li {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin: 0;
    padding: 0.5rem 0;
}

.media-list li:last-child {
    border-bottom: none;
}

.media-list img {
    flex: 0 0 auto;
    width: 3rem;
    height: 3rem;
    border-radius: var(--radius-sm);
    object-fit: cover;
}

.media-list li > div {
    flex: 1;
    min-width: 0;
}

.media-list small {
    display: block;
}

.media-list li > small {
    flex: 0 0 auto;
    align-self: flex-start;
    white-space: nowrap;
}

/* ── Decorative HR ────────────────────────────────────────── */
hr {
    max-width: var(--body-width);
    margin: 1rem auto;
    background-color: var(--bg);
    border: none;
    height: 12px;
    position: relative;
    overflow: visible;
}

hr::before {
    content: "";
    position: absolute;
    top: 50%;
    left: 10%;
    right: 10%;
    height: 1px;
    background: var(--muted);
    opacity: 0.5;
}

hr::after {
    content: "\00A7"; /* § */
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--bg);
    padding: 0 16px;
    font-size: 1.3rem;
    color: var(--muted);
    font-family: Georgia, 'Playfair Display', serif;
}

/* ── Shared utility classes ───────────────────────────────── */
.button-row {
    display: flex;
    column-gap: 1rem;
    flex-wrap: wrap;
    align-items: center;
}

.form-row {
    display: flex;
    column-gap: 0.5rem;
    align-items: center;
}

.form-row > * {
    flex: 1;
}

.form-row > button {
    flex: 0 0 auto;
}

a.btn {
    background-color: var(--accent);
    color: var(--text);
    border: none;
    padding: 0.45rem 1.25rem;
    border-radius: var(--radius);
    font-weight: 600;
    font-size: 0.875rem;
    cursor: pointer;
}

.admin-badge {
    padding: 0.2rem 0.3rem;
    font-size: 1rem;
    font-weight: 600;
    background-color: var(--link);
    color: var(--bg);
    border-radius: var(--radius);
    vertical-align: middle;
}

.no-margin-top {
    margin-top: 0;
}

/* ── Admin editor layout ──────────────────────────────────── */
body.admin {
    --body-width: 1248px;
}

#editor-form {
    margin-top: 1rem;
}

.admin-edit-layout {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
}

.editor-controls {
    margin-top: 1rem;
}

@media (min-width: 768px) {
    .admin-edit-layout {
        grid-template-columns: 2fr 1fr;
    }

    .editor-controls {
        grid-column: 1 / -1;
    }
}

.assets-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.assets-list li {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.assets-list li img {
    width: 3rem;
    height: auto;
}
.asset-img {
    width: 3rem;
    height: auto;
}

/* ── Mobile ───────────────────────────────────────────────── */
@media (max-width: 767px) {
    :root {
        --body-width: 100%;
        --content-width: 100%;
    }

    body  { font-size: 0.9375rem; line-height: 1.55; }
    h1    { font-size: 1.875rem; }
    h2    { font-size: 1.5rem; }
    h3    { font-size: 1.25rem; }

    header {
        margin: 0;
        border-radius: 0;
    }

    #main-content {
        padding: 1rem 0.75rem;
    }

    .blog-posts li {
        flex-direction: column;
        margin-bottom: 1rem;
    }

    .blog-posts li span {
        flex: none;
        margin-bottom: 0.25rem;
        font-size: 0.9rem;
    }

    .widget-container {
        margin-bottom: 1rem;
    }

    header h2 {
        font-size: 1.5rem;
    }

    header ul li a {
        font-size: 1rem;
    }
}
