/* Self-hosted fonts — no external CDN at runtime.
   Latin glyphs come from local woff2; CJK falls back to system fonts. */
@font-face {
  font-family: "Inter Local";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("../fonts/inter-latin.woff2") format("woff2");
}

@font-face {
  font-family: "JetBrains Mono Local";
  font-style: normal;
  font-weight: 400 600;
  font-display: swap;
  src: url("../fonts/jetbrains-mono-latin.woff2") format("woff2");
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

button,
input,
textarea,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

img,
svg {
  display: block;
  max-width: 100%;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

h1,
h2,
h3,
h4,
h5,
h6,
p {
  margin: 0;
}

ul,
ol {
  margin: 0;
  padding: 0;
}

[hidden] {
  display: none !important;
}

::selection {
  background: var(--selection);
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ------------------------- Design tokens ------------------------- */

:root {
  /* layout */
  --sidebar-width: 248px;
  --list-width: 336px;
  --topbar-height: 56px;
  --content-width: 760px;
  --radius: 10px;
  --radius-sm: 7px;
  --radius-lg: 14px;
  --radius-xl: 20px;
  --radius-pill: 999px;

  /* type */
  --font-ui: "Inter Local", "Inter", "SF Pro Text", -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  --font-content: "Inter Local", "Inter", "SF Pro Text", -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  --font-mono: "JetBrains Mono Local", "JetBrains Mono", "SFMono-Regular", "Cascadia Code", Consolas,
    "Liberation Mono", monospace;
  --font-size: 16px;
  --line-height: 1.78;

  /* motion */
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
  --fast: 140ms var(--ease);
  --normal: 220ms var(--ease);
}

/* ------------------------- Theme presets ------------------------- */

:root,
[data-theme="white"] {
  color-scheme: light;
  --bg: #ffffff;
  --bg-subtle: #f7f8fa;
  --bg-elevated: #ffffff;
  --surface: #ffffff;
  --surface-2: #f2f4f7;
  --surface-3: #e9edf2;
  --text: #1a1f26;
  --text-secondary: #5a6472;
  --text-muted: #8a93a1;
  --border: #e6e9ee;
  --border-strong: #d5dae2;
  --accent: #1f2328;
  --accent-hover: #000000;
  --accent-soft: rgba(31, 35, 40, 0.08);
  --accent-contrast: #ffffff;
  --danger: #d92d20;
  --danger-soft: rgba(217, 45, 32, 0.1);
  --success: #12915a;
  --success-soft: rgba(18, 145, 90, 0.1);
  --warning: #b76e00;
  --warning-soft: rgba(183, 110, 0, 0.12);
  --selection: rgba(31, 35, 40, 0.14);
  --code-bg: #f4f6f9;
  --code-text: #24292f;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow-md: 0 6px 20px rgba(16, 24, 40, 0.09);
  --shadow-lg: 0 20px 56px rgba(16, 24, 40, 0.16);
  --overlay: rgba(17, 24, 39, 0.42);
  --brand-gradient: linear-gradient(135deg, #346ddb 0%, #5b8def 46%, #22b8a6 100%);
}

[data-theme="paper"] {
  color-scheme: light;
  --bg: #fbfaf7;
  --bg-subtle: #f5f2ea;
  --bg-elevated: #fffefb;
  --surface: #fffefb;
  --surface-2: #f2eee4;
  --surface-3: #e9e4d8;
  --text: #2d2a24;
  --text-secondary: #625c50;
  --text-muted: #928a7b;
  --border: #e8e2d6;
  --border-strong: #d8d0c0;
  --accent: #a45b24;
  --accent-hover: #894a1b;
  --accent-soft: rgba(164, 91, 36, 0.11);
  --accent-contrast: #ffffff;
  --danger: #c0392b;
  --danger-soft: rgba(192, 57, 43, 0.1);
  --success: #2f7d4f;
  --success-soft: rgba(47, 125, 79, 0.1);
  --warning: #a76b00;
  --warning-soft: rgba(167, 107, 0, 0.12);
  --selection: rgba(164, 91, 36, 0.18);
  --code-bg: #f1ece1;
  --code-text: #3b3327;
  --shadow-sm: 0 1px 2px rgba(60, 48, 30, 0.06);
  --shadow-md: 0 6px 20px rgba(60, 48, 30, 0.09);
  --shadow-lg: 0 20px 56px rgba(60, 48, 30, 0.16);
  --overlay: rgba(43, 36, 25, 0.44);
  --brand-gradient: linear-gradient(135deg, #a45b24 0%, #c9833f 48%, #7a8f3c 100%);
}

[data-theme="sepia"] {
  color-scheme: light;
  --bg: #f4ecd8;
  --bg-subtle: #ede3cc;
  --bg-elevated: #faf3e3;
  --surface: #faf3e3;
  --surface-2: #ece1c8;
  --surface-3: #e2d5b8;
  --text: #433a2c;
  --text-secondary: #6d6250;
  --text-muted: #968a74;
  --border: #ddd0b6;
  --border-strong: #cbbca0;
  --accent: #8a5a1f;
  --accent-hover: #724a18;
  --accent-soft: rgba(138, 90, 31, 0.12);
  --accent-contrast: #fffdf6;
  --danger: #b3392c;
  --danger-soft: rgba(179, 57, 44, 0.1);
  --success: #3d7a4f;
  --success-soft: rgba(61, 122, 79, 0.1);
  --warning: #9c6a00;
  --warning-soft: rgba(156, 106, 0, 0.13);
  --selection: rgba(138, 90, 31, 0.2);
  --code-bg: #ebe0c7;
  --code-text: #4b3f2d;
  --shadow-sm: 0 1px 2px rgba(75, 60, 35, 0.07);
  --shadow-md: 0 6px 20px rgba(75, 60, 35, 0.1);
  --shadow-lg: 0 20px 56px rgba(75, 60, 35, 0.17);
  --overlay: rgba(60, 48, 28, 0.45);
  --brand-gradient: linear-gradient(135deg, #8a5a1f 0%, #b07b33 48%, #6f7d36 100%);
}

[data-theme="forest"] {
  color-scheme: light;
  --bg: #f7fbf7;
  --bg-subtle: #eef5ee;
  --bg-elevated: #ffffff;
  --surface: #ffffff;
  --surface-2: #eaf2ea;
  --surface-3: #dfeadf;
  --text: #1d2a20;
  --text-secondary: #4d6253;
  --text-muted: #7e9183;
  --border: #dce8de;
  --border-strong: #c9d9cc;
  --accent: #2f7d4f;
  --accent-hover: #24663f;
  --accent-soft: rgba(47, 125, 79, 0.11);
  --accent-contrast: #ffffff;
  --danger: #c43c33;
  --danger-soft: rgba(196, 60, 51, 0.1);
  --success: #2f7d4f;
  --success-soft: rgba(47, 125, 79, 0.1);
  --warning: #9a6a06;
  --warning-soft: rgba(154, 106, 6, 0.12);
  --selection: rgba(47, 125, 79, 0.18);
  --code-bg: #eef4ee;
  --code-text: #223026;
  --shadow-sm: 0 1px 2px rgba(20, 45, 28, 0.05);
  --shadow-md: 0 6px 20px rgba(20, 45, 28, 0.09);
  --shadow-lg: 0 20px 56px rgba(20, 45, 28, 0.16);
  --overlay: rgba(18, 34, 23, 0.42);
  --brand-gradient: linear-gradient(135deg, #2f7d4f 0%, #4c9f6e 48%, #6d9c3a 100%);
}

[data-theme="sakura"] {
  color-scheme: light;
  --bg: #fffafb;
  --bg-subtle: #fcf1f5;
  --bg-elevated: #ffffff;
  --surface: #ffffff;
  --surface-2: #f9edf2;
  --surface-3: #f2e0e8;
  --text: #33222a;
  --text-secondary: #6d5260;
  --text-muted: #9c8390;
  --border: #f1dde5;
  --border-strong: #e5ccd7;
  --accent: #c2446e;
  --accent-hover: #a8365c;
  --accent-soft: rgba(194, 68, 110, 0.1);
  --accent-contrast: #ffffff;
  --danger: #c53030;
  --danger-soft: rgba(197, 48, 48, 0.1);
  --success: #33815a;
  --success-soft: rgba(51, 129, 90, 0.1);
  --warning: #a96a06;
  --warning-soft: rgba(169, 106, 6, 0.12);
  --selection: rgba(194, 68, 110, 0.16);
  --code-bg: #f8edf2;
  --code-text: #3a2630;
  --shadow-sm: 0 1px 2px rgba(70, 30, 47, 0.05);
  --shadow-md: 0 6px 20px rgba(70, 30, 47, 0.09);
  --shadow-lg: 0 20px 56px rgba(70, 30, 47, 0.16);
  --overlay: rgba(50, 24, 35, 0.42);
  --brand-gradient: linear-gradient(135deg, #c2446e 0%, #dd6f92 48%, #b06ab3 100%);
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e1116;
  --bg-subtle: #11161c;
  --bg-elevated: #151a21;
  --surface: #151a21;
  --surface-2: #1b222b;
  --surface-3: #232c37;
  --text: #e6e9ee;
  --text-secondary: #a2acb8;
  --text-muted: #6f7a87;
  --border: #252d37;
  --border-strong: #33404d;
  --accent: #c7d0da;
  --accent-hover: #e6ebf1;
  --accent-soft: rgba(199, 208, 218, 0.16);
  --accent-contrast: #0b1020;
  --danger: #ff6b5e;
  --danger-soft: rgba(255, 107, 94, 0.14);
  --success: #3ddc97;
  --success-soft: rgba(61, 220, 151, 0.13);
  --warning: #f5b544;
  --warning-soft: rgba(245, 181, 68, 0.14);
  --selection: rgba(199, 208, 218, 0.24);
  --code-bg: #1a212a;
  --code-text: #d7dee9;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 6px 20px rgba(0, 0, 0, 0.38);
  --shadow-lg: 0 20px 56px rgba(0, 0, 0, 0.5);
  --overlay: rgba(0, 0, 0, 0.62);
  --brand-gradient: linear-gradient(135deg, #3f5bd8 0%, #6b8afd 48%, #21a89a 100%);
}

[data-theme="midnight"] {
  color-scheme: dark;
  --bg: #0a0f1f;
  --bg-subtle: #0d1327;
  --bg-elevated: #111a33;
  --surface: #111a33;
  --surface-2: #17213e;
  --surface-3: #1f2b4d;
  --text: #e4e9f8;
  --text-secondary: #a6b1cf;
  --text-muted: #7482a6;
  --border: #223054;
  --border-strong: #31416b;
  --accent: #c3cee6;
  --accent-hover: #dde5f5;
  --accent-soft: rgba(195, 206, 230, 0.16);
  --accent-contrast: #081021;
  --danger: #ff7b84;
  --danger-soft: rgba(255, 123, 132, 0.14);
  --success: #45ddb0;
  --success-soft: rgba(69, 221, 176, 0.13);
  --warning: #f4c15c;
  --warning-soft: rgba(244, 193, 92, 0.14);
  --selection: rgba(195, 206, 230, 0.24);
  --code-bg: #141e3a;
  --code-text: #d5defa;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.32);
  --shadow-md: 0 6px 20px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 20px 56px rgba(0, 0, 0, 0.52);
  --overlay: rgba(2, 6, 17, 0.66);
  --brand-gradient: linear-gradient(135deg, #3b4fd0 0%, #7c9cff 48%, #1fa6b8 100%);
}

[data-theme="graphite"] {
  color-scheme: dark;
  --bg: #14171c;
  --bg-subtle: #181b21;
  --bg-elevated: #1b1f26;
  --surface: #1b1f26;
  --surface-2: #232831;
  --surface-3: #2c323c;
  --text: #e3e6eb;
  --text-secondary: #a7afbb;
  --text-muted: #7b8592;
  --border: #2a2f38;
  --border-strong: #3a404b;
  --accent: #a8b2bf;
  --accent-hover: #c2cbd6;
  --accent-soft: rgba(168, 178, 191, 0.16);
  --accent-contrast: #12151a;
  --danger: #ff6b5e;
  --danger-soft: rgba(255, 107, 94, 0.14);
  --success: #3ddc97;
  --success-soft: rgba(61, 220, 151, 0.13);
  --warning: #f5b544;
  --warning-soft: rgba(245, 181, 68, 0.14);
  --selection: rgba(168, 178, 191, 0.24);
  --code-bg: #20252d;
  --code-text: #d9dee6;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.32);
  --shadow-md: 0 6px 20px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 20px 56px rgba(0, 0, 0, 0.52);
  --overlay: rgba(8, 10, 13, 0.66);
  --brand-gradient: linear-gradient(135deg, #6d7683 0%, #9aa5b1 48%, #4f8f84 100%);
}

/* ------------------------- Scrollbars ------------------------- */

* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

*::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

*::-webkit-scrollbar-track {
  background: transparent;
}

*::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border: 3px solid transparent;
  background-clip: content-box;
  border-radius: var(--radius-pill);
}

*::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
  border: 3px solid transparent;
  background-clip: content-box;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}