/* ============================================================
   House Style · tokens.css
   两套主题：data-theme="endfield"（默认） / "ios"
   明暗：  data-mode="light" | "dark"；不写则跟随系统
   ============================================================ */

/* ---------- 结构：两套主题共用 ---------- */
:root {
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;
  --sp-10: 40px;
  --sp-12: 48px;

  --fs-caption: 11px;
  --fs-label: 13px;
  --fs-body: 15px;
  --fs-body-lg: 17px;
  --fs-title: 20px;
  --fs-title-lg: 24px;
  --fs-display: 32px;
  --lh-tight: 1.2;
  --lh-body: 1.6;

  --sans: "Inter", -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
    "PingFang SC", "HarmonyOS Sans SC", "Noto Sans SC", system-ui, sans-serif;
  --mono: "IBM Plex Mono", "SF Mono", "JetBrains Mono", ui-monospace, Menlo,
    Consolas, monospace;
  --serif: "Noto Serif SC", "Songti SC", Georgia, serif;

  --ease: cubic-bezier(0.22, 0.8, 0.2, 1);
  --dur-fast: 120ms;
  --dur: 200ms;
  --dur-slow: 320ms;

  --container: 1200px;
  --reading: 720px;
  --bp-tablet: 760px;
  --focus-width: 2px;
}

/* ---------- 终末地 · 亮色（默认） ---------- */
:root,
:root[data-theme="endfield"] {
  color-scheme: light;

  --paper: #e8e8e2;
  --surface: #f2f2ec;
  --surface-2: #dcddd6;
  --surface-3: #d0d1ca;

  --ink: #101110;
  --ink-2: #4a4c48;
  --ink-3: #5f625c;
  --line: #d8d9d5;
  --line-strong: #b6b8b3;

  --signal: #fff500;
  --signal-deep: #e8e000;
  --signal-text: #6b5d00;
  --signal-soft: rgba(255, 245, 0, 0.18);
  --on-signal: #101110;

  --success: #2f9e44;
  --success-text: #1d6a2e;
  --success-soft: rgba(47, 158, 68, 0.12);
  --warning: #d9822b;
  --warning-text: #8a4a0e;
  --warning-soft: rgba(217, 130, 43, 0.12);
  --danger: #ff3b30;
  --danger-text: #c4261f;
  --danger-soft: rgba(255, 59, 48, 0.12);
  --on-danger: #ffffff;

  --focus: var(--signal-text);
  --link: var(--signal-text);
  --selection: #fff500;
  --on-selection: #101110;

  --shadow: none;
  --shadow-strong: none;

  --radius-sm: 0px;
  --radius: 0px;
  --radius-lg: 0px;
  --radius-pill: 999px;
  --control-h: 36px;
  --control-h-sm: 28px;

  --grid-cell: 4rem;
  --grid-line: rgba(16, 17, 16, 0.06);
}

/* ---------- iOS · 亮色 ---------- */
:root[data-theme="ios"] {
  color-scheme: light;

  --paper: #f2f2f7;
  --surface: #ffffff;
  --surface-2: #f7f7fa;
  --surface-3: #ececf1;

  --ink: #1c1c1e;
  --ink-2: #5a5a5f;
  --ink-3: #68686d;
  --line: #e5e5ea;
  --line-strong: #c7c7cc;

  --signal: #1c1c1e;
  --signal-deep: #3a3a3c;
  --signal-text: #0066cc;
  --signal-soft: rgba(0, 122, 255, 0.1);
  --on-signal: #ffffff;

  --success: #34c759;
  --success-text: #1b7f3b;
  --success-soft: rgba(52, 199, 89, 0.14);
  --warning: #ff9500;
  --warning-text: #b25000;
  --warning-soft: rgba(255, 149, 0, 0.14);
  --danger: #ff3b30;
  --danger-text: #d70015;
  --danger-soft: rgba(255, 59, 48, 0.14);
  --on-danger: #ffffff;

  --focus: #007aff;
  --link: #0066cc;
  --selection: #007aff;
  --on-selection: #ffffff;

  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 24px rgba(0, 0, 0, 0.04);
  --shadow-strong: 0 2px 8px rgba(0, 0, 0, 0.06),
    0 24px 48px -24px rgba(0, 0, 0, 0.18);

  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --radius-pill: 999px;
  --control-h: 44px;
  --control-h-sm: 32px;

  --grid-cell: 4rem;
  --grid-line: rgba(0, 0, 0, 0.04);
}

/* ---------- 跟随系统暗色 ---------- */
/* 注意：下面两块与「显式暗色」保持同步修改 */
@media (prefers-color-scheme: dark) {
  :root:not([data-mode="light"]) {
    color-scheme: dark;

    --paper: #101110;
    --surface: #181a18;
    --surface-2: #1e201d;
    --surface-3: #252825;

    --ink: #f5f5f0;
    --ink-2: #898d89;
    --ink-3: #888c86;
    --line: #343633;
    --line-strong: #4a4d49;

    --signal: #fff500;
    --signal-deep: #e8e000;
    --signal-text: #fff500;
    --signal-soft: rgba(255, 245, 0, 0.14);
    --on-signal: #101110;

    --success: #4fbf5c;
    --success-text: #4fbf5c;
    --success-soft: rgba(79, 191, 92, 0.16);
    --warning: #ffb700;
    --warning-text: #ffb700;
    --warning-soft: rgba(255, 183, 0, 0.16);
    --danger: #ff6b61;
    --danger-text: #ff6b61;
    --danger-soft: rgba(255, 107, 97, 0.16);
    --on-danger: #101110;

    --focus: #fff500;
    --link: #fff500;
    --selection: #fff500;
    --on-selection: #101110;

    --grid-line: rgba(245, 245, 240, 0.05);
  }

  :root[data-theme="ios"]:not([data-mode="light"]) {
    color-scheme: dark;

    --paper: #0b0b0c;
    --surface: #1a1a1c;
    --surface-2: #232326;
    --surface-3: #2c2c2e;

    --ink: #f2f2f7;
    --ink-2: #aeaeb2;
    --ink-3: #8e8e93;
    --line: #2a2a2e;
    --line-strong: #3a3a3c;

    --signal: #f2f2f7;
    --signal-deep: #d8d8dd;
    --signal-text: #0a84ff;
    --signal-soft: rgba(10, 132, 255, 0.16);
    --on-signal: #111112;

    --success: #30d158;
    --success-text: #30d158;
    --success-soft: rgba(48, 209, 88, 0.18);
    --warning: #ff9f0a;
    --warning-text: #ff9f0a;
    --warning-soft: rgba(255, 159, 10, 0.18);
    --danger: #ff453a;
    --danger-text: #ff453a;
    --danger-soft: rgba(255, 69, 58, 0.18);
    --on-danger: #101110;

    --focus: #0a84ff;
    --link: #0a84ff;
    --selection: #0a84ff;
    --on-selection: #ffffff;

    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-strong: 0 2px 8px rgba(0, 0, 0, 0.5),
      0 24px 48px -24px rgba(0, 0, 0, 0.6);

    --grid-line: rgba(255, 255, 255, 0.05);
  }
}

/* ---------- 显式暗色 ---------- */
:root[data-mode="dark"] {
  color-scheme: dark;

  --paper: #101110;
  --surface: #181a18;
  --surface-2: #1e201d;
  --surface-3: #252825;

  --ink: #f5f5f0;
  --ink-2: #898d89;
  --ink-3: #888c86;
  --line: #343633;
  --line-strong: #4a4d49;

  --signal: #fff500;
  --signal-deep: #e8e000;
  --signal-text: #fff500;
  --signal-soft: rgba(255, 245, 0, 0.14);
  --on-signal: #101110;

  --success: #4fbf5c;
  --success-text: #4fbf5c;
  --success-soft: rgba(79, 191, 92, 0.16);
  --warning: #ffb700;
  --warning-text: #ffb700;
  --warning-soft: rgba(255, 183, 0, 0.16);
  --danger: #ff6b61;
  --danger-text: #ff6b61;
  --danger-soft: rgba(255, 107, 97, 0.16);
  --on-danger: #101110;

  --focus: #fff500;
  --link: #fff500;
  --selection: #fff500;
  --on-selection: #101110;

  --grid-line: rgba(245, 245, 240, 0.05);
}

:root[data-theme="ios"][data-mode="dark"] {
  color-scheme: dark;

  --paper: #0b0b0c;
  --surface: #1a1a1c;
  --surface-2: #232326;
  --surface-3: #2c2c2e;

  --ink: #f2f2f7;
  --ink-2: #aeaeb2;
  --ink-3: #8e8e93;
  --line: #2a2a2e;
  --line-strong: #3a3a3c;

  --signal: #f2f2f7;
  --signal-deep: #d8d8dd;
  --signal-text: #0a84ff;
  --signal-soft: rgba(10, 132, 255, 0.16);
  --on-signal: #111112;

  --success: #30d158;
  --success-text: #30d158;
  --success-soft: rgba(48, 209, 88, 0.18);
  --warning: #ff9f0a;
  --warning-text: #ff9f0a;
  --warning-soft: rgba(255, 159, 10, 0.18);
  --danger: #ff453a;
  --danger-text: #ff453a;
  --danger-soft: rgba(255, 69, 58, 0.18);
  --on-danger: #101110;

  --focus: #0a84ff;
  --link: #0a84ff;
  --selection: #0a84ff;
  --on-selection: #ffffff;

  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-strong: 0 2px 8px rgba(0, 0, 0, 0.5),
    0 24px 48px -24px rgba(0, 0, 0, 0.6);

  --grid-line: rgba(255, 255, 255, 0.05);
}

/* ---------- 基础样式 ---------- */
* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: var(--fs-body);
  line-height: var(--lh-body);
  -webkit-font-smoothing: antialiased;
}

::selection {
  background: var(--selection);
  color: var(--on-selection);
}

input[type="search"]::-webkit-search-cancel-button,
input[type="search"]::-webkit-search-decoration {
  -webkit-appearance: none;
}

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

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

::-webkit-scrollbar-thumb {
  border: 3px solid transparent;
  border-radius: 999px;
  background: var(--line-strong);
  background-clip: content-box;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--signal-text);
  background-clip: content-box;
}

:focus-visible {
  outline: var(--focus-width) solid var(--focus);
  outline-offset: 2px;
}

code,
kbd,
samp,
pre {
  font-family: var(--mono);
}

table,
.num,
.mono {
  font-variant-numeric: tabular-nums;
}

/* ---------- 小工具 ---------- */
.container {
  width: min(100% - 32px, var(--container));
  margin-inline: auto;
}

.kicker {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  font-family: var(--mono);
  font-size: var(--fs-caption);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.kicker::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}

.mono {
  font-family: var(--mono);
}

.grid-texture {
  background-image: linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: var(--grid-cell) var(--grid-cell);
}

@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;
  }
}
