:root {
  /* ===== カラー（ベース/テキスト） ===== */
  --bg-app: #f5f7fb;
  --bg-0: #0b0b0c;
  --text-0: #0f172a;
  --text-1: #1e293b;
  --text-muted: #64748b;
  --separator: rgba(15, 23, 42, 0.08);
  --separator-weak: rgba(15, 23, 42, 0.05);
  /* Neutral scale that matches the refined palette */
  --neutral-50: #f8fafc;
  --neutral-100: #f1f5f9;
  --neutral-200: #e2e8f0;
  --neutral-300: #cbd5f5;
  --neutral-400: #94a3b8;
  --neutral-500: #64748b;

  /* ===== サーフェス階調 ===== */
  --surface-weak: rgba(255, 255, 255, 0.7);
  --surface: rgba(255, 255, 255, 0.88);
  --surface-strong: #ffffff;
  --surface-ultra: #ffffff;
  --ios-group: rgba(255,255,255,0.92);
  --ios-card: #ffffff;

  /* ===== 枠線/影 ===== */
  --hairline-light: rgba(15, 23, 42, 0.06);
  --hairline-strong: rgba(15, 23, 42, 0.08);
  --border: var(--hairline-strong);
  --border-strong: rgba(37, 99, 235, 0.22);
  --shadow: 0 18px 40px rgba(15, 23, 42, 0.12);
  --shadow-sm: 0 10px 24px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 32px 70px rgba(15, 23, 42, 0.16);
  --elev-1: 0 10px 26px rgba(15, 23, 42, 0.1);
  --elev-2: 0 18px 44px rgba(15, 23, 42, 0.12);
  --blur-xs: 10px;
  --blur-sm: 16px;
  --blur: 22px;
  --blur-lg: 28px;
  /* Motion tokens */
  --ease-smooth: cubic-bezier(.22,.61,.36,1);
  --ease-out: cubic-bezier(.2, .0, 0, 1);
  --dur-fast: 120ms;
  --dur: 200ms;
  --dur-slow: 320ms;

  /* ===== ブランド/状態色（iOSアクセントに寄せる） ===== */
  --brand: #2563eb;
  --brand-strong: #1d4ed8;
  --accent: #22d3ee;
  --success: #2ac769;
  --warning: #f0a020;
  --danger: #ff3b30;
  --grad-brand: linear-gradient(135deg, #2563eb 0%, #6366f1 50%, #22d3ee 100%);
  --grad-brand-soft: linear-gradient(135deg, rgba(37,99,235,0.12), rgba(34,211,238,0.12));
  --tint-blue: #2563eb;
  --tint-green: #22c55e;
  --tint-orange: #f59e0b;
  --tint-red: #ef4444;
  --tint-purple: #8b5cf6;

  /* ===== タイポグラフィ ===== */
  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
    "Hiragino Sans", "Noto Sans JP", ui-sans-serif, system-ui,
    Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  --font-size-body: 15px; /* iOS default size */
  --line-height-body: 1.7;
  --font-size-small: 13px;
  --line-height-small: 1.6;
  --font-size-meta: 12px;
  --line-height-meta: 1.5;
  --font-size-code: 13px;
  --line-height-code: 1.6;
  /* 見出し（流体タイポ） */
  --fz-display: clamp(28px, 5.2vw, 44px);
  --fz-h1: clamp(22px, 3.6vw, 30px);
  --tracking-tight: 0.005em;
  --tracking-normal: 0.01em;
  --weight-regular: 400;
  --weight-medium: 600;
  --weight-bold: 800;

  /* ===== スペーシング ===== */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-7: 32px;
  --sp-8: 40px;
  --sp-9: 56px;

  /* ===== 角丸（iOS寄り） ===== */
  --radius-1: 10px;
  --radius-2: 14px;
  --radius-3: 18px;
  --radius-4: 24px;
  --radius-round: 999px;

  /* ===== コンポーネント寸法 ===== */
  --topbar-h: 78px;
  --sidebar-w: min(320px, 22vw);
  --composer-h: 72px;
  --safe-bottom: env(safe-area-inset-bottom);

  /* ===== フィードバック/アクセシビリティ ===== */
  --focus-ring: 0 0 0 3px rgba(37, 99, 235, 0.24);
  --focus-border: var(--brand-strong);
  --scrollbar-thumb: rgba(37, 99, 235, 0.32);
  --scrollbar-thumb-hover: rgba(37, 99, 235, 0.45);
  --scrollbar-track: rgba(15,23,42,0.06);

  /* ===== コードテーマ ===== */
  --code-bg: #0f172a;
  --code-fg: #eef2ff;
  --shell-max: min(1320px, 96vw);
  --shell-gap: clamp(16px, 3vw, 32px);
  --shell-radius: 26px;
  --shell-border: rgba(99, 102, 241, 0.08);
  --shell-shadow: 0 28px 80px rgba(79, 70, 229, 0.15);
}

/* ===== レスポンシブ寸法（軽微調整） ===== */
@media (max-width: 960px) {
  :root { --sidebar-w: 76px; }
}
@media (max-height: 720px) {
  :root { --topbar-h: 48px; }
}

/* ===== 密度（コンパクト） ===== */
html[data-density="compact"] {
  --topbar-h: 64px;
  --composer-h: 64px;
  --font-size-body: 14px;
  --line-height-body: 1.6;
}

/* ===== ダークテーマ用トークン上書き ===== */
html[data-theme="dark"] {
  --bg-app: #0b1120;
  --text-0: #cbd5f5;
  --text-1: #f8fafc;
  --text-muted: #94a3b8;
  --surface-weak: rgba(17, 24, 39, 0.55);
  --surface: rgba(17, 24, 39, 0.68);
  --surface-strong: rgba(15, 23, 42, 0.86);
  --surface-ultra: rgba(10, 18, 35, 0.94);
  --separator: rgba(148, 163, 184, 0.28);
  --separator-weak: rgba(148, 163, 184, 0.18);
  --border: rgba(148, 163, 184, 0.24);
  --shadow: 0 24px 60px rgba(2, 6, 23, 0.76);
  --shadow-sm: 0 16px 38px rgba(2, 6, 23, 0.6);
  --shadow-lg: 0 40px 100px rgba(2, 6, 23, 0.78);
  --ios-group: rgba(13, 20, 38, 0.82);
  --ios-card: rgba(17, 24, 39, 0.88);
  --code-bg: #0b1120;
  --code-fg: #e2e8f0;
  --scrollbar-thumb: rgba(59, 130, 246, 0.4);
  --scrollbar-thumb-hover: rgba(96, 165, 250, 0.6);
  --scrollbar-track: rgba(15, 23, 42, 0.55);
}

/* ===== Simple Mode: minimal, calm palette ===== */
html[data-simple="on"] {
  --bg-app: #0f172a;
  --text-0: #e2e8f0;
  --text-1: #f8fafc;
  --text-muted: #94a3b8;
  --surface-weak: rgba(17, 24, 39, 0.6);
  --surface: rgba(17, 24, 39, 0.72);
  --surface-strong: rgba(15, 23, 42, 0.85);
  --surface-ultra: rgba(12, 18, 35, 0.94);
  --border: rgba(148, 163, 184, 0.18);
  --brand: #7c3aed;
  --brand-strong: #6d28d9;
  --accent: #8b5cf6;
  --shadow: 0 20px 48px rgba(3, 7, 18, 0.5);
  --shadow-sm: 0 12px 32px rgba(3, 7, 18, 0.4);
  --shadow-lg: 0 40px 96px rgba(3, 7, 18, 0.6);
  --scrollbar-track: rgba(15, 23, 42, 0.5);
}

/* ===== 高コントラスト トークン上書き ===== */
html[data-contrast="high"] {
  --border: rgba(10, 10, 20, 0.22);
  --surface-weak: rgba(255, 255, 255, 0.55);
  --surface: rgba(255, 255, 255, 0.86);
  --surface-strong: rgba(255, 255, 255, 0.98);
  --text-muted: #4b5563;
  --focus-ring: 0 0 0 3px rgba(37, 99, 235, 0.35);
}
html[data-theme="dark"][data-contrast="high"] {
  --border: rgba(255, 255, 255, 0.16);
  --surface-weak: rgba(20, 20, 35, 0.65);
  --surface: rgba(20, 20, 35, 0.86);
  --surface-strong: rgba(20, 20, 35, 0.96);
  --text-muted: #c7d2fe;
  --focus-ring: 0 0 0 3px rgba(96, 165, 250, 0.5);
}
