/**
 * 共享设计令牌 — 50 个新闻工具统一视觉规范
 * 各项目在 styles.css 中可覆盖 :root 变量实现局部定制。
 * 引入方式：<link rel="stylesheet" href="../shared/design-tokens.css" />
 */

/* ===== Light Mode ===== */
:root {
    /* 基础色 */
    --bg: #f4f0e8;
    --card: #ffffff;
    --ink: #1a1a1a;
    --ink-secondary: #555;
    --line: #e0d8cc;

    /* 品牌强调色 */
    --accent: #c7491f;
    --accent-hover: #a63a18;
    --accent-light: rgba(199, 73, 31, 0.08);

    /* 功能色 */
    --ok: #0b7a3b;
    --ok-light: #e8f5ee;
    --warn: #b86e00;
    --warn-light: #fef7e0;
    --bad: #a61f12;
    --bad-light: #fdecea;

    /* 排版 */
    --font-sans: "IBM Plex Sans", "Noto Sans SC", "PingFang SC", system-ui, sans-serif;
    --font-serif: "IBM Plex Serif", "Source Han Serif SC", "Noto Serif SC", serif;
    --font-mono: "IBM Plex Mono", "Fira Code", "Menlo", monospace;

    /* 间距 */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;

    /* 圆角 */
    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-pill: 999px;

    /* 阴影 */
    --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.06);
    --shadow-hover: 0 4px 12px rgba(0, 0, 0, 0.1);
}

/* ===== Dark Mode (auto + manual toggle) ===== */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #1a1a2e;
        --card: #242438;
        --ink: #e8e8f0;
        --ink-secondary: #aaa;
        --line: #3a3a50;

        --accent: #ff7b54;
        --accent-hover: #ff9268;
        --accent-light: rgba(255, 123, 84, 0.12);

        --ok: #4ade80;
        --ok-light: rgba(74, 222, 128, 0.12);
        --warn: #fbbf24;
        --warn-light: rgba(251, 191, 36, 0.12);
        --bad: #f87171;
        --bad-light: rgba(248, 113, 113, 0.12);

        --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.3);
        --shadow-hover: 0 4px 12px rgba(0, 0, 0, 0.4);
    }
}

/* Manual dark mode override */
:root[data-theme="dark"] {
    --bg: #1a1a2e;
    --card: #242438;
    --ink: #e8e8f0;
    --ink-secondary: #aaa;
    --line: #3a3a50;

    --accent: #ff7b54;
    --accent-hover: #ff9268;
    --accent-light: rgba(255, 123, 84, 0.12);

    --ok: #4ade80;
    --ok-light: rgba(74, 222, 128, 0.12);
    --warn: #fbbf24;
    --warn-light: rgba(251, 191, 36, 0.12);
    --bad: #f87171;
    --bad-light: rgba(248, 113, 113, 0.12);

    --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-hover: 0 4px 12px rgba(0, 0, 0, 0.4);
}

/* ===== Global Reset ===== */
*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    color: var(--ink);
    background: var(--bg);
    font-family: var(--font-sans);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

/* ===== Smooth Transitions (global) ===== */
body, .card, .hero, button, input, select, textarea, a {
    transition: background-color 0.25s ease, color 0.25s ease,
                border-color 0.25s ease, box-shadow 0.25s ease;
}

/* ===== Focus Visible (a11y) ===== */
:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 2px;
}

/* ===== Custom Scrollbar ===== */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: var(--line);
    border-radius: var(--radius-pill);
}
::-webkit-scrollbar-thumb:hover { background: var(--ink-secondary); }
@supports (scrollbar-width: thin) {
    * { scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
}

/* ===== Text Selection ===== */
::selection {
    background: var(--accent);
    color: #fff;
}

/* ===== Page Entrance Animation ===== */
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(16px); }
    to   { opacity: 1; transform: translateY(0); }
}
main, .app {
    animation: fadeInUp 0.4s ease-out;
}

/* ===== Card System ===== */
.card {
    background: var(--card);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-card);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-hover);
}

/* ===== Button System ===== */
button, .btn, [type="button"], [type="submit"] {
    position: relative;
    overflow: hidden;
    cursor: pointer;
    border: none;
    padding: 8px 18px;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 500;
    background: var(--accent);
    color: #fff;
    transition: transform 80ms ease, background 0.2s ease, box-shadow 0.2s ease;
}
button:hover, .btn:hover {
    background: var(--accent-hover);
    box-shadow: 0 2px 8px rgba(199, 73, 31, 0.25);
}
button:active, .btn:active {
    transform: scale(0.97);
}
/* Ripple effect */
button::after {
    content: "";
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at var(--ripple-x, 50%) var(--ripple-y, 50%),
        rgba(255,255,255,0.3) 0%, transparent 60%);
    opacity: 0;
    transition: opacity 0.4s;
    pointer-events: none;
}
button:active::after { opacity: 1; }

.btn-secondary, .ghost {
    background: transparent;
    color: var(--ink);
    border: 1px solid var(--line);
}
.btn-secondary:hover, .ghost:hover {
    background: var(--accent-light);
    border-color: var(--accent);
    color: var(--accent);
    box-shadow: none;
}

/* ===== Input System ===== */
input, textarea, select {
    font-family: inherit;
    font-size: 0.9rem;
    padding: 8px 12px;
    border: 1.5px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--card);
    color: var(--ink);
    transition: border-color 0.2s, box-shadow 0.2s;
}
input:focus, textarea:focus, select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-light);
    outline: none;
}

/* ===== Gradient Heading ===== */
.hero h1, h1.gradient {
    background: linear-gradient(135deg, var(--accent) 0%, var(--warn, #b86e00) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .hero h1,
    :root:not([data-theme="light"]) h1.gradient {
        background: linear-gradient(135deg, #ff7b54 0%, #fbbf24 100%);
        -webkit-background-clip: text;
        background-clip: text;
    }
}
:root[data-theme="dark"] .hero h1,
:root[data-theme="dark"] h1.gradient {
    background: linear-gradient(135deg, #ff7b54 0%, #fbbf24 100%);
    -webkit-background-clip: text;
    background-clip: text;
}

/* ===== Glassmorphism Utility ===== */
.glass {
    background: rgba(255, 255, 255, 0.6);
    backdrop-filter: blur(12px) saturate(160%);
    -webkit-backdrop-filter: blur(12px) saturate(160%);
    border: 1px solid rgba(255, 255, 255, 0.3);
}
:root[data-theme="dark"] .glass {
    background: rgba(36, 36, 56, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.08);
}
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .glass {
        background: rgba(36, 36, 56, 0.7);
        border: 1px solid rgba(255, 255, 255, 0.08);
    }
}

/* ===== Skeleton Loading ===== */
.skeleton {
    background: linear-gradient(90deg,
        var(--line) 25%, rgba(255,255,255,0.4) 50%, var(--line) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s ease infinite;
    border-radius: var(--radius-sm);
}
@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ===== Tooltip ===== */
[data-tooltip] {
    position: relative;
}
[data-tooltip]::before {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%) scale(0.9);
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 12px;
    white-space: nowrap;
    background: var(--ink);
    color: var(--bg);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s, transform 0.15s;
    z-index: 100;
}
[data-tooltip]:hover::before {
    opacity: 1;
    transform: translateX(-50%) scale(1);
}

/* ===== Badges ===== */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: var(--radius-pill);
    font-size: 11px;
    font-weight: 600;
    line-height: 1.4;
}
.badge-accent { background: var(--accent-light); color: var(--accent); }
.badge-ok { background: var(--ok-light); color: var(--ok); }
.badge-warn { background: var(--warn-light); color: var(--warn); }
.badge-bad { background: var(--bad-light); color: var(--bad); }

/* ===== Teach Card Animation ===== */
details.teach-card summary {
    cursor: pointer;
    font-weight: 600;
    transition: color 0.2s;
}
details.teach-card summary:hover { color: var(--accent); }
details.teach-card[open] > *:not(summary) {
    animation: fadeInUp 0.3s ease-out;
}

/* ===== Responsive ===== */
@media (max-width: 600px) {
    :root {
        --space-lg: 16px;
        --space-xl: 24px;
    }
    button { padding: 10px 16px; font-size: 0.85rem; }
    .hero h1 { font-size: 1.4rem; }
}

/* ===== Common Utilities ===== */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

/* ===== Print Stylesheet ===== */
@media print {
    /* Force light colors */
    :root {
        --bg: #fff !important;
        --card: #fff !important;
        --ink: #000 !important;
        --ink-secondary: #333 !important;
        --line: #ccc !important;
        --shadow-card: none !important;
        --shadow-hover: none !important;
    }

    /* Hide floating UI elements */
    #darkToggleBtn,
    #cmdPaletteOverlay,
    #toastContainer,
    #kbdHintBar,
    .onboarding-ring,
    .onboarding-tip,
    .no-print,
    nav[style],
    [style*="position:fixed"] {
        display: none !important;
    }

    /* Optimize for paper */
    body {
        font-size: 12pt;
        line-height: 1.4;
        background: #fff !important;
    }

    a { color: #000; text-decoration: underline; }
    a[href]::after { content: " (" attr(href) ")"; font-size: 9pt; opacity: 0.6; }
    a[href^="#"]::after, a[href^="javascript"]::after { content: ""; }

    .card {
        box-shadow: none !important;
        border: 1px solid #ddd;
        break-inside: avoid;
    }

    button { border: 1px solid #999; }
}