/* ============================================================ tokens ==== */
:root {
  color-scheme: light;
  --page:        #f9f9f7;
  --surface:     #fcfcfb;
  --surface-2:   #f2f1ec;
  --ink:         #0b0b0b;
  --ink-2:       #52514e;
  --ink-muted:   #898781;
  --line:        #e1e0d9;
  --axis:        #c3c2b7;
  --border:      rgba(11, 11, 11, .10);
  --shadow:      0 1px 2px rgba(11,11,11,.05), 0 8px 24px rgba(11,11,11,.06);
  --series-1:    #2a78d6;   /* books */
  --series-2:    #eb6834;   /* films */
  --accent-ink:  #ffffff;
  --good:        #0ca30c;
  --critical:    #d03b3b;
  --radius:      10px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page:      #0d0d0d;
    --surface:   #1a1a19;
    --surface-2: #232322;
    --ink:       #ffffff;
    --ink-2:     #c3c2b7;
    --ink-muted: #898781;
    --line:      #2c2c2a;
    --axis:      #383835;
    --border:    rgba(255, 255, 255, .10);
    --shadow:    0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.45);
    --series-1:  #3987e5;
    --series-2:  #d95926;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page:      #0d0d0d;
  --surface:   #1a1a19;
  --surface-2: #232322;
  --ink:       #ffffff;
  --ink-2:     #c3c2b7;
  --ink-muted: #898781;
  --line:      #2c2c2a;
  --axis:      #383835;
  --border:    rgba(255, 255, 255, .10);
  --shadow:    0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.45);
  --series-1:  #3987e5;
  --series-2:  #d95926;
}

/* ============================================================== base ==== */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--page);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
code {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: .88em;
  background: var(--surface-2);
  padding: .1em .4em;
  border-radius: 5px;
}
.wrap { max-width: 1000px; margin: 0 auto; padding: 0 20px; }
.muted { color: var(--ink-muted); }
.spacer { flex: 1; }
[hidden] { display: none !important; }

/* ============================================================ buttons === */
.btn {
  font: inherit;
  font-weight: 500;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  transition: background .12s, border-color .12s, opacity .12s;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary {
  background: var(--series-1);
  border-color: transparent;
  color: var(--accent-ink);
}
.btn-primary:hover { background: var(--series-1); filter: brightness(1.08); }
.btn-quiet { background: transparent; }
.btn-quiet:hover { background: var(--surface-2); }
.btn-danger { color: var(--critical); border-color: var(--border); background: transparent; }
.btn-danger:hover { background: color-mix(in srgb, var(--critical) 12%, transparent); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.icon-btn {
  font: inherit; font-size: 16px; line-height: 1;
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border-radius: 8px; border: 1px solid transparent;
  background: transparent; color: var(--ink-2); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
:focus-visible { outline: 2px solid var(--series-1); outline-offset: 2px; }

/* ============================================================= fields === */
.field { display: block; margin-bottom: 14px; }
.field-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .03em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin-bottom: 5px;
}
.hint { text-transform: none; letter-spacing: 0; font-weight: 400; }
input[type="email"], input[type="number"], input[type="date"], input[type="password"],
input:not([type]), input[type="search"], input[type="text"], select {
  font: inherit;
  width: 100%;
  padding: 9px 11px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}
input:focus, select:focus { border-color: var(--series-1); outline: none; }
.row { display: flex; gap: 12px; }
.row .grow { flex: 1 1 0; }
.row .narrow { flex: 0 0 108px; }

/* ============================================================== gates === */
.gate { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.gate-card {
  width: min(440px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 32px;
  box-shadow: var(--shadow);
}
.gate-title { font-size: 26px; margin-bottom: 8px; }
.gate-slim { width: min(360px, 100%); }
.gate-slim .gate-title { margin-bottom: 22px; }
#auth-submit { font-size: 17px; line-height: 1.2; }
.gate-text { color: var(--ink-2); margin: 0 0 16px; }
.auth-form { margin-top: 20px; }
.auth-form .btn { width: 100%; }
.hint-line {
  font-size: 12.5px; line-height: 1.45; color: var(--ink-muted);
  margin: -4px 0 14px;
}
.auth-msg { min-height: 20px; margin: 12px 0 0; font-size: 14px; color: var(--ink-2); }
.auth-msg.ok  { color: var(--good); }
.auth-msg.err { color: var(--critical); }

/* ============================================================= topbar === */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--page) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner { display: flex; align-items: center; gap: 16px; height: 58px; }
.brand {
  font-weight: 650; font-size: 17px; letter-spacing: -.02em;
  color: var(--ink); text-decoration: none;
}
.tabs { display: flex; gap: 2px; }
.tab {
  font: inherit; font-weight: 500;
  padding: 6px 12px; border-radius: 8px;
  border: none; background: transparent; color: var(--ink-muted); cursor: pointer;
}
.tab:hover { background: var(--surface-2); color: var(--ink); }
.tab.is-on { background: var(--surface-2); color: var(--ink); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.who {
  font-size: 13px; color: var(--ink-muted); max-width: 190px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.view { padding-top: 22px; padding-bottom: 64px; }

/* ============================================================ toolbar === */
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.search { flex: 1 1 200px; min-width: 160px; }
.select { width: auto; min-width: 132px; }
.seg {
  display: inline-flex; padding: 3px; gap: 2px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 9px;
}
.seg-wide { display: flex; margin-bottom: 16px; }
.seg-wide .seg-btn { flex: 1; padding: 8px; }
.seg-btn {
  font: inherit; font-size: 14px; font-weight: 500;
  padding: 5px 12px; border: none; border-radius: 6px;
  background: transparent; color: var(--ink-muted); cursor: pointer;
}
.seg-btn:hover { color: var(--ink); }
.seg-btn.is-on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.count { font-size: 13px; color: var(--ink-muted); margin: 0 0 10px; }

/* =============================================================== list === */
.list {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}
.list:empty { display: none; }
.item {
  display: grid;
  grid-template-columns: 30px 1fr auto auto;
  align-items: center;
  gap: 14px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  transition: background .1s;
  text-align: left;
  width: 100%;
  font: inherit;
  color: inherit;
  background: none;
  border-left: none; border-right: none; border-top: none;
}
.item:last-child { border-bottom: none; }
.item:hover { background: var(--surface-2); }
.item-kind { font-size: 17px; line-height: 1; text-align: center; }
.item-main { min-width: 0; }
.item-title { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-sub {
  font-size: 13px; color: var(--ink-muted);
  display: flex; gap: 6px; align-items: center; flex-wrap: wrap;
}
.tag {
  font-size: 11px; font-weight: 500;
  padding: 1px 7px; border-radius: 20px;
  background: var(--surface-2); color: var(--ink-2);
  border: 1px solid var(--border);
}
.pill {
  font-size: 11px; font-weight: 600; letter-spacing: .02em;
  padding: 3px 9px; border-radius: 20px;
  border: 1px solid var(--border);
  color: var(--ink-2); background: var(--surface-2);
  white-space: nowrap;
}
.pill[data-status="finished"] { color: var(--good); border-color: color-mix(in srgb, var(--good) 35%, transparent); }
.pill[data-status="active"] { color: var(--series-1); border-color: color-mix(in srgb, var(--series-1) 35%, transparent); }
.pill[data-status="dropped"] { color: var(--ink-muted); }
.item-score {
  font-variant-numeric: tabular-nums;
  font-weight: 600; font-size: 14px;
  min-width: 46px; text-align: right; color: var(--ink);
}
.item-score .of { color: var(--ink-muted); font-weight: 400; font-size: 12px; }
.item-score.none { color: var(--ink-muted); font-weight: 400; }
.empty {
  text-align: center; padding: 64px 20px; color: var(--ink-muted);
  border: 1px dashed var(--line); border-radius: 12px;
}
.empty strong { display: block; color: var(--ink); font-size: 16px; margin-bottom: 6px; }

/* ============================================================== modal === */
.modal {
  width: min(520px, calc(100vw - 32px));
  padding: 26px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
}
.modal::backdrop { background: rgba(0, 0, 0, .45); }
.modal-title { font-size: 19px; margin-bottom: 18px; }
.modal-actions { display: flex; gap: 8px; align-items: center; margin-top: 22px; }
.rating-row { display: flex; align-items: center; gap: 12px; }
.rating-row input[type="range"] { flex: 1; accent-color: var(--series-1); }
.rating-out { font-variant-numeric: tabular-nums; color: var(--ink); }
.form-error { color: var(--critical); font-size: 14px; margin: 8px 0 0; min-height: 18px; }

/* ============================================================== stats === */
.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}
.tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px;
}
.tile-label {
  font-size: 12px; font-weight: 600; letter-spacing: .03em;
  text-transform: uppercase; color: var(--ink-muted);
}
.tile-value { font-size: 30px; font-weight: 600; letter-spacing: -.02em; margin-top: 4px; }
.tile-note { font-size: 13px; color: var(--ink-muted); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 20px 14px;
  margin-bottom: 18px;
}
.card-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.card-title { font-size: 15px; }
.card-sub { font-size: 13px; color: var(--ink-muted); margin: 4px 0 14px; }
.legend { display: flex; gap: 14px; margin-left: auto; }
.legend-item { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink-2); }
.swatch { width: 10px; height: 10px; border-radius: 3px; }
.chart-scroll { overflow-x: auto; }
.chart { display: block; width: 100%; }
.chart text { font-family: var(--font); }
.tick { fill: var(--ink-muted); font-size: 11px; }
.tick-num { fill: var(--ink-muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.gridline { stroke: var(--line); stroke-width: 1; }
.baseline { stroke: var(--axis); stroke-width: 1; }
.bar { transition: opacity .1s; }
.bar-label { fill: var(--ink-2); font-size: 11px; font-variant-numeric: tabular-nums; }
.hit { fill: transparent; cursor: default; }

.tip {
  position: fixed; z-index: 60;
  pointer-events: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 8px 10px;
  font-size: 13px;
  color: var(--ink);
  white-space: nowrap;
}
.tip-title { font-weight: 600; margin-bottom: 4px; }
.tip-row { display: flex; align-items: center; gap: 8px; }
.tip-key { color: var(--ink-2); }
.tip-val { font-variant-numeric: tabular-nums; font-weight: 600; margin-left: auto; }

details.table-toggle { margin-top: 4px; }
details.table-toggle > summary {
  cursor: pointer; font-size: 13px; color: var(--ink-muted); padding: 4px 0;
}
details.table-toggle > summary:hover { color: var(--ink); }
table.data { border-collapse: collapse; width: 100%; font-size: 13px; margin-top: 8px; }
table.data th, table.data td {
  text-align: left; padding: 5px 10px 5px 0; border-bottom: 1px solid var(--line);
}
table.data th { color: var(--ink-muted); font-weight: 600; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* =========================================================== responsive = */
@media (max-width: 620px) {
  .item { grid-template-columns: 26px 1fr auto; gap: 4px 10px; }
  .item-kind  { grid-column: 1; grid-row: 1; }
  .item-main  { grid-column: 2 / -1; grid-row: 1; }
  .item .pill { grid-column: 2; grid-row: 2; justify-self: start; }
  .item-score { grid-column: 3; grid-row: 2; }
  .row { flex-wrap: wrap; }
  .row .narrow { flex: 1 1 100%; }
  .who { display: none; }
  .search { flex-basis: 100%; order: -1; }
  /* Scaling a 720-wide chart into a phone shrinks its labels to ~4px, so
     hold a legible width and let the card scroll sideways instead. */
  .chart { min-width: 660px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
