* {
    box-sizing: border-box;
}

:root {
    color-scheme: light;
    --bg: #f2f2f7;
    --surface: rgba(255, 255, 255, 0.82);
    --surface-strong: #ffffff;
    --surface-soft: #f7f7fa;
    --border: rgba(60, 60, 67, 0.12);
    --text: #0f172a;
    --muted: #6b7280;
    --primary: #111827;
    --danger: #dc2626;
    --shadow: 0 12px 34px rgba(15, 23, 42, 0.06);
}

html,
body {
    margin: 0;
    min-height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family:
        -apple-system,
        BlinkMacSystemFont,
        "SF Pro Text",
        "PingFang SC",
        "Helvetica Neue",
        sans-serif;
}

button,
a,
label,
img,
summary,
textarea {
    -webkit-tap-highlight-color: transparent;
}

.page-shell {
    width: min(860px, calc(100vw - 14px));
    margin: 0 auto;
    padding: 8px 0 20px;
}

.topbar,
.composer-shell {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 22px;
    box-shadow: var(--shadow);
    backdrop-filter: saturate(180%) blur(20px);
}

.topbar {
    position: sticky;
    top: 8px;
    z-index: 5;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 8px 10px;
    margin-bottom: 10px;
}

.topbar-status,
.topbar-meta,
.topbar-actions,
.image-viewer-actions,
.image-viewer-meta {
    display: flex;
    align-items: center;
}

.topbar-status {
    gap: 10px;
    min-width: 0;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 0 8px;
    min-height: 24px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.7);
    border: 1px solid var(--border);
    color: var(--muted);
    font-size: 11px;
    white-space: nowrap;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 999px;
    background: #22c55e;
}

.topbar-actions {
    gap: 6px;
    flex-shrink: 0;
}

.topbar-actions > * {
    min-height: 32px;
    padding: 0 12px;
}

.topbar-meta {
    flex-wrap: wrap;
    gap: 6px 10px;
    color: var(--muted);
    font-size: 11px;
}

.workspace {
    display: grid;
    gap: 10px;
}

.composer-shell {
    padding: 10px;
}

.primary-action,
.secondary-action,
.danger-action,
.viewer-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
    padding: 0 14px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface-soft);
    color: var(--text);
    font: inherit;
    font-size: 13px;
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
    transition: background 0.18s ease, border-color 0.18s ease, transform 0.18s ease;
    outline: none;
    appearance: none;
    -webkit-appearance: none;
}

.primary-action:active,
.secondary-action:active,
.danger-action:active,
.viewer-action:active {
    transform: scale(0.98);
}

.primary-action {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.danger-action,
.viewer-action.danger {
    color: var(--danger);
}

#image-input {
    display: none;
}



.rich-editor .ProseMirror {
    width: 100%;
    min-height: 46vh;
    padding: 16px;
    border-radius: 18px;
    background: var(--surface-strong);
    color: var(--text);
    font-size: 16px;
    outline: none;
    box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.04);
}

.rich-editor .ProseMirror:focus {
    box-shadow:
        inset 0 1px 2px rgba(15, 23, 42, 0.03),
        0 0 0 4px rgba(15, 23, 42, 0.06);
}

.rich-editor .ProseMirror p.is-editor-empty:first-child::before {
    content: attr(data-placeholder);
    float: left;
    height: 0;
    color: var(--muted);
    pointer-events: none;
}

.rich-editor img {
    display: block;
    max-width: 100%;
    height: auto;
    margin: 8px 0;
    border-radius: 10px;
}

.rich-editor img {
    cursor: pointer;
    transition: filter 0.12s, outline-color 0.12s;
}

.rich-editor img:hover {
    outline: 2px solid rgba(59, 130, 246, 0.25);
    outline-offset: 2px;
}

/* 选区里的图片：和文字选区同一个蓝，描边 + 压暗，让人一眼看出“图也选进去了” */
.rich-editor img.in-selection,
.rich-editor img.ProseMirror-selectednode {
    outline: 3px solid rgba(59, 130, 246, 0.85);
    outline-offset: 2px;
    filter: brightness(0.78) saturate(0.9);
}

.rich-editor table {
    width: 100%;
    margin: 8px 0;
    border-collapse: collapse;
}

.rich-editor th,
.rich-editor td {
    padding: 6px 8px;
    border: 1px solid var(--border);
    vertical-align: top;
}

.rich-editor th p,
.rich-editor td p {
    margin: 0;
}

.rich-editor blockquote {
    margin: 8px 0;
    padding-left: 12px;
    border-left: 3px solid var(--border);
    color: var(--muted);
}

.rich-editor code {
    padding: 1px 4px;
    border-radius: 4px;
    background: rgba(15, 23, 42, 0.06);
}

.rich-editor pre code {
    padding: 0;
    background: none;
}

.image-viewer {
    position: fixed;
    inset: 0;
    z-index: 30;
}

.image-viewer-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 18, 24, 0.88);
    backdrop-filter: blur(28px) saturate(160%);
}

.image-viewer-shell {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 14px;
    width: min(100vw - 24px, 1200px);
    height: 100vh;
    height: 100dvh;
    margin: 0 auto;
    padding: 12px 0 20px;
}

.image-viewer-stage {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 0;
    flex: 1;
    overflow: auto;
}

.image-viewer-img {
    max-width: 100%;
    max-height: calc(100vh - 144px);
    max-height: calc(100dvh - 144px);
    border-radius: 28px;
    box-shadow: 0 28px 72px rgba(0, 0, 0, 0.28);
    transition: transform 0.22s ease, border-radius 0.22s ease;
    cursor: pointer;
    transform-origin: center center;
}

.image-viewer-img.is-zoomed {
    cursor: zoom-out;
    transform: scale(1.9);
    border-radius: 12px;
}

.image-viewer-panel {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 14px;
    border-radius: 24px;
    background: rgba(28, 28, 30, 0.72);
    border: 1px solid rgba(255, 255, 255, 0.08);
    backdrop-filter: blur(24px);
}

.image-viewer-name {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: rgba(255, 255, 255, 0.92);
    font-size: 14px;
    font-weight: 700;
}

.image-viewer-meta {
    justify-content: space-between;
    gap: 12px;
}

.image-viewer-meta-text {
    color: rgba(255, 255, 255, 0.62);
    font-size: 12px;
}

.image-viewer-actions {
    gap: 8px;
}

.viewer-action {
    flex: 1 1 0;
    min-height: 40px;
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.92);
}

.markdown-body {
    line-height: 1.7;
    word-break: break-word;
}

.markdown-body :first-child {
    margin-top: 0;
}

.markdown-body pre {
    overflow: auto;
    padding: 12px;
    border-radius: 10px;
    background: #111827;
    color: #f9fafb;
}

.markdown-body a {
    color: var(--primary);
}

@media (min-width: 900px) {
    .page-shell {
        width: min(1100px, calc(100vw - 24px));
        padding-top: 12px;
    }

    .rich-editor .ProseMirror {
        min-height: 54vh;
    }
}

@media (max-width: 680px) {
    .page-shell {
        width: calc(100vw - 10px);
        padding-bottom: 16px;
    }

    .topbar {
        top: 6px;
        flex-direction: column;
        align-items: stretch;
        border-radius: 18px;
        gap: 6px;
    }

    .topbar-actions > * {
        flex: 1 1 0;
    }

    #updated-at {
        display: none;
    }

    .image-viewer-shell {
        width: calc(100vw - 12px);
        padding: 8px 0 12px;
    }

    .image-viewer-img {
        max-height: calc(100vh - 156px);
        max-height: calc(100dvh - 156px);
        border-radius: 22px;
    }

    .image-viewer-img.is-zoomed {
        transform: scale(1.55);
    }

    .image-viewer-panel {
        gap: 10px;
        padding: 12px;
    }

    .image-viewer-meta {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
    }
}

.viewer-action[hidden] {
    display: none;
}

.viewer-action:disabled {
    opacity: 0.4;
    cursor: default;
}

.image-editor {
    position: fixed;
    inset: 0;
    z-index: 40;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px 10px 6px;
    background: #0f1218;
}

.image-editor[hidden] {
    display: none;
}

.image-editor-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.image-editor-header .viewer-action {
    flex: 0 0 auto;
    min-height: 36px;
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.12);
    color: #fff;
}

.image-editor-header .primary-action {
    min-height: 36px;
    background: #fff;
    border-color: #fff;
    color: #111827;
}

.image-editor-title {
    color: rgba(255, 255, 255, 0.85);
    font-size: 14px;
    font-weight: 700;
}

/* 工具放底部，单手拿手机拇指够得着 */
.image-editor-tools {
    display: flex;
    justify-content: center;
    gap: 4px;
    padding-bottom: env(safe-area-inset-bottom);
}

.editor-tool {
    display: inline-flex;
    flex: 0 1 72px;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-height: 54px;
    padding: 4px 2px;
    border: 0;
    border-radius: 14px;
    background: transparent;
    color: rgba(255, 255, 255, 0.85);
    font: inherit;
    font-size: 11px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.editor-tool-icon {
    font-size: 22px;
    line-height: 1;
}

.editor-tool.is-active {
    background: rgba(59, 130, 246, 0.9);
    color: #fff;
}

.editor-tool:active {
    background: rgba(255, 255, 255, 0.12);
}

.editor-tool:disabled {
    opacity: 0.35;
    cursor: default;
}

.image-editor-color {
    width: 24px;
    height: 24px;
    padding: 0;
    border: 2px solid rgba(255, 255, 255, 0.85);
    border-radius: 999px;
    background: none;
    cursor: pointer;
}

.image-editor-color::-webkit-color-swatch-wrapper {
    padding: 0;
}

.image-editor-color::-webkit-color-swatch {
    border: 0;
    border-radius: 999px;
}

.image-editor-stage {
    display: flex;
    flex: 1;
    min-height: 0;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

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

#image-editor-canvas {
    display: block;
    touch-action: none;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
}

/* 裁剪框外压暗，框内保持原样 */
.image-editor-crop {
    position: absolute;
    border: 2px solid #fff;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.5);
    pointer-events: none;
}

.image-editor-crop[hidden] {
    display: none;
}

.image-editor-hint {
    margin: 0;
    color: rgba(255, 255, 255, 0.7);
    font-size: 12px;
    text-align: center;
}
