:root {
    color-scheme: light;
    --text: #1f2328;
    --muted: #656d76;
    --border: #d1d9e0;
    --bg: #ffffff;
    --accent: #0969da;
    --error: #cf222e;
    --fill: #f6f8fa;
}

/* Dark theme: driven by data-theme on <html>, set before first paint by the
   head script; palette matches the viewer's markdown-dark.css. */
:root[data-theme="dark"] {
    color-scheme: dark;
    --text: #e6edf3;
    --muted: #9ea7b3;
    --border: #3d3d40;
    --bg: #1e1e1e;
    --accent: #4493f8;
    --error: #f85149;
    --fill: #262727;
}

html, body {
    margin: 0;
    padding: 0;
    font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, sans-serif;
    color: var(--text);
    background: var(--bg);
}

h1:focus, h2:focus, h3:focus, h4:focus, h5:focus, h6:focus {
    outline: none;
}

.compose-shell {
    max-width: 760px;
    margin: 0 auto;
    padding: 32px 24px 64px;
}

.compose-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 28px;
}

.header-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 14px;
}

.header-link {
    color: var(--accent);
    font-weight: 600;
    font-size: 0.9rem;
    text-decoration: none;
}

.header-link:hover {
    text-decoration: underline;
}

/* Language and theme switchers: native <details> dropdowns styled as
   select lists. The theme switcher has a bare icon summary — no caret. */
.lang-switch,
.theme-switch {
    position: relative;
}

.lang-switch summary,
.theme-switch summary {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    list-style: none;
    cursor: pointer;
    user-select: none;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text);
    background: var(--bg);
}

.lang-switch summary::-webkit-details-marker,
.theme-switch summary::-webkit-details-marker {
    display: none;
}

.lang-switch summary::after {
    content: "";
    width: 0;
    height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 5px solid var(--muted);
    transition: transform 0.15s ease;
}

.lang-switch[open] summary::after {
    transform: rotate(180deg);
}

.lang-switch summary:hover,
.theme-switch summary:hover {
    background: var(--fill);
}

.lang-icon {
    color: var(--accent);
}

.lang-menu {
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    z-index: 30;
    margin: 0;
    padding: 4px;
    list-style: none;
    min-width: 140px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(31, 35, 40, 0.14);
}

.lang-menu a {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 7px;
    font-size: 0.9rem;
    color: var(--text);
    text-decoration: none;
}

.lang-menu a:hover {
    background: var(--fill);
}

.lang-menu a.is-active {
    font-weight: 700;
    color: var(--accent);
}

.lang-check {
    color: var(--accent);
    flex: none;
}

.lang-check-space {
    width: 14px;
    flex: none;
}

.compose-footer {
    margin-top: 56px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px 18px;
    color: var(--muted);
    font-size: 0.88rem;
}

.footer-brand {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--text);
    font-weight: 700;
    text-decoration: none;
}

.footer-brand img {
    display: block;
    height: 26px;
    width: auto;
}

.footer-brand:hover {
    filter: brightness(1.1);
}

.footer-copyright {
    color: var(--text);
}

.footer-links {
    margin-left: auto;
    display: flex;
    gap: 14px;
}

.footer-links a {
    color: var(--accent);
    text-decoration: none;
}

.footer-links a:hover {
    text-decoration: underline;
}

@media (max-width: 700px) {
    .compose-header {
        flex-wrap: wrap;
    }

    .header-actions {
        margin-left: 0;
        width: 100%;
        justify-content: flex-end;
    }

    .footer-links {
        margin-left: 0;
        width: 100%;
    }
}

.compose-brand {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: 1.25rem;
    color: var(--text);
    text-decoration: none;
}

.compose-brand img {
    display: block;
    width: 32px;
    height: 32px;
}

.compose-tag {
    color: var(--muted);
    font-size: 0.95rem;
}

.compose-main h1 {
    margin: 0 0 8px;
    font-size: 1.8rem;
}

.lede {
    color: var(--muted);
    margin: 0 0 24px;
}

.compose-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
    /* matches the form's internal gap: equal space above and below the
       publish button */
    margin-bottom: 16px;
}

.compose-form label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-weight: 600;
    font-size: 0.9rem;
}

.compose-form textarea,
.compose-form input[type="password"],
.compose-form input[type="text"],
.compose-form select {
    font: 15px/1.5 "Cascadia Code", Consolas, monospace;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text);
}

.compose-form textarea {
    width: 100%;
    box-sizing: border-box;
    resize: vertical;
}

.compose-row {
    display: grid;
    grid-template-columns: 1fr 1fr auto;
    gap: 16px;
    align-items: end;
}

.compose-form .check {
    flex-direction: row;
    align-items: center;
    font-weight: 500;
    /* vertically centered against the 43px select in the same grid row */
    align-self: end;
    padding-bottom: 0;
    margin-bottom: 11px;
}

.btn {
    display: inline-block;
    align-self: flex-start;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 10px 16px;
    /* <button> keeps the UA font otherwise — labels and buttons must match */
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
}

.btn:hover {
    filter: brightness(1.05);
}

.compose-form button[type="submit"] {
    background: #81c784;
}

.md-btn-ghost {
    background: transparent;
    color: var(--accent);
    border: 1px solid var(--border);
}

/* Terms of Service consent dialog on the start page. */
.compose-dialog {
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px 22px;
    max-width: 480px;
    box-shadow: 0 12px 40px rgba(31, 35, 40, 0.22);
}

.compose-dialog::backdrop {
    background: rgba(31, 35, 40, 0.45);
}

.compose-dialog h2 {
    margin: 0 0 10px;
    font-size: 1.15rem;
}

.compose-dialog p {
    margin: 0 0 10px;
}

.compose-dialog-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 14px;
}

.form-error {
    color: var(--error);
    font-weight: 600;
}

.result-card {
    border: 1px solid var(--border);
    background: var(--fill);
    border-radius: 10px;
    padding: 16px 18px;
    margin-bottom: 24px;
}

.result-card h2 {
    margin: 0 0 8px;
    font-size: 1.1rem;
}

.token-line {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin: 8px 0;
}

.token-line span {
    color: var(--muted);
    min-width: 7rem;
}

.token-line code {
    font-family: "Cascadia Code", Consolas, monospace;
    font-size: 0.85rem;
    word-break: break-all;
}

.hint {
    color: var(--muted);
    font-size: 0.9rem;
}

#blazor-error-ui {
    background: #fff8c5;
    bottom: 0;
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
    box-sizing: border-box;
}

:root[data-theme="dark"] #blazor-error-ui {
    background: #33270a;
    color: var(--text);
}

@media (max-width: 700px) {
    .compose-row {
        grid-template-columns: 1fr;
    }
}

/* Markdown file drop target on the start page. */
/* Drag&drop status line: invisible while empty, so it does not add flex
   gaps between the textarea and the settings row. */
#md-drop-status:empty {
    display: none;
}

#md-drop-status {
    margin: 0;
}

.compose-form textarea.is-drag-over {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(9, 105, 218, 0.18);
    background: var(--fill);
}

/* Text pages (Help, Terms, MDPack overview). */
.help-section {
    margin: 0 0 28px;
}

.help-section h2 {
    font-size: 1.25rem;
    margin: 0 0 10px;
}

.help-section p {
    margin: 0 0 10px;
}

.help-section a {
    color: var(--accent);
}

.md-benefits {
    margin: 0;
    padding-left: 20px;
    display: grid;
    gap: 8px;
}

.md-benefits li::marker {
    color: var(--accent);
}

/* MDPack overview: sample cards with one-click publishing. */
.mdpack-learn {
    margin: 14px 0 0;
    font-weight: 600;
}

.mdpack-learn a {
    color: var(--accent);
    text-decoration: none;
}

.mdpack-learn a:hover {
    text-decoration: underline;
}

.md-sample-card {
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: 18px;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 18px;
    background: var(--bg);
}

.md-sample-preview img {
    display: block;
    width: 100%;
    height: auto;
    border-radius: 10px;
    border: 1px solid var(--border);
}

.md-sample-body h3 {
    margin: 0 0 8px;
    font-size: 1.05rem;
}

.md-sample-body p {
    margin: 0 0 12px;
}

.md-sample-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.md-sample-actions .btn {
    align-self: auto;
}

.md-sample-result {
    margin: 10px 0 0;
    min-height: 1.2em;
}

.md-sample-url {
    display: block;
    word-break: break-all;
    margin-bottom: 6px;
}

.md-sample-result a {
    color: var(--accent);
    font-weight: 600;
    margin-right: 12px;
}

/* Narrow screens and tablets: compose pages. */
@media (max-width: 700px) {
    .compose-shell {
        padding: 20px 14px 48px;
    }

    .compose-main h1 {
        font-size: 1.5rem;
    }

    .md-sample-card {
        grid-template-columns: 1fr;
    }

    .compose-dialog {
        width: calc(100vw - 24px);
        max-width: none;
    }
}

@media (max-width: 480px) {
    .compose-header {
        gap: 8px;
    }

    .compose-tag {
        display: none;
    }

    /* 16px inputs prevent the iOS focus auto-zoom. */
    .compose-form textarea,
    .compose-form input[type="password"],
    .compose-form input[type="text"],
    .compose-form select {
        font-size: 16px;
    }

    .result-card {
        padding: 14px;
    }

    .result-card h2 {
        font-size: 1.05rem;
    }

    .footer-note {
        width: 100%;
    }
}

/* Definitions list on the Rules page. */
.terms-definitions {
    margin: 0 0 10px;
    display: grid;
    gap: 10px;
}

.terms-definitions dt {
    font-weight: 700;
}

.terms-definitions dd {
    margin: 2px 0 0;
}

/* MD Reader Pro page. */
.reader-hero {
    display: flex;
    align-items: center;
    gap: 18px;
    margin-bottom: 26px;
}

.reader-store {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.reader-store img {
    display: block;
}

.inline-icon {
    vertical-align: -5px;
    margin-right: 6px;
}

/* Demo publication reuse note on the MDPack page. */
.md-sample-reuse {
    margin-bottom: 6px;
}

.footer-links a img {
    vertical-align: -3px;
    margin-right: 5px;
}

/* The Store button sits inside .help-section, whose link color would
   otherwise override the .btn white-on-blue text. */
.btn.reader-store {
    color: #fff;
}

/* MDPack upload row on the start page: the styled chooser replaces the
   native file input, whose button text follows the browser language. */
.mdpack-upload-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
}

.mdpack-upload-row label {
    cursor: pointer;
}

#mdpack-file-name {
    max-width: 260px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Theme switcher: options menu, icon follows currentColor. */
.theme-icon {
    color: var(--accent);
}

.theme-menu button {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px 10px;
    border: none;
    border-radius: 7px;
    background: transparent;
    color: var(--text);
    font: inherit;
    font-size: 0.9rem;
    text-align: left;
    cursor: pointer;
}

.theme-menu button:hover {
    background: var(--fill);
}

.theme-menu button.is-active {
    color: var(--accent);
    font-weight: 700;
}

.theme-option-icon {
    color: var(--muted);
    flex: none;
}

.theme-menu button.is-active .theme-option-icon {
    color: var(--accent);
}

/* The summary icon follows the stored preference (system/light/dark).
   JS also sets the hidden attribute; !important wins over the show rule
   below, so a stale display value cannot leave the old icon on screen. */
.theme-switch .theme-icon-light,
.theme-switch .theme-icon-dark {
    display: none;
}

.theme-switch svg.theme-icon[hidden] {
    display: none !important;
}

.theme-switch[data-icon="light"] .theme-icon-system,
.theme-switch[data-icon="dark"] .theme-icon-system {
    display: none;
}

.theme-switch[data-icon="light"] .theme-icon-light {
    display: block;
}

.theme-switch[data-icon="dark"] .theme-icon-dark {
    display: block;
}

/* Microsoft Store badge on the MD Reader Pro page. */
.msstore-badge img {
    display: block;
    height: auto;
    transition: transform 0.15s ease;
}

.msstore-badge:hover img {
    transform: scale(1.03);
}

/* Product screenshot on the MD Reader Pro page. The column is 760px;
   the bitmap is 1024px wide so a click can open it larger than the article. */
.shot {
    margin: 16px 0 4px;
    display: flex;
    justify-content: center;
}

.shot-open {
    display: block;
    width: 100%;
    max-width: 100%;
    margin: 0;
    padding: 0;
    border: none;
    border-radius: 12px;
    background: transparent;
    cursor: zoom-in;
    line-height: 0;
}

.shot-open img {
    display: block;
    width: 100%;
    height: auto;
    border-radius: 12px;
}

.shot-open:hover img,
.shot-open:focus-visible img {
    outline: 1px solid var(--border);
    outline-offset: 0;
}

.shot-open:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
}

.shot-dialog {
    width: fit-content;
    max-width: calc(100vw - 24px);
    max-height: calc(100dvh - 24px);
    margin: auto;
    padding: 0;
    border: none;
    background: transparent;
    overflow: visible;
}

.shot-dialog::backdrop {
    background: rgba(15, 18, 22, 0.78);
}

.shot-frame {
    position: relative;
    line-height: 0;
}

.shot-dialog img {
    display: block;
    width: auto;
    height: auto;
    max-width: min(1024px, calc(100vw - 32px));
    max-height: calc(100dvh - 48px);
    border-radius: 10px;
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
}

.shot-close {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 1;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 1px solid rgba(31, 35, 40, 0.14);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.94);
    color: #1f2328;
    font: 400 24px/1 "Segoe UI", sans-serif;
    cursor: pointer;
}

.shot-close:hover {
    background: #fff;
}

.shot-close:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* Illustration figures inside the Help page. */
.help-figure {
    margin: 14px 0 16px;
    display: flex;
    justify-content: center;
}

.help-figure img {
    display: block;
    max-width: 100%;
    height: auto;
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 6px;
}

/* MD Reader Pro badge inside the MDPack card on the start page. */
.mdpack-app {
    margin-top: 16px;
}

.mdpack-app-note {
    margin: 8px 0 0;
}

/* MDPack publish result: roomy lines instead of a cramped run-on. */
#mdpack-result {
    display: grid;
    gap: 12px;
    margin-top: 16px;
    justify-items: start;
}

#mdpack-result .mdpack-published-line {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin: 0;
}

#mdpack-result .mdpack-published-line a {
    color: var(--accent);
    font-weight: 600;
}

#mdpack-result details summary {
    cursor: pointer;
}

#mdpack-result details[open] summary {
    margin-bottom: 6px;
}

/* The Markdown label line: caption left, "Format: …" right on the same
   baseline; the full status line sits under the textarea as before. */
.label-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 12px;
}

.md-file-format {
    font-weight: 400;
}

.md-file-status {
    margin: -4px 0 0;
    min-height: 1.2em;
}
