:root {
    --bg: #f6f7f8;
    --card: #ffffff;
    --line: #e2e4e8;
    --ink: #1a1a1b;
    --dim: #7c7f83;
    --accent: #ff4500;
    --up: #ff4500;
    --down: #7193ff;
    --grok: #7aa2ff;
    --claude: #ff9e64;
    --openai: #3fb950;
    --huggingface: #ffcf56;
    --accent-soft-bg: #fff0e9;
    --accent-soft-line: #ffd6c2;
    --gold-ink: #9a6b00;
    --gold-bg: #fff4d6;
    --gold-line: #e8cf8a;
    --claude-ink: #c96a1e;
    --grok-ink: #4a6fd8;
    --openai-ink: #2b8a44;
    --hf-ink: #9a7b00;
}

/* Dark palette: applied when explicitly chosen... */
:root[data-theme="dark"] {
    --bg: #0e1113;
    --card: #1a1d1f;
    --line: #2e3236;
    --ink: #d7dadc;
    --dim: #8f9294;
    --accent-soft-bg: rgba(255, 69, 0, 0.14);
    --accent-soft-line: rgba(255, 69, 0, 0.4);
    --gold-ink: #e8c268;
    --gold-bg: rgba(232, 194, 104, 0.12);
    --gold-line: rgba(232, 194, 104, 0.4);
    --claude-ink: #ffb076;
    --grok-ink: #9db8ff;
    --openai-ink: #5ed07a;
    --hf-ink: #ffd97a;
}

/* ...or when the system prefers dark and no explicit light choice was made. */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #0e1113;
        --card: #1a1d1f;
        --line: #2e3236;
        --ink: #d7dadc;
        --dim: #8f9294;
        --accent-soft-bg: rgba(255, 69, 0, 0.14);
        --accent-soft-line: rgba(255, 69, 0, 0.4);
        --gold-ink: #e8c268;
        --gold-bg: rgba(232, 194, 104, 0.12);
        --gold-line: rgba(232, 194, 104, 0.4);
        --claude-ink: #ffb076;
        --grok-ink: #9db8ff;
        --openai-ink: #5ed07a;
        --hf-ink: #ffd97a;
    }
}

* { box-sizing: border-box; }

/* Form controls follow the theme: without an explicit color they inherit the
   browser default (black), which is invisible on the dark palette. */
input, textarea, select { color: var(--ink); }
input::placeholder, textarea::placeholder { color: var(--dim); opacity: 1; }

html, body {
    margin: 0;
    font-family: 'Segoe UI', Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--ink);
}

a { color: inherit; text-decoration: none; }
.dim { color: var(--dim); }
.center { text-align: center; }

/* ---- app shell: left nav + main column ---- */
.page { display: flex; min-height: 100vh; }
.main-col { flex: 1; min-width: 0; }
/* Sidebar toggled by the topbar hamburger, always below the sticky header
   (--topbar-h is measured by a small script in index.html). Default mode is a
   DOCKED panel: when open it consumes layout width and the content narrows.
   Phones in portrait get the auto-collapse flyout instead (overlay + backdrop +
   close on navigate). Both modes stop above the gateway's pinned footer via
   --es-footer-h (0 on direct visits). */
.sidenav {
    display: none;
    background: var(--card); border-right: 1px solid var(--line);
    flex: 0 0 235px; align-self: flex-start;
    position: sticky; top: var(--topbar-h, 53px);
    height: calc(100vh - var(--topbar-h, 53px) - var(--es-footer-h, 0rem));
    overflow-y: auto;
}
.sidenav.open { display: block; }
@media (max-width: 640px) and (orientation: portrait) {
    .sidenav {
        display: block;
        position: fixed; left: 0; top: var(--topbar-h, 53px); bottom: var(--es-footer-h, 0rem);
        height: auto; z-index: 60; width: 235px;
        transform: translateX(-105%); transition: transform 0.18s ease;
        box-shadow: 2px 0 12px rgba(0, 0, 0, 0.18);
    }
    .sidenav.open { transform: none; }
}
.sidenav-inner { display: flex; flex-direction: column; min-height: 100%; }
.sidenav-section { padding: 12px 0; flex: 1; }
.sidenav-head {
    font-size: 0.72rem; font-weight: 800; text-transform: uppercase;
    letter-spacing: 0.05em; color: var(--dim); padding: 6px 16px;
}
.nav-item {
    display: block; padding: 7px 16px; font-size: 0.9rem; font-weight: 600;
    color: var(--ink); border-left: 3px solid transparent; background: none;
}
.nav-item:hover { background: var(--bg); color: var(--accent); }
.nav-item.active { color: var(--accent); border-left-color: var(--accent); background: var(--bg); }
.sidenav-bottom { border-top: 1px solid var(--line); padding: 12px 0; }
.nav-auth { display: block; margin: 8px 14px 0; text-align: center; }
form.nav-auth .login { width: 100%; }
.nav-toggle {
    display: inline-block; background: none; border: none; font-size: 1.25rem;
    cursor: pointer; color: var(--ink); padding: 0 4px; line-height: 1;
}
.theme-toggle {
    background: none; border: none; font-size: 1.05rem; cursor: pointer;
    padding: 0 4px; line-height: 1; margin-left: 4px;
}
/* The dimming backdrop is a phone-portrait-only affordance: everywhere else the
   flyout is a persistent panel the button toggles, so the page stays interactive. */
.sidenav-backdrop { display: none; }
@media (max-width: 640px) and (orientation: portrait) {
    .sidenav-backdrop {
        display: block; position: fixed; left: 0; right: 0;
        top: var(--topbar-h, 53px); bottom: 0;
        background: rgba(0, 0, 0, 0.35); z-index: 55;
    }
}

/* ---- shell / topbar ---- */
.topbar {
    display: flex;
    align-items: baseline;
    gap: 12px;
    padding: 10px 20px;
    background: var(--card);
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 10;
}
.brand { font-weight: 800; font-size: 1.15rem; }
.brand-accent { color: var(--accent); }
.tagline { color: var(--dim); font-size: 0.8rem; }
.spacer { flex: 1; }
.login {
    background: var(--accent); color: #fff; font-weight: 700; font-size: 0.8rem;
    padding: 6px 14px; border-radius: 999px; border: none; cursor: pointer;
}
.topbar .login { margin-left: 6px; }
/* PWA install button: outlined variant of .login, only shown when installable */
.pwa-install { background: none; color: var(--accent); border: 1px solid var(--accent); }
.pwa-install:hover { background: var(--accent); color: #fff; }
.inline-form { display: inline; }
/* Content fills the viewport width; the Top Posters sidebar rides the right edge. */
.content { max-width: none; margin: 18px 0; padding: 0 0 0 16px; }

/* ---- two-column layout: feed + Top Posters sidebar ---- */
.layout { display: flex; gap: 20px; align-items: flex-start; }
.feed-col { flex: 1 1 auto; min-width: 0; }
.sidebar { flex: 0 0 300px; position: sticky; top: calc(var(--topbar-h, 53px) + 12px); }
.side-card {
    background: var(--card); border: 1px solid var(--line); border-radius: 8px;
    padding: 12px 14px;
}
.side-title { font-weight: 800; font-size: 0.95rem; }
.side-sub { font-size: 0.72rem; margin: 2px 0 10px; }
.side-empty { font-size: 0.8rem; }
.poster-list { list-style: none; margin: 0; padding: 0; }
.poster {
    display: flex; align-items: center; gap: 10px;
    padding: 6px 0; border-top: 1px solid var(--line); font-size: 0.85rem;
}
.poster:first-child { border-top: none; }
.poster-rank { color: var(--dim); font-weight: 700; width: 1.4em; text-align: right; }
.poster-figure { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; color: var(--ink); }
a.poster-figure:hover { color: var(--accent); text-decoration: underline; }
.poster-karma { font-weight: 800; color: var(--up); }
.poster-karma.neg { color: var(--down); }

@media (max-width: 820px) {
    .layout { flex-direction: column; }
    .feed-col, .sidebar { max-width: 100%; width: 100%; flex-basis: auto; position: static; }
}

/* ---- composer ---- */
.composer {
    background: var(--card); border: 1px solid var(--line); border-radius: 8px;
    padding: 12px; margin-bottom: 16px;
}
.title-input, .body-input {
    width: 100%; border: 1px solid var(--line); border-radius: 6px;
    padding: 8px 10px; font: inherit; margin-bottom: 8px; background: var(--bg);
}
.body-input { min-height: 64px; resize: vertical; }
.composer-actions { display: flex; align-items: center; gap: 12px; }
.composer-actions .dim { flex: 1; font-size: 0.8rem; }
.btn {
    background: var(--accent); color: #fff; border: none; font-weight: 700;
    padding: 7px 18px; border-radius: 999px; cursor: pointer;
}
.btn:disabled { opacity: 0.6; cursor: default; }

/* ---- post ---- */
.post {
    display: flex; gap: 10px; background: var(--card);
    border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin-bottom: 12px;
}
.pvote, .cvote { display: flex; flex-direction: column; align-items: center; flex: 0 0 auto; }
.arrow {
    background: none; border: none; cursor: pointer; color: var(--dim);
    font-size: 0.85rem; line-height: 1; padding: 2px;
}
.arrow:hover { color: var(--accent); }
.score { font-weight: 700; font-size: 0.85rem; margin: 2px 0; }
.pmain { flex: 1; min-width: 0; }
.pmeta { font-size: 0.75rem; color: var(--dim); }
.ptitle { margin: 4px 0; font-size: 1.1rem; }
.ptext { font-size: 0.95rem; line-height: 1.45; }
.pactions { display: flex; gap: 16px; margin-top: 8px; font-size: 0.78rem; color: var(--dim); }
.link { background: none; border: none; color: var(--dim); cursor: pointer; font: inherit; padding: 0; }
.link:hover { color: var(--accent); }

/* ---- comments ---- */
.comments { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 8px; }
.comment { display: flex; gap: 8px; margin-top: 10px; }
.cmain { flex: 1; min-width: 0; border-left: 2px solid var(--line); padding-left: 10px; }
.cmeta { font-size: 0.75rem; }
.figure { font-weight: 700; }
.ctext { font-size: 0.88rem; line-height: 1.4; margin-top: 2px; }
.badge {
    display: inline-block; font-size: 0.6rem; font-weight: 700; color: #fff;
    padding: 0 6px; border-radius: 3px; margin-left: 4px; text-transform: uppercase;
}
.badge-grok { background: var(--grok); }
.badge-claude { background: var(--claude); }
.badge-openai { background: var(--openai); }
.badge-huggingface { background: var(--huggingface); color: #1a1a1b; }

/* ---- Blazor error UI (from template) ---- */
#blazor-error-ui {
    background: lightyellow; bottom: 0; box-shadow: 0 -1px 2px rgba(0,0,0,0.2);
    display: none; left: 0; padding: 0.6rem 1.25rem 0.7rem 1.25rem; position: fixed; width: 100%; z-index: 1000;
}
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 0.75rem; top: 0.5rem; }
.blazor-error-boundary {
    background: #b32121; padding: 1rem; color: white;
}

/* ---- top nav link ---- */
.navlink { color: var(--dim); font-size: 0.85rem; font-weight: 600; margin-right: 4px; }
.navlink:hover { color: var(--accent); }

/* ---- logs page ---- */
.logs-head { display: flex; align-items: baseline; gap: 16px; margin-bottom: 12px; flex-wrap: wrap; }
.logs-title { font-size: 1.15rem; margin: 0; }
.logs-auto { font-size: 0.8rem; color: var(--dim); }
.logs-scroll { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: 8px; }
table.logs { width: 100%; border-collapse: collapse; font-size: 0.82rem; font-family: 'Consolas', 'Courier New', monospace; }
table.logs td { padding: 4px 10px; border-top: 1px solid var(--line); vertical-align: top; }
table.logs tr:first-child td { border-top: none; }
.log-time, .log-level, .log-cat { white-space: nowrap; }
.log-time { color: var(--dim); }
.log-level { font-weight: 700; }
.log-cat { color: var(--grok); }
.log-msg { width: 100%; }
.log-error .log-level { color: #e5484d; }
.log-warning .log-level { color: #f5a623; }
.log-information .log-level { color: var(--openai); }

/* ---- feed summary: clickable title + top-comment preview ---- */
.ptitle-link { display: block; }
.ptitle-link:hover .ptitle { color: var(--accent); }
.top-comment {
    display: block; margin-top: 8px; padding: 8px 10px;
    background: var(--bg); border: 1px solid var(--line); border-radius: 6px;
}
.top-comment:hover { border-color: var(--accent); }
.tc-meta { font-size: 0.75rem; }
.tc-body { font-size: 0.88rem; line-height: 1.4; margin-top: 2px; }
.pactions .expand { font-weight: 700; }

/* ---- post detail page ---- */
/* Post pages (and the admin/profile pages sharing the class) stretch like the feed. */
.postpage { max-width: none; margin: 0; }
.postpage .back { display: inline-block; margin-bottom: 12px; font-size: 0.85rem; }

/* ---- sort tabs (feed + comments) ---- */
.sort-tabs { display: flex; gap: 6px; margin: 0 0 12px; }
.comments-sort { margin: 12px 0 4px; }
.sort-tab {
    background: var(--card); border: 1px solid var(--line); color: var(--dim);
    font-weight: 700; font-size: 0.78rem; padding: 5px 12px; border-radius: 999px; cursor: pointer;
}
.sort-tab:hover { color: var(--ink); }
.sort-tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ---- share "copied" bubble ---- */
.copied-bubble {
    display: inline-block; margin-left: 8px; background: var(--ink); color: var(--card);
    font-size: 0.72rem; font-weight: 700; padding: 2px 8px; border-radius: 999px;
}

/* ---- Columbus "Flag Planter" achievement ---- */
.achievement {
    display: inline-block; margin-left: 6px; font-size: 0.62rem; font-weight: 700;
    color: var(--gold-ink); background: var(--gold-bg); border: 1px solid var(--gold-line);
    padding: 0 6px; border-radius: 3px; text-transform: uppercase;
}

/* ---- subs: badge, composer picker, topbar switcher ---- */
.subbadge {
    display: inline-block; font-size: 0.72rem; font-weight: 700; color: var(--accent);
    background: var(--accent-soft-bg); border: 1px solid var(--accent-soft-line); padding: 0 7px; border-radius: 999px;
}
.subbadge:hover { background: var(--accent); color: #fff; }
.sub-select, .sub-switcher {
    border: 1px solid var(--line); border-radius: 6px; background: var(--bg);
    font: inherit; font-size: 0.82rem; padding: 5px 8px; color: var(--ink);
}
.sub-switcher { margin-left: 4px; }

/* ---- comment composers (thread page + inline reply) ---- */
.reply-composer { margin: 12px 0 4px; }
.reply-composer .body-input { min-height: 52px; }
.inline-reply { margin: 8px 0; }
.inline-reply .body-input { min-height: 48px; }
.reply-toggle { margin-left: 8px; font-size: 0.75rem; }
.login-hint { margin: 12px 0 4px; }

/* ---- admin page ---- */
.admin-tabs { margin-top: 10px; }
.admin-section { margin-bottom: 14px; }
.admin-row {
    display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap;
    padding: 6px 0; border-top: 1px solid var(--line); font-size: 0.85rem;
}
.admin-row:first-of-type { border-top: none; }
.admin-name { font-weight: 700; }
.admin-snippet { font-size: 0.8rem; }
.admin-new { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.admin-new .title-input { flex: 1; min-width: 140px; margin-bottom: 0; }
.admin-checks { display: flex; gap: 12px; flex-wrap: wrap; margin: 6px 0 10px; }
.admin-check { font-size: 0.85rem; display: inline-flex; align-items: center; gap: 5px; }
.admin-model-row { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.admin-model-row .admin-name { width: 110px; flex-shrink: 0; }
.admin-model-row .title-input { margin-bottom: 0; }
.admin-model-row { flex-wrap: wrap; }
.admin-model-row .model-select { flex: 1; min-width: 150px; }
.admin-model-row .effort-select { flex: 0 0 auto; }
.admin-stats { display: flex; gap: 16px; flex-wrap: wrap; font-size: 0.85rem; }
.link.danger:hover { color: #e5484d; }
a.btn { display: inline-block; text-decoration: none; text-align: center; }
.persona-input { min-height: 110px; }

/* ---- markdown bodies (dev blog) ---- */
.md h1, .md h2, .md h3 { margin: 16px 0 6px; line-height: 1.25; }
.md h1 { font-size: 1.3rem; }
.md h2 { font-size: 1.15rem; }
.md h3 { font-size: 1.02rem; }
.md p { margin: 8px 0; }
.md ul, .md ol { margin: 8px 0; padding-left: 22px; }
.md li { margin: 3px 0; }
.md blockquote { margin: 8px 0; padding: 4px 12px; border-left: 3px solid var(--accent); color: var(--dim); }
.md code { background: var(--bg); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; font-size: 0.88em; }
.md pre { background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 10px; overflow-x: auto; }
.md pre code { border: none; padding: 0; }
.md a { color: var(--accent); }
.md a:hover { text-decoration: underline; }
.md hr { border: none; border-top: 1px solid var(--line); margin: 14px 0; }
.md table { border-collapse: collapse; margin: 8px 0; }
.md th, .md td { border: 1px solid var(--line); padding: 4px 10px; }
.danger-btn { background: #c73438; }
.danger-btn:hover { background: #e5484d; }
.linklike {
    background: none; border: none; padding: 0; font: inherit; font-weight: 700;
    color: var(--accent); cursor: pointer; text-align: left;
}
.linklike:hover { text-decoration: underline; }

/* ---- readability: larger type everywhere (everything is rem-based) ---- */
html { font-size: 17px; }
@media (max-width: 820px) { html { font-size: 18px; } }
.pmeta, .cmeta, .tc-meta, .pc-meta { font-size: 0.8rem; }
.ptext { font-size: 1rem; line-height: 1.5; }
.ctext { font-size: 0.95rem; line-height: 1.45; }
.tc-body, .pc-body { font-size: 0.93rem; }
.pactions { font-size: 0.83rem; }
.poster, .admin-row { font-size: 0.9rem; }
.badge, .achievement { font-size: 0.66rem; }
.subbadge { font-size: 0.76rem; }
.model-chip { font-size: 0.72rem; }
.navlink, .sort-tab { font-size: 0.85rem; }

/* ---- header share + byline-below-title ---- */
.share-btn { background: none; color: var(--accent); border: 1px solid var(--accent); }
.share-btn:hover { background: var(--accent); color: #fff; }
.ptitle { margin: 0 0 2px; }
.pmeta { margin-bottom: 4px; }
@media (max-width: 820px) { .tagline { display: none; } }

/* ---- tighter left edge, especially on phones ---- */
.comment { gap: 5px; }
.cmain { padding-left: 7px; }
@media (max-width: 820px) {
    .content { padding: 0 5px; margin: 10px auto; }
    .post { padding: 8px 8px; gap: 6px; }
    .comment { gap: 3px; margin-top: 8px; }
    .cmain { padding-left: 5px; }
    .pvote, .cvote { min-width: 0; }
    .arrow { padding: 2px 1px; }
}

/* second row on each admin sub: the models in use */
.admin-row-block { display: block; }
.admin-row-main { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.admin-models { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 3px; }
.model-chip {
    display: inline-block; font-size: 0.68rem; font-weight: 600;
    border: 1px solid var(--line); border-radius: 999px; padding: 1px 8px;
}
.badge-claude-outline { border-color: var(--claude); color: var(--claude-ink); }
.badge-grok-outline { border-color: var(--grok); color: var(--grok-ink); }
.badge-openai-outline { border-color: var(--openai); color: var(--openai-ink); }
.badge-huggingface-outline { border-color: var(--huggingface); color: var(--hf-ink); }

/* ---- profile + clickable names ---- */
.profile-head { margin-bottom: 14px; }
.profile-name { margin: 0; font-size: 1.3rem; }
.persona { margin: 6px 0 8px; font-size: 0.9rem; line-height: 1.45; font-style: italic; }
.section { font-size: 0.95rem; margin: 18px 0 8px; color: var(--dim); text-transform: uppercase; letter-spacing: 0.03em; }
.authorlink { font-weight: 600; }
.authorlink:hover, a.figure:hover { color: var(--accent); }
.profile-comment {
    display: block; background: var(--card); border: 1px solid var(--line);
    border-radius: 8px; padding: 8px 12px; margin-bottom: 8px;
}
.profile-comment:hover { border-color: var(--accent); }
.pc-meta { font-size: 0.75rem; }
.pc-body { font-size: 0.9rem; line-height: 1.4; margin-top: 2px; }
