/* =========================================================================
   manuelre.com — theme
   Reading-first structure (à la darioamodei.com) with restrained,
   navy-charcoal-on-warm-white discipline (à la company31.com).

   Light + dark themes via plain CSS-variable overrides on [data-theme]
   (set on <html> by a tiny inline script using the saved choice or the OS
   preference). No light-dark() dependency, so it works in every browser
   that supports CSS variables. All text pairs meet WCAG 2.1 AA (most AAA);
   UI borders + focus rings meet 3:1. Verified contrast ratios in comments.
   ========================================================================= */

:root {
    color-scheme: light dark;

    /* ----- LIGHT palette (default) ----- */
    --paper:        #FCFCFA;   /* page background */
    --surface:      #FFFFFF;   /* cards, inputs */
    --admin-bg:     #F1F0EC;
    --code-bg:      #EEEDE8;

    --ink:          #16181D;   /* body text     17:1 */
    --muted:        #585C64;   /* secondary    6.5:1 */
    --faint:        #62666E;   /* meta / hints 5.6:1 */
    --accent:       #1B2A4A;   /* links / focus */

    --hairline:     #E2E1DC;   /* decorative rules */
    --field-border: #7B7F87;   /* UI borders   3.9:1 */

    --btn-bg:       #16181D;
    --btn-text:     #FCFCFA;

    --badge-pub-bg:     #DDEAD9;  --badge-pub-text:   #2C4A28;
    --badge-draft-bg:   #EFE3D2;  --badge-draft-text: #6E4F23;
    --notice-bg:        #E7F0E3;  --notice-text:      #2C4A28;  --notice-border:  #CBD9C4;
    --callout-bg:       #FBF3E3;  --callout-text:     #6E4F23;  --callout-border: #EAD9B0;
    --error-bg:         #FBEAEA;  --error-text:       #8A2A2A;  --error-border:   #E6C3C3;

    --shadow-color: rgba(0,0,0,0.07);
    --focus-ring:   rgba(27,42,74,0.20);

    --measure: 42rem;
    --wide:    52rem;

    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
            Arial, "Helvetica Neue", sans-serif;
    --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
            "Liberation Mono", monospace;

    --step--1: 0.86rem;
    --step-0:  1.0rem;
    --step-1:  1.2rem;
    --step-2:  1.5rem;
    --step-3:  2.0rem;
    --step-4:  2.6rem;
}

/* ----- DARK palette (applied when <html data-theme="dark">) ----- */
:root[data-theme="dark"] {
    color-scheme: dark;

    --paper:        #15171C;
    --surface:      #1C1F26;
    --admin-bg:     #101217;
    --code-bg:      #23262E;

    --ink:          #E8E7E2;   /* body text   14.5:1 */
    --muted:        #A7ABB3;   /* secondary    7.8:1 */
    --faint:        #9398A0;   /* meta / hints 6.2:1 */
    --accent:       #A8C1FF;   /* links / focus */

    --hairline:     #2A2D35;
    --field-border: #686D78;   /* UI borders   3.2:1 */

    --btn-bg:       #E8E7E2;
    --btn-text:     #15171C;

    --badge-pub-bg:     #1E2C1A;  --badge-pub-text:   #A7D39C;
    --badge-draft-bg:   #2E2616;  --badge-draft-text: #E0C089;
    --notice-bg:        #182414;  --notice-text:      #A7D39C;  --notice-border:  #2E4A26;
    --callout-bg:       #2E2616;  --callout-text:     #E0C089;  --callout-border: #4A3E1E;
    --error-bg:         #2C1717;  --error-text:       #F0A9A9;  --error-border:   #5A2A2A;

    --shadow-color: rgba(0,0,0,0.5);
    --focus-ring:   rgba(168,193,255,0.30);
}

:root[data-theme="light"] { color-scheme: light; }

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

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

body {
    margin: 0;
    background: var(--paper);
    color: var(--ink);
    font-family: var(--font);
    font-size: 18px;
    line-height: 1.65;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

a {
    color: var(--ink);
    text-decoration: underline;
    text-decoration-color: var(--field-border);
    text-underline-offset: 0.18em;
    transition: color 0.15s ease, text-decoration-color 0.15s ease;
}
a:hover { color: var(--accent); text-decoration-color: var(--accent); }

hr {
    border: 0;
    border-top: 1px solid var(--hairline);
    margin: 2.5rem 0;
}

/* ----- Accessibility: focus, skip link, motion ----- */

:where(a, button, summary, input, select, textarea, [tabindex]):focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 3px;
}

.skip-link {
    position: absolute;
    left: -9999px;
    top: 0;
    z-index: 100;
    background: var(--surface);
    color: var(--ink);
    padding: 0.6rem 1rem;
    border: 1px solid var(--field-border);
    border-radius: 8px;
    text-decoration: none;
    font-weight: 600;
}
.skip-link:focus { left: 1rem; top: 1rem; }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
        scroll-behavior: auto !important;
    }
}

/* ----- Theme toggle ----- */

.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    padding: 0;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 9px;
    color: var(--muted);
    cursor: pointer;
    transition: color 0.15s ease, border-color 0.15s ease;
}
.theme-toggle:hover { color: var(--accent); border-color: var(--field-border); }
.theme-toggle .icon { display: block; }
/* Show the icon for the theme you'll switch TO. Default (light) → moon. */
.theme-toggle .icon-sun  { display: none; }
.theme-toggle .icon-moon { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-sun  { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

.page-toggle { position: fixed; top: 1rem; right: 1rem; z-index: 50; }

/* =========================================================================
   Public layout
   ========================================================================= */

.wrap {
    max-width: var(--measure);
    margin: 0 auto;
    padding: 3.5rem 1.5rem 5rem;
}

.site-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 3.5rem;
}
.head-right { display: flex; align-items: center; gap: 1.25rem; }
.site-name {
    font-weight: 600;
    font-size: var(--step-0);
    letter-spacing: -0.01em;
    text-decoration: none;
}
.site-nav a {
    color: var(--muted);
    font-size: var(--step--1);
    text-decoration: none;
    letter-spacing: 0.02em;
}
.site-nav a:hover { color: var(--accent); }

.content { min-height: 40vh; }

.site-foot {
    margin-top: 5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--hairline);
    color: var(--faint);
    font-size: var(--step--1);
}
.site-foot p { margin: 0; }

/* ----- Home: bio ----- */

.display-name {
    font-size: var(--step-4);
    font-weight: 700;
    letter-spacing: -0.025em;
    line-height: 1.1;
    margin: 0 0 1.25rem;
}
.bio-text { font-size: var(--step-1); color: var(--ink); }
.bio-text p { margin: 0 0 1rem; }
.bio-more { margin-top: 0.5rem; }
.bio-more summary {
    cursor: pointer;
    color: var(--muted);
    font-size: var(--step-0);
    list-style: none;
    display: inline-block;
}
.bio-more summary::-webkit-details-marker { display: none; }
.bio-more summary:hover { color: var(--accent); }
.bio-more[open] summary { margin-bottom: 0.75rem; }

/* ----- Section labels ----- */

.section-label {
    font-size: var(--step--1);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--muted);
    margin: 3.25rem 0 1.25rem;
    padding-bottom: 0.6rem;
    border-bottom: 1px solid var(--hairline);
}

/* ----- Entry lists (essays / archive) ----- */

.entries { list-style: none; margin: 0; padding: 0; }
.entry {
    padding: 0.85rem 0;
    border-bottom: 1px solid var(--hairline);
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}
.entry:last-child { border-bottom: 0; }
.entry-title {
    font-size: var(--step-1);
    font-weight: 600;
    letter-spacing: -0.01em;
    text-decoration: none;
}
.entry-dek { margin: 0.1rem 0 0; color: var(--muted); font-size: var(--step-0); }
.entry-date { color: var(--faint); font-size: var(--step--1); }

.more-link { margin-top: 1.5rem; }
.more-link a { color: var(--muted); text-decoration: none; font-size: var(--step-0); }
.more-link a:hover { color: var(--accent); }

.page-title {
    font-size: var(--step-3);
    font-weight: 700;
    letter-spacing: -0.02em;
    margin: 0 0 2rem;
}

/* =========================================================================
   Essay page
   ========================================================================= */

.essay-title {
    font-size: var(--step-3);
    font-weight: 700;
    letter-spacing: -0.025em;
    line-height: 1.15;
    margin: 0 0 0.5rem;
}
.essay-dek {
    font-size: var(--step-1);
    color: var(--muted);
    margin: 0 0 0.75rem;
    line-height: 1.4;
}
.essay-meta {
    color: var(--faint);
    font-size: var(--step--1);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin: 0 0 2.5rem;
}

.essay-body { font-size: 1.18rem; line-height: 1.75; }
.essay-body p { margin: 0 0 1.4rem; }
.essay-body h2 {
    font-size: var(--step-2);
    font-weight: 700;
    letter-spacing: -0.015em;
    margin: 2.6rem 0 0.9rem;
}
.essay-body h3 {
    font-size: var(--step-1);
    font-weight: 700;
    margin: 2rem 0 0.75rem;
}
.essay-body a { text-decoration-color: var(--muted); }
.essay-body ul, .essay-body ol { padding-left: 1.4rem; margin: 0 0 1.4rem; }
.essay-body li { margin: 0.35rem 0; }
.essay-body blockquote {
    margin: 1.8rem 0;
    padding: 0.2rem 0 0.2rem 1.4rem;
    border-left: 3px solid var(--field-border);
    color: var(--muted);
    font-style: italic;
}
.essay-body code {
    font-family: var(--mono);
    font-size: 0.88em;
    background: var(--code-bg);
    padding: 0.15em 0.4em;
    border-radius: 4px;
}
.essay-body pre {
    background: var(--code-bg);
    padding: 1rem 1.2rem;
    border-radius: 8px;
    overflow-x: auto;
    margin: 0 0 1.4rem;
}
.essay-body pre code { background: none; padding: 0; font-size: 0.85rem; }
.essay-body img { max-width: 100%; height: auto; border-radius: 8px; }
.essay-body hr { margin: 2.5rem 0; }

.back-link { margin-top: 4rem; }
.back-link a { color: var(--muted); text-decoration: none; font-size: var(--step-0); }
.back-link a:hover { color: var(--accent); }

/* =========================================================================
   Admin
   ========================================================================= */

body.admin { background: var(--admin-bg); }

.admin-wrap { max-width: var(--wide); margin: 0 auto; padding: 1.5rem 1.5rem 4rem; }

.admin-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 0 1.25rem;
    margin-bottom: 2rem;
    border-bottom: 1px solid var(--hairline);
}
.admin-brand { font-weight: 700; text-decoration: none; letter-spacing: -0.01em; }
.admin-head-right { display: flex; flex-wrap: wrap; align-items: center; gap: 1.1rem; }
.admin-nav { display: flex; flex-wrap: wrap; gap: 1.1rem; }
.admin-nav a { color: var(--muted); text-decoration: none; font-size: var(--step--1); }
.admin-nav a:hover { color: var(--accent); }

.admin-main h1 { font-size: var(--step-2); font-weight: 700; margin: 0 0 1.5rem; letter-spacing: -0.02em; }

/* notices */
.notice {
    background: var(--notice-bg);
    border: 1px solid var(--notice-border);
    color: var(--notice-text);
    padding: 0.7rem 1rem;
    border-radius: 8px;
    margin-bottom: 1.5rem;
    font-size: var(--step-0);
}

/* ----- essay table ----- */
.essay-table { width: 100%; border-collapse: collapse; }
.essay-table th {
    text-align: left;
    font-size: var(--step--1);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
    font-weight: 600;
    padding: 0 0.6rem 0.6rem;
    border-bottom: 1px solid var(--hairline);
}
.essay-table td {
    padding: 0.85rem 0.6rem;
    border-bottom: 1px solid var(--hairline);
    vertical-align: middle;
}
.essay-table .t-title { font-weight: 600; }
.essay-table .t-title a { text-decoration: none; }
.essay-table .t-actions { text-align: right; white-space: nowrap; }
.row-actions { display: inline-flex; gap: 0.5rem; align-items: center; }

.badge {
    display: inline-block;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 0.2em 0.6em;
    border-radius: 999px;
}
.badge-published { background: var(--badge-pub-bg); color: var(--badge-pub-text); }
.badge-draft { background: var(--badge-draft-bg); color: var(--badge-draft-text); }

.empty-state { color: var(--muted); padding: 2rem 0; }

/* ----- buttons ----- */
.btn {
    display: inline-block;
    font: inherit;
    font-size: var(--step-0);
    font-weight: 600;
    color: var(--btn-text);
    background: var(--btn-bg);
    border: 1px solid var(--btn-bg);
    padding: 0.6rem 1.1rem;
    border-radius: 8px;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.btn:hover { background: var(--accent); border-color: var(--accent); color: var(--btn-text); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-ghost { background: transparent; color: var(--ink); border-color: var(--field-border); }
.btn-ghost:hover { background: transparent; color: var(--accent); border-color: var(--accent); }
.btn-sm { padding: 0.35rem 0.7rem; font-size: var(--step--1); }
.btn-link {
    font: inherit;
    font-size: var(--step--1);
    color: var(--muted);
    background: none;
    border: 0;
    padding: 0.35rem 0.25rem;
    cursor: pointer;
    text-decoration: underline;
    text-decoration-color: var(--field-border);
}
.btn-link:hover { color: var(--accent); text-decoration-color: var(--accent); }
.btn-danger { color: var(--error-text); }
.btn-danger:hover { color: var(--error-text); text-decoration-color: var(--error-text); }

/* ----- forms ----- */
form label {
    display: block;
    margin-bottom: 1.25rem;
    font-size: var(--step-0);
    font-weight: 600;
}
form input[type="text"],
form input[type="password"],
form input[type="date"],
form input[type="email"],
form select,
form textarea {
    display: block;
    width: 100%;
    margin-top: 0.4rem;
    font: inherit;
    font-weight: 400;
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--field-border);
    border-radius: 8px;
    padding: 0.6rem 0.75rem;
}
form input:focus, form select:focus, form textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--focus-ring);
}
form input:focus-visible, form select:focus-visible, form textarea:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}
form textarea { resize: vertical; }
.editor-body { min-height: 24rem; font-family: var(--mono); font-size: 0.95rem; line-height: 1.6; }
.hint { display: block; margin-top: 0.35rem; font-size: var(--step--1); font-weight: 400; color: var(--faint); }

.field-row { display: flex; gap: 1.25rem; flex-wrap: wrap; }
.field-row > label { flex: 1 1 12rem; }

.form-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-top: 0.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--hairline);
}

.form-error {
    background: var(--error-bg);
    border: 1px solid var(--error-border);
    color: var(--error-text);
    padding: 0.7rem 1rem;
    border-radius: 8px;
    margin: 0 0 1.5rem;
    font-size: var(--step-0);
    font-weight: 400;
}
ul.form-error { padding-left: 1.8rem; }
ul.form-error li { margin: 0.2rem 0; }

.muted { color: var(--muted); }
.callout {
    background: var(--callout-bg);
    border: 1px solid var(--callout-border);
    color: var(--callout-text);
    padding: 0.8rem 1rem;
    border-radius: 8px;
    font-size: var(--step-0);
}
code {
    font-family: var(--mono);
    font-size: 0.88em;
    background: var(--code-bg);
    padding: 0.12em 0.4em;
    border-radius: 4px;
}

/* ----- login / install card ----- */
.admin-login {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 1.5rem;
}
.login-card {
    width: 100%;
    max-width: 24rem;
    background: var(--surface);
    border: 1px solid var(--hairline);
    border-radius: 14px;
    padding: 2.25rem;
    box-shadow: 0 1px 2px var(--shadow-color), 0 8px 24px var(--shadow-color);
}
.login-card h1 { font-size: var(--step-2); font-weight: 700; margin: 0 0 1.5rem; }
.login-card .btn { width: 100%; text-align: center; }
.install-card { max-width: 30rem; }
.install-card .btn { width: auto; }
.install-card .btn + .btn { margin-left: 0.5rem; }

/* =========================================================================
   Responsive
   ========================================================================= */

@media (max-width: 600px) {
    body { font-size: 17px; }
    .wrap { padding: 2.5rem 1.25rem 4rem; }
    .display-name { font-size: var(--step-3); }
    .essay-body { font-size: 1.1rem; }
    .essay-table thead { display: none; }
    .essay-table, .essay-table tbody, .essay-table tr, .essay-table td { display: block; width: 100%; }
    .essay-table tr { padding: 0.75rem 0; border-bottom: 1px solid var(--hairline); }
    .essay-table td { border: 0; padding: 0.2rem 0; }
    .essay-table .t-actions { text-align: left; margin-top: 0.5rem; }
}
