:root {
    color-scheme: light;
    --canvas: #f5f7fb;
    --canvas-2: #eef2f8;
    --surface: #ffffff;
    --surface-soft: #f8fafc;
    --surface-hover: #f2f6ff;
    --ink: #111827;
    --ink-2: #334155;
    --muted: #64748b;
    --faint: #94a3b8;
    --line: #dbe3ef;
    --line-strong: #c7d2e2;
    --primary: #285eea;
    --primary-2: #174bd2;
    --primary-soft: #e8efff;
    --success: #047857;
    --success-soft: #e7f8ef;
    --warn: #a16207;
    --warn-soft: #fff7d6;
    --danger: #c2414b;
    --danger-2: #a8323c;
    --danger-soft: #fff0f2;
    --focus: #f59e0b;
    --radius-sm: 10px;
    --radius-md: 16px;
    --radius-lg: 24px;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
    --shadow-card: 0 18px 50px rgba(15, 23, 42, 0.08);
    --font-ui: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
    --font-mono: ui-monospace, 'SFMono-Regular', 'Cascadia Code', Consolas, monospace;
    --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    min-height: 100dvh;
    font-family: var(--font-ui);
    font-size: 15px;
    line-height: 1.55;
    color: var(--ink);
    background:
        radial-gradient(circle at 10% -10%, rgba(40, 94, 234, 0.12), transparent 28rem),
        linear-gradient(180deg, #fbfcff 0, var(--canvas) 17rem, var(--canvas-2) 100%);
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 3px solid rgba(245, 158, 11, 0.7); outline-offset: 2px; }
:focus:not(:focus-visible) { outline: none; }

header {
    position: sticky;
    top: 0;
    z-index: 10;
    background: rgba(255, 255, 255, 0.82);
    border-bottom: 1px solid rgba(203, 213, 225, 0.7);
    backdrop-filter: blur(20px) saturate(160%);
}

header .bar {
    max-width: 1180px;
    margin: auto;
    padding: 14px 24px;
    display: flex;
    align-items: center;
    gap: 18px;
}

.brand { font-size: 17px; font-weight: 800; letter-spacing: -0.03em; color: var(--ink); }
.brand small { margin-left: 8px; color: var(--muted); font-size: 12px; font-weight: 500; letter-spacing: 0; }
nav { display: flex; gap: 4px; margin-left: auto; }
nav a {
    display: inline-flex;
    align-items: center;
    min-height: 38px;
    padding: 8px 13px;
    border-radius: 999px;
    color: var(--ink-2);
    font-size: 14px;
    font-weight: 650;
    transition: color 150ms var(--ease-out), background 150ms var(--ease-out), transform 120ms var(--ease-out);
}
nav a:hover { background: var(--primary-soft); color: var(--primary); text-decoration: none; }
nav a.active { background: var(--ink); color: white; }
nav a:active { transform: scale(0.97); }

main { max-width: 1180px; margin: auto; padding: 36px 24px 72px; }
.page-hero, .firmware-hero {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 24px;
    margin: 10px 0 22px;
}
.page-kicker, .hero-copy { max-width: 68ch; margin: 0; color: var(--muted); }
h1 { margin: 0 0 8px; font-size: clamp(32px, 4vw, 48px); line-height: 1.02; letter-spacing: -0.055em; font-weight: 850; }
h2 { margin: 36px 0 14px; font-size: 20px; line-height: 1.2; letter-spacing: -0.02em; font-weight: 800; }
h3 { margin: 0 0 14px; font-size: 16px; line-height: 1.25; font-weight: 800; }
.card h2, .panel h2, .card h3, .panel h3 { margin-top: 0; }
.eyebrow { margin: 0 0 10px; color: var(--primary); font-size: 12px; font-weight: 900; letter-spacing: 0.14em; text-transform: uppercase; }
small, .muted { color: var(--muted); }
.right { text-align: right; }
.center { text-align: center; }
.ok { color: var(--success); }
.warn { color: var(--warn); }
.bad { color: var(--danger); }

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 250px), 1fr)); gap: 16px; }
.status-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.two { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr)); gap: 18px; }
.firmware-layout { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(280px, 0.8fr); gap: 18px; align-items: stretch; }
.learning-grid { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(280px, 0.75fr); gap: 18px; margin-top: 18px; align-items: stretch; }

.card, .panel {
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid rgba(203, 213, 225, 0.8);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-card);
    padding: 24px;
}
.panel.soft { background: linear-gradient(180deg, #ffffff, #f8fbff); }
.card.interactive, .button, button { transition: background 160ms var(--ease-out), border-color 160ms var(--ease-out), transform 130ms var(--ease-out), box-shadow 160ms var(--ease-out); }
.card.interactive:hover { transform: translateY(-2px); border-color: #b7c7e4; background: #fff; }
.danger-zone { background: linear-gradient(180deg, #fff7f8, #ffffff); border-color: #ffc9cf; }

.metric { font-size: clamp(34px, 5vw, 52px); line-height: 1; font-weight: 850; letter-spacing: -0.05em; font-variant-numeric: tabular-nums; }
.metric-card { position: relative; overflow: hidden; }
.metric-card::after { content: ''; position: absolute; inset: auto -30px -50px auto; width: 160px; height: 160px; border-radius: 50%; background: rgba(40, 94, 234, 0.08); pointer-events: none; }
.metric-card.primary { background: linear-gradient(135deg, #ffffff, #edf3ff); border-color: #bfd0f2; }
.metric-label { margin-top: 8px; color: var(--ink-2); font-weight: 750; }
.metric-meta { margin-top: 10px; color: var(--muted); font-size: 13px; }

.notice {
    margin: 14px 0;
    padding: 13px 16px;
    border-radius: var(--radius-md);
    border: 1px solid #c9d8ff;
    background: var(--primary-soft);
    color: #173a91;
    font-size: 14px;
    animation: notice-in 180ms var(--ease-out);
}
.notice.ok { background: var(--success-soft); border-color: #a7e5c1; color: var(--success); }
.notice.warn { background: var(--warn-soft); border-color: #f5d66d; color: var(--warn); }
.notice.bad { background: var(--danger-soft); border-color: #ffc9cf; color: var(--danger); }
@keyframes notice-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }

.study-hero {
    padding: 28px;
    border: 1px solid rgba(199, 210, 226, 0.65);
    border-radius: 32px;
    background:
        radial-gradient(circle at 80% 20%, rgba(40, 94, 234, 0.14), transparent 22rem),
        rgba(255, 255, 255, 0.72);
    box-shadow: var(--shadow-card);
}

.study-card { background: rgba(255, 255, 255, 0.94); }
.section-head { display: flex; justify-content: space-between; gap: 18px; align-items: flex-start; margin-bottom: 18px; }
.section-head h2 { margin-bottom: 6px; }
.study-chart { height: 220px; padding: 18px 6px 0; }
.study-chart .bar { background: linear-gradient(180deg, #285eea, #86a5ff); border-radius: 999px 999px 6px 6px; }
.study-chart .bar-wrap:hover .bar { background: linear-gradient(180deg, #174bd2, #285eea); }
.study-suggestion { padding: 16px; border-radius: 18px; background: #f4f7ff; border: 1px solid #d8e3ff; }
.study-suggestion b { display: block; color: var(--ink); font-size: 16px; line-height: 1.45; }
.study-suggestion p { margin: 10px 0 0; color: var(--muted); }
.study-checklist { display: grid; gap: 10px; margin-top: 16px; }
.study-checklist span { padding: 11px 13px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface-soft); color: var(--ink-2); font-weight: 750; }
.empty-state { min-height: 190px; display: flex; flex-direction: column; align-items: center; justify-content: center; border: 1px dashed var(--line-strong); border-radius: 22px; background: var(--surface-soft); text-align: center; }
.empty-state b { font-size: 18px; }
.empty-state p { margin: 6px 0 0; color: var(--muted); }

label { display: block; margin: 13px 0 6px; color: var(--ink-2); font-size: 13px; font-weight: 700; }
label:first-child { margin-top: 0; }
input, select, textarea {
    width: 100%;
    min-height: 46px;
    padding: 11px 13px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    background: #fbfdff;
    color: var(--ink);
    font: inherit;
    box-shadow: var(--shadow-sm);
    transition: border-color 150ms var(--ease-out), box-shadow 150ms var(--ease-out), background 150ms var(--ease-out);
}
textarea { min-height: 112px; resize: vertical; }
input::placeholder, textarea::placeholder { color: var(--faint); }
input:focus, select:focus, textarea:focus { border-color: var(--primary); background: white; box-shadow: 0 0 0 4px rgba(40, 94, 234, 0.12); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.form-grid .wide { grid-column: 1 / -1; }
.check, .switch-row { display: flex; align-items: center; gap: 10px; margin: 10px 0; color: var(--ink-2); }
.check input, .switch-row input { width: auto; min-height: auto; box-shadow: none; }

button, .button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 44px;
    min-width: 44px;
    padding: 10px 16px;
    border: 0;
    border-radius: 999px;
    background: var(--primary);
    color: white;
    font: inherit;
    font-size: 14px;
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 10px 22px rgba(40, 94, 234, 0.22);
}
button:hover, .button:hover { background: var(--primary-2); text-decoration: none; }
button:active, .button:active { transform: scale(0.97); }
button.secondary, .button.secondary { background: #edf2fb; color: var(--ink-2); box-shadow: none; }
button.secondary:hover, .button.secondary:hover { background: #dfe8f7; color: var(--ink); }
button.danger, .button.danger { background: var(--danger); box-shadow: 0 10px 22px rgba(194, 65, 75, 0.18); }
button.danger:hover, .button.danger:hover { background: var(--danger-2); }
.button.small, button.small { min-height: 36px; padding: 7px 11px; font-size: 13px; }

.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin: 2px;
    padding: 4px 9px;
    border-radius: 999px;
    background: #eef2f7;
    color: var(--ink-2);
    font-size: 12px;
    font-weight: 800;
}
.badge.ok { background: var(--success-soft); color: var(--success); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--danger-soft); color: var(--danger); }

.actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.stack > * + * { margin-top: 10px; }
.inline { display: inline; }

.scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--line); border-radius: var(--radius-lg); background: white; box-shadow: var(--shadow-card); }
table { width: 100%; border-collapse: separate; border-spacing: 0; background: white; font-size: 14px; }
th, td { padding: 13px 14px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { color: var(--muted); font-size: 12px; font-weight: 850; letter-spacing: 0.02em; white-space: nowrap; background: #f8fafc; }
tr:last-child td { border-bottom: 0; }
tbody tr { transition: background 140ms var(--ease-out); }
tbody tr:hover { background: #f8fbff; }

.ai-panel { margin-bottom: 22px; background: linear-gradient(180deg, #f0f5ff, #ffffff); border-color: #c5d4f2; }
.ai-panel[open] { padding-bottom: 22px; }
.ai-summary { display: flex; justify-content: space-between; gap: 14px; align-items: flex-start; flex-wrap: wrap; }
.ai-summary b { display: block; font-size: 16px; }
.ai-summary p { margin: 6px 0 0; }

.kv { display: grid; grid-template-columns: 120px 1fr; gap: 10px 14px; align-items: baseline; }
.kv > :nth-child(odd) { color: var(--muted); font-size: 13px; font-weight: 700; }
code { font-family: var(--font-mono); font-size: 12px; color: #24468f; background: #eef4ff; padding: 3px 7px; border-radius: 8px; word-break: break-all; }
pre code { display: block; overflow-x: auto; padding: 14px; border: 1px solid var(--line); background: #f8fafc; line-height: 1.65; }

.device-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; flex-wrap: wrap; }
.device-card { display: flex; flex-direction: column; gap: 12px; }
.device-title { display: flex; align-items: center; gap: 8px; min-width: 0; }
.device-title b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.device-meta { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: auto; }
.device-meta span { display: block; color: var(--muted); font-size: 12px; font-weight: 700; }
.device-meta strong { display: block; color: var(--ink); font-size: 14px; font-weight: 800; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #94a3b8; display: inline-block; flex: 0 0 auto; }
.dot.online { background: #10b981; box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.12); }
.dot.stale { background: #f59e0b; }

.firmware-hero-card {
    padding: 18px;
    border-radius: var(--radius-lg);
    background: var(--ink);
    color: white;
    min-width: 260px;
    box-shadow: var(--shadow-card);
}
.firmware-hero-card small { color: #cbd5e1; }
.firmware-hero-card strong { display: block; margin-top: 4px; font-size: 22px; letter-spacing: -0.04em; }
.firmware-panel-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.firmware-panel-title h2 { margin: 0; }
.firmware-help { margin: 0 0 18px; color: var(--muted); }
.env-card { display: grid; gap: 14px; }
.env-item { padding: 14px; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--surface-soft); }
.env-item span { display: block; margin-bottom: 6px; color: var(--muted); font-size: 12px; font-weight: 800; }
.release-url { max-width: 320px; display: inline-block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: middle; }

.chart { display: flex; align-items: flex-end; gap: 5px; height: 130px; padding-top: 8px; }
.chart .bar-wrap { flex: 1; height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; }
.chart .bar { width: 100%; max-width: 32px; min-height: 2px; border-radius: 8px 8px 0 0; background: var(--primary); transition: height 220ms var(--ease-out), background 160ms var(--ease-out); }
.chart .bar-wrap:hover .bar { background: var(--primary-2); }
.chart .bar-wrap small { margin-top: 5px; color: var(--muted); font-size: 10px; white-space: nowrap; }

.task-status { display: inline-flex; align-items: center; font-size: 13px; font-weight: 800; }
.task-status.done { color: var(--success); }
.task-status.open { color: var(--muted); }
details summary { min-height: 38px; display: flex; align-items: center; color: var(--ink-2); cursor: pointer; user-select: none; }
details summary:hover { color: var(--primary); }
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100dvh; padding: 24px; }
.login-box { width: 100%; max-width: 420px; }
.login-box h1 { text-align: center; }

@media (max-width: 860px) {
    header .bar { padding: 12px 16px; flex-wrap: wrap; }
    nav { width: 100%; margin-left: 0; overflow-x: auto; padding-bottom: 2px; }
    nav a { flex: 0 0 auto; white-space: nowrap; }
    main { padding: 26px 16px 56px; }
    .page-hero, .firmware-hero { align-items: flex-start; flex-direction: column; }
    .right { text-align: left; }
    .status-grid, .firmware-layout, .learning-grid { grid-template-columns: 1fr; }
    .study-hero { padding: 20px; border-radius: 24px; }
    .section-head { flex-direction: column; }
    .form-grid { grid-template-columns: 1fr; }
    .form-grid .wide { grid-column: auto; }
    .card, .panel { padding: 18px; border-radius: 20px; }
    h1 { font-size: 34px; }
    .kv { grid-template-columns: 1fr; gap: 3px; }
    .kv > :nth-child(even) { margin-bottom: 8px; }
    .device-meta { grid-template-columns: 1fr; }
    .ai-summary { flex-direction: column; }
    .firmware-hero-card { width: 100%; }
    th, td { padding: 10px 11px; }
}

@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; }
    button:active, .button:active, nav a:active { transform: none; }
    .notice { animation: none; }
}

@media (prefers-reduced-transparency: reduce) {
    header { background: #ffffff; backdrop-filter: none; }
}
