/*
 * Notion 内容渲染样式
 * 从 NotionNext (2090行 notion.css) + nextjs-notion-starter-kit 精简移植
 * 移除所有 Tailwind @apply，转为纯 CSS
 */

/* ─── 颜色变量 ────────────────────────────────────── */

:root {
    --fg-color: rgb(55, 53, 47);
    --fg-color-secondary: rgba(55, 53, 47, 0.65);
    --fg-color-0: rgba(55, 53, 47, 0.09);
    --fg-color-1: rgba(55, 53, 47, 0.16);
    --fg-color-2: rgba(55, 53, 47, 0.4);
    --fg-color-3: rgba(55, 53, 47, 0.6);
    --fg-color-6: rgba(55, 53, 47, 0.8);
    --bg-color-0: rgba(135, 131, 120, 0.15);
    --bg-color-1: rgb(247, 246, 243);
    --bg-color-2: rgba(135, 131, 120, 0.15);
    --bg-color-secondary: rgb(247, 246, 243);
    --code-header-bg: rgb(247, 246, 243);
    --code-header-fg: rgba(55, 53, 47, 0.65);
    --callout-border: rgba(55, 53, 47, 0.12);

    --notion-red: rgb(224, 62, 62);
    --notion-pink: rgb(173, 26, 114);
    --notion-blue: rgb(11, 110, 153);
    --notion-purple: rgb(105, 64, 165);
    --notion-teal: rgb(15, 123, 108);
    --notion-yellow: rgb(223, 171, 1);
    --notion-orange: rgb(217, 115, 13);
    --notion-brown: rgb(100, 71, 58);
    --notion-gray: rgb(155, 154, 151);

    --notion-red_background: rgb(251, 228, 228);
    --notion-pink_background: rgb(244, 223, 235);
    --notion-blue_background: rgb(221, 235, 241);
    --notion-purple_background: rgb(234, 228, 242);
    --notion-teal_background: rgb(221, 237, 234);
    --notion-yellow_background: rgb(251, 243, 219);
    --notion-orange_background: rgb(250, 235, 221);
    --notion-brown_background: rgb(233, 229, 227);
    --notion-gray_background: rgb(241, 241, 239);
}

.dark-mode {
    --fg-color: rgba(255, 255, 255, 0.81);
    --fg-color-secondary: rgba(222, 237, 246, 0.78);
    --fg-color-0: rgba(255, 255, 255, 0.094);
    --fg-color-1: rgba(255, 255, 255, 0.161);
    --fg-color-2: rgba(255, 255, 255, 0.4);
    --fg-color-3: rgba(255, 255, 255, 0.6);
    --fg-color-6: rgba(255, 255, 255, 0.8);
    --bg-color-0: rgba(135, 131, 120, 0.15);
    --bg-color-1: rgb(47, 52, 55);
    --bg-color-2: rgb(63, 68, 71);
    --bg-color-secondary: rgba(255, 255, 255, 0.06);
    --code-header-bg: rgba(11, 24, 36, 0.9);
    --code-header-fg: rgba(222, 237, 246, 0.84);
    --callout-border: rgba(132, 174, 195, 0.30);

    --notion-red: rgb(255, 115, 105);
    --notion-pink: rgb(226, 85, 161);
    --notion-blue: rgb(82, 156, 202);
    --notion-purple: rgb(154, 109, 215);
    --notion-teal: rgb(77, 171, 154);
    --notion-yellow: rgb(255, 220, 73);
    --notion-orange: rgb(255, 163, 68);
    --notion-brown: rgb(186, 133, 111);
    --notion-gray: rgb(159, 164, 169);

    --notion-red_background: rgba(251, 228, 228, 0.12);
    --notion-pink_background: rgba(244, 223, 235, 0.12);
    --notion-blue_background: rgba(221, 235, 241, 0.12);
    --notion-purple_background: rgba(234, 228, 242, 0.12);
    --notion-teal_background: rgba(221, 237, 234, 0.12);
    --notion-yellow_background: rgba(251, 243, 219, 0.12);
    --notion-orange_background: rgba(250, 235, 221, 0.12);
    --notion-brown_background: rgba(233, 229, 227, 0.12);
    --notion-gray_background: rgba(241, 241, 239, 0.08);
}

/* ─── 基础 Notion 排版 ───────────────────────────── */

.notion {
    font-size: 16px;
    line-height: 1.7;
    color: var(--fg-color);
    word-break: break-word;
}

.notion>* {
    padding: 3px 0;
}

.notion b {
    font-weight: 600;
}

/* ─── 文本颜色 ───────────────────────────────────── */

.notion-red {
    color: var(--notion-red);
}

.notion-pink {
    color: var(--notion-pink);
}

.notion-blue {
    color: var(--notion-blue);
}

.notion-purple {
    color: var(--notion-purple);
}

.notion-teal {
    color: var(--notion-teal);
}

.notion-yellow {
    color: var(--notion-yellow);
}

.notion-orange {
    color: var(--notion-orange);
}

.notion-brown {
    color: var(--notion-brown);
}

.notion-gray {
    color: var(--notion-gray);
}

/* ─── 背景颜色 ───────────────────────────────────── */

.notion-red_background {
    background-color: var(--notion-red_background);
}

.notion-pink_background {
    background-color: var(--notion-pink_background);
}

.notion-blue_background {
    background-color: var(--notion-blue_background);
}

.notion-purple_background {
    background-color: var(--notion-purple_background);
}

.notion-teal_background {
    background-color: var(--notion-teal_background);
}

.notion-yellow_background {
    background-color: var(--notion-yellow_background);
}

.notion-orange_background {
    background-color: var(--notion-orange_background);
}

.notion-brown_background {
    background-color: var(--notion-brown_background);
}

.notion-gray_background {
    background-color: var(--notion-gray_background);
}

/* ─── 标题 ───────────────────────────────────────── */

.notion-title {
    width: 100%;
    font-size: 2.5em;
    font-weight: 700;
    margin-bottom: 20px;
    line-height: 1.2;
}

.notion-h {
    position: relative;
    font-weight: 600;
    line-height: 1.3;
    padding: 3px 2px;
    margin-bottom: 1px;
    max-width: 100%;
    white-space: pre-wrap;
    word-break: break-word;
}

.notion-h1 {
    font-size: 1.575em;
    margin-top: 1.4em;
    padding-bottom: 0.3em;
    border-bottom: 1px solid var(--fg-color-0);
    width: 100%;
}

.notion-h2 {
    font-size: 1.4em;
    margin-top: 1.2em;
    width: 100%;
}

.notion-h3 {
    font-size: 1.25em;
    margin-top: 1em;
    width: 100%;
}

.notion-h1:first-child {
    margin-top: 0;
}

.notion-h:hover .notion-hash-link {
    opacity: 1;
}

.notion-hash-link {
    opacity: 0;
    text-decoration: none;
    float: left;
    margin-left: -22px;
    padding-right: 4px;
    fill: var(--fg-color-2);
    transition: opacity 0.2s ease;
}

.dark-mode .notion-hash-link {
    fill: var(--fg-color-3);
}

.notion-header-anchor {
    position: absolute;
    top: -70px;
    left: 0;
}

/* ─── 段落和文本 ─────────────────────────────────── */

.notion-text {
    width: 100%;
    white-space: pre-wrap;
    word-break: break-word;
    padding: 3px 2px;
    margin: 1px 0;
}

.notion-text:first-child {
    margin-top: 2px;
}

.notion-text-children {
    padding-left: 1.5em;
    display: flex;
    flex-direction: column;
}

.notion-blank {
    width: 100%;
    min-height: 1rem;
    padding: 3px 2px;
    margin: 1px 0;
}

/* ─── 链接 ───────────────────────────────────────── */

.notion-link {
    position: relative;
    color: inherit;
    word-break: break-word;
    text-decoration: none;
    border-bottom: 0.05em solid;
    border-color: var(--fg-color-2);
    opacity: 0.7;
    transition: border-color 0.2s ease, opacity 0.2s ease;
    background: transparent;
    background-origin: border-box;
    background-repeat: no-repeat;
    background-position: 50% 100%;
    background-size: 0 0.1rem;
}

.notion-link:hover {
    border-color: transparent;
    opacity: 1;
    background-image: linear-gradient(90.68deg, #667eea 0.26%, #764ba2 102.37%);
    background-repeat: no-repeat;
    background-position: 0 100%;
    background-size: 100% 0.1rem;
    transition-property: background-position, background-size;
    transition-duration: 300ms;
}

/* ─── 行内代码 ───────────────────────────────────── */

.notion-inline-code {
    color: #eb5757;
    padding: 0.2em 0.4em;
    background: var(--bg-color-2);
    border-radius: 4px;
    font-size: 85%;
    font-family: 'JetBrains Mono', 'SFMono-Regular', Consolas, 'Liberation Mono',
        Menlo, Courier, monospace;
}

.dark-mode .notion-inline-code {
    background: rgb(71, 76, 80);
    color: #ff4081;
}

.notion-inline-underscore {
    text-decoration: underline;
}

/* ─── 代码块 ─────────────────────────────────────── */

.notion-code-wrapper {
    width: 100%;
    margin: 0.6em 0;
    border-radius: 10px;
    overflow: hidden;
    border: 1px solid var(--code-border, #e5e7eb);
}

.notion-code-header {
    padding: 8px 16px;
    background: var(--code-header-bg, var(--bg-color-secondary, #f7f6f3));
    border-bottom: 1px solid var(--code-border, #e5e7eb);
    font-size: 0.78rem;
    color: var(--code-header-fg, var(--fg-color-secondary, rgba(55, 53, 47, 0.65)));
    font-family: 'JetBrains Mono', monospace;
    font-weight: 500;
}

.dark-mode .notion-code-header {
    background: var(--code-header-bg);
    border-bottom-color: var(--code-border, rgba(58, 88, 108, 0.9));
    color: var(--code-header-fg);
}

.notion-code-lang {
    color: inherit;
}

.notion-code {
    padding: 20px 16px 20px 20px;
    tab-size: 2;
    display: block;
    overflow-x: auto;
    font-size: 0.88rem;
    line-height: 1.6;
    font-family: 'JetBrains Mono', 'SFMono-Regular', Consolas, 'Liberation Mono',
        Menlo, Courier, monospace;
    background: var(--code-bg, #f9fafb);
    margin: 0;
    border: none;
    border-radius: 0;
}

.dark-mode .notion-code {
    background: #111827;
}

/* ─── 引用 ───────────────────────────────────────── */

.notion-quote {
    display: block;
    width: 100%;
    white-space: pre-wrap;
    word-break: break-word;
    border-left: 4px solid #667eea;
    padding: 0.3em 0.9em;
    margin: 8px 0;
    font-size: 1.1em;
    line-height: 1.6;
    font-style: italic;
    color: var(--fg-color-3);
}

/* ─── Callout ────────────────────────────────────── */

.notion-callout {
    display: flex;
    gap: 12px;
    padding: 16px 18px;
    margin: 8px 0;
    border-radius: 10px;
    background: var(--bg-color-secondary, #f7f6f3);
    border: 1px solid var(--callout-border, rgba(55, 53, 47, 0.12));
    color: var(--fg-color);
}

.notion-callout-icon {
    font-size: 1.3em;
    flex-shrink: 0;
    line-height: 1.4;
}

.notion-callout-text {
    flex: 1;
    min-width: 0;
    line-height: 1.6;
    color: inherit;
}

.dark-mode .notion-callout {
    background: rgba(255, 255, 255, 0.045);
    border-color: var(--callout-border, rgba(132, 174, 195, 0.30));
}

/* 颜色 callout 在浅/深色都走对应背景色，并保持 block 形态 */
.notion-callout.notion-red_background,
.notion-callout.notion-pink_background,
.notion-callout.notion-blue_background,
.notion-callout.notion-purple_background,
.notion-callout.notion-teal_background,
.notion-callout.notion-yellow_background,
.notion-callout.notion-orange_background,
.notion-callout.notion-brown_background,
.notion-callout.notion-gray_background {
    padding: 16px 18px;
    margin: 8px 0;
    border-radius: 10px;
    border-bottom-left-radius: 10px;
}

.notion-callout.notion-red_background { background-color: var(--notion-red_background); }
.notion-callout.notion-pink_background { background-color: var(--notion-pink_background); }
.notion-callout.notion-blue_background { background-color: var(--notion-blue_background); }
.notion-callout.notion-purple_background { background-color: var(--notion-purple_background); }
.notion-callout.notion-teal_background { background-color: var(--notion-teal_background); }
.notion-callout.notion-yellow_background { background-color: var(--notion-yellow_background); }
.notion-callout.notion-orange_background { background-color: var(--notion-orange_background); }
.notion-callout.notion-brown_background { background-color: var(--notion-brown_background); }
.notion-callout.notion-gray_background { background-color: var(--notion-gray_background); }

.dark-mode .notion-callout.notion-red_background,
.dark-mode .notion-callout.notion-pink_background,
.dark-mode .notion-callout.notion-blue_background,
.dark-mode .notion-callout.notion-purple_background,
.dark-mode .notion-callout.notion-teal_background,
.dark-mode .notion-callout.notion-yellow_background,
.dark-mode .notion-callout.notion-orange_background,
.dark-mode .notion-callout.notion-brown_background,
.dark-mode .notion-callout.notion-gray_background {
    border-color: var(--callout-border, rgba(132, 174, 195, 0.30));
}

/* ─── 列表 ───────────────────────────────────────── */

.notion-list {
    margin: 0.4em 0;
    width: 100%;
}

.notion-list-disc {
    list-style-type: disc;
    padding-inline-start: 1.5em;
}

.notion-list-numbered {
    list-style-type: decimal;
    padding-inline-start: 1.6em;
}

.notion-list-numbered>.notion-list-numbered {
    list-style-type: lower-alpha;
}

.notion-list-numbered>.notion-list-numbered>.notion-list-numbered {
    list-style-type: lower-roman;
}

.notion-list-disc li {
    padding-left: 0.1em;
}

.notion-list-numbered li {
    padding-left: 0.2em;
}

.notion-list li {
    padding: 2px 0;
    white-space: pre-wrap;
}

/* ─── 分割线 ─────────────────────────────────────── */

.notion-hr {
    width: 100%;
    margin: 1.5em 0;
    padding: 0;
    border: none;
    border-top: 1px solid var(--fg-color-0);
}

/* ─── 图片和资源 ─────────────────────────────────── */

.notion-asset-wrapper {
    margin: 0.8em 0;
    max-width: 100%;
    align-self: center;
    display: flex;
    flex-direction: column;
}

.notion-asset-wrapper-image {
    max-width: 100%;
}

.notion-asset-wrapper img {
    height: auto;
    max-height: 100%;
    margin: auto;
    border-radius: 8px;
}

.notion-asset-wrapper iframe {
    border: none;
    border-radius: 8px;
}

.notion-asset-caption {
    text-align: center;
    font-size: 0.85em;
    color: var(--fg-color-2);
    padding: 8px 0;
    line-height: 1.5;
}

/* ─── 书签 ───────────────────────────────────────── */

.notion-bookmark {
    display: flex;
    width: 100%;
    margin: 0.5em 0;
    padding: 14px 16px;
    border: 1px solid var(--fg-color-0);
    border-radius: 10px;
    transition: all 0.25s ease;
    color: var(--fg-color);
}

.notion-bookmark:hover {
    border-color: var(--accent, #667eea);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.notion-bookmark-content {
    flex: 1;
    min-width: 0;
}

.notion-bookmark-title {
    font-weight: 600;
    font-size: 0.95em;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.notion-bookmark-link {
    font-size: 0.8em;
    color: var(--fg-color-2);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ─── 待办 ───────────────────────────────────────── */

.notion-to-do {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 3px 0;
    width: 100%;
    color: var(--fg-color);
}

.notion-to-do input[type="checkbox"] {
    margin-top: 4px;
    width: 16px;
    height: 16px;
    accent-color: var(--accent, #2563eb);
    border: 1px solid var(--fg-color-1);
    border-radius: 4px;
    background: transparent;
    flex-shrink: 0;
}

.notion-to-do-checked span {
    text-decoration: line-through;
    color: var(--fg-color-2);
}

.dark-mode .notion-to-do input[type="checkbox"] {
    border-color: rgba(255, 255, 255, 0.28);
    background: rgba(255, 255, 255, 0.04);
}

/* ─── 折叠块 ─────────────────────────────────────── */

.notion-toggle {
    width: 100%;
    padding: 3px 0;
}

.notion-toggle>summary {
    cursor: pointer;
    padding: 4px 0;
    font-weight: 500;
    list-style: disclosure-closed;
}

.notion-toggle[open]>summary {
    list-style: disclosure-open;
}

.notion-toggle-content {
    padding-left: 1.5em;
    margin-top: 4px;
}

/* ─── 分栏 ───────────────────────────────────────── */

.notion-row {
    display: flex;
    overflow: hidden;
    width: 100%;
    gap: 24px;
    padding: 6px 0;
}

.notion-column {
    display: flex;
    flex: 1;
    flex-direction: column;
    padding: 6px 0;
}

.notion-column>*:first-child {
    margin-top: 0;
}

.notion-column>*:last-child {
    margin-bottom: 0;
}

@media (max-width: 640px) {
    .notion-row {
        flex-direction: column;
        gap: 8px;
    }
}

/* ─── 表格 ───────────────────────────────────────── */

.notion-simple-table {
    width: 100%;
    border-collapse: collapse;
    margin: 0.5em 0;
    font-size: 0.92em;
}

.notion-simple-table th,
.notion-simple-table td {
    padding: 8px 12px;
    border: 1px solid var(--fg-color-0);
    text-align: left;
}

.notion-simple-table th {
    background: var(--bg-color-1);
    font-weight: 600;
}

.notion-simple-table tr:hover td {
    background: var(--bg-color-1);
}

/* ─── 背景高亮效果（从 starter-kit 移植） ────────── */

:not(.notion-callout).notion-red_background,
:not(.notion-callout).notion-pink_background,
:not(.notion-callout).notion-blue_background,
:not(.notion-callout).notion-purple_background,
:not(.notion-callout).notion-teal_background,
:not(.notion-callout).notion-yellow_background,
:not(.notion-callout).notion-orange_background,
:not(.notion-callout).notion-brown_background,
:not(.notion-callout).notion-gray_background {
    padding: 0 0.5rem;
    margin: 0 -0.5rem 0 -0.25rem;
    border-radius: 0.5rem;
    border-bottom-left-radius: 0.125rem;
    box-decoration-break: clone;
}

/* ─── 暗色模式下禁用背景高亮（同 starter-kit） ──── */

.dark-mode :not(.notion-callout).notion-red_background,
.dark-mode :not(.notion-callout).notion-pink_background,
.dark-mode :not(.notion-callout).notion-blue_background,
.dark-mode :not(.notion-callout).notion-purple_background,
.dark-mode :not(.notion-callout).notion-teal_background,
.dark-mode :not(.notion-callout).notion-yellow_background,
.dark-mode :not(.notion-callout).notion-orange_background,
.dark-mode :not(.notion-callout).notion-brown_background,
.dark-mode :not(.notion-callout).notion-gray_background {
    padding: 2px 6px;
    margin: 0;
    border-radius: 4px;
}
