/* Life Tracker - design system */
:root {
  color-scheme: light;
  --page: #f6f6f3;
  --surface: #fcfcfb;
  --surface-2: #f1f0ec;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --hover: rgba(11, 11, 11, 0.04);
  --accent: #2a78d6;
  --accent-ink: #1c5cab;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --good: #006300; --bad: #d03b3b;
  --heat-0: #ebeae5; --heat-1: #b7d3f6; --heat-2: #6da7ec; --heat-3: #2a78d6; --heat-4: #184f95;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.04), 0 4px 16px rgba(11, 11, 11, 0.04);
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d; --surface: #1a1a19; --surface-2: #232321;
    --ink: #ffffff; --ink-2: #c3c2b7; --muted: #898781;
    --grid: #2c2c2a; --axis: #383835;
    --border: rgba(255, 255, 255, 0.10); --hover: rgba(255, 255, 255, 0.05);
    --accent: #3987e5; --accent-ink: #86b6ef;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
    --good: #0ca30c; --bad: #e66767;
    --heat-0: #262624; --heat-1: #104281; --heat-2: #1c5cab; --heat-3: #3987e5; --heat-4: #86b6ef;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --surface-2: #232321;
  --ink: #ffffff; --ink-2: #c3c2b7; --muted: #898781;
  --grid: #2c2c2a; --axis: #383835;
  --border: rgba(255, 255, 255, 0.10); --hover: rgba(255, 255, 255, 0.05);
  --accent: #3987e5; --accent-ink: #86b6ef;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --good: #0ca30c; --bad: #e66767;
  --heat-0: #262624; --heat-1: #104281; --heat-2: #1c5cab; --heat-3: #3987e5; --heat-4: #86b6ef;
  --shadow: none;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--page); color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent-ink); }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 1.6rem; font-weight: 650; letter-spacing: -0.01em; }
h2 { font-size: 1rem; font-weight: 600; }
h3 { font-size: 0.8rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
button, input, select { font: inherit; color: inherit; }

/* Top bar */
.topbar { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--page) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--border); }
.topbar-in { max-width: 1200px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 16px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--ink); text-decoration: none; white-space: nowrap; }
.brand-mark { width: 18px; height: 18px; border-radius: 5px; background: linear-gradient(135deg, var(--s1), var(--s3)); }
.topnav { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; flex: 1; }
.topnav::-webkit-scrollbar { display: none; }
.topnav a { padding: 7px 12px; border-radius: 8px; color: var(--ink-2); text-decoration: none; font-size: 0.92rem; white-space: nowrap; }
.topnav a:hover { background: var(--hover); color: var(--ink); }
.topnav a.active { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: inset 0 0 0 1px var(--border); }
.theme-btn { background: none; border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px; cursor: pointer; color: var(--ink-2); display: flex; }
.theme-btn:hover { color: var(--ink); background: var(--hover); }
@media (max-width: 720px) {
  .topbar-in { flex-wrap: wrap; gap: 8px; }
  .topnav { order: 3; flex-basis: 100%; }
  .brand { flex: 1; }
}

/* Page */
.wrap { max-width: 1200px; margin: 0 auto; padding: 20px 16px 48px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head .sub { color: var(--muted); margin-top: 2px; }
.grid { display: grid; gap: 16px; }
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cols-main { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); }
@media (max-width: 900px) { .cols-2, .cols-3, .cols-main { grid-template-columns: minmax(0, 1fr); } }
.section { margin-top: 16px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.card-head .meta { color: var(--muted); font-size: 0.85rem; }
.card-head a.meta { text-decoration: none; }
.card-head a.meta:hover { color: var(--accent-ink); }

/* Stat tiles */
.tiles { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
@media (max-width: 520px) {
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .tile .value { font-size: 1.25rem; }
  .hero .value { font-size: 2rem; }
}
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; box-shadow: var(--shadow); color: inherit; text-decoration: none; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
a.tile:hover { border-color: var(--axis); }
.tile .label { font-size: 0.82rem; color: var(--ink-2); }
.tile .value { font-size: 1.5rem; font-weight: 650; letter-spacing: -0.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .foot { font-size: 0.78rem; color: var(--muted); display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.tile .spark { height: 30px; margin-top: 6px; }
.hero .value { font-size: 2.6rem; line-height: 1.1; }

.delta { font-size: 0.78rem; font-weight: 600; white-space: nowrap; }
.delta.good { color: var(--good); }
.delta.bad { color: var(--bad); }
.delta.neutral, .delta.flat { color: var(--ink-2); font-weight: 500; }

/* Charts */
.chart { position: relative; width: 100%; min-height: 40px; }
.chart svg { display: block; overflow: visible; }
.chart text { font-size: 11px; fill: var(--muted); font-variant-numeric: tabular-nums; }
.chart .grid-line { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.chart .base-line { stroke: var(--axis); stroke-width: 1; shape-rendering: crispEdges; }
.chart .end-label { fill: var(--ink); font-weight: 600; font-size: 12px; }
.chart .cross { stroke: var(--axis); stroke-width: 1; }
.chart .hit { fill: transparent; cursor: default; }
.chart a .hm-cell:hover, .chart .bar-hover { opacity: 0.8; }
.chart .hm-cell { stroke: var(--surface); stroke-width: 0; }
.chart .empty-msg { fill: var(--muted); font-size: 13px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 0.82rem; color: var(--ink-2); margin-top: 8px; }
.legend .key { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.heat-legend { display: flex; align-items: center; gap: 3px; justify-content: flex-end; font-size: 0.75rem; color: var(--muted); margin-top: 6px; }
.heat-legend i { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }
.heat-legend span { margin: 0 4px; }

.tip { position: fixed; z-index: 50; pointer-events: none; background: var(--surface); color: var(--ink); border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; font-size: 0.82rem; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.14); min-width: 120px; max-width: 260px; }
.tip .t-head { color: var(--muted); font-size: 0.76rem; margin-bottom: 3px; }
.tip .t-row { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.tip .t-row b { font-weight: 650; font-variant-numeric: tabular-nums; }
.tip .t-name { color: var(--ink-2); display: flex; align-items: center; gap: 6px; }
.tip .t-key { width: 12px; height: 2px; border-radius: 1px; display: inline-block; }

/* Lists */
.list { display: flex; flex-direction: column; }
.row { display: flex; align-items: center; gap: 12px; padding: 9px 4px; border-bottom: 1px solid var(--grid); min-width: 0; }
.row:last-child { border-bottom: none; }
.row:hover { background: var(--hover); }
.row .time { color: var(--muted); font-size: 0.82rem; min-width: 62px; font-variant-numeric: tabular-nums; }
.row .grow { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.row .right { color: var(--muted); font-size: 0.82rem; white-space: nowrap; }
.t-link { color: inherit; text-decoration: none; }
.t-link:hover { text-decoration: underline; }
.group-label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 12px 0 2px; }
.group-label:first-child { margin-top: 0; }
.empty { color: var(--muted); font-size: 0.92rem; padding: 8px 0; }
.scroll { max-height: 520px; overflow-y: auto; margin: 0 -6px; padding: 0 6px; }

.pill { display: inline-block; font-size: 0.72rem; background: var(--surface-2); color: var(--ink-2); border-radius: 999px; padding: 2px 9px; white-space: nowrap; text-decoration: none; }
.count { font-size: 0.75rem; color: var(--muted); font-variant-numeric: tabular-nums; }

/* Horizontal bar rows (rendered in HTML) */
.hbars { display: flex; flex-direction: column; gap: 8px; }
.hbar { display: grid; grid-template-columns: minmax(90px, 34%) 1fr auto; gap: 10px; align-items: center; font-size: 0.88rem; }
.hbar .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink); text-decoration: none; }
a.hbar:hover .name { text-decoration: underline; }
.hbar .track { height: 12px; }
.hbar .fill { height: 100%; background: var(--s1); border-radius: 0 4px 4px 0; min-width: 2px; }
.hbar .num { color: var(--ink-2); font-variant-numeric: tabular-nums; font-size: 0.82rem; min-width: 3ch; text-align: right; }
a.hbar { color: inherit; text-decoration: none; }

/* Tables */
.tbl-wrap { overflow-x: auto; margin: 0 -4px; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.tbl th { text-align: left; font-weight: 600; font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; padding: 6px 8px; border-bottom: 1px solid var(--axis); white-space: nowrap; }
.tbl td { padding: 8px; border-bottom: 1px solid var(--grid); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: none; }
.tbl tbody tr:hover { background: var(--hover); }
.tbl .n { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tbl a { color: inherit; text-decoration: none; }
.tbl a:hover { text-decoration: underline; }
details.table-view { margin-top: 10px; font-size: 0.85rem; }
details.table-view summary { cursor: pointer; color: var(--muted); }
details.table-view .tbl-wrap { max-height: 260px; overflow-y: auto; margin-top: 6px; }

/* Controls */
.controls { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 2px; }
.seg a, .seg button { border: none; background: none; padding: 5px 12px; border-radius: 7px; font-size: 0.86rem; color: var(--ink-2); text-decoration: none; cursor: pointer; white-space: nowrap; }
.seg a:hover { color: var(--ink); }
.seg a.on { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08); }
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 9px; border: 1px solid var(--border); background: var(--surface); color: var(--ink); text-decoration: none; font-size: 0.88rem; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--hover); }
.btn.icon { padding: 7px 10px; }
.btn.primary { background: var(--ink); color: var(--page); border-color: var(--ink); }
.input { padding: 8px 11px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface); width: 100%; }
.input:focus, .btn:focus-visible, .seg a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
select.input { width: auto; }

.x-btn { background: none; border: none; color: var(--muted); font-size: 1.15rem; line-height: 1; cursor: pointer; padding: 4px 6px; border-radius: 6px; opacity: 0; }
.row:hover .x-btn, .x-btn:focus-visible { opacity: 1; }
@media (hover: none) { .x-btn { opacity: 0.6; } }
.x-btn:hover { color: var(--ink); background: var(--hover); }
.linkbtn { background: none; border: none; color: var(--accent-ink); cursor: pointer; font-size: 0.85rem; padding: 2px 4px; }
details.hidden-sec { margin-top: 10px; font-size: 0.85rem; color: var(--muted); }
details.hidden-sec summary { cursor: pointer; padding: 4px; }

/* Calendar */
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.cal .dow { text-align: center; font-size: 0.72rem; color: var(--muted); text-transform: uppercase; padding: 4px 0; }
.cal .cell { min-height: 84px; background: var(--surface-2); border-radius: 10px; padding: 6px 8px; font-size: 0.8rem; display: flex; flex-direction: column; gap: 3px; color: inherit; text-decoration: none; overflow: hidden; border: 1px solid transparent; }
.cal a.cell:hover { border-color: var(--axis); }
.cal .cell.blank { background: none; }
.cal .cell.today { border-color: var(--accent); }
.cal .dnum { font-weight: 650; display: flex; justify-content: space-between; align-items: center; }
.cal .dot { width: 8px; height: 8px; border-radius: 50%; }
.cal .act { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--ink-2); font-size: 0.75rem; }
.cal .more { color: var(--muted); font-size: 0.72rem; }
@media (max-width: 640px) { .cal .cell { min-height: 54px; } .cal .act, .cal .more { display: none; } }

.badge-row { display: flex; gap: 6px; flex-wrap: wrap; }
.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
.kv-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.kv.kv-4 div b { font-size: 1rem; white-space: nowrap; }
@media (max-width: 420px) { .kv-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.kv div b { display: block; font-size: 1.15rem; font-weight: 650; }
.kv div span { font-size: 0.78rem; color: var(--muted); }
.note { color: var(--muted); font-size: 0.82rem; }
.progress { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--s3); border-radius: 3px; }

@media print {
  .topbar, .controls, .theme-btn, .x-btn, .no-print { display: none !important; }
  body { background: #fff; }
  .card, .tile { box-shadow: none; break-inside: avoid; }
}

/* Books */
.books-top { grid-template-columns: minmax(260px, 1fr) minmax(0, 2fr); }
@media (max-width: 900px) { .books-top { grid-template-columns: minmax(0, 1fr); } }
.rings { display: flex; justify-content: space-around; gap: 12px; flex-wrap: wrap; }
.ring { display: flex; flex-direction: column; align-items: center; }
.ring-track { fill: none; stroke: var(--heat-1); stroke-width: 8; }
.ring-fill { fill: none; stroke: var(--accent); stroke-width: 8; stroke-linecap: round; }
.ring.done .ring-fill { stroke: var(--s3); }
.ring-val { font-size: 15px; font-weight: 650; fill: var(--ink); }
.ring-sub { font-size: 10px; fill: var(--muted); }
.ring-label { font-size: 0.8rem; color: var(--ink-2); margin-top: 2px; }
.streak { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--grid); text-align: center; }
.streak b { display: block; font-size: 1.3rem; font-weight: 650; }
.streak span { font-size: 0.75rem; color: var(--muted); }

.shelf { display: flex; flex-direction: column; gap: 4px; }
.shelf-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 8px; }
.shelf-item { display: flex; gap: 14px; padding: 10px; margin: 0 -10px; border-radius: 10px; color: inherit; text-decoration: none; align-items: flex-start; }
.shelf-item:hover { background: var(--hover); }
.shelf-body { display: flex; flex-direction: column; gap: 3px; min-width: 0; flex: 1; }
.shelf-body b { font-size: 1rem; overflow-wrap: anywhere; }
.progress-row { display: flex; align-items: center; gap: 8px; margin: 4px 0 2px; }
.progress-row .progress { flex: 1; max-width: 260px; }
.progress-lg { height: 10px; border-radius: 5px; }

.cover { flex: none; border-radius: 4px 8px 8px 4px; overflow: hidden; position: relative; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, hsl(var(--cover-hue) 45% 42%), hsl(var(--cover-hue) 50% 26%));
  box-shadow: inset 4px 0 0 rgba(0, 0, 0, 0.18), 0 2px 6px rgba(0, 0, 0, 0.18); }
.cover span { color: rgba(255, 255, 255, 0.9); font-weight: 700; letter-spacing: 0.04em; }
.cover img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.cover-sm { width: 56px; height: 84px; }
.cover-sm span { font-size: 1rem; }
.cover-lg { width: 120px; height: 180px; }
.cover-lg span { font-size: 2rem; }
.book-head { display: flex; gap: 22px; align-items: flex-start; }
.book-meta { flex: 1; min-width: 0; }
.book-meta h1 { margin-top: 6px; font-size: 1.9rem; }
.book-progress { margin-top: 14px; max-width: 420px; }
.book-progress .progress-row .progress { max-width: none; }
.status-reading { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent-ink); }
.status-finished { background: color-mix(in srgb, var(--good) 16%, transparent); color: var(--good); }
@media (max-width: 520px) { .book-head { gap: 14px; } .cover-lg { width: 84px; height: 126px; } .book-meta h1 { font-size: 1.4rem; } }

/* Edit mode */
.edit-card { border-color: var(--accent); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px 16px; }
.form-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 0.82rem; color: var(--ink-2); }
.row-form { display: flex; gap: 6px; align-items: center; }
.row-form .input { width: 70px; padding: 5px 8px; }
.row-form .btn { padding: 5px 10px; }
.flash { margin-top: 16px; padding: 10px 14px; border-radius: 10px; font-size: 0.9rem; }
.flash.ok { background: color-mix(in srgb, var(--good) 14%, transparent); color: var(--good); }
.flash.err { background: color-mix(in srgb, var(--bad) 14%, transparent); color: var(--bad); }

/* Reading Log */
.book-mark { background: linear-gradient(135deg, var(--s2), var(--s4)); border-radius: 3px 5px 5px 3px; box-shadow: inset 3px 0 0 rgba(0, 0, 0, 0.18); }
.ext-link { font-size: 0.85rem; text-decoration: none; white-space: nowrap; }
.tbl .day-row td { background: var(--surface-2); border-bottom: none; padding-top: 7px; padding-bottom: 7px; }
.tbl tbody.day-group:target .day-row td { background: color-mix(in srgb, var(--accent) 16%, transparent); }
.seg a .count { margin-left: 2px; }
@media (max-width: 520px) { .ext-link { display: none; } }
html { scroll-padding-top: 80px; }
