:root {
  color-scheme: light;
  --paper: #f6f1e6;
  --paper-2: #fffcf7;
  --paper-3: #eee3cd;
  --ink: #221a12;
  --ink-2: #5c4d3d;
  --ink-muted: #94836c;
  --accent: #7c2d33;
  --accent-2: #9c3f42;
  --accent-ink: #fdf6ec;
  --gold: #a97423;
  --star-on: #b6862c;
  --star-off: #e3d7bd;
  --border: rgba(34, 26, 18, 0.13);
  --border-soft: rgba(34, 26, 18, 0.07);
  --shadow-sm: 0 1px 2px rgba(34, 26, 18, 0.06);
  --shadow-md: 0 14px 32px -16px rgba(34, 26, 18, 0.28);
  --radius-lg: 22px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --bad: #ab3a3a;

  --mono-1-bg: #f1e0da; --mono-1-fg: #9c4a3c;
  --mono-2-bg: #ece1c9; --mono-2-fg: #93701f;
  --mono-3-bg: #e2e6d9; --mono-3-fg: #5f7a52;
  --mono-4-bg: #e5e1ea; --mono-4-fg: #6b5b8a;
  --mono-5-bg: #dbe6e6; --mono-5-fg: #396d6d;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --paper: #16110c;
    --paper-2: #1f1812;
    --paper-3: #2a2118;
    --ink: #f3ead9;
    --ink-2: #cbb99f;
    --ink-muted: #927f68;
    --accent: #d98188;
    --accent-2: #e39a9f;
    --accent-ink: #2a0e10;
    --gold: #d9ab4e;
    --star-on: #d9ab4e;
    --star-off: #3a3025;
    --border: rgba(243, 234, 217, 0.13);
    --border-soft: rgba(243, 234, 217, 0.07);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
    --shadow-md: 0 16px 36px -16px rgba(0, 0, 0, 0.55);
    --bad: #d97a7a;

    --mono-1-bg: #3a2621; --mono-1-fg: #e0a190;
    --mono-2-bg: #362c1c; --mono-2-fg: #dcbd6c;
    --mono-3-bg: #26302a; --mono-3-fg: #a5c99c;
    --mono-4-bg: #2b2735; --mono-4-fg: #bdaad8;
    --mono-5-bg: #1e2d2d; --mono-5-fg: #92c9c9;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15.5px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
h1, h2, h3 { font-family: "Fraunces", Georgia, "Iowan Old Style", serif; font-weight: 600; margin: 0; }
a { color: var(--accent); }
img { max-width: 100%; display: block; }
button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
svg { display: block; }

.wrap {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 24px 72px;
}

/* Icons */
.icon { flex-shrink: 0; }
.icon-badge {
  width: 44px;
  height: 44px;
  border-radius: 13px;
  background: var(--accent);
  color: var(--accent-ink);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-sm);
}

/* Header */
.site-header {
  position: relative;
  padding: 40px 24px 22px;
  text-align: center;
}
.site-header .brand {
  display: inline-flex;
  align-items: center;
  gap: 14px;
}
.site-header .brand h1 {
  font-size: 30px;
  letter-spacing: -0.01em;
}
.site-header .kicker {
  margin: 6px 0 0;
  font-size: 12.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-muted);
  font-weight: 600;
}
.site-header .quote {
  margin: 22px auto 0;
  max-width: 520px;
  text-align: left;
  border-left: 2px solid var(--accent);
  padding: 2px 0 2px 16px;
  font-family: "Fraunces", Georgia, serif;
  font-style: italic;
  color: var(--ink-2);
  font-size: 15px;
  line-height: 1.5;
}
.site-header .quote cite {
  display: block;
  margin-top: 4px;
  font-style: normal;
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-muted);
}
.top-link {
  position: absolute;
  top: 34px;
  right: 24px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  color: var(--ink-2);
  border: 1px solid var(--border);
  padding: 8px 14px 8px 12px;
  border-radius: 999px;
  background: var(--paper-2);
  box-shadow: var(--shadow-sm);
  transition: border-color 0.15s, color 0.15s, transform 0.15s;
}
.top-link:hover { color: var(--accent); border-color: var(--accent); transform: translateY(-1px); }
@media (max-width: 640px) {
  .site-header { padding-top: 22px; }
  .top-link { position: static; display: flex; width: fit-content; margin: 0 auto 20px; }
  .site-header .brand h1 { font-size: 25px; }
}

/* Cards */
.card {
  background: var(--paper-2);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 22px 24px;
}

/* Hero: currently reading */
.hero-grid {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 16px;
  margin-top: 28px;
}
@media (max-width: 700px) {
  .hero-grid { grid-template-columns: 1fr; }
}
.reading-card { display: flex; gap: 18px; align-items: center; }
.cover {
  width: 78px;
  height: 112px;
  border-radius: 8px;
  flex-shrink: 0;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.reading-card .label {
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 11px;
  color: var(--accent);
  font-weight: 700;
}
.reading-card h3 { font-size: 19px; margin-top: 5px; line-height: 1.25; }
.reading-card .author { color: var(--ink-2); font-size: 13.5px; margin-top: 2px; }
.progress-track {
  margin-top: 12px;
  height: 7px;
  border-radius: 999px;
  background: var(--paper-3);
  overflow: hidden;
  box-shadow: inset 0 1px 1px rgba(0,0,0,0.06);
}
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); border-radius: 999px; transition: width 0.4s ease; }
.progress-label { margin-top: 7px; font-size: 12px; color: var(--ink-muted); font-variant-numeric: tabular-nums; }

.side-cards { display: flex; flex-direction: column; gap: 16px; }
.mini-card .label {
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 11px;
  color: var(--ink-muted);
  font-weight: 700;
}
.mini-card .value { margin-top: 8px; font-size: 15px; font-family: "Fraunces", Georgia, serif; }

.author-highlight { margin-top: 16px; text-align: center; }
.author-highlight .value { font-size: 20px; }
.author-highlight .value .sub { display: block; margin-top: 4px; font-size: 12.5px; font-family: "Inter", sans-serif; color: var(--ink-muted); }

/* Stats */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-top: 16px;
}
@media (max-width: 700px) { .stats-grid { grid-template-columns: repeat(2, 1fr); } }
.stat-tile { text-align: center; padding: 20px 10px; }
.stat-tile .num { font-family: "Fraunces", Georgia, serif; font-size: 28px; font-weight: 600; font-variant-numeric: tabular-nums; color: var(--ink); }
.stat-tile .lbl { font-size: 11.5px; color: var(--ink-muted); margin-top: 4px; text-transform: uppercase; letter-spacing: 0.08em; }

/* Year tabs */
.year-tabs {
  display: flex;
  gap: 8px;
  margin: 36px 0 8px;
  flex-wrap: wrap;
}
.year-tab {
  border: 1px solid var(--border);
  background: var(--paper-2);
  padding: 7px 18px;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13.5px;
  color: var(--ink-2);
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  font-variant-numeric: tabular-nums;
}
.year-tab:hover { border-color: var(--accent); color: var(--accent); }
.year-tab.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.section-title {
  font-size: 21px;
  margin: 34px 0 16px;
  display: flex;
  align-items: baseline;
  gap: 12px;
}
.section-title .count { font-size: 13px; color: var(--ink-muted); font-weight: 400; font-family: "Inter", sans-serif; font-variant-numeric: tabular-nums; }
.section-title .rule { flex: 1; height: 1px; background: var(--border); }

/* Monogram cover tiles */
.mono-tile {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
}
.mono-tile .mono-letter { font-family: "Fraunces", Georgia, serif; font-weight: 600; font-size: 1.9em; }
.mono-1 { background: var(--mono-1-bg); color: var(--mono-1-fg); }
.mono-2 { background: var(--mono-2-bg); color: var(--mono-2-fg); }
.mono-3 { background: var(--mono-3-bg); color: var(--mono-3-fg); }
.mono-4 { background: var(--mono-4-bg); color: var(--mono-4-fg); }
.mono-5 { background: var(--mono-5-bg); color: var(--mono-5-fg); }

/* Book grid */
.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(152px, 1fr));
  gap: 18px;
}
.book-card {
  background: var(--paper-2);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}
.book-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }
.book-card .cover-wrap {
  aspect-ratio: 2 / 3;
  background: var(--paper-3);
}
.book-card .cover-wrap img { width: 100%; height: 100%; object-fit: cover; }
.book-card .info { padding: 12px 13px 14px; flex: 1; display: flex; flex-direction: column; gap: 5px; }
.book-card .title { font-family: "Fraunces", Georgia, serif; font-weight: 600; font-size: 14.5px; line-height: 1.3; }
.book-card .author { font-size: 12.5px; color: var(--ink-2); }
.book-card .meta-row {
  margin-top: auto;
  padding-top: 6px;
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  font-size: 11px;
}
.tag {
  background: var(--paper-3);
  color: var(--ink-2);
  border-radius: 999px;
  padding: 3px 9px;
  letter-spacing: 0.02em;
}

/* Stars */
.star-row { display: inline-flex; gap: 2px; }
.star-ico { width: 14px; height: 14px; color: var(--star-off); }
.star-ico.on { color: var(--star-on); }
.mini-card .star-row .star-ico { width: 15px; height: 15px; }

/* Simple lists (abandoned, want to read, wishlist) */
.simple-list { display: flex; flex-direction: column; gap: 8px; }
.simple-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  background: var(--paper-2);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  align-items: center;
}
.simple-row .title { font-family: "Fraunces", Georgia, serif; font-weight: 600; font-size: 14.5px; }
.simple-row .author { color: var(--ink-2); font-size: 13px; }
.simple-row .when { color: var(--ink-muted); font-size: 12.5px; white-space: nowrap; font-variant-numeric: tabular-nums; }

.empty-state {
  color: var(--ink-muted);
  font-size: 13.5px;
  padding: 22px;
  text-align: center;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
}

/* Charts */
.charts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 36px;
}
@media (max-width: 700px) { .charts-grid { grid-template-columns: 1fr; } }
.viz-root {
  color-scheme: light;
  --v-surface:   #fcfcfb;
  --v-text:      #0b0b0b;
  --v-text-2:    #52514e;
  --v-muted:     #898781;
  --v-grid:      #e1e0d9;
  --v-baseline:  #c3c2b7;
  --v-bar:       #2a78d6;
}
@media (prefers-color-scheme: dark) {
  .viz-root {
    color-scheme: dark;
    --v-surface:  #1a1a19;
    --v-text:     #ffffff;
    --v-text-2:   #c3c2b7;
    --v-muted:    #898781;
    --v-grid:     #2c2c2a;
    --v-baseline: #383835;
    --v-bar:      #3987e5;
  }
}
.viz-root {
  background: var(--v-surface);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-soft);
  padding: 16px 18px 10px;
}
.viz-root h4 { font-size: 12px; color: var(--v-text-2); font-weight: 600; margin-bottom: 10px; font-family: "Inter", sans-serif; text-transform: uppercase; letter-spacing: 0.08em; }
.viz-root svg text { fill: var(--v-muted); font-size: 10px; font-family: "Inter", sans-serif; }
.viz-root .bar { fill: var(--v-bar); transition: opacity 0.15s; }
.viz-root .bar:hover { opacity: 0.8; }
.viz-root .axis-line { stroke: var(--v-baseline); stroke-width: 1; }
.viz-tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--v-text);
  color: var(--v-surface);
  font-size: 11px;
  padding: 4px 8px;
  border-radius: 6px;
  transform: translate(-50%, -130%);
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.1s;
  font-family: "Inter", sans-serif;
}
.viz-wrap { position: relative; }

footer.site-footer {
  text-align: center;
  color: var(--ink-muted);
  font-size: 13.5px;
  font-family: "Fraunces", Georgia, serif;
  font-style: italic;
  margin-top: 56px;
  padding-top: 28px;
  border-top: 1px solid var(--border-soft);
}

/* ---- Admin page ---- */
.admin-wrap { max-width: 720px; }
.token-panel { margin-top: 28px; }
.token-panel h3 { font-size: 19px; margin-bottom: 10px; }
.token-panel p { color: var(--ink-2); font-size: 14px; }
.token-panel ol { color: var(--ink-2); font-size: 14px; padding-left: 20px; }
.token-panel li { margin-bottom: 4px; }
.token-panel code { background: var(--paper-3); padding: 1px 6px; border-radius: 4px; font-size: 0.92em; }
.field { margin-bottom: 15px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; margin-bottom: 6px; color: var(--ink-2); text-transform: uppercase; letter-spacing: 0.04em; }
.field input[type="text"],
.field input[type="number"],
.field input[type="date"],
.field input[type="password"],
.field select,
.field textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--paper);
  color: var(--ink);
  transition: border-color 0.15s;
}
.field input:focus, .field textarea:focus { outline: none; border-color: var(--accent); }
.field textarea { min-height: 70px; resize: vertical; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.checkbox-row { display: flex; align-items: center; gap: 8px; }
.checkbox-row input { width: 16px; height: 16px; accent-color: var(--accent); }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  padding: 11px 20px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.btn:hover { background: var(--accent-2); }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.secondary {
  background: transparent;
  color: var(--ink-2);
  border: 1px solid var(--border);
}
.btn.secondary:hover { border-color: var(--accent); color: var(--accent); background: transparent; }
.btn.danger { background: var(--bad); color: #fff; }
.btn.danger:hover { background: var(--bad); opacity: 0.85; }
.btn.small { padding: 6px 14px; font-size: 12px; }

.star-picker { display: inline-flex; gap: 5px; }
.star-picker button { background: none; border: none; padding: 2px; cursor: pointer; line-height: 0; }
.star-picker .star-ico { width: 24px; height: 24px; transition: color 0.1s, transform 0.1s; }
.star-picker button:hover .star-ico { transform: scale(1.12); }

.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin: 26px 0 20px; border-bottom: 1px solid var(--border); }
.tab-btn {
  background: none;
  border: none;
  padding: 9px 15px;
  cursor: pointer;
  color: var(--ink-muted);
  font-weight: 600;
  font-size: 13.5px;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 0.15s, border-color 0.15s;
}
.tab-btn:hover { color: var(--ink-2); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.entry-list { margin-top: 20px; display: flex; flex-direction: column; gap: 8px; }
.entry-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--paper-2);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
}
.entry-row .info { flex: 1; font-size: 13.5px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.entry-row .info .t { font-weight: 600; font-family: "Fraunces", Georgia, serif; }
.entry-row .info .s { color: var(--ink-muted); font-size: 12px; }

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--paper);
  padding: 11px 20px;
  border-radius: 999px;
  font-size: 13.5px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 50;
  box-shadow: var(--shadow-md);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-6px); }
.toast.error { background: var(--bad); color: #fff; }

.field input[type="date"] { color-scheme: light dark; cursor: pointer; }
.field input[type="date"]::-webkit-calendar-picker-indicator { cursor: pointer; opacity: 0.7; }
.field input[type="date"]::-webkit-calendar-picker-indicator:hover { opacity: 1; }

.lookup-row { display: flex; gap: 10px; align-items: flex-end; }
.lookup-row .field { flex: 1; margin-bottom: 0; }
.lookup-row .btn { white-space: nowrap; margin-bottom: 1px; }

.session-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  color: var(--ink-muted);
  margin-bottom: 6px;
}

/* ---- Motion ---- */
.fade-swap { transition: opacity 0.16s ease; }
.fade-swap.fading { opacity: 0; }

@media (prefers-reduced-motion: no-preference) {
  @keyframes fadeSlideUp {
    from { opacity: 0; transform: translateY(14px); }
    to { opacity: 1; transform: translateY(0); }
  }
  @keyframes popIn {
    from { opacity: 0; transform: scale(0.85); }
    to { opacity: 1; transform: scale(1); }
  }
  .reveal { animation: fadeSlideUp 0.6s cubic-bezier(0.16, 1, 0.3, 1) both; }
  .book-card, .simple-row, .entry-row {
    animation: fadeSlideUp 0.45s cubic-bezier(0.16, 1, 0.3, 1) both;
  }
  .tab-panel.active { animation: fadeSlideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1) both; }
  .toast.show { animation: none; }
  .star-picker button.just-set .star-ico { animation: popIn 0.25s cubic-bezier(0.34, 1.56, 0.64, 1) both; }
  .viz-root .bar {
    transform-box: fill-box;
    transform-origin: bottom;
    animation: barGrow 0.5s cubic-bezier(0.16, 1, 0.3, 1) both;
  }
  @keyframes barGrow {
    from { transform: scaleY(0); }
    to { transform: scaleY(1); }
  }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}
