:root {
    color-scheme: light dark;
    --primary: #3b82f6;
    --primary-dark: #1d4ed8;
    --bg: #0f172a;
    --surface: rgba(15, 23, 42, 0.65);
    --surface-light: rgba(30, 41, 59, 0.85);
    --border: rgba(148, 163, 184, 0.2);
    --text: #e2e8f0;
    --muted: #94a3b8;
    --danger: #f87171;
    --success: #34d399;
    --warning: #fbbf24;
    /* readable measure used across the site for article content */
    --readable-width: 760px;
    /* background tuning */
    --bg-image: none;
    --bg-size: cover;
    --bg-position: center center;
    --bg-brightness: 1;
    --bg-blur: 0px;
    --frost: 12px;
    font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background: radial-gradient(circle at top, rgba(59, 130, 246, 0.15), transparent 45%), #020617;
    color: var(--text);
}

a {
    color: inherit;
    text-decoration: none;
}

a:hover {
    color: var(--primary);
}

.container {
    /* increase max-width so editor columns (50/50) are wider on desktop */
    max-width: 1300px;
    margin: 4rem auto;
    /* slightly reduce side padding to give more horizontal room */
    padding: 0 1rem;
}

.navbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 2.5rem;
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(2, 6, 23, 0.65);
    backdrop-filter: blur(var(--frost));
    border-bottom: 1px solid var(--border);
}

/* Fullscreen background layer */
#site-bg{
    position: fixed;
    inset: 0;
    z-index: -1;
    background-image: var(--bg-image);
    background-size: var(--bg-size);
    background-position: var(--bg-position);
    background-repeat: no-repeat;
    filter: blur(var(--bg-blur)) brightness(var(--bg-brightness));
    transition: filter 240ms ease, opacity 240ms ease;
}

/* subtle overlay between background and content */
#bg-overlay{
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    background: rgba(2,6,23,0.35);
}

/* Settings UI */
.bg-settings-toggle{position:fixed;right:16px;bottom:16px;z-index:9999}
.bg-settings-panel{position:fixed;right:16px;bottom:72px;width:300px;max-width:calc(100vw - 32px);background:rgba(2,6,23,0.9);border:1px solid var(--border);border-radius:12px;padding:0.75rem;z-index:9999;color:var(--text);box-shadow:0 10px 40px rgba(2,6,23,0.6)}
.bg-settings-panel label{font-size:0.85rem;color:var(--muted);display:block;margin-top:0.6rem}
.bg-settings-panel input[type="range"]{width:100%}
.bg-settings-panel input[type="text"]{width:100%;padding:0.4rem;border-radius:6px;border:1px solid var(--border);background:rgba(255,255,255,0.02);color:var(--text)}
.bg-settings-panel .row{display:flex;gap:0.5rem;align-items:center}
.bg-settings-panel .btn{margin-top:0.6rem}

.navbar__logo a {
    font-size: 1.4rem;
    font-weight: 700;
}

.navbar__links {
    display: flex;
    gap: 1rem;
    align-items: center;
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    border-radius: 999px;
    padding: 0.6rem 1.3rem;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.button:hover {
    transform: translateY(-1px);
    box-shadow: 0 10px 30px rgba(59, 130, 246, 0.25);
}

.button--ghost {
    background: transparent;
    border: 1px solid var(--border);
}

.button--secondary {
    background: rgba(148, 163, 184, 0.15);
}

.hero {
    text-align: center;
    background: var(--surface);
    border-radius: 24px;
    padding: 3rem 2rem;
    box-shadow: 0 20px 50px rgba(15, 23, 42, 0.35);
}

.hero h1 {
    font-size: 2.5rem;
    margin-bottom: 1rem;
}

.post-grid {
    display: grid;
    gap: 1.5rem;
    margin-top: 3rem;
}

.card {
    background: var(--surface-light);
    border-radius: 20px;
    padding: 1.75rem;
    border: 1px solid var(--border);
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.3);
}

.card__meta {
    color: var(--muted);
    font-size: 0.9rem;
}

.flash-container {
    display: grid;
    gap: 0.75rem;
    margin-bottom: 2rem;
}

.flash {
    border-radius: 14px;
    padding: 0.9rem 1.1rem;
    border: 1px solid var(--border);
    transition: opacity 0.6s ease;
}

.flash--success { border-left: 4px solid var(--success); }
.flash--danger { border-left: 4px solid var(--danger); }
.flash--info { border-left: 4px solid var(--primary); }
.flash--hide { opacity: 0; }

.auth-card {
    max-width: 420px;
    margin: 0 auto;
    padding: 2.5rem;
    background: var(--surface);
    border-radius: 22px;
    border: 1px solid var(--border);
    box-shadow: 0 20px 45px rgba(2, 6, 23, 0.4);
}

.form {
    display: grid;
    gap: 1.2rem;
}

/* Admin edit user specific layout improvements */
.admin-edit-user {
    max-width: 720px; /* constrain the form to a comfortable reading width */
    margin: 0 auto;
    padding: 2rem;
    background: var(--surface);
    border-radius: 12px;
    border: 1px solid var(--border);
}

.form-compact {
    display: grid;
    gap: 1rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.form input.form-control {
    padding: 0.85rem 1rem;
    border-radius: 10px;
    font-size: 1rem;
}

.form-check-row {
    display: flex;
    gap: 1rem;
    align-items: center;
    flex-wrap: wrap;
}

.form-check-inline {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    background: rgba(255,255,255,0.02);
    padding: 0.35rem 0.6rem;
    border-radius: 8px;
    border: 1px solid transparent;
}

.form-check-inline input[type="checkbox"] {
    width: 18px;
    height: 18px;
}

.admin-edit-user .muted {
    display: block;
    margin-top: 0.4rem;
    color: var(--muted);
    font-size: 0.9rem;
}

@media (max-width: 720px) {
    .admin-edit-user {
        padding: 1rem;
        margin: 1rem;
    }
    .form-check-row {
        gap: 0.6rem;
    }
}

.form label {
    display: grid;
    gap: 0.6rem;
    font-weight: 600;
}

.form input,
.form textarea,
.form select {
    width: 100%;
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 0.75rem 1rem;
    color: var(--text);
    font-size: 1rem;
}

.form textarea {
    resize: vertical;
}

/* Resend-confirm UI in login page */
.resend-block {
    margin-top: 0.4rem;
    display: flex;
    align-items: center;
    gap: 0.35rem; /* make label and form closer */
    flex-wrap: wrap;
}
.resend-block__label {
    color: var(--muted);
    font-size: 0.92rem;
}
.resend-confirm {
    display: flex;
    gap: 0.4rem;
    align-items: center;
}
.resend-confirm__input {
    background: rgba(15, 23, 42, 0.5);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 0.36rem 0.8rem; /* slightly less padding so it stays compact */
    color: var(--text);
    font-size: 0.95rem;
    min-width: 140px; /* allow smaller inputs so button sits next to it */
}
.resend-confirm__button {
    padding: 0.36rem 0.9rem;
    border-radius: 999px;
    font-size: 0.95rem;
    white-space: nowrap; /* prevent wrapping like before */
}
.visually-hidden { /* accessible label helper */
    position: absolute !important;
    height: 1px; width: 1px;
    overflow: hidden; clip: rect(1px, 1px, 1px, 1px);
    white-space: nowrap; border: 0; padding: 0; margin: -1px;
}

@media (max-width: 520px) {
    .resend-confirm {
        width: 100%;
        gap: 0.4rem;
    }
    .resend-confirm__input {
        flex: 1 1 auto;
        min-width: 0;
    }
}

/* Improved file input UI: style the selector button and keep filename text readable.
   Uses ::file-selector-button where supported and fallbacks for webkit/old browsers.
*/
.form input[type="file"] {
    /* let the control size to content instead of full-width */
    width: auto;
    padding: 0;
    background: transparent;
    color: var(--text);
    font-size: 1rem;
}

.form label.file-input {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.form input[type="file"]::file-selector-button,
.form input[type="file"]::-webkit-file-upload-button {
    appearance: none;
    -webkit-appearance: none;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    border: none;
    padding: 0.45rem 0.9rem;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    margin-right: 0.4rem;
}

.form input[type="file"]::file-selector-button:hover,
.form input[type="file"]::-webkit-file-upload-button:hover {
    transform: translateY(-1px);
    box-shadow: 0 8px 20px rgba(59,130,246,0.18);
}

/* For accessibility and long filenames, let the filename text wrap or truncate gracefully */
.form input[type="file"] {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 60ch;
}

/* On very small screens allow file input to take full width */
@media (max-width: 480px) {
    .form label.file-input {
        flex-direction: column;
        align-items: flex-start;
    }
    .form input[type="file"] {
        max-width: 100%;
        width: 100%;
    }
}

.table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border-radius: 16px;
    overflow: hidden;
}

.table th,
.table td {
    padding: 1rem;
    border-bottom: 1px solid var(--border);
    text-align: left;
}

.table thead {
    background: rgba(59, 130, 246, 0.08);
}

.table__actions {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

.link-button {
    background: none;
    border: none;
    color: var(--primary);
    cursor: pointer;
    font: inherit;
}

.editor textarea {
    min-height: 260px;
}

/* Split editor/preview layout */
.editor-split {
    display: flex;
    gap: 1rem;
    align-items: flex-start;
    width: 100%;
}
.editor-column {
    min-width: 0; /* allow flex children to shrink properly */
    box-sizing: border-box;
}

/* Expand preview to cover the window (not true fullscreen) */
.preview-fullscreen {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    z-index: 9999 !important;
    background: var(--bg, #fff);
    box-shadow: 0 0 0 9999px rgba(0,0,0,0.3);
    margin: 0 !important;
    border-radius: 0 !important;
}

/* Optional body state while preview covers the page: hide scroll on body and dim underlay is achieved by box-shadow above */
.preview-cover-active {
    overflow: hidden;
}

/* Controls that live inside the preview when expanded */
#preview-container {
    position: relative;
}
#preview-controls {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 10000;
    display: flex;
    gap: 0.5rem;
}
#preview-controls .button {
    width: 40px;
    height: 40px;
    padding: 0;
    border-radius: 10px;
    display: inline-grid;
    place-items: center;
}
#preview-controls .button svg {
    display: block;
}

/* When preview is expanded, make the article content width match the post detail page
   - center the content
   - constrain the readable measure to approx 800-900px (similar to post detail)
   - preserve markdown-body styles
*/
.preview-fullscreen #preview-content {
    padding-top: 3.5rem; /* leave space for header/title area */
    padding-left: 1.25rem;
    padding-right: 1.25rem;
    /* make preview content fill the viewport so internal scrolling works and no large bottom gap appears */
    height: calc(100vh - 48px);
    overflow: auto;
     /* Use block layout for normal flow; center inner .markdown-body via margin:auto
         (flex was causing unexpected narrow-column rendering in some cases). */
     display: block;
    box-sizing: border-box;
}
.preview-fullscreen #preview-content.markdown-body,
.preview-fullscreen #preview-content .markdown-body {
    /* Center the article inside the preview window and constrain readable measure.
       Use the shared --readable-width so it's easy to adjust site-wide.
    */
    max-width: 1300px;
    width: 100%;
    box-sizing: border-box;
    margin: 0 auto; /* center horizontally when narrower than the container */
    font-size: 1.05rem;
    line-height: 1.8;
    padding-bottom: 0.9rem;
}

/* On small screens, use nearly full width but keep padding */
@media (max-width: 900px) {
    .preview-fullscreen #preview-content .markdown-body {
        /* allow full-width on smaller screens but keep horizontal padding */
        max-width: calc(100vw - 48px);
        width: calc(100% - 2.5rem);
    }
}
/* Fixed percentage widths so left+right never exceed container width */
.editor-column--left {
    /* default: when preview is not open, left takes full width via modifier rules below */
    box-sizing: border-box;
    min-width: 0;
}
.editor-column--right {
    /* default right column styles handled by modifier rules */
    box-sizing: border-box;
    min-width: 0;
}

/* When preview is closed (default), left column is full width, right column collapsed */
.editor-split:not(.preview-open) {
    /* ensure no unintended gaps */
    align-items: flex-start;
}
.editor-split:not(.preview-open) .editor-column--left {
    flex: 1 1 100%;
    max-width: 100%;
}
.editor-split:not(.preview-open) .editor-column--right {
    flex: 0 0 0;
    max-width: 0;
    overflow: hidden;
}

/* When preview is open, split 50/50. Account for gap (1rem) so two columns sum to full width. */
.editor-split.preview-open {
    /* prevent horizontal overflow from gap/scrollbars */
    overflow: hidden;
}
.editor-split.preview-open .editor-column--left,
.editor-split.preview-open .editor-column--right {
    /* subtract half the gap (0.5rem) from each column so they total 100% with the gap */
    flex: 0 0 calc(50% - 0.5rem);
    max-width: calc(50% - 0.5rem);
}
.editor-split.preview-open .editor-column--right {
    display: block;
    /* allow preview to scroll internally if content is long */
    overflow: auto;
}
#post-content {
    /* make the textarea taller to give room for editing */
    min-height: 60vh;
    height: 60vh;
    resize: vertical;
    width: 100%;
    box-sizing: border-box;
}
#preview-container {
    display: block;
    width: 100%;
    box-sizing: border-box;
}
#preview-content {
    height: 60vh;
    overflow: auto;
    padding: 1rem;
    box-sizing: border-box;
}

@media (max-width: 900px) {
    .editor-split {
        flex-direction: column;
    }
    .editor-column--right {
        max-width: 100%;
    }
    #post-content, #preview-content {
        height: 45vh;
    }
}

.comment-list {
    display: grid;
    gap: 1rem;
    margin-top: 1.5rem;
}

.comment {
    background: var(--surface);
    border-radius: 16px;
    padding: 1.2rem;
    border: 1px solid var(--border);
}

.comment__header {
    display: flex;
    justify-content: space-between;
    color: var(--muted);
    font-size: 0.9rem;
    margin-bottom: 0.75rem;
}

.markdown-body {
    line-height: 1.8;
    font-size: 1.05rem;
}

/* Links inside rendered markdown: visible color hint, subtle underline and focus ring for accessibility */
.markdown-body a {
    color: var(--primary);
    text-decoration: none;
    border-bottom: 1px solid rgba(59,130,246,0.12);
    padding-bottom: 1px;
    transition: color 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
}
.markdown-body a:hover,
.markdown-body a:focus {
    color: var(--primary-dark);
    border-bottom-color: rgba(29,78,216,0.35);
    outline: none;
}
.markdown-body a:focus-visible {
    box-shadow: 0 0 0 4px rgba(59,130,246,0.12);
    border-radius: 6px;
}
.markdown-body a:visited {
    /* slightly muted visited color while keeping recognizability */
    color: color-mix(in srgb, var(--primary) 60%, #334155 40%);
}

/* Ensure article detail uses the same readable measure as the preview fullscreen */
/* Note: article detail uses the default .markdown-body layout; we intentionally
   do not override it here so preview can match the viewing page. */

.markdown-body pre {
    background: rgba(15, 23, 42, 0.9);
    padding: 1rem;
    border-radius: 14px;
    overflow-x: auto;
    border: 1px solid var(--border);
}

.markdown-body code {
    background: rgba(15, 23, 42, 0.6);
    padding: 0.2rem 0.4rem;
    border-radius: 6px;
}

/* Make images inside markdown-preview responsive: fit container width, keep aspect ratio */
.markdown-body img,
#preview-content img {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 0.5rem auto; /* center images inside preview */
}

.profile__grid {
    display: grid;
    gap: 1.5rem;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

.avatar {
    width: 110px;
    height: 110px;
    border-radius: 50%;
    overflow: hidden;
    margin-bottom: 1rem;
    display: grid;
    place-items: center;
    background: rgba(59, 130, 246, 0.15);
    font-size: 2.2rem;
    font-weight: 700;
}

.avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.dashboard__stats {
    display: grid;
    gap: 1.5rem; /* increase gap between stat cards */
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    margin-bottom: 2.5rem; /* more space below stats */
}

/* Layout for the two-column dashboard cards (最新文章 & 新注册用户) */
.dashboard__columns {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem; /* larger gap between the two cards */
    margin-bottom: 1.75rem;
}

.dashboard__actions {
    margin-bottom: 1.5rem; /* increase spacing between action buttons and stats */
}

    /* Header for admin lists (posts management) */
    .admin-list__header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 1rem;
        margin-bottom: 1.75rem; /* larger gap between header and list */
    }

.stat-card {
    background: var(--surface);
    border-radius: 18px;
    padding: 1.4rem;
    border: 1px solid var(--border);
}

.stat-card__label {
    color: var(--muted);
    font-size: 0.95rem;
}

.stat-card__value {
    font-size: 2rem;
    font-weight: 700;
}

.footer {
    text-align: center;
    padding: 2rem 1rem 3rem;
    color: var(--muted);
}

@media (max-width: 768px) {
    .navbar {
        flex-direction: column;
        gap: 1rem;
    }
    .container {
        margin: 2rem auto;
    }
}

/* Responsive spacing tweaks for dashboard/admin pages */
@media (max-width: 900px) {
    .dashboard__stats {
        gap: 1rem;
        margin-bottom: 1.25rem;
    }
    .admin-list__header {
        margin-bottom: 1rem;
        gap: 0.5rem;
        flex-direction: column;
        align-items: stretch;
    }
    .dashboard__actions {
        margin-bottom: 1rem;
    }
}
