:root {
    color-scheme: light;
    --bg: #f6f7f9;
    --panel: #ffffff;
    --text: #20242a;
    --muted: #667085;
    --line: #d9dee7;
    --accent: #146c94;
    --accent-strong: #0d4f6f;
    --danger: #b42318;
}

* {
    box-sizing: border-box;
}

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

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

a:hover {
    text-decoration: underline;
}

input,
textarea,
button {
    font: inherit;
}

input,
textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 10px 12px;
    background: #fff;
}

.tooltip-field {
    position: relative;
}

.tooltip-field::after {
    content: attr(data-tooltip);
    position: absolute;
    left: 0;
    bottom: -34px;
    z-index: 2;
    display: none;
    padding: 5px 9px;
    border-radius: 6px;
    background: #20242a;
    color: #fff;
    font-size: 0.85rem;
    line-height: 1.3;
    white-space: nowrap;
}

.tooltip-field:hover::after,
.tooltip-field:focus-within::after {
    display: block;
}

textarea {
    resize: vertical;
    font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
    line-height: 1.55;
}

button,
.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    border: 0;
    border-radius: 6px;
    padding: 8px 16px;
    background: var(--accent);
    color: #fff;
    cursor: pointer;
}

button:hover,
.button:hover {
    background: var(--accent-strong);
    text-decoration: none;
}

.secondary {
    background: #e8eef3;
    color: var(--text);
}

.secondary:hover {
    background: #dce5ec;
}

.danger {
    background: var(--danger);
}

.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    background: #e8eef3;
}

.login-shell {
    width: min(420px, calc(100vw - 32px));
}

.login-panel,
.post-card,
.side-panel,
.upload-box,
.result-box {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 24px;
}

.login-panel h1 {
    margin: 0;
    font-size: 2rem;
}

.login-panel p {
    margin: 4px 0 24px;
    color: var(--muted);
}

.site-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 32px;
    background: #fff;
    border-bottom: 1px solid var(--line);
}

.brand {
    color: var(--text);
    font-weight: 700;
}

.site-header nav {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
}

.site-header form {
    margin: 0;
}

.link-button {
    min-height: auto;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--accent);
}

.link-button:hover {
    background: transparent;
    text-decoration: underline;
}

.container {
    width: min(1080px, calc(100vw - 32px));
    margin: 32px auto 56px;
}

.narrow {
    width: min(820px, calc(100vw - 32px));
}

.page-head {
    margin-bottom: 24px;
}

.page-head h1,
.post-detail h1,
.container h1 {
    margin: 0 0 8px;
    line-height: 1.25;
}

.page-head p,
.meta,
.side-panel p {
    color: var(--muted);
}

.post-list {
    display: grid;
    gap: 12px;
}

.post-card {
    display: flex;
    justify-content: space-between;
    gap: 16px;
}

.post-title {
    color: var(--text);
    font-size: 1.15rem;
    font-weight: 700;
}

.meta {
    margin: 4px 0 0;
    font-size: 0.92rem;
}

.draft {
    display: inline-block;
    margin-left: 8px;
    padding: 1px 8px;
    border-radius: 999px;
    background: #fff3cd;
    color: #7a4d00;
    font-size: 0.85rem;
}

.stack {
    display: grid;
    gap: 16px;
}

.editor-page {
    width: min(1320px, calc(100vw - 32px));
}

.editor-form {
    margin-top: 16px;
}

.editor-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(320px, 0.9fr);
    gap: 18px;
    align-items: start;
}

.editor-pane {
    display: grid;
    gap: 8px;
}

.preview-pane {
    min-width: 0;
}

.preview-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 8px;
}

.preview-head h2 {
    margin: 0;
    font-size: 1rem;
}

.preview-head span {
    color: var(--muted);
    font-size: 0.88rem;
}

.checkbox-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.checkbox-row input {
    width: auto;
}

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

.delete-form {
    margin-top: 24px;
}

.markdown-help {
    display: grid;
    gap: 10px;
    margin-top: 18px;
}

.markdown-help code {
    display: block;
    padding: 10px;
    overflow-wrap: anywhere;
    background: #f1f3f5;
    border-radius: 6px;
}

.upload-status {
    min-height: 28px;
    margin: 8px 0 0;
    color: var(--muted);
    font-size: 0.92rem;
}

.upload-status.failed {
    color: var(--danger);
}

.page-drop-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: none;
    place-items: center;
    border: 6px dashed var(--accent);
    background: rgba(20, 36, 48, 0.58);
    color: var(--accent-strong);
    font-size: 2rem;
    font-weight: 700;
    pointer-events: auto;
    color: #ffffff;
}

.page-drop-overlay.visible {
    display: grid;
}

.drag-upload-active,
.drag-upload-active body {
    overflow: hidden;
}

.markdown-body {
    margin-top: 28px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 28px;
}

.preview-body {
    min-height: 520px;
    max-height: 720px;
    margin-top: 0;
    overflow: auto;
}

.markdown-body img,
.markdown-body video {
    max-width: 100%;
    height: auto;
    border-radius: 6px;
}

.markdown-body pre {
    overflow-x: auto;
    padding: 14px;
    background: #f1f3f5;
    border-radius: 6px;
}

.alert,
.notice,
.field-error {
    color: var(--danger);
}

.notice {
    margin-bottom: 16px;
}

.empty {
    color: var(--muted);
}

.result-box {
    margin-top: 24px;
}

.result-box h2 {
    margin-top: 0;
}

.file-list {
    display: grid;
    gap: 14px;
}

.file-card {
    display: grid;
    grid-template-columns: 180px minmax(0, 1fr);
    gap: 18px;
    align-items: start;
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
}

.file-preview {
    display: grid;
    place-items: center;
    aspect-ratio: 4 / 3;
    overflow: hidden;
    border-radius: 6px;
    background: #eef2f6;
    color: var(--muted);
    font-weight: 700;
}

.file-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.video-preview {
    background: #203040;
    color: #fff;
}

.file-info {
    display: grid;
    gap: 10px;
    min-width: 0;
}

.file-info h2 {
    margin: 0;
    overflow-wrap: anywhere;
    font-size: 1rem;
}

@media (max-width: 760px) {
    .site-header,
    .post-card {
        align-items: flex-start;
        flex-direction: column;
    }

    .editor-grid {
        grid-template-columns: 1fr;
    }

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