:root {
    --bg: #f7f8fa;
    --surface: #ffffff;
    --surface-2: #f3f4f7;
    --ink: #16181d;
    --ink-soft: #3c414d;
    --muted: #6e7484;
    --faint: #a6abba;
    --line: #e9eaef;
    --line-strong: #dcdee6;
    --brand: #003fdb;
    --brand-dark: #0034b4;
    --brand-soft: #eaf0ff;
    --upvote: #ef5f2b;
    --downvote: #5b63e8;
    --r-sm: 8px;
    --r: 12px;
    --r-lg: 16px;
    --pill: 999px;
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.04);
    --shadow-md: 0 10px 28px -14px rgba(16, 24, 40, 0.22);
    --ring: 0 0 0 3px rgba(0, 63, 219, 0.16);
    --font: "DM Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
    --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
    --header-h: 61px;
}

* { box-sizing: border-box; }
html {
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}
body {
    margin: 0;
    font-family: var(--font);
    font-size: 0.975rem;
    color: var(--ink);
    background: var(--bg);
    line-height: 1.55;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    overflow-x: clip;
}
img { max-width: 100%; height: auto; }

a { color: var(--brand-dark); text-decoration: none; }
a:hover { text-decoration: underline; }
svg { display: block; }

:focus-visible {
    outline: 2px solid var(--brand);
    outline-offset: 2px;
    border-radius: 4px;
}

.sr-only, .d-none, [hidden] {
    position: absolute !important;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0, 0, 0, 0);
    border: 0;
}
.is-hidden { display: none !important; }

.skip-link {
    position: absolute; left: -999px; top: 0; z-index: 100;
    background: var(--ink); color: #fff;
    padding: 0.6rem 1rem; border-radius: 0 0 var(--r-sm) 0;
    font-size: 0.88rem; font-weight: 600;
}
.skip-link:focus { left: 0; text-decoration: none; }

.container { width: min(1080px, calc(100% - 2.5rem)); margin: 0 auto; }

/* ---------- Header ---------- */

.site-header {
    position: sticky; top: 0; z-index: 50;
    background: rgba(255, 255, 255, 0.82);
    backdrop-filter: blur(14px) saturate(1.4);
    border-bottom: 1px solid var(--line);
}
.header-inner {
    display: flex; align-items: center; gap: 1rem;
    padding: 0.7rem 0; flex-wrap: wrap;
}

.brand {
    display: flex; align-items: center; gap: 0.55rem;
    color: inherit; text-decoration: none;
}
.brand:hover { text-decoration: none; }
.brand-logo { height: 26px; width: auto; }
.brand-tag {
    padding: 0.16rem 0.45rem; border-radius: 6px;
    background: var(--surface-2); color: var(--muted);
    font-size: 0.66rem; font-weight: 700;
    text-transform: uppercase; letter-spacing: 0.09em;
}

.header-search { flex: 1 1 220px; max-width: 440px; margin: 0 auto; }
.search-field { position: relative; display: block; }
.search-icon {
    position: absolute; left: 0.8rem; top: 50%; transform: translateY(-50%);
    width: 16px; height: 16px; color: var(--faint); pointer-events: none;
}
.header-search input {
    width: 100%; border: 1px solid transparent; border-radius: var(--pill);
    background: var(--surface-2); color: var(--ink);
    padding: 0.55rem 0.9rem 0.55rem 2.3rem;
    font: inherit; font-size: 0.9rem;
    transition: background-color 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.header-search input::placeholder { color: var(--muted); }
.header-search input:focus {
    outline: none; background: #fff;
    border-color: var(--line-strong); box-shadow: var(--ring);
}

/* Cached pages ship both signed-in and signed-out markup; the skc-authed class
   is set on <html> from the identity cookie before first paint, so only the
   wrong half is ever hidden and the visible half keeps its own display value. */
html:not(.skc-authed) .skc-user-only { display: none; }
html.skc-authed .skc-guest-only { display: none; }

.header-actions { display: flex; align-items: center; gap: 0.85rem; }
.user-chip {
    display: inline-flex; align-items: center; gap: 0.4rem;
    color: var(--ink); font-weight: 600; font-size: 0.88rem;
}
.user-chip:hover { text-decoration: none; color: var(--brand-dark); }
/* Scoped to the chip so it outranks the smaller byline .avatar size. */
.user-chip .avatar { width: 24px; height: 24px; font-size: 0.78rem; }
.text-link { color: var(--muted); font-size: 0.86rem; }
.text-link:hover { color: var(--ink); text-decoration: none; }

.ask-label-short { display: none; }
.btn-ask .ask-label-full,
.btn-ask .ask-label-short { line-height: 1; }

.submit-guest-note {
    margin: 0 0 1rem;
    padding: 0.7rem 0.85rem;
    background: var(--brand-soft);
    border-radius: var(--r);
    color: var(--ink-soft);
    font-size: 0.9rem;
}
.draft-ready {
    display: flex; flex-wrap: wrap; align-items: center; gap: 0.65rem 0.75rem;
    margin: 0 0 1.1rem; padding: 0.85rem 1rem;
    background: #f3f8ff; border: 1px solid #c9dbff;
    border-radius: var(--r-lg);
}
.draft-ready[hidden] { display: none !important; }
.draft-ready p {
    margin: 0; flex: 1 1 12rem;
    font-weight: 600; color: var(--ink); letter-spacing: -0.01em;
}
.modal-actions { margin-top: 1.15rem; flex-wrap: wrap; }
.modal-dialog p { line-height: 1.45; }


/* ---------- Buttons ---------- */

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
    border: 1px solid transparent; border-radius: var(--pill);
    padding: 0.55rem 1.05rem;
    font: inherit; font-size: 0.89rem; font-weight: 600; line-height: 1.2;
    cursor: pointer; text-decoration: none; white-space: nowrap;
    transition: background-color 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-primary:disabled { background: var(--faint); cursor: default; }
.btn-secondary { background: var(--surface-2); color: var(--ink); }
.btn-secondary:hover { background: #e7e9ef; }
.btn-ghost { background: transparent; color: var(--muted); border-color: var(--line-strong); }
.btn-ghost:hover { color: var(--ink); background: var(--surface-2); }
.btn-block { width: 100%; }

/* ---------- Layout ---------- */

.layout-grid {
    display: grid; grid-template-columns: 208px minmax(0, 1fr);
    gap: 2.25rem; padding: 1.75rem 0 4rem; align-items: start;
}
.sidebar, .main { min-width: 0; }
.sidebar { position: sticky; top: calc(var(--header-h) + 1.25rem); }

.sidebar-nav { margin-bottom: 1.5rem; }
.sidebar-title {
    margin: 0 0 0.5rem; padding-left: 0.65rem;
    font-size: 0.68rem; font-weight: 700; text-transform: uppercase;
    letter-spacing: 0.1em; color: var(--faint);
}
/* Every community carries its own --cc, set inline from skc_community_theme(),
   which tints its sidebar row, its chips on cards, and its page banner. */
.community-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.12rem; }
.community-link {
    display: flex; align-items: center; gap: 0.55rem;
    padding: 0.36rem 0.55rem; border-radius: var(--r-sm);
    color: var(--ink-soft); font-size: 0.9rem; font-weight: 500;
    text-decoration: none; transition: background-color 0.12s, color 0.12s;
}
.community-icon {
    display: grid; place-items: center; flex: none;
    width: 25px; height: 25px; border-radius: 7px;
    background: color-mix(in srgb, var(--cc) 14%, #fff);
    color: var(--cc);
    transition: background-color 0.12s, color 0.12s;
}
.community-icon svg { width: 14px; height: 14px; }
.community-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.community-link:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.community-link:hover .community-icon { background: color-mix(in srgb, var(--cc) 24%, #fff); }
.community-link.is-active {
    background: color-mix(in srgb, var(--cc) 10%, #fff);
    color: var(--ink); font-weight: 600;
}
.community-link.is-active .community-icon { background: var(--cc); color: #fff; }

.sidebar-about {
    background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--r-lg); padding: 1.05rem;
}
.sidebar-about .sidebar-title { padding-left: 0; }
.sidebar-copy { margin: 0 0 0.9rem; color: var(--muted); font-size: 0.86rem; line-height: 1.5; }

/* ---------- Sort tabs / breadcrumbs / hero ---------- */

.sort-tabs {
    display: inline-flex; gap: 0.15rem; margin-bottom: 1.15rem;
    padding: 0.2rem; background: var(--surface-2); border-radius: var(--pill);
}
.sort-tab {
    display: inline-flex; align-items: center; gap: 0.35rem;
    padding: 0.38rem 0.85rem; border-radius: var(--pill);
    color: var(--muted); font-size: 0.85rem; font-weight: 600; text-decoration: none;
    transition: background-color 0.15s, color 0.15s, box-shadow 0.15s;
}
.sort-tab svg { width: 14px; height: 14px; }
.sort-tab:hover { color: var(--ink); text-decoration: none; }
.sort-tab.is-active { background: #fff; color: var(--brand-dark); box-shadow: var(--shadow-sm); }

.breadcrumbs {
    display: flex; align-items: center; flex-wrap: wrap; gap: 0.4rem;
    margin: 0 0 1.1rem; font-size: 0.82rem; color: var(--muted);
}
.breadcrumbs a { color: var(--muted); }
.breadcrumbs a:hover { color: var(--ink); text-decoration: none; }
.breadcrumbs a:last-child { color: var(--ink); font-weight: 600; }
.breadcrumbs .sep { color: var(--line-strong); }

.page-hero { margin-bottom: 1.25rem; }
.page-hero h1 {
    margin: 0 0 0.3rem;
    font-size: clamp(1.5rem, 2.2vw, 1.85rem);
    font-weight: 700; letter-spacing: -0.025em; line-height: 1.15;
}
.page-hero p { margin: 0; color: var(--muted); font-size: 0.94rem; max-width: 62ch; }

.hero-banner {
    display: flex; align-items: center; gap: 0.95rem;
    padding: 1.1rem 1.25rem;
    border: 1px solid color-mix(in srgb, var(--cc) 20%, var(--line));
    border-radius: var(--r-lg);
    background: radial-gradient(130% 150% at 0% 0%, color-mix(in srgb, var(--cc) 13%, #fff), #fff 64%);
}
.hero-icon {
    position: relative; overflow: hidden;
    display: grid; place-items: center; flex: none;
    width: 46px; height: 46px; border-radius: 14px;
    background: var(--cc); color: #fff;
    box-shadow: 0 7px 18px -7px color-mix(in srgb, var(--cc) 75%, transparent);
}
.hero-avatar { font-size: 1.25rem; font-weight: 700; line-height: 1; }
.hero-text { min-width: 0; }
.hero-banner h1 { margin: 0; font-size: clamp(1.35rem, 2vw, 1.65rem); }
.hero-banner p { margin: 0.1rem 0 0; }
.profile .hero-banner { flex-wrap: wrap; }
.hero-actions { margin-left: auto; flex: none; }
.hero-actions .btn { padding: 0.4rem 0.85rem; font-size: 0.82rem; }

.username-editor {
    margin: -0.35rem 0 1.25rem;
    padding: 1rem 1.15rem;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
}
.username-field {
    display: flex; align-items: center;
    border: 1px solid var(--line-strong); border-radius: var(--r);
    background: #fff; overflow: hidden;
}
.username-field:focus-within { border-color: var(--brand); box-shadow: var(--ring); }
.username-prefix {
    padding: 0.65rem 0.15rem 0.65rem 0.8rem;
    color: var(--muted); font-weight: 600;
}
.username-field input {
    flex: 1 1 auto; min-width: 0;
    border: 0; border-radius: 0; padding: 0.65rem 0.8rem 0.65rem 0.15rem;
    font: inherit; font-size: 0.95rem; color: var(--ink); background: transparent;
}
.username-field input:focus { outline: none; box-shadow: none; }
.username-status { margin: 0.55rem 0 0; min-height: 1.2em; font-size: 0.84rem; color: var(--muted); }
.username-status.is-ok { color: #067647; }
.username-status.is-taken { color: #b42318; }

.profile-editor {
    margin: -0.35rem 0 1.25rem;
    padding: 1rem 1.15rem;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
}
.profile-form label {
    display: block; margin: 0 0 0.4rem;
    font-weight: 600; font-size: 0.88rem; color: var(--ink);
}
.profile-form label:not(:first-child) { margin-top: 0.9rem; }
.profile-field {
    position: relative;
}
.profile-field input,
.profile-field textarea {
    width: 100%; padding: 0.65rem 3.5rem 0.65rem 0.8rem;
    border: 1px solid var(--line-strong); border-radius: var(--r);
    font: inherit; font-size: 0.95rem; color: var(--ink); background: #fff;
}
.profile-field textarea {
    resize: vertical; min-height: 4.5rem; font-family: inherit; line-height: 1.5;
}
.profile-field input:focus,
.profile-field textarea:focus {
    outline: none; border-color: var(--brand); box-shadow: var(--ring);
}
.char-counter {
    position: absolute; right: 0.7rem; top: 0.7rem;
    font-size: 0.77rem; color: var(--muted); font-weight: 500;
    pointer-events: none;
}
.profile-field textarea + .char-counter { top: 0.65rem; }
.profile-status {
    margin: 0.55rem 0 0; min-height: 1.2em; font-size: 0.84rem; color: var(--muted);
}
.profile-status.is-error { color: #b42318; }
.profile-username {
    margin: 0.25rem 0 0; font-size: 0.92rem; color: var(--muted);
}
.profile-bio {
    margin: 0.65rem 0 0; font-size: 0.92rem; color: var(--ink-soft); line-height: 1.5;
}
.profile-stats {
    margin: 0.25rem 0 0; font-size: 0.92rem; color: var(--muted);
}

/* ---------- Post cards ---------- */

.post-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.6rem; }
.post-card {
    display: grid; grid-template-columns: 34px minmax(0, 1fr); gap: 0.9rem;
    background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--r-lg); padding: 1rem 1.15rem;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.post-list .post-card:hover {
    border-color: color-mix(in srgb, var(--cc) 32%, var(--line));
    box-shadow: var(--shadow-md);
}
.post-card--detail { padding: 1.4rem 1.5rem; margin-bottom: 1.75rem; }
.post-card-body, .comment-body { min-width: 0; }
.post-title, .post-excerpt, .post-body, .comment-text { overflow-wrap: anywhere; }

.post-meta {
    display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem;
    font-size: 0.79rem; color: var(--muted); margin-bottom: 0.45rem;
}
.post-meta a { color: var(--muted); font-weight: 500; }
.post-meta a:hover { color: var(--ink); text-decoration: none; }
.post-meta time { color: var(--faint); }
.dot { color: var(--line-strong); }

.chip {
    display: inline-flex; align-items: center; gap: 0.28rem;
    padding: 0.14rem 0.55rem 0.14rem 0.42rem; border-radius: var(--pill);
    background: color-mix(in srgb, var(--cc, var(--brand)) 12%, #fff);
    color: color-mix(in srgb, var(--cc, var(--brand)) 80%, #000) !important;
    font-size: 0.75rem; font-weight: 600;
    transition: background-color 0.12s;
}
.chip svg { width: 13px; height: 13px; flex: none; }
.chip:hover { background: color-mix(in srgb, var(--cc, var(--brand)) 20%, #fff); text-decoration: none; }

/* Initial-and-colour avatars: enough to tell authors apart in a thread
   without storing images or calling out to a third-party avatar service. */
.avatar {
    position: relative; overflow: hidden;
    display: inline-grid; place-items: center; flex: none;
    width: 19px; height: 19px; border-radius: 50%;
    background: var(--av, var(--brand)); color: #fff;
    font-size: 0.63rem; font-weight: 700; line-height: 1;
}
/* Covers the initial when the image server has a photo for this user; the
   markup removes the image on error, which uncovers the initial again. */
.avatar-photo {
    position: absolute; inset: 0;
    width: 100%; height: 100%;
    object-fit: cover; border-radius: inherit;
    /* --av on bylines, --cc on the profile banner, so a photo with
       transparency sits on the same colour as the initial it replaced. */
    background: var(--av, var(--cc, var(--brand)));
}
.byline { display: inline-flex; align-items: center; gap: 0.35rem; }

.tag-answer {
    display: inline-flex; align-items: center;
    padding: 0.1rem 0.5rem; border-radius: var(--pill);
    background: #fff4e3; color: #9a5b06;
    font-size: 0.72rem; font-weight: 700;
}

.post-title { margin: 0 0 0.35rem; font-size: 1.04rem; font-weight: 600; letter-spacing: -0.012em; line-height: 1.38; }
.post-title a { color: inherit; text-decoration: none; }
.post-title a:hover { color: var(--brand-dark); }
.post-card--detail .post-title {
    font-size: clamp(1.3rem, 2vw, 1.55rem); line-height: 1.25;
    letter-spacing: -0.025em; margin-bottom: 0.15rem;
}

.post-excerpt { margin: 0; color: var(--muted); font-size: 0.9rem; line-height: 1.55; }
.post-body { margin-top: 0.85rem; color: var(--ink-soft); font-size: 1rem; line-height: 1.7; }
.post-body a { text-decoration: underline; text-underline-offset: 2px; }

.post-footer {
    display: flex; align-items: center; gap: 1rem;
    margin-top: 0.85rem; font-size: 0.82rem; color: var(--muted);
}
.post-card--detail .post-footer { padding-top: 0.9rem; border-top: 1px solid var(--line); }
.meta-action {
    display: inline-flex; align-items: center; gap: 0.35rem;
    color: var(--muted); font-weight: 600;
}
.meta-action:hover { color: var(--ink); text-decoration: none; }
.meta-action svg { width: 15px; height: 15px; }
.meta-action--link { color: var(--brand-dark); }
.meta-action--link:hover { color: var(--brand); }

/* ---------- Voting ---------- */

.vote { display: flex; flex-direction: column; align-items: center; gap: 0.05rem; }
.vote-btn {
    display: grid; place-items: center;
    width: 26px; height: 23px; padding: 0;
    border: 0; border-radius: 7px; background: transparent;
    color: var(--faint); cursor: pointer;
    transition: background-color 0.12s, color 0.12s;
}
.vote-btn svg { width: 14px; height: 14px; pointer-events: none; }
.vote-btn:hover { background: var(--surface-2); color: var(--ink); }
.vote-up:hover, .vote-btn.is-up { color: var(--upvote); }
.vote-down:hover, .vote-btn.is-down { color: var(--downvote); }
.vote-btn.is-up { background: rgba(239, 95, 43, 0.1); }
.vote-btn.is-down { background: rgba(91, 99, 232, 0.1); }
.vote-score {
    font-size: 0.8rem; font-weight: 700; color: var(--ink);
    font-variant-numeric: tabular-nums; min-width: 1.5rem; text-align: center;
}

/* ---------- Comments ---------- */

.comments-heading, .section-title {
    display: flex; align-items: center; gap: 0.5rem;
    margin: 0 0 1rem; font-size: 1rem; font-weight: 700; letter-spacing: -0.015em;
}
.section-title { margin-top: 2rem; }
.comments-heading > svg, .section-title > svg { width: 17px; height: 17px; flex: none; color: var(--faint); }
.count-badge {
    display: inline-flex; justify-content: center; min-width: 1.35rem;
    padding: 0.05rem 0.4rem; border-radius: var(--pill);
    background: var(--surface-2); color: var(--muted);
    font-size: 0.76rem; font-weight: 600;
}

.comment-thread { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.35rem; }
.comment { padding: 0.2rem 0; }
.comment-row { display: grid; grid-template-columns: 30px minmax(0, 1fr); gap: 0.75rem; }
.comment-children {
    margin: 0.4rem 0 0 0.9rem; padding-left: 1rem;
    border-left: 1px solid var(--line);
}
.comment-meta {
    display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem;
    font-size: 0.8rem; color: var(--muted);
}
.comment-author {
    display: inline-flex; align-items: center; gap: 0.35rem;
    color: var(--ink); font-weight: 600;
}
.comment-author:hover { text-decoration: none; color: var(--brand-dark); }
.comment-meta time { color: var(--faint); }
.comment-text { margin: 0.3rem 0 0; color: var(--ink-soft); font-size: 0.95rem; line-height: 1.65; }
.comment-actions { margin-top: 0.4rem; }

.text-btn {
    border: 0; background: transparent; color: var(--muted);
    font: inherit; font-size: 0.82rem; font-weight: 600;
    cursor: pointer; padding: 0;
}
.text-btn:hover { color: var(--brand-dark); }
.thread-toggle {
    display: inline-grid; place-items: center;
    width: 20px; height: 20px; padding: 0;
    border: 0; border-radius: 6px; background: transparent;
    color: var(--faint); cursor: pointer;
    font-family: var(--mono); font-size: 0.7rem;
}
.thread-toggle:hover { background: var(--surface-2); color: var(--ink); }
.comment.is-collapsed > .comment-row .comment-text,
.comment.is-collapsed > .comment-row .comment-actions,
.comment.is-collapsed > .comment-row .reply-slot,
.comment.is-collapsed > .comment-children { display: none; }

/* Posting an answer lands on it, and in a long thread the reply that was just
   written needs to stand out from the ones around it. */
.comment:target > .comment-row {
    border-radius: var(--r);
    outline: 2px solid color-mix(in srgb, var(--brand) 35%, transparent);
    outline-offset: 6px;
    animation: skc-settle 2.6s ease-out forwards;
}
@keyframes skc-settle {
    0%, 55% { background: var(--brand-soft); }
    100% { background: transparent; outline-color: transparent; }
}

/* ---------- Forms ---------- */

.comment-form, .comment-login-cta {
    background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--r-lg); padding: 1.15rem 1.25rem; margin-top: 1.75rem;
}
.comment-form label, .auth-form label, .submit-form label {
    display: block; font-weight: 600; font-size: 0.89rem; margin: 0 0 0.45rem;
}
.auth-form label, .submit-form label { margin-top: 1.05rem; }
.auth-form label:first-of-type, .submit-form label:first-of-type { margin-top: 0; }
.comment-login-cta { color: var(--muted); font-size: 0.92rem; }

.answer-form { scroll-margin-top: calc(var(--header-h) + 1rem); }
.answer-head { margin-bottom: 0.85rem; }
.answer-title {
    margin: 0; font-size: 1.05rem; font-weight: 700; letter-spacing: -0.015em;
}
.answer-byline {
    display: flex; align-items: center; gap: 0.4rem;
    margin: 0.3rem 0 0; color: var(--muted); font-size: 0.86rem;
}
.answer-byline .avatar { --av: var(--brand); width: 20px; height: 20px; font-size: 0.66rem; }

.form-note { color: var(--muted); font-size: 0.82rem; }

.reply-form {
    background: var(--surface-2); border-radius: var(--r);
    padding: 0.85rem; margin-top: 0.6rem;
}

.header-search input,
.auth-form input, .submit-form input, .submit-form textarea, .submit-form select,
.comment-form textarea, .reply-form textarea, .search-form input {
    font-family: inherit;
}
.auth-form input, .submit-form input, .submit-form textarea, .submit-form select,
.comment-form textarea, .reply-form textarea, .search-form input {
    width: 100%; border: 1px solid var(--line-strong); border-radius: var(--r);
    padding: 0.7rem 0.85rem; font-size: 0.95rem; color: var(--ink);
    background: #fff; transition: border-color 0.15s, box-shadow 0.15s;
}
.auth-form input:focus, .submit-form input:focus, .submit-form textarea:focus,
.submit-form select:focus, .comment-form textarea:focus, .reply-form textarea:focus,
.search-form input:focus {
    outline: none; border-color: var(--brand); box-shadow: var(--ring);
}
.comment-form textarea, .reply-form textarea, .submit-form textarea { resize: vertical; }
::placeholder { color: var(--faint); }

/* ---------- Rich text editor ---------- */

.rte {
    position: relative;
    border: 1px solid var(--line-strong); border-radius: var(--r);
    background: #fff; overflow: hidden;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.rte:focus-within { border-color: var(--brand); box-shadow: var(--ring); }
/* Dragging a screenshot anywhere over the editor shows where it will land. */
.rte.is-dropping { border-color: var(--brand); border-style: dashed; background: var(--brand-soft); }
.rte.is-dropping textarea { background: transparent; }
/* Children would otherwise swallow the drop and fire dragleave on every hop. */
.rte.is-dropping * { pointer-events: none; }
.rte textarea,
.comment-form .rte textarea, .reply-form .rte textarea, .submit-form .rte textarea {
    display: block; border: 0; border-radius: 0;
    min-height: 11rem; line-height: 1.65;
    /* The box grows with its content, so a drag handle would only fight it. */
    resize: none;
}
.rte textarea:focus,
.comment-form .rte textarea:focus, .reply-form .rte textarea:focus,
.submit-form .rte textarea:focus { box-shadow: none; }
.rte.is-previewing textarea { display: none; }
/* Nested replies get a shorter box so threads stay readable. */
.reply-form .rte textarea, .reply-form .rte-preview { min-height: 7rem; }

.rte-toolbar {
    display: flex; align-items: center; gap: 0.15rem; flex-wrap: wrap;
    padding: 0.35rem 0.4rem; border-bottom: 1px solid var(--line);
    background: var(--surface-2); border-radius: var(--r) var(--r) 0 0;
}
.rte-gap { flex: 1 1 auto; }
.rte-btn {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 30px; height: 30px; padding: 0 0.4rem;
    border: 0; border-radius: var(--r-sm); background: transparent;
    color: var(--muted); cursor: pointer; font: inherit; font-size: 0.82rem;
}
.rte-btn:hover { background: #fff; color: var(--ink); }
.rte-btn:focus-visible { outline: 2px solid var(--brand); outline-offset: -2px; }
.rte-tab { font-weight: 600; color: var(--brand); padding: 0 0.6rem; }

.rte-preview {
    padding: 0.7rem 0.85rem; min-height: 11rem;
    color: var(--ink-soft); font-size: 0.95rem; line-height: 1.65;
    overflow-wrap: anywhere;
}
.rte-empty { color: var(--faint); margin: 0; }
.rte-status {
    display: flex; align-items: center; gap: 0.4rem;
    margin: 0; padding: 0.45rem 0.85rem;
    border-top: 1px solid var(--line); background: var(--brand-soft);
    color: var(--brand-dark); font-size: 0.82rem; font-weight: 600;
}
.rte-status::before {
    content: ""; flex: none;
    width: 12px; height: 12px; border-radius: 50%;
    border: 2px solid currentColor; border-top-color: transparent;
    animation: skc-spin 0.7s linear infinite;
}
.rte-status.is-error { background: #fef3f2; color: #b42318; }
.rte-status.is-error::before { animation: none; border-top-color: currentColor; }
@keyframes skc-spin { to { transform: rotate(360deg); } }
.rte.is-previewing .rte-thumbs { display: none; }
/* Small strip of the screenshots in the box; scrolls sideways instead of growing. */
.rte-thumbs {
    display: flex; gap: 0.5rem; align-items: center;
    padding: 0.7rem 0.8rem 0.5rem; border-top: 1px solid var(--line);
    background: var(--surface-2); overflow-x: auto;
}
.rte-thumbs[hidden] { display: none; }
.rte-thumb {
    position: relative; flex: none;
    width: 64px; height: 64px;
    border: 1px solid var(--line-strong); border-radius: var(--r-sm);
    background: #fff;
}
.rte-thumb img {
    display: block; width: 100%; height: 100%;
    object-fit: cover; border-radius: inherit;
}
.rte-thumb.is-broken img { visibility: hidden; }
.rte-thumb-x {
    position: absolute; top: -6px; right: -6px;
    width: 20px; height: 20px; padding: 0;
    display: inline-flex; align-items: center; justify-content: center;
    border: 1px solid var(--line-strong); border-radius: 50%;
    background: #fff; color: var(--muted);
    font: inherit; font-size: 14px; line-height: 1; cursor: pointer;
}
.rte-thumb-x:hover { color: #b42318; border-color: #b42318; }
.rte-thumb-x:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
@media (max-width: 460px) {
    .rte-thumb { width: 52px; height: 52px; }
    /* Bigger tap target without growing the visible button. */
    .rte-thumb-x { width: 24px; height: 24px; top: -8px; right: -8px; }
}
.rte-hint {
    margin: 0; padding: 0.4rem 0.6rem; border-top: 1px solid var(--line);
    color: var(--faint); font-size: 0.75rem;
}
.rte-hint code { background: var(--surface-2); padding: 0.05rem 0.25rem; border-radius: 4px; }

/* ---------- Rendered Markdown ---------- */

.post-body > :first-child, .comment-text > :first-child, .rte-preview > :first-child { margin-top: 0; }
.post-body > :last-child, .comment-text > :last-child, .rte-preview > :last-child { margin-bottom: 0; }
.post-body p, .comment-text p, .rte-preview p { margin: 0 0 0.75em; }
.post-body ul, .post-body ol,
.comment-text ul, .comment-text ol,
.rte-preview ul, .rte-preview ol { margin: 0 0 0.75em; padding-left: 1.4em; }
.post-body li, .comment-text li, .rte-preview li { margin: 0.2em 0; }
.post-body blockquote, .comment-text blockquote, .rte-preview blockquote {
    margin: 0 0 0.75em; padding: 0.1em 0 0.1em 0.85em;
    border-left: 3px solid var(--line-strong); color: var(--muted);
}
.post-body code, .comment-text code, .rte-preview code {
    font-family: var(--mono); font-size: 0.875em;
    background: var(--surface-2); padding: 0.1em 0.3em; border-radius: 4px;
}
.post-body pre, .comment-text pre, .rte-preview pre {
    margin: 0 0 0.75em; padding: 0.7rem 0.85rem; overflow-x: auto;
    background: var(--surface-2); border-radius: var(--r-sm);
}
.post-body pre code, .comment-text pre code, .rte-preview pre code {
    background: none; padding: 0; font-size: 0.85em;
}
.comment-text a, .rte-preview a { text-decoration: underline; text-underline-offset: 2px; }

/* Screenshots are capped so one tall image can't push the rest of a thread
   off the screen; the link opens the original at full size. */
.md-image { display: inline-block; max-width: 100%; text-decoration: none !important; }
.md-image img {
    display: block; max-height: 420px; width: auto;
    border: 1px solid var(--line); border-radius: var(--r);
    background: var(--surface-2); cursor: zoom-in;
    transition: border-color 0.15s;
}
.md-image:hover img { border-color: var(--line-strong); }

.form-actions { display: flex; align-items: center; gap: 0.5rem; margin-top: 0.85rem; }

.modal[hidden] { display: none !important; }
.modal {
    position: fixed; inset: 0; z-index: 80;
    display: grid; place-items: center; padding: 1.25rem;
}
.modal-backdrop {
    position: absolute; inset: 0;
    background: rgba(22, 24, 29, 0.48);
}
.modal-dialog {
    position: relative; width: min(420px, 100%);
    background: var(--surface); border-radius: var(--r-lg);
    padding: 1.4rem 1.4rem 1.25rem;
    box-shadow: 0 24px 48px -20px rgba(16, 24, 40, 0.45);
}
.modal-dialog h2 {
    margin: 0 0 0.4rem;
    font-size: 1.15rem; font-weight: 700; letter-spacing: -0.02em;
}
.modal-dialog p { margin: 0; color: var(--ink-soft); }
body.modal-open { overflow: hidden; }

/* ---------- Panels ---------- */

.auth-panel, .submit-panel, .search-panel, .error-panel {
    background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--r-lg); padding: 1.6rem; box-shadow: var(--shadow-sm);
}
.auth-panel { max-width: 440px; margin: 1.5rem auto; }
.auth-panel .page-hero h1, .error-panel .page-hero h1 { font-size: 1.45rem; }
.auth-form, .submit-form { max-width: 560px; }
.auth-form .btn-block { margin-top: 1.3rem; }
.auth-help { color: var(--muted); font-size: 0.89rem; margin: 1.25rem 0 0; }
.auth-social-label { margin: 0 0 0.7rem; text-align: center; font-weight: 600; font-size: 0.89rem; }
.social-login-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }
.social-login-btn {
    display: flex; align-items: center; justify-content: center; gap: 0.45rem;
    padding: 0.55rem 0.65rem; border: 1px solid var(--line-strong); border-radius: var(--r);
    background: #fff; color: var(--ink); font-weight: 600; font-size: 0.88rem;
}
.social-login-btn:hover { background: var(--surface-2); text-decoration: none; color: var(--ink); }
.social-login-btn svg { width: 18px; height: 18px; flex: none; }
.auth-divider {
    display: flex; align-items: center; gap: 0.75rem;
    margin: 1.1rem 0 0.15rem; color: var(--muted);
    font-size: 0.72rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase;
}
.auth-divider::before, .auth-divider::after {
    content: ""; flex: 1; height: 1px; background: var(--line);
}
.search-form { display: flex; gap: 0.5rem; margin-bottom: 1.5rem; }
.search-form input { flex: 1 1 auto; min-width: 0; }
.search-form select {
    flex: 0 0 auto; border: 1px solid var(--line-strong); border-radius: var(--r);
    padding: 0.7rem 0.6rem; font-family: inherit; font-size: 0.95rem;
    color: var(--ink); background: #fff;
}
.search-form select:focus { outline: none; border-color: var(--brand); box-shadow: var(--ring); }
.search-form .btn { flex: 0 0 auto; }

.search-note {
    margin: -0.5rem 0 1rem; padding: 0.6rem 0.8rem;
    background: var(--brand-soft); border-radius: var(--r);
    color: var(--ink-soft); font-size: 0.86rem;
}
.search-tips { font-size: 0.86rem; }
.empty-state p { margin: 0 0 0.6rem; }
.empty-state p:last-child { margin-bottom: 0; }
.empty-state .btn { margin: 0.35rem 0.2rem 0; }

mark {
    background: #fff3c4; color: inherit;
    padding: 0.05em 0.1em; border-radius: 3px;
}

.alert {
    padding: 0.75rem 0.95rem; border-radius: var(--r);
    background: var(--brand-soft); border: 1px solid rgba(0, 63, 219, 0.16);
    color: var(--brand-dark); font-size: 0.9rem; margin-bottom: 1.1rem;
}
.alert-error { background: #fef3f2; border-color: #fecdca; color: #b42318; }

.empty-state {
    margin: 0; padding: 2.25rem 1.25rem; text-align: center;
    color: var(--muted); font-size: 0.92rem;
    background: var(--surface); border: 1px dashed var(--line-strong);
    border-radius: var(--r-lg);
}

/* ---------- Pagination ---------- */

.pagination {
    display: flex; align-items: center; justify-content: center;
    flex-wrap: wrap; gap: 0.3rem; margin-top: 1.5rem;
}
.page-link {
    display: inline-flex; align-items: center; justify-content: center; gap: 0.3rem;
    min-width: 2.15rem; padding: 0.42rem 0.6rem;
    background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--r-sm);
    color: var(--muted); font-size: 0.87rem; font-weight: 600;
    transition: border-color 0.15s, color 0.15s, background-color 0.15s;
}
.page-link:hover {
    color: var(--ink); border-color: var(--line-strong);
    background: var(--surface-2); text-decoration: none;
}
.page-link.is-active {
    background: var(--brand); border-color: var(--brand);
    color: #fff; cursor: default;
}
.page-step { padding: 0.42rem 0.8rem; }
.page-link.is-disabled { color: var(--faint); background: var(--surface-2); }
.page-gap { padding: 0 0.2rem; color: var(--faint); }

.profile-comments { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.6rem; }
.profile-comment {
    background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--r-lg); padding: 1rem 1.15rem;
}
.profile-comment > a { font-size: 0.88rem; font-weight: 600; }
.profile-comment time { display: block; margin-top: 0.45rem; font-size: 0.79rem; color: var(--faint); }

/* ---------- Footer ---------- */

.site-footer {
    border-top: 1px solid var(--line); background: #fff;
    padding: 1.75rem 0; color: var(--muted); font-size: 0.87rem;
}
.footer-inner {
    display: flex; align-items: center; justify-content: space-between;
    gap: 1rem 1.5rem; flex-wrap: wrap;
}
.footer-brand { margin: 0; }
.footer-brand strong { color: var(--ink); font-weight: 600; }
.footer-links { display: flex; align-items: center; gap: 1.1rem; flex-wrap: wrap; }
.footer-links a { color: var(--muted); }
.footer-links a:hover { color: var(--ink); text-decoration: none; }

/* ---------- Responsive ---------- */

@media (max-width: 900px) {
    .layout-grid { grid-template-columns: minmax(0, 1fr); gap: 1.25rem; padding-top: 1.25rem; }
    .sidebar { position: static; }
    .sidebar-nav { margin: 0; }
    .sidebar .sidebar-title { display: none; }
    .sidebar-about { display: none; }
    .community-list {
        display: flex; gap: 0.4rem; overflow-x: auto;
        padding-bottom: 0.15rem; scrollbar-width: none;
        -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain;
    }
    .community-list::-webkit-scrollbar { display: none; }
    .community-link {
        white-space: nowrap; background: var(--surface);
        border: 1px solid var(--line); border-radius: var(--pill);
        padding: 0.28rem 0.75rem 0.28rem 0.32rem; font-size: 0.85rem; gap: 0.4rem;
    }
    .community-icon { width: 21px; height: 21px; border-radius: 50%; }
    .community-icon svg { width: 12px; height: 12px; }
    .community-link.is-active {
        border-color: color-mix(in srgb, var(--cc) 30%, var(--line));
    }
}

@media (max-width: 760px) {
    .container { width: calc(100% - 1.75rem); }
    .header-inner { gap: 0.6rem 0.75rem; }
    .header-search { order: 3; flex-basis: 100%; max-width: none; margin: 0; }
    .header-actions { margin-left: auto; }
    .post-card { padding: 0.9rem 1rem; gap: 0.7rem; }
    .post-card--detail { padding: 1.15rem 1.15rem; }
    .hero-banner { padding: 0.95rem 1rem; gap: 0.75rem; }
    .hero-icon { width: 38px; height: 38px; border-radius: 11px; }
    .hero-icon svg { width: 19px; height: 19px; }
    .hero-avatar { font-size: 1.05rem; }
    .comment-children { margin-left: 0.25rem; padding-left: 0.75rem; }
    .search-form { flex-direction: column; align-items: stretch; }
    .layout-grid { padding-bottom: 2.5rem; }
    .breadcrumbs { font-size: 0.78rem; }
    .breadcrumbs a:last-child {
        min-width: 0; max-width: 100%;
        overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    }
    .post-body { font-size: 0.97rem; line-height: 1.65; }
    .comment-form, .comment-login-cta { padding: 1rem; margin-top: 1.25rem; }
    .auth-panel, .submit-panel, .search-panel, .error-panel { padding: 1.2rem; }
    .auth-panel { margin: 0.5rem auto; }
    .footer-inner { flex-direction: column; align-items: flex-start; }
    .form-actions .btn { flex: 1 1 auto; }
    .comment-form .form-actions .btn { flex: 0 0 auto; }
    /* 16px inputs stop iOS Safari from zooming on focus. */
    .header-search input,
    .auth-form input, .submit-form input, .submit-form textarea, .submit-form select,
    .comment-form textarea, .reply-form textarea,
    .username-field input,
    .profile-field input, .profile-field textarea,
    .search-form input, .search-form select { font-size: 16px; }
    .hero-actions { margin-left: 0; flex-basis: 100%; }
}

@media (max-width: 460px) {
    .container { width: calc(100% - 1.5rem); }
    .brand-tag { display: none; }
    .ask-label-full { display: none; }
    .ask-label-short { display: inline; }
    .header-actions .text-link { font-size: 0.82rem; }
    .post-card { grid-template-columns: 28px minmax(0, 1fr); gap: 0.6rem; padding: 0.85rem 0.85rem; }
    .post-card--detail { padding: 1rem 0.9rem; }
    .comment-row { grid-template-columns: 26px minmax(0, 1fr); gap: 0.55rem; }
    .comment-children { margin-left: 0; padding-left: 0.6rem; }
    .social-login-grid { grid-template-columns: 1fr; }
    .header-actions { gap: 0.6rem; }
    .header-actions .btn { padding: 0.5rem 0.85rem; font-size: 0.85rem; }
    .brand-logo { height: 24px; }
    .user-chip { display: none; }
}

@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    * { transition: none !important; }
}
