/* =====================================================
   CSS Custom Properties — Light & Dark Theme
   ===================================================== */
:root {
    --bg:          #ffffff;
    --surface:     #f6f8fa;
    --text:        #24292f;
    --text-muted:  #57606a;
    --accent:      #0969da;
    --accent-dark: #0550ae;
    --border:      #d0d7de;
    --code-bg:     #f6f8fa;
    --code-text:   #24292f;
    --shadow:      0 1px 3px rgba(0,0,0,.12);
    --radius:      6px;
    --max-w:       720px;
}

[data-theme="dark"] {
    --bg:          #0d1117;
    --surface:     #161b22;
    --text:        #e6edf3;
    --text-muted:  #8b949e;
    --accent:      #58a6ff;
    --accent-dark: #79c0ff;
    --border:      #30363d;
    --code-bg:     #161b22;
    --code-text:   #e6edf3;
    --shadow:      0 1px 3px rgba(0,0,0,.4);
}

/* =====================================================
   Reset & Base
   ===================================================== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; scroll-behavior: smooth; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    transition: background .2s, color .2s;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

img { max-width: 100%; height: auto; display: block; }

/* =====================================================
   Header & Navigation
   ===================================================== */
header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-inner {
    max-width: var(--max-w);
    margin: 0 auto;
    padding: .75rem 1.25rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.site-name {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text);
    white-space: nowrap;
}
.site-name:hover { text-decoration: none; color: var(--accent); }

.nav-links {
    display: flex;
    align-items: center;
    gap: 1.25rem;
}

.nav-links a {
    font-size: .9rem;
    color: var(--text-muted);
    font-weight: 500;
}
.nav-links a:hover { color: var(--text); text-decoration: none; }

[hidden] { display: none !important; }

/* Theme toggle button */
#theme-toggle {
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    padding: .25rem .5rem;
    font-size: 1rem;
    line-height: 1;
    display: flex;
    align-items: center;
}

/* Show correct icon for each mode — handled by JS in footer.php */

/* =====================================================
   Main Content
   ===================================================== */
main {
    flex: 1;
    max-width: var(--max-w);
    width: 100%;
    margin: 0 auto;
    padding: 2rem 1.25rem;
}

/* =====================================================
   Footer
   ===================================================== */
footer {
    border-top: 1px solid var(--border);
    background: var(--surface);
    padding: 1rem 1.25rem;
}

.footer-inner {
    max-width: var(--max-w);
    margin: 0 auto;
    text-align: center;
    font-size: .85rem;
    color: var(--text-muted);
}

/* =====================================================
   Index — Post Cards
   ===================================================== */
.page-heading {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 1.5rem;
    color: var(--text);
}

.post-cards { display: flex; flex-direction: column; gap: 1.25rem; }

.post-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem 1.5rem;
    transition: border-color .15s, box-shadow .15s;
}
.post-card:hover {
    border-color: var(--accent);
    box-shadow: var(--shadow);
}

.post-card-title {
    font-size: 1.15rem;
    font-weight: 600;
    margin-bottom: .3rem;
}
.post-card-title a { color: var(--text); }
.post-card-title a:hover { color: var(--accent); text-decoration: none; }

.post-card-meta {
    font-size: .8rem;
    color: var(--text-muted);
    margin-bottom: .6rem;
}

.post-card-summary {
    font-size: .95rem;
    color: var(--text-muted);
    margin-bottom: .75rem;
}

.read-more {
    font-size: .85rem;
    font-weight: 500;
}

.empty-state {
    color: var(--text-muted);
    text-align: center;
    padding: 3rem 0;
}

/* =====================================================
   Single Post Page
   ===================================================== */
.post-header { margin-bottom: 2rem; }

.post-title {
    font-size: 2rem;
    font-weight: 700;
    line-height: 0.8;
    margin-bottom: .5rem;
}

.post-meta {
    font-size: .85rem;
    color: var(--text-muted);
}

.post-content {
    font-size: 1.05rem;
    line-height: 1.75;
}

/* Markdown rendered content typography */
.post-content h1,
.post-content h2,
.post-content h3,
.post-content h4,
.post-content h5,
.post-content h6 {
    margin: 1.75em 0 .5em;
    line-height: 1.3;
    font-weight: 600;
}
.post-content h1 { font-size: 1.75rem; }
.post-content h2 { font-size: 1.4rem; border-bottom: 1px solid var(--border); padding-bottom: .3em; }
.post-content h3 { font-size: 1.2rem; }

.post-content p  { margin-bottom: 1em; }
.post-content ul,
.post-content ol { margin: 0 0 1em 1.5em; }
.post-content li { line-height: 1.5em; }

.post-content a  { color: var(--accent); text-decoration: underline; }

.post-content strong { font-weight: 600; }
.post-content em     { font-style: italic; }
.post-content u      { text-decoration: underline; }
.post-content del    { text-decoration: line-through; color: var(--text-muted); }

.post-content hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 2em 0;
}

.post-content blockquote {
    border-left: 4px solid var(--accent);
    padding: .5em 1em;
    margin: 1em 0;
    background: var(--surface);
    border-radius: 0 var(--radius) var(--radius) 0;
    color: var(--text-muted);
    font-style: italic;
}
.post-content blockquote p { margin: 0; }

.post-content pre {
    background: var(--code-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
    overflow-x: auto;
    margin: 1em 0;
}

.post-content pre code {
    background: none;
    border: none;
    padding: 0;
    font-size: .9rem;
    color: var(--code-text);
    font-family: 'Fira Code', 'Cascadia Code', Consolas, 'Courier New', monospace;
}

.post-content code {
    background: var(--code-bg);
    border: 1px solid var(--border);
    border-radius: 3px;
    padding: .1em .35em;
    font-size: .88em;
    font-family: 'Fira Code', 'Cascadia Code', Consolas, 'Courier New', monospace;
    color: var(--code-text);
}

.post-content p + ul,
.post-content p + ol {
    margin-top: -.6em; /* pull list up when a paragraph leads into it */
}

.post-content p.tight {
    margin-bottom: .15em; /* explicit tight — end any line with \ */
    text-align: center;
}
.post-content figure img {
    max-width: 100%;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    margin: 0 auto;
}
.post-content figcaption {
    font-size: .85rem;
    color: var(--text-muted);
    margin-top: .5em;
    font-style: italic;
}

/* Back link */
.back-link {
    display: inline-block;
    margin-bottom: 1.5rem;
    font-size: .9rem;
    color: var(--text-muted);
}
.back-link:hover { color: var(--text); text-decoration: none; }

/* Post tags */
.post-tags {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
    margin-top: 2rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--border);
}
.post-tag {
    font-size: .85rem;
    font-weight: 500;
    color: #8250df;
    text-decoration: none;
    padding: .2em .5em;
    border-radius: 999px;
    background: #f3ebff;
    border: 1px solid #d8b4fe;
    transition: background .15s, color .15s;
}
.post-tag:hover { background: #8250df; color: #fff; text-decoration: none; }
[data-theme="dark"] .post-tag {
    color: #d2a8ff;
    background: #2d1a4a;
    border-color: #6e40c9;
}
[data-theme="dark"] .post-tag:hover { background: #8250df; color: #fff; }

/* =====================================================
   About Page
   ===================================================== */
.about-content { max-width: 600px; }
.about-content p { margin-bottom: 1em; font-size: 1.05rem; line-height: 1.75; }

/* =====================================================
   Contact Page
   ===================================================== */
.contact-wrap { max-width: 620px; }

.contact-intro p {
    font-size: 1.05rem;
    line-height: 1.75;
    color: var(--text-muted);
    margin-bottom: .75em;
}
.contact-intro { margin-bottom: 1.75rem; }

.contact-form { margin-top: .5rem; }

.required { color: #cf222e; font-size: .85em; }
[data-theme="dark"] .required { color: #ffa198; }

.contact-success,
.contact-error {
    display: flex;
    align-items: flex-start;
    gap: .6rem;
    padding: .85rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1.25rem;
    font-size: .95rem;
}
.contact-success {
    background: #dafbe1;
    border: 1px solid #abeebb;
    color: #116329;
}
.contact-success-icon { font-size: 1.1rem; line-height: 1.4; }
.contact-error {
    background: #ffebe9;
    border: 1px solid #ff818266;
    color: #82071e;
}
[data-theme="dark"] .contact-success {
    background: #0d4429;
    border-color: #2ea04380;
    color: #3fb950;
}
[data-theme="dark"] .contact-error {
    background: #3d0c10;
    border-color: #cf222e;
    color: #ffa198;
}

/* =====================================================
   Admin — General
   ===================================================== */
.admin-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: .75rem;
}

.btn {
    display: inline-block;
    padding: .45rem .9rem;
    border-radius: var(--radius);
    font-size: .9rem;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid transparent;
    text-decoration: none;
    line-height: 1.5;
}
.btn-primary   { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-dark); text-decoration: none; }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { border-color: var(--text-muted); text-decoration: none; }
.btn-danger    { background: #cf222e; color: #fff; border-color: #cf222e; }
.btn-danger:hover { background: #a40e26; text-decoration: none; }
.btn-sm { padding: .25rem .6rem; font-size: .8rem; }

/* Admin posts table */
.posts-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .9rem;
}
.posts-table th,
.posts-table td {
    text-align: left;
    padding: .6rem .75rem;
    border-bottom: 1px solid var(--border);
}
.posts-table th {
    background: var(--surface);
    font-weight: 600;
    font-size: .8rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-muted);
}
.posts-table tr:hover td { background: var(--surface); }

.status-badge {
    display: inline-block;
    font-size: .75rem;
    font-weight: 600;
    padding: .15em .5em;
    border-radius: 999px;
    text-transform: capitalize;
}
.status-published { background: #dafbe1; color: #116329; }
.status-draft     { background: #fff8c5; color: #9a6700; }
[data-theme="dark"] .status-published { background: #0d4429; color: #3fb950; }
[data-theme="dark"] .status-draft     { background: #3d2b00; color: #d29922; }

.table-actions { display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; }

/* =====================================================
   Admin — Forms
   ===================================================== */
.form-group { margin-bottom: 1.1rem; }

.form-group label {
    display: block;
    font-weight: 600;
    font-size: .9rem;
    margin-bottom: .35rem;
}

.form-group input[type="text"],
.form-group input[type="email"],
.form-group select,
.form-group textarea {
    width: 100%;
    padding: .5rem .75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--text);
    font-size: .95rem;
    font-family: inherit;
    transition: border-color .15s, box-shadow .15s;
}
.form-group input[type="text"]:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(9,105,218,.15);
}

.form-group textarea { resize: vertical; min-height: 80px; }
.form-hint { font-size: .8rem; color: var(--text-muted); margin-top: .3rem; }

.form-row { display: flex; gap: 1rem; }
.form-row .form-group { flex: 1; }

.form-actions { display: flex; gap: .75rem; align-items: center; margin-top: 1.5rem; }

.error-msg {
    background: #ffebe9;
    border: 1px solid #ff818266;
    border-radius: var(--radius);
    padding: .75rem 1rem;
    margin-bottom: 1rem;
    font-size: .9rem;
    color: #82071e;
}
[data-theme="dark"] .error-msg {
    background: #3d0c10;
    border-color: #cf222e;
    color: #ffa198;
}

/* =====================================================
   Admin — Split Editor
   ===================================================== */
.editor-label {
    font-weight: 600;
    font-size: .9rem;
    margin-bottom: .35rem;
    display: block;
    color: var(--text-muted);
}

.editor-wrap {
    display: flex;
    gap: 1rem;
    height: 60vh;
    min-height: 400px;
    margin-bottom: 1.1rem;
}

.editor-pane,
.preview-pane {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.editor-pane textarea {
    flex: 1;
    width: 100%;
    padding: .75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--text);
    font-family: 'Fira Code', 'Cascadia Code', Consolas, 'Courier New', monospace;
    font-size: .88rem;
    line-height: 1.6;
    resize: none;
    transition: border-color .15s;
}
.editor-pane textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(9,105,218,.15);
}

.preview-pane .preview-content {
    flex: 1;
    overflow-y: auto;
    padding: .75rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
}

/* =====================================================
   Wide layout (admin editor)
   ===================================================== */
.main-wide { max-width: 1400px; }

/* =====================================================
   Markdown cheatsheet modal
   ===================================================== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.55);
    z-index: 500;
    display: flex;
    align-items: center;
    justify-content: center;
}
.modal-overlay[hidden] { display: none; }

.modal-box {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    width: min(560px, 92vw);
    max-height: 82vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 32px rgba(0,0,0,.25);
}
.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .85rem 1.25rem;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--bg);
    border-radius: var(--radius) var(--radius) 0 0;
}
.modal-head h3 { font-size: 1rem; font-weight: 600; }
.modal-close {
    background: none; border: none; cursor: pointer;
    font-size: 1.1rem; color: var(--text-muted); padding: .2rem .4rem;
    border-radius: var(--radius);
    line-height: 1;
}
.modal-close:hover { color: var(--text); background: var(--surface); }
.modal-body { overflow-y: auto; padding: .75rem 1.25rem 1.25rem; }

.cheatsheet-table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.cheatsheet-table th {
    text-align: left; padding: .4rem .6rem;
    font-size: .75rem; text-transform: uppercase; letter-spacing: .04em;
    color: var(--text-muted); border-bottom: 2px solid var(--border);
}
.cheatsheet-table td { padding: .45rem .6rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.cheatsheet-table tr:last-child td { border-bottom: none; }
.cheatsheet-table td:first-child code { white-space: pre; }

/* =====================================================
   Responsive
   ===================================================== */
@media (max-width: 640px) {
    .post-title { font-size: 1.5rem; }
    .form-row { flex-direction: column; }

    .editor-wrap {
        flex-direction: column;
        height: auto;
    }
    .editor-pane textarea  { height: 280px; }
    .preview-pane .preview-content { height: 280px; }

    .posts-table { font-size: .82rem; }
    .posts-table th, .posts-table td { padding: .5rem; }

    .editor-pane{ min-height: 450px;}
}
