/* ────────────────────────────────────────────────────────────
   首页（index.php）外壳样式。
   设计令牌见 tokens.css，渲染结果样式见 markdown.css —— 不要在这里
   重复 .md-body 的任何规则，否则又会和分享页跑偏。
   加载顺序：fonts.css → tokens.css → markdown.css → index.css
   ──────────────────────────────────────────────────────────── */

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

html {
    font-size: 16px;
    scroll-behavior: smooth;
    overflow-x: hidden;
}

body {
    overflow-x: hidden;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: background 0.4s, color 0.4s;
    padding-top: var(--topbar-h, 52px);
}

/* ─── Top Bar ─── */
.topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    border-bottom: 1px solid var(--border-light);
    backdrop-filter: saturate(180%) blur(14px);
    -webkit-backdrop-filter: saturate(180%) blur(14px);
    background: color-mix(in srgb, var(--bg) 82%, transparent);
}

.topbar-inner {
    max-width: 1280px;
    margin: 0 auto;
    padding: 11px 32px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    position: relative;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 1rem;
    color: var(--text);
    letter-spacing: -0.02em;
    white-space: nowrap;
    min-width: 0;
    flex-shrink: 1;
    overflow: hidden;
}

.logo-icon {
    width: 28px;
    height: 28px;
    background: var(--accent);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 700;
    font-size: 15px;
    font-family: var(--mono);
    letter-spacing: -0.5px;
    flex-shrink: 0;
    box-shadow: 0 2px 6px -2px color-mix(in srgb, var(--accent) 70%, transparent);
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--bg-card);
    color: var(--text-secondary);
    font-size: 0.82rem;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.18s var(--ease);
    white-space: nowrap;
    min-height: 32px;
    box-shadow: var(--shadow-xs);
}

.btn:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-soft);
}

.btn:active {
    transform: translateY(1px);
}

.btn.active {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-soft);
}

.btn-icon {
    padding: 7px 9px;
}

.btn svg {
    width: 16px;
    height: 16px;
}

.file-name {
    font-size: 0.8rem;
    color: var(--text-muted);
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ─── Language Switcher ─── */
.lang-switcher {
    position: relative;
}

.lang-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.lang-current {
    font-size: 0.75rem;
    font-weight: 400;
    color: var(--text-secondary);
}

.lang-menu {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 4px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    min-width: 100px;
    z-index: 200;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-4px);
    transition: all 0.2s;
}

.lang-menu.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.lang-option {
    display: block;
    padding: 8px 14px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
}

.lang-option:hover {
    background: var(--accent-soft);
    color: var(--accent);
}

.lang-option.active {
    color: var(--accent);
    font-weight: 400;
}

.lang-option:first-child {
    border-radius: var(--radius-md) var(--radius-md) 0 0;
}

.lang-option:last-child {
    border-radius: 0 0 var(--radius-md) var(--radius-md);
}

/* ─── Layout ─── */
.container {
    max-width: 1280px;
    width: 100%;
    margin: 0 auto;
    padding: 24px 32px 80px;
    flex: 1;
    display: flex;
    flex-direction: column;
}

/* ─── Landing / Input State ─── */
.landing {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    min-height: 0;
    gap: 32px;
    animation: fadeUp 0.6s ease;
}

@keyframes fadeUp {
    from {
            opacity: 0;
            transform: translateY(16px);
}

    to {
            opacity: 1;
            transform: translateY(0);
}
}

.landing-title {
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    text-align: center;
    color: var(--text);
}

.landing-subtitle {
    font-size: 1rem;
    color: var(--text-muted);
    text-align: center;
    margin-top: -16px;
    font-weight: 400;
}

.landing-counter {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-align: center;
    margin-top: -20px;
    font-family: var(--mono);
    opacity: 0;
    transition: opacity 0.5s;
}

.landing-counter.loaded {
    opacity: 1;
}

.input-area {
    width: 100%;
    max-width: 780px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Drop zone */
.dropzone {
    border: 2px dashed var(--border);
    border-radius: var(--radius-md);
    padding: 40px 24px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s;
    background: var(--bg-card);
    position: relative;
}

.dropzone:hover,
.dropzone.drag-over {
    border-color: var(--accent);
    background: var(--accent-soft);
}

.dropzone.drag-over {
    transform: scale(1.01);
}

.dropzone-icon {
    width: 48px;
    height: 48px;
    margin: 0 auto 12px;
    border-radius: var(--radius-lg);
    background: var(--accent-soft);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent);
}

.dropzone-icon svg {
    width: 24px;
    height: 24px;
}

.dropzone-text {
    font-size: 0.92rem;
    color: var(--text-secondary);
}

.dropzone-text strong {
    color: var(--accent);
    cursor: pointer;
}

.dropzone-hint {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 6px;
}

.separator {
    display: flex;
    align-items: center;
    gap: 16px;
    color: var(--text-muted);
    font-size: 0.8rem;
}

.separator::before,
.separator::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}

/* Textarea */
.editor-wrap {
    position: relative;
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 1px solid var(--border);
    background: var(--bg-card);
    transition: border-color 0.3s;
}

.editor-wrap:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.editor {
    width: 100%;
    min-height: 220px;
    max-height: 400px;
    padding: 20px;
    border: none;
    outline: none;
    resize: vertical;
    font-family: var(--mono);
    font-size: 0.85rem;
    line-height: 1.7;
    color: var(--text);
    background: transparent;
    tab-size: 2;
}

.editor::placeholder {
    color: var(--text-muted);
}

.editor-actions {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    padding: 10px 16px;
    border-top: 1px solid var(--border-light);
    gap: 8px;
}

.editor-hint {
    margin-right: auto;
    font-size: 0.72rem;
    color: var(--text-muted);
    font-family: var(--mono);
    user-select: none;
}

.btn-render {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
    font-weight: 500;
}

.btn-render:hover {
    background: color-mix(in srgb, var(--accent) 85%, #000);
    border-color: transparent;
    color: #fff;
}

/* ─── Loading Indicator ─── */
.render-loading {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    gap: 16px;
    animation: fadeUp 0.3s ease;
}

.render-loading.visible {
    display: flex;
}

.render-loading-inner {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.88rem;
    color: var(--text-secondary);
}

.render-spinner {
    width: 20px;
    height: 20px;
    border: 2.5px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
            transform: rotate(360deg);
}
}

.render-progress-bar {
    width: 240px;
    max-width: 80%;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    overflow: hidden;
}

.render-progress-fill {
    height: 100%;
    width: 0%;
    background: var(--accent);
    border-radius: 2px;
    transition: width 0.3s ease;
}

/* ─── Preview State ─── */
.preview-container {
    display: none;
    animation: fadeUp 0.5s ease;
}

.preview-container.active {
    display: block;
}

.landing.hidden {
    display: none;
}

/* ─── Back to top ─── */
.back-to-top {
    position: fixed;
    bottom: 28px;
    right: 28px;
    z-index: 200;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-secondary);
    box-shadow: var(--shadow);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity .3s, border-color .2s, color .2s;
}

.back-to-top.visible { opacity: 1; pointer-events: auto; }

.back-to-top:hover { border-color: var(--accent); color: var(--accent); }

.back-to-top svg { width: 18px; height: 18px; }

/* ─── TOC Sidebar ─── */
.toc-toggle {
    display: none;
}

.toc-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 49;
}

.toc-overlay.visible {
    display: block;
}

.toc-panel {
    position: fixed;
    right: 24px;
    top: calc(var(--topbar-h, 52px) + 8px);
    width: 240px;
    max-height: calc(100vh - var(--topbar-h, 52px) - 28px);
    overflow-y: auto;
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    padding: 16px 18px;
    box-shadow: var(--shadow);
    z-index: 50;
    display: none;
    animation: fadeUp 0.3s ease;
}

.toc-panel.visible {
    display: block;
}

.toc-title {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin-bottom: 10px;
    font-family: var(--font);
}

.toc-panel a {
    display: block;
    font-size: 0.8rem;
    line-height: 1.5;
    color: var(--text-secondary);
    text-decoration: none;
    padding: 3px 0;
    transition: color 0.2s;
}

.toc-panel a:hover {
    color: var(--accent);
}

.toc-panel a.toc-h3 {
    padding-left: 14px;
    font-size: 0.76rem;
}

.toc-panel a.toc-h4 {
    padding-left: 28px;
    font-size: 0.73rem;
}

/* ─── Share Modal ─── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(4px);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s;
}

.modal-overlay.visible {
    opacity: 1;
    pointer-events: auto;
}

.modal {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 32px;
    max-width: 460px;
    width: 90%;
    box-shadow: var(--shadow-lg);
    transform: translateY(12px) scale(0.97);
    transition: transform 0.25s;
}

.modal-overlay.visible .modal {
    transform: translateY(0) scale(1);
}

.modal-title {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 6px;
    font-family: var(--font);
}

.modal-desc {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 20px;
    line-height: 1.5;
}

.modal-link-row {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.modal-link-input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--bg-secondary);
    color: var(--text);
    font-size: 0.84rem;
    font-family: var(--mono);
    outline: none;
}

.modal-link-input:focus {
    border-color: var(--accent);
}

.btn-copy-link {
    padding: 10px 16px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius-md);
    font-size: 0.84rem;
    font-family: inherit;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.2s;
}

.btn-copy-link:hover {
    background: color-mix(in srgb, var(--accent) 85%, #000);
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 4px;
}

/* ─── 分享有效期选择 ─── */
.field-label {
    font-size: 0.76rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 9px;
}

.day-picker {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 6px;
}

.day-opt {
    padding: 9px 0;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--bg-card);
    color: var(--text-secondary);
    font-family: var(--mono);
    font-variant-numeric: tabular-nums;
    font-size: 0.86rem;
    line-height: 1;
    cursor: pointer;
    transition: all 0.16s var(--ease);
}

.day-opt:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.day-opt.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
    font-weight: 700;
    box-shadow: 0 2px 8px -3px color-mix(in srgb, var(--accent) 80%, transparent);
}

.day-picker-hint {
    margin-top: 10px;
    font-size: 0.78rem;
    color: var(--text-muted);
    line-height: 1.5;
    min-height: 1.2em;
}

.modal-close {
    padding: 8px 18px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.84rem;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s;
}

.modal-close:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.share-loading {
    text-align: center;
    padding: 20px 0;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.share-error {
    color: #d04040;
    font-size: 0.84rem;
    margin-bottom: 12px;
}

.share-expire-hint {
    font-size: 0.78rem;
    color: var(--text-muted);
    line-height: 1.5;
    padding: 10px 12px;
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    margin-bottom: 14px;
}

.share-expire-hint svg {
    width: 13px;
    height: 13px;
    vertical-align: -2px;
    margin-right: 4px;
}

/* ─── Footer ─── */
.site-footer {
    text-align: center;
    padding: 24px 16px 32px;
    font-size: 0.76rem;
    color: var(--text-muted);
    line-height: 1.7;
    border-top: 1px solid var(--border-light);
    max-width: 1280px;
    margin: 0 auto;
}

.site-footer strong {
    font-weight: 500;
    color: var(--text-secondary);
}

.site-footer .icp-link {
    color: var(--text-muted);
    text-decoration: none;
    transition: color 0.2s;
}

.site-footer .icp-link:hover {
    color: var(--accent);
}

/* ─── Print ─── */
@media print {
    .topbar,
.toc-panel,
.toc-overlay,
.modal-overlay,
.landing,
.site-footer,
#btnBack,
#btnToc,
#btnPrint,
#btnShare {
            display: none !important;
}

    .preview-container {
            display: block !important;
}

    body {
            background: #fff !important;
            color: #000 !important;
}

    .container {
            padding: 0;
            max-width: 100%;
}
}

/* ─── Responsive: Tablet ─── */
@media (max-width: 900px) {
    .topbar-inner {
            padding: 10px 16px;
}

    .container {
            padding: 16px 16px 48px;
}

    .landing {
            gap: 24px;
}

    .landing-title {
            font-size: 1.75rem;
}

    .landing-subtitle {
            font-size: 0.92rem;
}

    .toc-panel {
            position: fixed;
            right: 0;
            left: 0;
            bottom: 0;
            top: auto;
            width: 100%;
            max-height: 55vh;
            border-radius: var(--radius-lg) var(--radius-lg) 0 0;
            box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.12);
            padding: 20px 20px 28px;
            animation: slideUp 0.3s ease;
}

    @keyframes slideUp {
            from {
                transform: translateY(100%);
            }
    
            to {
                transform: translateY(0);
            }
}

    .toc-overlay {
            background: rgba(0, 0, 0, 0.3);
}
}

/* ─── Responsive: Mobile ─── */
@media (max-width: 600px) {
    .topbar-inner {
            padding: 8px 12px;
            gap: 6px;
}

    .logo>span:not(.file-name) {
            display: none;
}

    .logo .file-name {
            max-width: 90px;
            font-size: 0.7rem;
}

    .topbar-actions {
            gap: 3px;
}

    .btn {
            padding: 6px 8px;
            font-size: 0.78rem;
}

    .btn span.label {
            display: none;
}

    .btn svg {
            width: 15px;
            height: 15px;
}

    .btn-icon {
            padding: 6px 7px;
}

    #btnPrint {
            display: none !important;
}

    .container {
            padding: 12px 14px 40px;
}

    .landing {
            gap: 20px;
}

    .landing-title {
            font-size: 1.35rem;
            letter-spacing: -0.02em;
}

    .landing-subtitle {
            font-size: 0.85rem;
            margin-top: -10px;
}

    .dropzone {
            padding: 28px 16px;
}

    .dropzone-icon {
            width: 40px;
            height: 40px;
            border-radius: var(--radius-lg);
}

    .dropzone-icon svg {
            width: 20px;
            height: 20px;
}

    .dropzone-text {
            font-size: 0.84rem;
}

    .dropzone-hint {
            font-size: 0.72rem;
}

    .editor {
            min-height: 160px;
            padding: 14px;
            font-size: 0.8rem;
            line-height: 1.6;
}

    .editor-actions {
            padding: 8px 12px;
}

    .separator {
            font-size: 0.74rem;
            gap: 10px;
}

    .site-footer {
            padding: 20px 14px 24px;
            font-size: 0.7rem;
}

    .modal {
            padding: 24px 20px;
            border-radius: var(--radius-lg);
}

    .modal-title {
            font-size: 1rem;
}

    .modal-desc {
            font-size: 0.8rem;
}

    .modal-link-input {
            font-size: 0.76rem;
            padding: 8px 10px;
}

    .btn-copy-link {
            padding: 8px 12px;
            font-size: 0.78rem;
}
}

/* ─── Responsive: Small Mobile ─── */
@media (max-width: 380px) {
    .landing-title {
            font-size: 1.2rem;
}

    .editor {
            min-height: 140px;
            font-size: 0.76rem;
}
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

