/* =========================================================================
   Theme variables
   ========================================================================= */

:root {
    /* Surface */
    --clr-bg: #f8f5ff;
    --clr-surface: #ffffff;
    --clr-surface-alt: #f0eaff;
    --clr-border: #d6c9f5;

    /* Text */
    --clr-text: #1a1025;
    --clr-text-muted: #5a4e72;

    /* Accent — lilac/violet */
    --clr-accent: #7c3aed;
    --clr-accent-dim: #6d28d9;
    --clr-accent-fg: #ffffff;

    /* Semantic */
    --clr-error: #b91c1c;
    --clr-error-bg: #fef2f2;
    --clr-success: #15803d;
    --clr-success-bg: #f0fdf4;

    /* Shadows */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.10);

    /* Sizing */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --max-width: 720px;

    /* Transitions */
    --transition: 150ms ease;
}

/* System default: follow the OS preference */
@media (prefers-color-scheme: dark) {
    :root {
        --clr-bg: #0d0b14;
        --clr-surface: #16121f;
        --clr-surface-alt: #1f1830;
        --clr-border: #2e2645;

        --clr-text: #e8e0f7;
        --clr-text-muted: #9585b8;

        --clr-accent: #a78bfa;
        --clr-accent-dim: #8b5cf6;
        --clr-accent-fg: #0d0b14;

        --clr-error: #f87171;
        --clr-error-bg: #1f0d0d;
        --clr-success: #4ade80;
        --clr-success-bg: #0d1f12;

        --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.30);
        --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.40);
    }
}

/* Explicit overrides — specificity 0,2,0 beats the media query's 0,1,0 */

:root[data-theme="light"] {
    --clr-bg: #f8f5ff;
    --clr-surface: #ffffff;
    --clr-surface-alt: #f0eaff;
    --clr-border: #d6c9f5;

    --clr-text: #1a1025;
    --clr-text-muted: #5a4e72;

    --clr-accent: #7c3aed;
    --clr-accent-dim: #6d28d9;
    --clr-accent-fg: #ffffff;

    --clr-error: #b91c1c;
    --clr-error-bg: #fef2f2;
    --clr-success: #15803d;
    --clr-success-bg: #f0fdf4;

    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.10);
}

:root[data-theme="dark"] {
    --clr-bg: #0d0b14;
    --clr-surface: #16121f;
    --clr-surface-alt: #1f1830;
    --clr-border: #2e2645;

    --clr-text: #e8e0f7;
    --clr-text-muted: #9585b8;

    --clr-accent: #a78bfa;
    --clr-accent-dim: #8b5cf6;
    --clr-accent-fg: #0d0b14;

    --clr-error: #f87171;
    --clr-error-bg: #1f0d0d;
    --clr-success: #4ade80;
    --clr-success-bg: #0d1f12;

    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.30);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.40);
}


/* =========================================================================
   Reset / base
   ========================================================================= */

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

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background-color: var(--clr-bg);
    color: var(--clr-text);
    line-height: 1.65;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
}


/* =========================================================================
   Typography
   ========================================================================= */

h1,
h2,
h3,
h4,
h5,
h6 {
    line-height: 1.25;
    font-weight: 600;
    color: var(--clr-text);
    margin-bottom: 0.5em;
}

h1 {
    font-size: 1.875rem;
}

h2 {
    font-size: 1.5rem;
}

h3 {
    font-size: 1.25rem;
}

h4 {
    font-size: 1.125rem;
}

p {
    margin-bottom: 0.875rem;
    color: var(--clr-text);
}

p:last-child {
    margin-bottom: 0;
}

a {
    color: var(--clr-accent);
    text-decoration: underline;
    text-decoration-color: transparent;
    transition: text-decoration-color var(--transition);
}

a:hover {
    text-decoration-color: var(--clr-accent);
}

strong,
b {
    font-weight: 600;
}

small {
    color: var(--clr-text-muted);
}

code,
kbd,
samp,
pre {
    font-family: "Fira Code", "Cascadia Code", ui-monospace, monospace;
    font-size: 0.9em;
}

code {
    background: var(--clr-surface-alt);
    border: 1px solid var(--clr-border);
    border-radius: var(--radius-sm);
    padding: 0.1em 0.35em;
}

hr {
    border: none;
    border-top: 1px solid var(--clr-border);
    margin: 1.25rem 0;
}

dl {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 0.25rem 1rem;
}

dt {
    font-weight: 600;
    color: var(--clr-text-muted);
}

dd {
    color: var(--clr-text);
}

summary {
    cursor: pointer;
    font-weight: 500;
    color: var(--clr-text-muted);
    margin-bottom: 0.5rem;
}

summary:hover {
    color: var(--clr-text);
}

details[open] summary {
    margin-bottom: 0.75rem;
}


/* =========================================================================
   Layout — site chrome
   ========================================================================= */

body>header {
    background: var(--clr-surface);
    border-bottom: 1px solid var(--clr-border);
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 0;
    z-index: 100;
}

body>header nav {
    max-width: var(--max-width);
    margin-inline: auto;
    padding: 0.75rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

body>header nav>a:first-child {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--clr-accent);
    text-decoration: none;
    margin-right: auto;
}

body>header nav>a:first-child:hover {
    color: var(--clr-accent-dim);
}

body>header nav span {
    color: var(--clr-text-muted);
    font-size: 0.9rem;
}

body>header nav>a:not(:first-child) {
    font-size: 0.9rem;
    color: var(--clr-text-muted);
}

body>header nav>a:not(:first-child):hover {
    color: var(--clr-text);
}

/* Hide the separator pipe characters that are part of the markup */
body>header nav>*+*::before {
    content: none;
}

body>header hr {
    display: none;
}

body>main {
    flex: 1;
    max-width: var(--max-width);
    width: 100%;
    margin-inline: auto;
    padding: 2rem 1.5rem;
}

body>footer {
    background: var(--clr-surface);
    border-top: 1px solid var(--clr-border);
}

body>footer hr {
    display: none;
}

body>footer p {
    max-width: var(--max-width);
    margin-inline: auto;
    padding: 0.875rem 1.5rem;
    font-size: 0.85rem;
    color: var(--clr-text-muted);
    margin-bottom: 0;
}


/* =========================================================================
   Forms
   ========================================================================= */

fieldset {
    border: 1px solid var(--clr-border);
    border-radius: var(--radius-md);
    padding: 0.75rem 1.5rem 1.5rem;
    background: var(--clr-surface);
    box-shadow: var(--shadow-sm);
    max-width: 24rem;
}

legend {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--clr-text-muted);
    padding-inline: 0.5rem;
}

label {
    display: block;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--clr-text-muted);
    margin-bottom: 0.25rem;
}

input[type="text"],
input[type="email"],
input[type="password"] {
    display: block;
    width: 100%;
    padding: 0.5rem 0.75rem;
    background: var(--clr-bg);
    color: var(--clr-text);
    border: 1px solid var(--clr-border);
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-family: inherit;
    transition:
        border-color var(--transition),
        box-shadow var(--transition);
    outline: none;
}

input[type="text"]:focus,
input[type="email"]:focus,
input[type="password"]:focus {
    border-color: var(--clr-accent);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--clr-accent) 20%, transparent);
}

select {
    display: block;
    width: 100%;
    padding: 0.5rem 0.75rem;
    background: var(--clr-bg);
    color: var(--clr-text);
    border: 1px solid var(--clr-border);
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-family: inherit;
    cursor: pointer;
    outline: none;
    transition:
        border-color var(--transition),
        box-shadow var(--transition);
}

select:focus {
    border-color: var(--clr-accent);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--clr-accent) 20%, transparent);
}

textarea {
    display: block;
    width: 100%;
    padding: 0.5rem 0.75rem;
    background: var(--clr-bg);
    color: var(--clr-text);
    border: 1px solid var(--clr-border);
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-family: inherit;
    resize: vertical;
    transition:
        border-color var(--transition),
        box-shadow var(--transition);
    outline: none;
}

textarea:focus {
    border-color: var(--clr-accent);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--clr-accent) 20%, transparent);
}

input[type="checkbox"] {
    width: 1rem;
    height: 1rem;
    accent-color: var(--clr-accent);
    cursor: pointer;
    vertical-align: middle;
}

/* Inline checkbox label (the label follows the checkbox) */
input[type="checkbox"]+label {
    display: inline;
    font-weight: normal;
    color: var(--clr-text);
    cursor: pointer;
}


/* =========================================================================
   Buttons
   ========================================================================= */

button,
input[type="submit"],
input[type="button"] {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.5rem 1.125rem;
    background: var(--clr-accent);
    color: var(--clr-accent-fg);
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-family: inherit;
    font-weight: 500;
    cursor: pointer;
    transition:
        background-color var(--transition),
        box-shadow var(--transition),
        transform var(--transition);
    white-space: nowrap;
}

button:hover,
input[type="submit"]:hover,
input[type="button"]:hover {
    background: var(--clr-accent-dim);
    box-shadow: var(--shadow-sm);
}

button:active,
input[type="submit"]:active,
input[type="button"]:active {
    transform: translateY(1px);
}

button:focus-visible,
input[type="submit"]:focus-visible,
input[type="button"]:focus-visible {
    outline: 2px solid var(--clr-accent);
    outline-offset: 2px;
}

/* Inline form buttons (e.g. sign-out in the nav) — scoped to header only */
header form[style*="inline"] button {
    padding: 0.25rem 0.625rem;
    font-size: 0.85rem;
    background: transparent;
    color: var(--clr-text-muted);
    border: 1px solid var(--clr-border);
    border-radius: var(--radius-sm);
}

header form[style*="inline"] button:hover {
    background: var(--clr-surface-alt);
    color: var(--clr-text);
    box-shadow: none;
}


/* =========================================================================
   Theme toggle — segmented control in the nav
   ========================================================================= */

.theme-toggle {
    display: inline-flex;
    align-items: stretch;
    border: 1px solid var(--clr-border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--clr-surface-alt);
    /* Reset any inherited margins from nav spacing */
    margin: 0;
}

/* Override the global button styles for the toggle buttons */
.theme-toggle button {
    background: transparent;
    color: var(--clr-text-muted);
    border: none;
    border-radius: 0;
    border-right: 1px solid var(--clr-border);
    padding: 0.25rem 0.625rem;
    font-size: 0.8rem;
    font-weight: 500;
    box-shadow: none;
    transform: none;
    text-align: center;
    transition:
        background-color var(--transition),
        color var(--transition);
}

.theme-toggle button:last-child {
    border-right: none;
}

.theme-toggle button:hover {
    background: var(--clr-border);
    color: var(--clr-text);
    box-shadow: none;
    transform: none;
}

.theme-toggle button:active {
    transform: none;
}

/* Active state — the currently selected theme */
.theme-toggle button[aria-pressed="true"] {
    background: var(--clr-accent);
    color: var(--clr-accent-fg);
}

.theme-toggle button[aria-pressed="true"]:hover {
    background: var(--clr-accent-dim);
    color: var(--clr-accent-fg);
}


/* =========================================================================
   Status messages
   ========================================================================= */

.msg-error,
.msg-success {
    display: block;
    padding: 0.6rem 0.875rem;
    border-radius: var(--radius-sm);
    font-weight: 500;
    font-size: 0.9rem;
    margin-bottom: 1rem;
}

.msg-error {
    background: var(--clr-error-bg);
    color: var(--clr-error);
    border: 1px solid color-mix(in srgb, var(--clr-error) 30%, transparent);
}

.msg-success {
    background: var(--clr-success-bg);
    color: var(--clr-success);
    border: 1px solid color-mix(in srgb, var(--clr-success) 30%, transparent);
}


/* =========================================================================
   Buttons — secondary / size variants
   ========================================================================= */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.5rem 1.125rem;
    background: var(--clr-accent);
    color: var(--clr-accent-fg);
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-family: inherit;
    font-weight: 500;
    line-height: 1;
    cursor: pointer;
    text-decoration: none;
    transition:
        background-color var(--transition),
        box-shadow var(--transition);
    white-space: nowrap;
}

.btn:hover {
    background: var(--clr-accent-dim);
    color: var(--clr-accent-fg);
    text-decoration: none;
}

.btn-sm {
    padding: 0.3rem 0.7rem;
    font-size: 0.82rem;
}

.btn-xs {
    padding: 0.15rem 0.5rem;
    font-size: 0.78rem;
}

.btn-danger {
    background: var(--clr-error);
    color: #fff;
}

.btn-danger:hover {
    background: color-mix(in srgb, var(--clr-error) 80%, black);
    color: #fff;
}


/* =========================================================================
   Badges
   ========================================================================= */

.badge {
    display: inline-block;
    font-size: 0.72rem;
    font-weight: 600;
    padding: 0.15em 0.5em;
    border-radius: var(--radius-sm);
    background: var(--clr-surface-alt);
    color: var(--clr-text-muted);
    border: 1px solid var(--clr-border);
    vertical-align: middle;
}

.badge-locked {
    color: var(--clr-error);
    border-color: color-mix(in srgb, var(--clr-error) 30%, transparent);
    background: var(--clr-error-bg);
}


/* =========================================================================
   Breadcrumb
   ========================================================================= */

.breadcrumb {
    font-size: 0.875rem;
    color: var(--clr-text-muted);
    margin-bottom: 1rem;
}

.breadcrumb a {
    color: var(--clr-text-muted);
}

.breadcrumb a:hover {
    color: var(--clr-text);
}


/* =========================================================================
   Forums — channel list
   ========================================================================= */

.forum-header {
    display: flex;
    align-items: baseline;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1.25rem;
}

.forum-header h1 {
    margin-bottom: 0;
}

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

.forum-actions form,
.thread-actions form,
.comment-actions form {
    display: contents;
}

.channel-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.channel-item {
    background: var(--clr-surface);
    border: 1px solid var(--clr-border);
    border-radius: var(--radius-md);
    padding: 1rem 1.25rem;
    box-shadow: var(--shadow-sm);
}

.channel-name {
    font-size: 1.05rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.channel-name a {
    text-decoration: none;
    color: var(--clr-text);
}

.channel-name a:hover {
    color: var(--clr-accent);
}

.channel-desc {
    font-size: 0.9rem;
    color: var(--clr-text-muted);
    margin-bottom: 0.25rem;
}

.channel-meta {
    margin: 0;
    font-size: 0.82rem;
}


/* =========================================================================
   Forums — thread list
   ========================================================================= */

.thread-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.thread-item {
    background: var(--clr-surface);
    border: 1px solid var(--clr-border);
    border-radius: var(--radius-sm);
    padding: 0.75rem 1rem;
}

.thread-title {
    font-weight: 600;
    margin-bottom: 0.2rem;
}

.thread-title a {
    text-decoration: none;
    color: var(--clr-text);
}

.thread-title a:hover {
    color: var(--clr-accent);
}

.thread-meta {
    font-size: 0.82rem;
    color: var(--clr-text-muted);
    margin: 0;
}


/* =========================================================================
   Forums — thread view
   ========================================================================= */

.thread-header {
    margin-bottom: 1.5rem;
}

.thread-header h1 {
    margin-bottom: 0.25rem;
}

.thread-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-top: 0.75rem;
}

/* Rendered markdown body */
.thread-body {
    background: var(--clr-surface);
    border: 1px solid var(--clr-border);
    border-radius: var(--radius-md);
    padding: 1.25rem 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow-sm);
    line-height: 1.7;
    overflow-wrap: break-word;
}

.thread-body h1,
.thread-body h2,
.thread-body h3,
.thread-body h4 {
    margin-top: 0.25em;
    margin-bottom: 0.5em;
}

.thread-body ul,
.thread-body ol {
    padding-left: 1.5rem;
    margin-bottom: 0.875rem;
}

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

.thread-body pre {
    background: var(--clr-surface-alt);
    border: 1px solid var(--clr-border);
    border-radius: var(--radius-sm);
    padding: 0.75rem 1rem;
    overflow-x: auto;
    margin-bottom: 0.875rem;
}

.thread-body blockquote {
    border-left: 3px solid var(--clr-accent);
    margin-left: 0;
    padding-left: 1rem;
    color: var(--clr-text-muted);
}

.thread-body table {
    border-collapse: collapse;
    width: 100%;
    margin-bottom: 0.875rem;
}

.thread-body th,
.thread-body td {
    border: 1px solid var(--clr-border);
    padding: 0.4rem 0.75rem;
    text-align: left;
}

.thread-body th {
    background: var(--clr-surface-alt);
    font-weight: 600;
}

.replies-heading {
    margin-bottom: 0.5rem;
}

#comments-frame {
    display: block;
    width: 100%;
    min-height: 500px;
    border: 1px solid var(--clr-border);
    border-radius: var(--radius-md);
    background: var(--clr-surface);
}

.iframe-hint {
    margin-top: 0.375rem;
    color: var(--clr-text-muted);
}

.add-comment {
    margin-top: 1.5rem;
}

.add-comment h3 {
    margin-bottom: 0.75rem;
}

.locked-notice {
    margin-top: 1.25rem;
    color: var(--clr-text-muted);
    font-style: italic;
}


/* =========================================================================
   Forums — comments frame (iframe body)
   ========================================================================= */

body.comments-frame-body {
    padding: 0.75rem 1rem;
    background: var(--clr-bg);
}

.comments-frame {
    display: flex;
    flex-direction: column;
    gap: 0;
    padding: 0;
}

.no-comments {
    color: var(--clr-text-muted);
    font-style: italic;
    padding: 0.5rem 0;
}

.comment-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0;
}

.comment {
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--clr-border);
}

.comment:last-of-type {
    border-bottom: none;
}

.comment-meta {
    font-size: 0.82rem;
    color: var(--clr-text-muted);
    margin-bottom: 0.3rem;
}

.comment-body {
    white-space: pre-wrap;
    overflow-wrap: break-word;
    font-size: 0.95rem;
    line-height: 1.6;
}

.comment-actions {
    margin-top: 0.4rem;
    display: flex;
    align-items: center;
    gap: 0.375rem;
}

.pagination {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--clr-border);
    margin-top: 0.5rem;
}

.page-info {
    font-size: 0.85rem;
    color: var(--clr-text-muted);
}


/* =========================================================================
   Utility
   ========================================================================= */

:focus-visible {
    outline: 2px solid var(--clr-accent);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

.spoiler {
    color: inherit;
    filter: blur(5px);
    transition: filter 0.1s ease;
}

.spoiler:hover {
    filter: blur(0);
}