/* ── Inter Variable ── */
@font-face {
    font-family: 'Inter';
    font-style: normal;
    font-weight: 100 900;
    font-display: swap;
    src: url('/static/Inter-Variable.woff2') format('woff2');
}

/* ── Reset ── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

/* ── Root Tokens ── */
/* Light mode — all text colors verified ≥ 4.5:1 on #fafafa */
:root {
    --fg:       #1a1a1a;  /* 17.4:1 on bg */
    --fg2:      #555;     /*  7.5:1 on bg */
    --fg3:      #666;     /*  5.7:1 on bg — labels, timestamps */
    --fg-muted: #999;     /*  3.0:1 on bg — decorative only (hash) */
    --bg:       #fafafa;
    --bg2:      #f0f0f0;
    --bg3:      #e5e5e5;
    --rule:     #ccc;     /* borders only, never used as text */
    --red:      #c00;     /*  5.9:1 on bg */
    --green:    #1a7f37;  /*  5.2:1 on bg */
    --mono:  'Inter', ui-monospace, 'SFMono-Regular', 'SF Mono', Menlo, Consolas, monospace;
    --sans:  'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --fs-xs:  0.6875rem;   /* 11px */
    --fs-sm:  0.75rem;     /* 12px */
    --fs-base: 0.8125rem;  /* 13px */
    --fs-md:  0.875rem;    /* 14px */
    --fs-lg:  1rem;        /* 16px */
    --fs-xl:  1.125rem;    /* 18px */
    --fs-2xl: 1.5rem;      /* 24px */
    --lh:     1.5;
    --max-w:  64rem;       /* 1024px */
    --gutter: 1.25rem;     /* 20px */
}

/* ── Base ── */
html {
    background: var(--bg);
    color: var(--fg);
    font-family: var(--sans);
    font-size: 16px;
    line-height: var(--lh);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

body {
    max-width: var(--max-w);
    margin: 0 auto;
    padding: 0;
}

/* ── Top Bar ── */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.375rem var(--gutter);
    border-bottom: 1px solid var(--rule);
    font-size: var(--fs-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--fg3);
    background: var(--bg);
}

.top-bar .site-id {
    color: var(--fg2);
}

.top-bar .security-notice {
    color: var(--red);
}

/* ── Page Header ── */
.page-header {
    padding: var(--gutter);
    border-bottom: 1px solid var(--rule);
}

.page-header h1 {
    font-size: var(--fs-2xl);
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1.2;
    color: var(--fg);
    text-transform: uppercase;
}

.page-header .subtitle {
    font-size: var(--fs-sm);
    color: var(--fg3);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-top: 0.125rem;
}

/* ── Navigation ── */
nav {
    display: flex;
    gap: 0;
    font-size: var(--fs-sm);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    overflow-x: auto;
}

nav a {
    padding: 0.5rem var(--gutter);
    color: var(--fg2);
    text-decoration: none;
    border-right: 1px solid var(--rule);
    border-bottom: 1px solid var(--rule);
    white-space: nowrap;
    transition: background 0.1s, color 0.1s;
}

nav a:last-child {
    border-right: none;
}

nav::after {
    content: '';
    flex: 1;
    border-bottom: 1px solid var(--rule);
}

nav a:hover {
    background: var(--fg);
    color: var(--bg);
}

nav a.active {
    background: var(--fg);
    color: var(--bg);
}

/* ── Main Content ── */
.content {
    padding: var(--gutter);
}

/* ── Section Headers ── */
.section-header {
    font-size: var(--fs-xs);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--fg3);
    padding-bottom: 0.375rem;
    border-bottom: 1px solid var(--rule);
    margin-bottom: 0.75rem;
    margin-top: 1.5rem;
}

.section-header:first-child {
    margin-top: 0;
}

/* ── Site Entry (index page) ── */
.site-entry {
    padding: 0.625rem 0;
    border-bottom: 1px solid var(--bg3);
}

.site-entry:last-child {
    border-bottom: none;
}

.site-row {
    display: flex;
    align-items: baseline;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.site-name {
    font-size: var(--fs-md);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: -0.01em;
    color: var(--fg);
    white-space: nowrap;
}

.site-url {
    font-size: var(--fs-xs);
    color: var(--fg3);
    word-break: break-all;
    font-weight: 400;
}

.site-status {
    font-size: var(--fs-xs);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-left: auto;
    white-space: nowrap;
}

.st-up   { color: var(--green); }
.st-down { color: var(--red); }

.site-uptime {
    font-size: var(--fs-xs);
    color: var(--fg2);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.site-meta {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-top: 0.25rem;
    flex-wrap: wrap;
}

.site-desc {
    font-size: var(--fs-sm);
    color: var(--fg2);
    font-style: italic;
    margin-top: 0.25rem;
}

.site-alert {
    font-size: var(--fs-xs);
    font-weight: 700;
    color: var(--red);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-top: 0.25rem;
}

/* ── Uptime Graph ── */
.graph {
    display: flex;
    gap: 1px;
    margin-top: 0.375rem;
    height: 1rem;
    background: var(--bg2);
    border: 1px solid var(--rule);
    border-radius: 1px;
    overflow: hidden;
}

.block {
    flex: 1;
    min-width: 3px;
    transition: opacity 0.1s;
    cursor: default;
    position: relative;
}

.block:hover {
    opacity: 0.7;
}

/* ── Mirrors Dropdown ── */
.mirrors-dropdown {
    margin-top: 0.375rem;
    font-size: var(--fs-sm);
}

.mirrors-dropdown summary {
    cursor: pointer;
    color: var(--fg2);
    font-weight: 600;
    text-transform: uppercase;
    font-size: var(--fs-xs);
    letter-spacing: 0.04em;
    list-style: none;
    user-select: none;
}

.mirrors-dropdown summary::-webkit-details-marker { display: none; }
.mirrors-dropdown summary::before { content: "[+] "; font-weight: 400; }
.mirrors-dropdown[open] summary::before { content: "[\2212] "; }

.mirrors-dropdown ul {
    list-style: none;
    padding: 0.25rem 0 0 0;
    margin: 0;
}

.mirrors-dropdown li {
    padding: 0.125rem 0;
}

.mirrors-dropdown li a {
    color: var(--fg2);
    font-size: var(--fs-xs);
    word-break: break-all;
    text-decoration: none;
    border-bottom: 1px solid var(--rule);
    transition: color 0.1s;
}

.mirrors-dropdown li a:hover {
    color: var(--fg);
}

/* ── Resources List ── */
.resource-entry {
    padding: 0.375rem 0;
    border-bottom: 1px solid var(--bg3);
}

.resource-entry:last-child {
    border-bottom: none;
}

.resource-name {
    font-weight: 700;
    font-size: var(--fs-md);
    text-transform: uppercase;
}

.resource-name a {
    color: var(--fg);
    text-decoration: none;
    border-bottom: 1px solid var(--rule);
    transition: border-color 0.1s;
}

.resource-name a:hover {
    border-color: var(--fg);
}

.resource-desc {
    font-size: var(--fs-sm);
    color: var(--fg2);
}

/* ── Links ── */
a {
    color: var(--fg);
    text-decoration: none;
    border-bottom: 1px solid var(--rule);
    transition: border-color 0.1s, color 0.1s;
}

a:hover {
    border-color: var(--fg);
}

/* ── Footer ── */
.footer {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 0.375rem var(--gutter);
    border-top: 1px solid var(--rule);
    margin-top: 1.5rem;
    font-size: var(--fs-xs);
    color: var(--fg3);
    font-variant-numeric: tabular-nums;
    gap: 1rem;
}

.footer .hash {
    font-family: var(--mono);
    font-size: 0.5625rem; /* 9px */
    color: var(--fg-muted);
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.footer .meta {
    text-align: right;
    white-space: nowrap;
}

/* ── Body Text / Page Content ── */
.page-body {
    font-size: var(--fs-base);
    line-height: var(--lh);
    color: var(--fg);
}

.page-body p {
    margin-bottom: 0.75rem;
}

.page-body h1, .page-body h2, .page-body h3 {
    font-weight: 700;
    text-transform: uppercase;
    margin-top: 1.5rem;
    margin-bottom: 0.5rem;
    letter-spacing: -0.01em;
}

.page-body h1 { font-size: var(--fs-xl); }
.page-body h2 { font-size: var(--fs-lg); }
.page-body h3 { font-size: var(--fs-md); }

.page-body ul, .page-body ol {
    padding-left: 1.25rem;
    margin-bottom: 0.75rem;
}

.page-body li {
    margin-bottom: 0.25rem;
}

.page-body code {
    font-family: var(--mono);
    font-size: 0.9em;
    background: var(--bg2);
    padding: 0.1em 0.3em;
    border-radius: 2px;
}

.page-body pre {
    background: var(--fg);
    color: var(--bg);
    padding: 0.75rem 1rem;
    overflow-x: auto;
    font-size: var(--fs-sm);
    font-family: var(--mono);
    line-height: 1.5;
    margin-bottom: 0.75rem;
    border-radius: 2px;
    white-space: pre-wrap;
    overflow-wrap: break-word;
}

.page-body pre code {
    background: none;
    padding: 0;
    font-size: inherit;
}

/* ── PGP Key ── */
pre.pgp-key {
    background: var(--fg);
    color: var(--bg);
    padding: 0.75rem 1rem;
    overflow-x: auto;
    font-size: var(--fs-sm);
    font-family: var(--mono);
    line-height: 1.5;
    border-radius: 2px;
    white-space: pre-wrap;
    overflow-wrap: break-word;
}

/* ── Tutorial List ── */
.tutorial-list {
    list-style: none;
    padding: 0;
}

.tutorial-list li {
    padding: 0.375rem 0;
    border-bottom: 1px solid var(--bg3);
}

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

.tutorial-list a {
    font-weight: 600;
    font-size: var(--fs-md);
    color: var(--fg);
    text-decoration: none;
    border-bottom: 1px solid var(--rule);
}

.tutorial-list a:hover {
    border-color: var(--fg);
}

/* ── Back Link ── */
.back-link {
    display: inline-block;
    margin-top: 1rem;
    font-size: var(--fs-sm);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--fg2);
    border-bottom: 1px solid var(--rule);
    text-decoration: none;
}

.back-link:hover {
    color: var(--fg);
    border-color: var(--fg);
}

/* ── Error / Status Pages ── */
.error-code {
    font-size: var(--fs-2xl);
    font-weight: 700;
    color: var(--red);
    text-transform: uppercase;
}

.error-message {
    font-size: var(--fs-base);
    color: var(--fg2);
    margin-top: 0.25rem;
}

/* ── Forms (admin/login) ── */
.form-panel {
    border: 1px solid var(--rule);
    padding: 1.25rem;
    background: var(--bg);
}

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

label {
    display: block;
    font-size: var(--fs-xs);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--fg2);
    margin-bottom: 0.25rem;
}

input[type="text"],
input[type="password"],
textarea {
    font-family: var(--sans);
    font-size: var(--fs-base);
    font-weight: 500;
    padding: 0.5rem 0.625rem;
    border: 1px solid var(--rule);
    background: #fff;
    color: var(--fg);
    width: 100%;
    outline: none;
    border-radius: 0;
    transition: border-color 0.15s;
}

textarea {
    resize: vertical;
    min-height: 8rem;
    font-family: var(--mono);
    font-size: var(--fs-sm);
    line-height: 1.6;
}

input[type="text"]:focus,
input[type="password"]:focus,
textarea:focus {
    border-color: var(--fg);
}

button {
    font-family: var(--sans);
    font-size: var(--fs-sm);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 0.5rem 1rem;
    background: var(--fg);
    color: var(--bg);
    border: 1px solid var(--fg);
    cursor: pointer;
    border-radius: 0;
    transition: background 0.1s, color 0.1s;
}

button:hover {
    background: var(--red);
    border-color: var(--red);
}

button.secondary {
    background: var(--bg);
    color: var(--fg);
    border: 1px solid var(--rule);
}

button.secondary:hover {
    background: var(--bg2);
    border-color: var(--fg2);
}

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

button.danger:hover {
    background: #900;
    border-color: #900;
}

/* ── Admin: Error Message ── */
#error-msg {
    font-size: var(--fs-sm);
    font-weight: 700;
    color: var(--bg);
    background: var(--red);
    padding: 0.5rem 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 0.75rem;
}

#error-msg:empty {
    display: none;
}

/* ── Admin: Site/Resource/Tutorial List ── */
#site-list,
#resource-list-admin,
#tutorial-list-admin,
#page-list-admin {
    list-style: none;
    padding: 0;
}

#site-list li,
#resource-list-admin li,
#tutorial-list-admin li,
#page-list-admin li {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.375rem 0;
    border-bottom: 1px solid var(--bg3);
    font-size: var(--fs-sm);
    flex-wrap: wrap;
}

#site-list li span,
#resource-list-admin li span,
#tutorial-list-admin li span,
#page-list-admin li span {
    font-weight: 700;
    text-transform: uppercase;
}

#site-list li button,
#resource-list-admin li button,
#tutorial-list-admin li button,
#page-list-admin li button {
    font-size: var(--fs-xs);
    padding: 0.2rem 0.5rem;
}

/* ── Admin: Edit Sections ── */
#edit-site-section,
#edit-resource-section,
#edit-tutorial-section,
#edit-page-section {
    border: 1px solid var(--rule);
    padding: 1rem;
    margin-bottom: 1rem;
    background: var(--bg2);
}

/* ── noscript handling ── */
.noscript-hide {
    display: none;
}

/* ── Divider ── */
hr {
    border: none;
    border-top: 1px solid var(--rule);
    margin: 1.5rem 0;
}

/* ── Utility ── */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0,0,0,0);
    border: 0;
}

.flex-row { display: flex; gap: 0.5rem; align-items: center; }
.mt-0 { margin-top: 0; }

/* ── Responsiveness ── */
@media (max-width: 640px) {
    :root {
        --gutter: 0.75rem;
    }

    .page-header h1 {
        font-size: var(--fs-xl);
    }

    nav {
        flex-wrap: wrap;
    }

    nav::after {
        display: none;
    }

    nav a {
        flex: 1 1 auto;
        text-align: center;
        border-bottom: 1px solid var(--rule);
    }

    .footer .hash {
        white-space: normal;
        word-break: break-all;
        overflow: visible;
    }

    .site-row {
        flex-direction: column;
        gap: 0;
    }

    .site-status {
        margin-left: 0;
    }

    .site-meta {
        flex-direction: column;
        align-items: flex-start;
    }

    .footer {
        flex-direction: column;
        gap: 0.375rem;
    }

    .footer .meta {
        text-align: left;
    }

    .graph {
        overflow-x: auto;
        flex-wrap: nowrap;
    }

    .block {
        min-width: 4px;
        flex: 1 0 auto;
    }
}

/* ── Dark Mode ── */
/* All text colors verified ≥ 4.5:1 on #141414 */
@media (prefers-color-scheme: dark) {
    :root {
        --fg:       #e8e8e8;  /* 15.8:1 on bg */
        --fg2:      #b0b0b0;  /*  8.6:1 on bg */
        --fg3:      #999;     /*  6.3:1 on bg — labels, timestamps */
        --fg-muted: #666;     /*  3.3:1 on bg — decorative (hash) */
        --bg:       #141414;
        --bg2:      #1c1c1c;
        --bg3:      #282828;
        --rule:     #3a3a3a;  /* borders only */
        --red:      #f56565;  /*  6.3:1 on bg */
        --green:    #68d391;  /*  9.3:1 on bg */
    }

    html {
        color-scheme: dark;
    }

    input[type="text"],
    input[type="password"],
    textarea {
        background: var(--bg2);
        color: var(--fg);
        border-color: var(--rule);
    }

    input[type="text"]:focus,
    input[type="password"]:focus,
    textarea:focus {
        border-color: var(--fg2);
    }

    pre.pgp-key {
        background: var(--bg2);
        color: var(--fg);
        border: 1px solid var(--rule);
    }

    .page-body pre {
        background: var(--bg2);
        color: var(--fg);
        border: 1px solid var(--rule);
    }

    .page-body code {
        background: var(--bg3);
    }

    .form-panel {
        background: var(--bg2);
    }

    #edit-site-section,
    #edit-resource-section,
    #edit-tutorial-section,
    #edit-page-section {
        background: var(--bg2);
    }

    .graph {
        background: var(--bg3);
    }

    button {
        background: var(--fg);
        color: var(--bg);
        border-color: var(--fg);
    }

    button.secondary {
        background: var(--bg2);
        color: var(--fg);
        border-color: var(--rule);
    }

    button.danger {
        color: #fff;
    }

    #error-msg {
        color: #fff;
    }
}
