/* Maude's Library — all styles. Colours are defined once here. */

:root {
  --bg: #f4efe5;
  --surface: #fbf8f2;
  --line: #e3dbca;
  --line-soft: #ece5d7;
  --ink: #2a2924;
  --muted: #7b7566;
  --pill: #e9e3d4;
  --table-head: #efe8da;

  /* Accent: the big "Total read" card, active buttons, focus rings */
  --accent: #3d5a45;
  --accent-strong: #2f4737;
  --on-accent: #eef0e6;          /* text on the accent colour */
  --total-number: #eef0e6;       /* the big number in the Total card */

  /* Genre chart slices + legend dots: Fiction, Non-fiction, Tool */
  --chart-1: #3d5a45;
  --chart-2: #c8a26a;
  --chart-3: #a8b49a;

  /* Cover placeholder */
  --cover-bg: #e7dfcc;
  --cover-border: #d9cfb8;
  --cover-icon: #a8b49a;

  /* Genre pills: background / text */
  --pill-fiction-bg: #dfe6d9;     --pill-fiction-fg: #2f4737;
  --pill-nonfiction-bg: #efe2c9;  --pill-nonfiction-fg: #7a5a26;
  --pill-tool-bg: #e3e6dc;        --pill-tool-fg: #55624a;
  --pill-fastfood-bg: #ece6dc;    --pill-fastfood-fg: #7b7566;

  --serif: "Newsreader", "Songti TC", "Noto Serif TC", Georgia, serif;
  --sans: "Inter", "PingFang TC", "Noto Sans TC", system-ui, sans-serif;
  --radius: 12px;
}

/* ---------- Colour palettes ----------
   Visitors can shuffle between these with the button in the header
   (app.js sets <html data-palette="...">). "current" = the :root colours
   above. To add a palette: copy a block, change the colours, and add its
   name to PALETTES in config.py. */

/* Lemons: #464f42 olive · #fbde44 lemon · #ede5d1 cream */
:root[data-palette="lemons"] {
  --bg: #ede5d1; --surface: #f8f3e7; --line: #dbd1b6; --line-soft: #e7dfca;
  --ink: #2b2f28; --muted: #6d7164; --pill: #e3dac2; --table-head: #e5dcc5;
  --accent: #464f42; --accent-strong: #353c32; --on-accent: #f3eedf; --total-number: #fbde44;
  --chart-1: #464f42; --chart-2: #fbde44; --chart-3: #b4b49a;
  --cover-bg: #e3dac2; --cover-border: #d3c8ab; --cover-icon: #9ba08d;
  --pill-fiction-bg: #dfe2d6;    --pill-fiction-fg: #464f42;
  --pill-nonfiction-bg: #fcefa5; --pill-nonfiction-fg: #5e5000;
  --pill-tool-bg: #e7e4d3;       --pill-tool-fg: #575e4f;
  --pill-fastfood-bg: #e9e2d1;   --pill-fastfood-fg: #6d7164;
}

/* IDEA: #204e93 blue · #d83e7f pink · #edebdc paper */
:root[data-palette="idea"] {
  --bg: #edebdc; --surface: #f8f7ef; --line: #d9d6c3; --line-soft: #e5e3d3;
  --ink: #1b2233; --muted: #686d77; --pill: #e2e0cf; --table-head: #e3e1d0;
  --accent: #204e93; --accent-strong: #183c72; --on-accent: #eef2fa; --total-number: #ffffff;
  --chart-1: #204e93; --chart-2: #d83e7f; --chart-3: #a9b6cf;
  --cover-bg: #e2e0cf; --cover-border: #d1ceb9; --cover-icon: #9badcb;
  --pill-fiction-bg: #dde5f3;    --pill-fiction-fg: #204e93;
  --pill-nonfiction-bg: #f8dbe8; --pill-nonfiction-fg: #a3265b;
  --pill-tool-bg: #e5e8ee;       --pill-tool-fg: #475367;
  --pill-fastfood-bg: #e8e6d8;   --pill-fastfood-fg: #686d77;
}

/* Autumn: #9f483e rust · #f09c41 amber · #f5e3bf wheat */
:root[data-palette="autumn"] {
  --bg: #f5e7cb; --surface: #fcf5e6; --line: #e7d1a8; --line-soft: #efdfbf;
  --ink: #3a1f1a; --muted: #84655a; --pill: #efdcb8; --table-head: #f0dfbd;
  --accent: #9f483e; --accent-strong: #7e372f; --on-accent: #fbeedd; --total-number: #f5e3bf;
  --chart-1: #9f483e; --chart-2: #f09c41; --chart-3: #e2c898;
  --cover-bg: #f5e3bf; --cover-border: #e6cd9c; --cover-icon: #d3a46d;
  --pill-fiction-bg: #f2dad4;    --pill-fiction-fg: #8a3a31;
  --pill-nonfiction-bg: #fde3c3; --pill-nonfiction-fg: #93501a;
  --pill-tool-bg: #efe1c6;       --pill-tool-fg: #775838;
  --pill-fastfood-bg: #f0e6d4;   --pill-fastfood-fg: #84655a;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
html.modal-open { overflow: hidden; }          /* lock page scroll while the pop-up is open */
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { font-family: var(--serif); font-weight: 400; margin: 0; }
p { margin: 0; }
a { color: inherit; }
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.wrap { max-width: 1200px; margin: 0 auto; padding: 0 24px; }
.eyebrow { font-size: 10.5px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.muted { color: var(--muted); font-size: 13px; }
.empty { padding: 40px 0; text-align: center; color: var(--muted); }
.empty-small { color: var(--muted); font-size: 13px; padding: 12px 0; }

/* ---------- Text truncation ----------
   Every clamped element has a FIXED height (lines × line-height), so short
   and long text take exactly the same space and rows/cards never change size.
   app.js compares scrollHeight/clientHeight to decide whether to show "More". */
.clamp {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: var(--lines);
  line-clamp: var(--lines);
  overflow: hidden;
  line-height: 1.45;
  height: calc(var(--lines) * 1.45em);
  overflow-wrap: anywhere;
}
.clamp-2 { --lines: 2; }
.clamp-4 { --lines: 4; }
/* One line: ellipsis on the same line (detected via scrollWidth) */
.clamp-1 {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.45;
  height: 1.45em;
}

/* ---------- Header ---------- */
.site-header { border-bottom: 1px solid var(--line); }
.header-inner { display: flex; align-items: center; gap: 24px; height: 60px; }
.brand { display: flex; align-items: center; gap: 8px; font: 20px var(--serif); text-decoration: none; }
.brand svg { width: 20px; height: 20px; }
.nav { display: flex; gap: 28px; margin-left: auto; margin-right: auto; font-size: 13px; }
.nav a { text-decoration: none; color: var(--muted); padding: 19px 0; border-bottom: 2px solid transparent; }
.nav a[aria-current="page"] { color: var(--ink); border-color: var(--accent); }
.palette-btn {
  display: flex; align-items: center; gap: 6px; height: 30px; padding: 0 10px 0 8px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--surface);
  color: var(--muted); font-size: 12px; cursor: pointer;
}
.palette-btn:hover { border-color: var(--accent); color: var(--ink); }
.palette-btn svg { width: 15px; height: 15px; }
.palette-dots { display: flex; }
.palette-dots i { width: 9px; height: 9px; border-radius: 50%; margin-left: -3px; border: 1px solid var(--surface); }
.palette-dots i:nth-child(1) { background: var(--chart-1); margin-left: 0; }
.palette-dots i:nth-child(2) { background: var(--chart-2); }
.palette-dots i:nth-child(3) { background: var(--chart-3); }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  background: var(--pill); color: var(--accent); font: 13px var(--serif);
}

/* ---------- Hero ---------- */
.hero { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; padding: 44px 0 28px; }
.hero h1 { font-size: 46px; letter-spacing: -.01em; margin: 6px 0 6px; }
.lede { color: var(--muted); }
.year-picker {
  display: flex; align-items: center; gap: 12px; padding: 6px 6px 6px 14px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px; font-size: 12px; color: var(--muted);
}
.year-picker select, .select select {
  appearance: none; border: 1px solid var(--line); background: var(--bg) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='m3 4.5 3 3 3-3' fill='none' stroke='%237b7566' stroke-width='1.4'/%3E%3C/svg%3E") no-repeat right 10px center / 12px;
  border-radius: 8px; padding: 7px 32px 7px 12px; color: var(--ink); cursor: pointer;
}
.year-picker select { font-weight: 600; min-width: 96px; }

/* ---------- Statistics ---------- */
.stats { display: grid; grid-template-columns: 0.8fr 1.1fr 1.1fr 1.1fr; gap: 16px;
  grid-auto-flow: row dense; }   /* "dense" lets a card fill a gap left by the wide Top 10 */
.year-part { display: contents; }   /* children join the parent grid */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; min-width: 0; }
.card-title { font-size: 18px; margin-bottom: 10px; }
.card-foot { font-size: 11.5px; color: var(--muted); margin-top: 12px; }
.card-total { background: var(--accent); border-color: var(--accent); color: var(--on-accent); display: flex; flex-direction: column; }
.card-label { font-size: 12px; opacity: .85; }
.total-number { font-size: 14px; display: flex; align-items: baseline; gap: 8px; margin: 14px 0 auto; }
.total-number span { font: 64px/1 var(--serif); color: var(--total-number); }
.total-foot { border-top: 1px solid rgba(255,255,255,.18); padding-top: 10px; margin-top: 18px; font-size: 12px; opacity: .9; }

.top-list { list-style: none; margin: 0; padding: 0; }
.top-row { display: grid; grid-template-columns: 14px 26px minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 7px 0; border-top: 1px solid var(--line-soft); }
.top-row:first-child { border-top: 0; }
.top-rank { font: 13px var(--serif); color: var(--muted); }
.top-text { min-width: 0; }
.top-title { font-size: 13px; }
.top-meta { font-size: 11px; color: var(--muted); }
.top-rating { font-size: 12px; font-weight: 500; }

.genre-body { display: flex; align-items: center; gap: 12px; }
.pie {
  --c1: var(--chart-1); --c2: var(--chart-2); --c3: var(--chart-3);
  flex: none; width: 80px; height: 80px; border-radius: 50%;
  background: conic-gradient(var(--c1) 0 var(--a), var(--c2) var(--a) var(--b), var(--c3) var(--b) 100%);
}
.pie[data-empty] { background: var(--line); }
.legend { list-style: none; margin: 0; padding: 0; flex: 1; min-width: 0; font-size: 12px; }
.legend li { display: flex; align-items: center; gap: 6px; padding: 3px 0; white-space: nowrap; }
.legend-pct { margin-left: auto; font-weight: 500; white-space: nowrap; }
.legend-count { font-weight: 400; color: var(--muted); font-size: 11px; }
.dot { width: 8px; height: 8px; border-radius: 50%; }
.dot-1 { background: var(--chart-1); } .dot-2 { background: var(--chart-2); } .dot-3 { background: var(--chart-3); }

/* "All years": the Top 10 card spans two grid columns; its list fills
   two columns top-to-bottom (1–5 left, 6–10 right). */
.card-wide { grid-column: span 2; }
.top-list-columns {
  display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: repeat(5, auto);
  grid-auto-flow: column; column-gap: 28px;
}
.top-list-columns .top-row:nth-child(6) { border-top: 0; }
.top-list-columns .top-row { grid-template-columns: 18px 26px minmax(0, 1fr) auto; }

/* ---------- Covers (real image or placeholder) ---------- */
.cover { flex: none; display: block; border-radius: 3px; object-fit: cover; background: var(--pill); }
.cover-xs { width: 26px; height: 38px; }
.cover-md { width: 72px; height: 106px; }
.cover-lg { width: 110px; height: 162px; }
.cover-empty { display: grid; place-items: center; background: var(--cover-bg); border: 1px solid var(--cover-border); }
.cover-empty svg { width: 55%; height: 55%; fill: var(--cover-icon); }
.cover-xs.cover-empty svg { width: 70%; }

.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11.5px; background: var(--pill); white-space: nowrap; }
.pill-fiction { background: var(--pill-fiction-bg); color: var(--pill-fiction-fg); }
.pill-non-fiction { background: var(--pill-nonfiction-bg); color: var(--pill-nonfiction-fg); }
.pill-tool { background: var(--pill-tool-bg); color: var(--pill-tool-fg); }
.pill-fast-food { background: var(--pill-fastfood-bg); color: var(--pill-fastfood-fg); }

/* ---------- Reading list ---------- */
.library { margin-top: 44px; }
.section-title { font-size: 30px; margin: 4px 0 2px; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: 18px 0 14px; }
.search {
  flex: 1 1 240px; max-width: 340px; display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 0 12px;
}
.search svg { width: 15px; height: 15px; color: var(--muted); flex: none; }
.search input { border: 0; background: none; outline: none; width: 100%; padding: 8px 0; }
.search:focus-within { border-color: var(--accent); }
.select select { background-color: var(--surface); }
.chip {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 7px 14px; font-size: 12.5px; cursor: pointer; color: var(--muted); white-space: nowrap;
}
.chip:hover { border-color: var(--accent); }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.view-toggle { margin-left: auto; display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--surface); }
.view-toggle button { display: flex; align-items: center; gap: 6px; border: 0; background: none; padding: 7px 12px; cursor: pointer; font-size: 12.5px; color: var(--muted); }
.view-toggle button svg { width: 14px; height: 14px; }
.view-toggle button[aria-pressed="true"] { background: var(--pill); color: var(--ink); }

button:focus-visible, select:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* List view — a CSS grid that looks like a table on wide screens */
.book-table { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.table-head, .book-row {
  display: grid;
  grid-template-columns:
    2.2rem minmax(0, 1.5fr) minmax(0, 1.3fr) 4rem minmax(0, 1.1fr) 3.4rem 6.4rem minmax(0, 2.2fr) 7.6rem 3.6rem;
  gap: 14px; align-items: start; padding: 12px 16px;
}
.table-head { background: var(--table-head); font-size: 10.5px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); padding-block: 10px; }
/* Every row has the same 1px top border, so all rows are exactly the same height. */
.book-row { border-top: 1px solid var(--line-soft); font-size: 13px; }
.row-title-wrap { display: flex; gap: 10px; align-items: flex-start; }
.book-row .title { font-family: var(--serif); font-size: 15px; }
.c-isbn { font-variant-numeric: tabular-nums; font-size: 12px; }
.c-num { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 12px; padding-top: 2px; }
.m-label { display: none; }
.more {
  border: 1px solid var(--line); background: var(--bg); border-radius: 6px; padding: 3px 9px;
  font-size: 11.5px; cursor: pointer; color: var(--accent-strong);
}
.more:hover { border-color: var(--accent); }

/* Cards view */
.card-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.book-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.book-card > .eyebrow { margin-top: 8px; }
.bc-head { display: flex; gap: 14px; margin-bottom: 4px; }
.bc-head-text { min-width: 0; flex: 1; }
.bc-title { font-size: 19px; margin-top: 2px; }
.bc-author { color: var(--muted); font-size: 12.5px; margin-top: 4px; }
.bc-meta { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 10px 0 0; padding: 10px 0; border-block: 1px solid var(--line-soft); }
.bc-meta dt, .detail-grid dt { font-size: 10px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.bc-meta dd, .detail-grid dd { margin: 2px 0 0; font-size: 13px; }
.bc-foot { display: flex; justify-content: space-between; align-items: flex-end; margin-top: auto; padding-top: 10px; font-size: 12.5px; }

.list-foot { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-top: 14px; font-size: 12px; color: var(--muted); }

/* ---------- About + footer ---------- */
.about { margin: 64px 0 40px; max-width: 640px; }
.about > p:not(.eyebrow) { color: var(--muted); margin-top: 8px; }
.about-quote { margin: 20px 0 0; padding-left: 16px; border-left: 2px solid var(--accent); }
.about-quote p { font: italic 20px/1.4 var(--serif); color: var(--ink); }
.about-quote footer { margin-top: 6px; font-size: 13px; color: var(--muted); }
.site-footer { border-top: 1px solid var(--line); padding: 22px 0 32px; font-size: 12px; color: var(--muted); }
.footer-inner { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; align-items: baseline; }
.footer-quote { font: italic 18px var(--serif); color: var(--accent); }

/* ---------- "More" pop-up ---------- */
#book-modal {
  padding: 0; border: 0; border-radius: 16px; background: var(--surface); color: var(--ink);
  width: min(640px, calc(100% - 32px)); max-height: 85vh;
  box-shadow: 0 20px 60px rgba(30, 30, 20, .25);
}
#book-modal::backdrop { background: rgba(35, 33, 26, .5); }
.modal-panel { position: relative; display: flex; flex-direction: column; max-height: 85vh; }
.modal-body { overflow-y: auto; padding: 28px; overscroll-behavior: contain; }   /* only the pop-up scrolls */
.modal-close {
  position: absolute; top: 8px; right: 8px; width: 44px; height: 44px; border: 0; border-radius: 50%;
  background: var(--surface); font-size: 26px; line-height: 1; cursor: pointer; color: var(--muted); z-index: 1;
}
.modal-close:hover { background: var(--pill); color: var(--ink); }
.detail-head { display: flex; gap: 20px; margin-bottom: 20px; padding-right: 36px; }
.detail-title { font-size: 26px; line-height: 1.25; margin-top: 2px; overflow-wrap: anywhere; }
.detail-second { color: var(--muted); margin-top: 6px; overflow-wrap: anywhere; }
.detail-author { margin-top: 10px; }
.detail-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin: 0 0 20px; padding: 14px 0; border-block: 1px solid var(--line-soft); }
.detail-summary { margin-top: 4px; white-space: pre-line; overflow-wrap: anywhere; line-height: 1.6; }

/* ---------- Responsive ---------- */
@media (max-width: 1080px) {
  .stats { grid-template-columns: 1fr 1fr; }
  .card-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* Below 960px the list becomes stacked blocks, like the mobile design */
@media (max-width: 960px) {
  .table-head { display: none; }
  .book-row {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    grid-template-areas:
      "title  title  title  title"
      "author author author author"
      "second second second second"
      "rating read   genre  genre"
      "summary summary summary summary"
      "isbn   isbn   isbn   more";
    gap: 8px 12px; padding: 16px;
  }
  .book-row { position: relative; }
  .book-row .c-num { position: absolute; top: 14px; right: 16px; }
  .c-title { grid-area: title; padding-right: 2.5rem; } .c-author { grid-area: author; } .c-second { grid-area: second; }
  .c-rating { grid-area: rating; } .c-read { grid-area: read; } .c-genre { grid-area: genre; }
  .c-summary { grid-area: summary; } .c-isbn { grid-area: isbn; } .c-more { grid-area: more; justify-self: end; align-self: end; }
  .m-label { display: block; font-size: 10px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); margin-bottom: 2px; }
  .c-title .m-label, .c-author .m-label { display: none; }
  .book-row .title { font-size: 18px; }
  .c-author { color: var(--muted); margin-top: -4px; }
}

@media (max-width: 640px) {
  .wrap { padding: 0 16px; }
  .nav { display: none; }
  .header-inner { justify-content: space-between; gap: 10px; }
  .palette-btn { margin-left: auto; }
  .hero { flex-direction: column; align-items: stretch; padding-top: 28px; }
  .hero h1 { font-size: 36px; }
  .year-picker { justify-content: space-between; }
  .stats { grid-template-columns: 1fr; }
  .card-wide { grid-column: 1 / -1; }
  .top-list-columns { grid-template-columns: 1fr; grid-template-rows: none; grid-auto-flow: row; }
  .top-list-columns .top-row:nth-child(6) { border-top: 1px solid var(--line-soft); }
  .card-grid { grid-template-columns: 1fr; }
  .search { max-width: none; flex-basis: 100%; }
  .detail-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .detail-head { flex-direction: column; }

  /* Pop-up becomes (nearly) full-screen on phones */
  #book-modal { width: calc(100% - 16px); max-width: none; max-height: calc(100dvh - 16px); border-radius: 14px; }
  .modal-panel { max-height: calc(100dvh - 16px); }
  .modal-body { padding: 22px 18px 28px; }
}
