:root {
    --bg: #f6f3ee;
    --panel: #ffffff;
    --panel-soft: #faf8f4;
    --text: #23201c;
    --muted: #7a736a;
    --line: #e7e1d8;
    --accent: #c2410c;
    --accent-soft: #fde7d9;
    --danger: #b91c1c;
    --track: #efeae2;
    --shadow: 0 1px 2px rgba(35, 32, 28, 0.06), 0 8px 24px rgba(35, 32, 28, 0.05);
    --radius: 14px;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #171512;
        --panel: #211e1a;
        --panel-soft: #282420;
        --text: #f1ece5;
        --muted: #a69d92;
        --line: #36312b;
        --accent: #fb923c;
        --accent-soft: #3a2618;
        --danger: #f87171;
        --track: #2d2924;
        --shadow: none;
        color-scheme: dark;
    }
}

* { box-sizing: border-box; }

/* 组件上的 display 规则不能覆盖 hidden 属性。 */
[hidden] { display: none !important; }

html, body { margin: 0; }

body {
    background: var(--bg);
    color: var(--text);
    font: 15px/1.55 -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei",
        "Noto Sans SC", sans-serif;
    -webkit-font-smoothing: antialiased;
}

button, input, select { font: inherit; color: inherit; }

.sr-only {
    position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

.muted { color: var(--muted); }

/* 顶栏 */
.topbar {
    display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between;
    max-width: 1180px; margin: 0 auto; padding: 24px 16px 8px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
    width: 36px; height: 36px; border-radius: 50%;
    background: conic-gradient(var(--accent) 0 35%, #f59e0b 35% 55%, #6366f1 55% 85%, #22c55e 85% 100%);
    -webkit-mask: radial-gradient(circle, transparent 9px, #000 10px);
    mask: radial-gradient(circle, transparent 9px, #000 10px);
}
.brand h1 { margin: 0; font-size: 22px; letter-spacing: 0.02em; }
.brand p { margin: 0; color: var(--muted); font-size: 13px; }
.updated { margin: 0; font-size: 13px; }
.load-error {
    max-width: 1148px; margin: 16px auto; padding: 14px 16px; border-radius: var(--radius);
    background: var(--accent-soft); color: var(--danger);
}

/* 布局 */
.layout {
    display: grid; gap: 16px; max-width: 1180px; margin: 0 auto; padding: 8px 16px 24px;
    grid-template-columns: minmax(0, 1fr);
}
@media (min-width: 960px) {
    .layout { grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); align-items: start; }
    .day-panel { grid-row: span 2; }
}

.panel {
    background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
    box-shadow: var(--shadow); padding: 18px;
}
.panel h2 { margin: 0 0 12px; font-size: 17px; }
.panel h3 { margin: 0; font-size: 15px; }

/* 按钮 */
button {
    cursor: pointer; border-radius: 10px; border: 1px solid transparent; padding: 7px 14px;
    background: var(--panel-soft); transition: background 0.15s, border-color 0.15s;
}
button:focus-visible, input:focus-visible, select:focus-visible {
    outline: 2px solid var(--accent); outline-offset: 2px;
}
button.ghost { background: transparent; border-color: var(--line); }
button.ghost:hover { background: var(--panel-soft); }
button.small { padding: 5px 10px; font-size: 13px; }
button.icon { width: 36px; height: 36px; padding: 0; font-size: 20px; line-height: 1; border-color: var(--line); }

/* 日期切换 */
.day-nav { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.date-field input {
    height: 36px; padding: 0 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel-soft);
}
.day-title { margin: 12px 0 10px !important; font-size: 20px !important; }

/* 时间轴 */
.timeline { margin-bottom: 18px; }
.timeline-track {
    position: relative; height: 34px; border-radius: 10px; background: var(--track); overflow: hidden;
}
.timeline-segment {
    position: absolute; top: 0; bottom: 0; min-width: 2px; border-right: 1px solid var(--panel);
}
.timeline-segment:hover { filter: brightness(1.08); }
.timeline-ticks {
    display: flex; justify-content: space-between; margin-top: 4px; font-size: 11px; color: var(--muted);
}

/* 记录列表 */
.entries-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 8px; }
.entries { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.entry {
    display: grid; grid-template-columns: 6px minmax(0, 1fr); gap: 12px; align-items: center;
    padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel);
}
.entry-bar { align-self: stretch; border-radius: 3px; }
.entry-main { min-width: 0; }
.entry-time { font-variant-numeric: tabular-nums; font-weight: 600; }
.entry-meta { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.empty { color: var(--muted); text-align: center; padding: 18px 0 6px; margin: 0; }

/* 当天分布 */
.distribution { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 18px; align-items: center; }
@media (max-width: 480px) { .distribution { grid-template-columns: minmax(0, 1fr); justify-items: center; } }
.donut { width: 150px; height: 150px; }
.donut-label { font-size: 13px; fill: var(--muted); }
.donut-value { font-size: 18px; font-weight: 700; fill: var(--text); }
.legend { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; width: 100%; }
.legend li { display: grid; grid-template-columns: 12px minmax(0, 1fr) auto; gap: 8px; align-items: center; font-size: 14px; }
.legend .value { font-variant-numeric: tabular-nums; color: var(--muted); }
.swatch { width: 12px; height: 12px; border-radius: 4px; }

/* 累计统计 */
.range-head { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.range-head h2 { margin: 0 !important; }
.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.segmented button { border-radius: 0; background: transparent; padding: 6px 12px; font-size: 13px; }
.segmented button[aria-selected="true"] { background: var(--accent); color: #fff; }
.stacked { display: flex; align-items: flex-end; gap: 3px; height: 140px; margin: 12px 0 16px; overflow-x: auto; }
.stacked-day {
    flex: 1 0 14px; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; min-width: 14px;
    cursor: pointer;
}
.stacked-col {
    display: flex; flex-direction: column-reverse; border-radius: 4px 4px 0 0; overflow: hidden; background: var(--track);
    flex: 1 1 auto;
}
.stacked-col span { display: block; }
.stacked-label { font-size: 10px; color: var(--muted); text-align: center; margin-top: 3px; font-variant-numeric: tabular-nums; }
.stacked-note { color: var(--muted); font-size: 13px; align-self: center; margin: auto; }
.totals { width: 100%; border-collapse: collapse; font-size: 14px; }
.totals th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; padding: 6px 4px; border-bottom: 1px solid var(--line); }
.totals td { padding: 8px 4px; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.totals .category-name { display: inline-flex; align-items: center; gap: 8px; }
.totals tr:last-child td { border-bottom: 0; }

.footer { max-width: 1180px; margin: 0 auto; padding: 0 16px 32px; text-align: center; color: var(--muted); font-size: 12px; }
.footer p { margin: 4px 0; }
.footer a { color: inherit; }
