/* =========================================================
   apple.css — Apple HIG 设计令牌层（全站共享，所有页面在自身样式之后/之前引入均可）
   规范依据：Apple HIG color.md / typography.md / dark-mode.md / materials.md / accessibility.md
   - 浅色/深色双外观：跟随系统 prefers-color-scheme（不做 App 级切换开关）
   - 语义化动态色：颜色按用途命名，同一颜色不表达两种含义
   - 字体：SF Pro / PingFang SC 系统栈；正文 ≥17px（移动端默认），最小 11px
   - 材质（毛玻璃）：仅用于悬浮功能层（导航/toast/弹窗遮罩），内容层不使用
   - 用户自定义背景（settings.js 动态主题）通过覆盖同名变量继续生效
   ========================================================= */

:root {
    /* ---- 字体 ---- */
    --font: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'SF Pro Display',
            'PingFang SC', 'Helvetica Neue', 'Helvetica', sans-serif;
    --font-mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
    /* Dynamic Type 层级（iOS 默认字号） */
    --type-large-title: 34px;   /* Large Title */
    --type-title1: 28px;        /* Title 1 */
    --type-title2: 22px;        /* Title 2 */
    --type-title3: 20px;        /* Title 3 */
    --type-headline: 17px;      /* Headline（17 semibold） */
    --type-body: 17px;          /* Body */
    --type-callout: 16px;       /* Callout */
    --type-subhead: 15px;       /* Subheadline */
    --type-footnote: 13px;      /* Footnote */
    --type-caption1: 12px;      /* Caption 1（下限） */
    --type-caption2: 11px;      /* Caption 2（绝对下限，HIG accessibility） */

    /* ---- 语义色（浅色 = iOS 系统色板） ---- */
    --bg: #F2F2F7;                       /* systemGroupedBackground */
    --surface: #FFFFFF;                  /* secondarySystemGroupedBackground */
    --surface-hover: rgba(120,120,128,0.08);   /* systemGray5 @ fill */
    --surface-active: rgba(120,120,128,0.12);  /* systemGray4 @ fill */
    --fill-quaternary: rgba(120,120,128,0.18);
    --border: rgba(60,60,67,0.29);             /* separator */
    --border-strong: rgba(60,60,67,0.36);      /* opaque separator 近似 */

    --text: #000000;                       /* label */
    --text-secondary: rgba(60,60,67,0.60); /* secondaryLabel */
    --text-tertiary: rgba(60,60,67,0.30);  /* tertiaryLabel */
    --text-on-bg: var(--text);
    --text-on-bg-secondary: var(--text-secondary);
    --text-on-bg-tertiary: var(--text-tertiary);

    --primary: #007AFF;                    /* systemBlue */
    --primary-hover: #0062CC;
    --primary-bg: rgba(0,122,255,0.12);    /* tinted fill */
    --green: #34C759;   --green-bg: rgba(52,199,89,0.14);
    --red: #FF3B30;     --red-bg: rgba(255,59,48,0.14);
    --orange: #FF9500;  --orange-bg: rgba(255,149,0,0.14);
    --gold: #FFCC00;
    --purple: #AF52DE;  --purple-bg: rgba(175,82,222,0.14);
    --teal: #30B0C7;    --pink: #FF2D55;   --indigo: #5856D6;
    --mint: #00C7BE;    --cyan: #32ADE6;   --brown: #A2845E;
    --yellow: #FFCC00;

    /* ---- 圆角（连续曲率观感） ---- */
    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;

    /* ---- 阴影 ---- */
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.06);
    --shadow: 0 2px 10px rgba(0,0,0,0.08), 0 0 1px rgba(0,0,0,0.10);
    --shadow-lg: 0 8px 28px rgba(0,0,0,0.12), 0 0 1px rgba(0,0,0,0.10);
    --shadow-xl: 0 16px 48px rgba(0,0,0,0.18), 0 0 1px rgba(0,0,0,0.12);

    /* ---- 材质：仅悬浮功能层使用 ---- */
    --material-bar: rgba(249,249,249,0.82);       /* 导航/工具条 */
    --material-bar-dark: rgba(30,30,30,0.78);
    --material-overlay: rgba(0,0,0,0.35);         /* 弹窗遮罩 */
    --material-blur: saturate(180%) blur(20px);
    --material-blur-soft: saturate(180%) blur(8px);

    /* ---- 动效 ---- */
    --transition: .22s cubic-bezier(.25,.1,.25,1);
    --transition-fast: .15s cubic-bezier(.25,.1,.25,1);
    --spring: .32s cubic-bezier(.22,1,.36,1);
    --focus-ring: 0 0 0 3.5px rgba(0,122,255,0.35);
}

/* ---- 深色外观（跟随系统，语义色整体切换） ---- */
@media (prefers-color-scheme: dark) {
    :root {
        --bg: #000000;                            /* systemGroupedBackground */
        --surface: #1C1C1E;                       /* secondarySystemGroupedBackground */
        --surface-hover: rgba(120,120,128,0.24);
        --surface-active: rgba(120,120,128,0.32);
        --fill-quaternary: rgba(118,118,128,0.18);
        --border: rgba(84,84,88,0.60);
        --border-strong: rgba(84,84,88,0.75);

        --text: #FFFFFF;                          /* label */
        --text-secondary: rgba(235,235,245,0.60); /* secondaryLabel */
        --text-tertiary: rgba(235,235,245,0.30);
        --text-on-bg: var(--text);
        --text-on-bg-secondary: var(--text-secondary);
        --text-on-bg-tertiary: var(--text-tertiary);

        --primary: #0A84FF;
        --primary-hover: #409CFF;
        --primary-bg: rgba(10,132,255,0.22);
        --green: #30D158;   --green-bg: rgba(48,209,88,0.22);
        --red: #FF453A;     --red-bg: rgba(255,69,58,0.22);
        --orange: #FF9F0A;  --orange-bg: rgba(255,159,10,0.22);
        --gold: #FFD60A;
        --purple: #BF5AF2;  --purple-bg: rgba(191,90,242,0.22);
        --teal: #40C8E0;    --pink: #FF375F;   --indigo: #5E5CE6;
        --mint: #63E6E2;    --cyan: #64D2FF;   --brown: #AC8E68;
        --yellow: #FFD60A;

        --shadow-sm: 0 1px 2px rgba(0,0,0,0.5);
        --shadow: 0 2px 10px rgba(0,0,0,0.55), 0 0 1px rgba(0,0,0,0.6);
        --shadow-lg: 0 8px 28px rgba(0,0,0,0.6), 0 0 1px rgba(0,0,0,0.6);
        --shadow-xl: 0 16px 48px rgba(0,0,0,0.7), 0 0 1px rgba(0,0,0,0.6);

        --material-bar: rgba(30,30,30,0.78);
        --material-bar-dark: rgba(30,30,30,0.78);
        --material-overlay: rgba(0,0,0,0.5);
        --focus-ring: 0 0 0 3.5px rgba(10,132,255,0.45);
    }
}

/* =========================================================
   基础
   ========================================================= */
html { color-scheme: light dark; }
body {
    font-family: var(--font);
    font-size: var(--type-body);
    line-height: 1.47;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

/* 键盘焦点环（accessibility：桌面端所有可交互元素可见焦点） */
:focus { outline: none; }
:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
    border-radius: var(--radius-sm);
}

/* =========================================================
   组件基类（各页可直接使用，也可仅引用变量）
   ========================================================= */

/* 按钮：filled / tinted / gray / plain 四式（HIG buttons.md） */
.abtn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    min-height: 44px;                    /* 触控目标 44pt（手机最小 28pt） */
    padding: 10px 20px;
    border: none; border-radius: var(--radius-sm);
    font-family: var(--font); font-size: var(--type-callout); font-weight: 600;
    cursor: pointer; white-space: nowrap;
    transition: transform var(--transition-fast), background var(--transition-fast), opacity var(--transition-fast);
    -webkit-tap-highlight-color: transparent;
}
.abtn:active { transform: scale(.97); }
.abtn:disabled { opacity: .4; cursor: default; transform: none; }
.abtn-filled { background: var(--primary); color: #fff; }
.abtn-filled:disabled { color: #fff; }
.abtn-tinted { background: var(--primary-bg); color: var(--primary); }
.abtn-gray { background: var(--fill-quaternary); color: var(--text); }
.abtn-plain { background: transparent; color: var(--primary); }
.abtn-destructive { background: var(--red); color: #fff; }
.abtn-destructive-tinted { background: var(--red-bg); color: var(--red); }
.abtn-success { background: var(--green); color: #fff; }

/* 卡片 */
.acard {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
}

/* 输入框 */
.ainput {
    width: 100%;
    padding: 11px 14px;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: var(--font); font-size: var(--type-callout);
    outline: none;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.ainput::placeholder { color: var(--text-tertiary); }
.ainput:focus-visible { border-color: var(--primary); box-shadow: 0 0 0 3.5px var(--primary-bg); }

/* iOS 开关 */
.aswitch { position: relative; display: inline-block; width: 51px; height: 31px; flex-shrink: 0; }
.aswitch input { opacity: 0; width: 0; height: 0; }
.aswitch .track {
    position: absolute; inset: 0; border-radius: 31px;
    background: var(--fill-quaternary);
    transition: background var(--transition-fast);
}
.aswitch .track::before {
    content: ''; position: absolute; top: 2px; left: 2px;
    width: 27px; height: 27px; border-radius: 50%;
    background: #fff; box-shadow: 0 2px 5px rgba(0,0,0,.2);
    transition: transform var(--transition-fast);
}
.aswitch input:checked + .track { background: var(--green); }
.aswitch input:checked + .track::before { transform: translateX(20px); }
.aswitch input:focus-visible + .track { box-shadow: var(--focus-ring); }

/* 徽标 */
.abadge {
    display: inline-flex; align-items: center;
    padding: 2px 8px; border-radius: 6px;
    font-size: var(--type-caption1); font-weight: 600;
    background: var(--fill-quaternary); color: var(--text-secondary);
}
.abadge.blue { background: var(--primary-bg); color: var(--primary); }
.abadge.green { background: var(--green-bg); color: var(--green); }
.abadge.red { background: var(--red-bg); color: var(--red); }
.abadge.orange { background: var(--orange-bg); color: var(--orange); }

/* 毛玻璃工具条：仅用于悬浮层 */
.amaterial {
    background: var(--material-bar);
    -webkit-backdrop-filter: var(--material-blur);
    backdrop-filter: var(--material-blur);
}

/* =========================================================
   无障碍偏好（HIG accessibility.md / motion.md / materials.md）
   ========================================================= */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
    }
}
@media (prefers-reduced-transparency: reduce) {
    :root {
        --material-bar: #F9F9F9;
        --material-blur: none;
        --material-blur-soft: none;
    }
}
@media (prefers-color-scheme: dark) {
    @media (prefers-reduced-transparency: reduce) {
        :root { --material-bar: #1E1E1E; }
    }
}
@media (prefers-contrast: more) {
    :root {
        --text-secondary: rgba(0,0,0,0.85);
        --text-tertiary: rgba(0,0,0,0.55);
        --border: rgba(0,0,0,0.5);
        --border-strong: rgba(0,0,0,0.65);
    }
    @media (prefers-color-scheme: dark) {
        :root {
            --text-secondary: rgba(255,255,255,0.9);
            --text-tertiary: rgba(255,255,255,0.6);
            --border: rgba(255,255,255,0.5);
            --border-strong: rgba(255,255,255,0.65);
        }
    }
}

/* 触控设备：控件达到 44pt 目标（HIG accessibility：移动端默认 44×44pt） */
@media (pointer: coarse) {
    button, [role="button"], input[type="submit"] { min-height: 44px; }
}

/* 滚动条 */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--fill-quaternary); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }
