:root {
  --ink: #3A4550;
  --ink-soft: #66727D;
  --slate: #5D7F99;
  --slate-dark: #45657D;
  --sage: #8DAE9C;
  --sage-dark: #5E8270;
  --mustard: #E2B24A;
  --rust: #C6643A;
  --cream: #F3E9D6;
  --paper: #EADCC2;
  --paper-deep: #DCCAA9;
  --card: #FAF4E8;
  --line: rgba(58, 69, 80, 0.16);
  --line-strong: rgba(58, 69, 80, 0.32);

  --display: 'Cormorant Garamond', 'Iowan Old Style', Georgia, serif;
  --body: 'EB Garamond', 'Iowan Old Style', Georgia, serif;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tabbar-h: 62px;
  --radius: 10px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--cream);
  color: var(--ink);
  font-family: var(--body);
  font-size: 17px;
  line-height: 1.5;
  overscroll-behavior-y: none;
}
button, input, textarea, select { font: inherit; color: inherit; }
a { color: inherit; }
img { display: block; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.view {
  min-height: 100vh;
  padding-bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 24px);
  max-width: 560px;
  margin: 0 auto;
}
.pad { padding: 0 18px; }

/* ---------- page header ---------- */
.page-head {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 12px;
  padding-top: calc(var(--safe-top) + 28px);
  padding-bottom: 6px;
}
.page-head-text { min-width: 0; }
.page-head .spines { width: 88px; height: 56px; flex: 0 0 88px; margin-bottom: -2px; }
.wave-line { display: block; width: 100%; height: 16px; margin-bottom: 4px; }
.note-card { background: var(--card); border-radius: 14px; padding: 18px 22px 22px; text-align: center; }
.note-card .wave-line { width: 70%; margin: 0 auto 10px; }
.note-card p { font-family: var(--display); font-style: italic; font-size: 23px; line-height: 1.35; margin: 6px 0 0; white-space: pre-wrap; }
.note-saved { margin-bottom: 10px; font-family: var(--display); font-style: italic; font-size: 19px; line-height: 1.4; }
.note-date { font-family: var(--body); font-style: normal; font-size: 13px; color: var(--ink-soft); margin-top: 4px; }
.wave-mini { display: block; width: 64px; height: 12px; margin: 0 auto 8px; }
.page-head.home .page-title { font-style: normal; font-weight: 500; letter-spacing: .08em; line-height: 1; }
.page-head.home .name { display: block; font-size: 38px; }
.page-head.home .small-i { letter-spacing: .02em; margin-right: .04em; }
.page-head.home .shelf-word { display: block; font-size: 17px; letter-spacing: .32em; color: var(--ink-soft); margin-top: 6px; }
.credit { text-align: center; font-size: 13px; color: var(--ink-soft); margin: 40px 0 0; letter-spacing: .02em; }
.page-title {
  font-family: var(--display);
  font-style: italic;
  font-weight: 500;
  font-size: 34px;
  line-height: 1.05;
  margin: 2px 0 0;
  letter-spacing: -0.01em;
}
.page-sub { margin: 4px 0 0; color: var(--ink-soft); font-size: 15px; }
h2.section {
  font-family: var(--display);
  font-style: italic;
  font-weight: 500;
  font-size: 23px;
  margin: 26px 0 10px;
  display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
}
h2.section small { font-family: var(--body); font-style: normal; font-size: 14px; color: var(--ink-soft); }

/* ---------- year switcher + goal ---------- */
.year-row { display: flex; align-items: center; justify-content: space-between; margin-top: 14px; }
.year-switch { display: flex; align-items: center; gap: 4px; }
.year-switch button {
  border: 0; background: none; width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center; cursor: pointer; color: var(--ink);
}
.year-switch button:active { background: var(--paper); }
.year-switch button svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.year-switch .year { font-family: var(--display); font-weight: 600; font-size: 22px; min-width: 56px; text-align: center; }
.goal-text { font-size: 15px; color: var(--ink-soft); text-align: right; }
.goal-text b { color: var(--ink); font-weight: 500; }
.goal-bar { height: 10px; border-radius: 10px; background: var(--paper); overflow: hidden; margin: 10px 0 4px; position: relative; }
.goal-bar > i {
  display: block; height: 100%; border-radius: 10px;
  background: var(--slate-dark);
  transition: width .6s ease;
}
.goal-note { font-size: 14px; color: var(--ink-soft); font-style: italic; }
.link-btn { border: 0; background: none; padding: 0; color: var(--slate-dark); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; font-size: 14px; }

/* ---------- segmented ---------- */
.segmented {
  display: flex; background: var(--paper); border-radius: 999px; padding: 3px; margin: 22px 0 6px;
}
.segmented button {
  flex: 1; border: 0; background: none; border-radius: 999px; padding: 7px 4px; cursor: pointer;
  font-size: 15px; color: var(--ink-soft);
}
.segmented button[aria-pressed="true"] { background: var(--card); color: var(--ink); box-shadow: 0 1px 2px rgba(58,69,80,.15); }
.segmented .count { font-size: 12px; opacity: .7; margin-left: 3px; }

/* ---------- bookshelf ---------- */
.shelf { margin-top: 14px; }
.shelf-row {
  display: flex; align-items: flex-end; gap: 12px;
  padding: 14px 14px 0;
  min-height: 150px;
  position: relative;
  margin-bottom: 26px;
}
.shelf-row::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -12px; height: 12px;
  background: var(--ink); border-radius: 2px;
  box-shadow: 0 6px 0 -2px var(--paper-deep);
}
.book-tile {
  flex: 0 0 calc((100% - 36px) / 4);
  border: 0; padding: 0; background: none; cursor: pointer; position: relative;
  transform-origin: bottom center;
  transition: transform .15s ease;
}
.book-tile:active { transform: translateY(-4px); }
.book-tile .cover { width: 100%; aspect-ratio: 2 / 3; }
.book-tile .stars-mini { position: absolute; left: 4px; bottom: 4px; }
.cover {
  border-radius: 2px 4px 4px 2px; overflow: hidden; background: var(--paper);
  box-shadow: inset 3px 0 0 rgba(0,0,0,.12), 0 2px 4px rgba(58,69,80,.25);
  position: relative;
}
.cover img, .cover svg { width: 100%; height: 100%; object-fit: cover; display: block; }
.badge-dnf {
  position: absolute; top: 6px; right: -4px; background: var(--rust); color: var(--cream);
  font-size: 11px; padding: 1px 6px; border-radius: 3px; letter-spacing: .04em;
}

.empty {
  text-align: center; padding: 34px 20px 10px; color: var(--ink-soft);
}
.empty svg { width: 110px; height: 64px; margin: 0 auto 8px; display: block; }
.empty p { margin: 6px 0 14px; }

/* currently reading */
.reading-list { display: flex; flex-direction: column; gap: 12px; }
.reading-card {
  display: flex; gap: 14px; align-items: center; background: var(--card);
  border-radius: var(--radius); padding: 12px; border: 1px solid var(--line); cursor: pointer;
  text-align: left; width: 100%;
}
.reading-card .cover { width: 54px; flex: 0 0 54px; aspect-ratio: 2/3; }
.reading-card .meta { flex: 1; min-width: 0; }
.reading-card .title { font-weight: 500; line-height: 1.25; }
.reading-card .author { font-size: 14px; color: var(--ink-soft); }
.mini-bar { height: 6px; background: var(--paper); border-radius: 6px; margin-top: 8px; overflow: hidden; }
.mini-bar i { display: block; height: 100%; background: var(--mustard); border-radius: 6px; }
.mini-label { font-size: 13px; color: var(--ink-soft); margin-top: 3px; }

/* list rows (want to read, search results) */
.list { display: flex; flex-direction: column; }
.row {
  display: flex; gap: 14px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line);
  background: none; border-left: 0; border-right: 0; border-top: 0; text-align: left; width: 100%; cursor: pointer;
}
.row .cover { width: 48px; flex: 0 0 48px; aspect-ratio: 2/3; }
.row .meta { flex: 1; min-width: 0; }
.row .title { font-weight: 500; line-height: 1.25; }
.row .sub { font-size: 14px; color: var(--ink-soft); }
.row .chev { width: 16px; height: 16px; fill: none; stroke: var(--ink-soft); stroke-width: 1.8; flex: 0 0 16px; }

/* ---------- forms ---------- */
.search-box { position: relative; margin-top: 14px; }
.search-box input[type="search"] { padding-left: 40px; }
.search-box svg { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; fill: none; stroke: var(--ink-soft); stroke-width: 1.8; }
input[type="text"], input[type="number"], input[type="date"], input[type="search"], textarea, select {
  width: 100%; border: 1px solid var(--line-strong); background: var(--card); border-radius: var(--radius);
  padding: 11px 13px; font-size: 17px; outline: none; -webkit-appearance: none; appearance: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--slate); box-shadow: 0 0 0 3px rgba(93,127,153,.18); }
textarea { min-height: 120px; resize: vertical; line-height: 1.5; }
input[type="date"] { min-height: 46px; }
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%233A4550' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; background-size: 16px; padding-right: 36px;
}
label.field { display: block; margin-top: 16px; }
label.field > span { display: block; font-size: 14px; color: var(--ink-soft); margin-bottom: 5px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.two-col label.field { margin-top: 16px; }
.hint { font-size: 14px; color: var(--ink-soft); margin: 6px 0 0; }
.error { color: var(--rust); font-size: 14px; margin-top: 6px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--ink); background: transparent; color: var(--ink);
  border-radius: 999px; padding: 10px 20px; font-size: 16px; cursor: pointer; text-decoration: none;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--ink); color: var(--cream); }
.btn.ghost { border-color: transparent; color: var(--slate-dark); }
.btn.danger { border-color: var(--rust); color: var(--rust); }
.btn.block { width: 100%; }
.btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.btn-row { display: flex; gap: 10px; margin-top: 22px; }
.btn-row .btn { flex: 1; }

.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip {
  border: 1px solid var(--line-strong); background: var(--card); border-radius: 999px;
  padding: 5px 13px; font-size: 15px; cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--ink); color: var(--cream); border-color: var(--ink); }
.chip.status-want[aria-pressed="true"] { background: var(--sage-dark); border-color: var(--sage-dark); }
.chip.status-reading[aria-pressed="true"] { background: var(--mustard); border-color: var(--mustard); color: #3A2A08; }
.chip.status-read[aria-pressed="true"] { background: var(--slate-dark); border-color: var(--slate-dark); }
.chip.status-dnf[aria-pressed="true"] { background: var(--rust); border-color: var(--rust); }

/* stars */
.stars { display: inline-flex; gap: 2px; touch-action: none; }
.stars button { border: 0; background: none; padding: 2px; cursor: pointer; width: 38px; height: 38px; }
.stars svg { width: 100%; height: 100%; }
.stars.readonly button { cursor: default; width: 22px; height: 22px; padding: 1px; }
.stars-mini { display: inline-flex; gap: 1px; background: rgba(243,233,214,.92); border-radius: 3px; padding: 1px 3px; }
.stars-mini svg { width: 9px; height: 9px; }

/* ---------- book detail ---------- */
.detail-top { position: relative; padding: calc(var(--safe-top) + 10px) 18px 0; }
.back-btn {
  border: 0; background: none; padding: 6px 0; display: inline-flex; align-items: center; gap: 4px;
  color: var(--slate-dark); cursor: pointer; font-size: 16px;
}
.back-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.detail-hero { display: flex; gap: 18px; align-items: flex-end; margin-top: 10px; }
.detail-hero .cover { width: 120px; flex: 0 0 120px; aspect-ratio: 2/3; }
.detail-hero h1 { font-family: var(--display); font-weight: 600; font-size: 28px; line-height: 1.08; margin: 0; }
.detail-hero .author { color: var(--ink-soft); margin-top: 4px; }
.facts { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 16px; font-size: 15px; color: var(--ink-soft); }
.facts span { display: inline-flex; align-items: center; gap: 5px; }
.status-pill { display: inline-block; font-size: 13px; padding: 2px 10px; border-radius: 999px; margin-top: 8px; }
.status-pill.want { background: #DCE8E0; color: #3E5E4E; }
.status-pill.reading { background: #F6E3B6; color: #6A4C10; }
.status-pill.read { background: #D7E2EA; color: #34536A; }
.status-pill.dnf { background: #F2D5C7; color: #8A3F1F; }

.notes-card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; white-space: pre-wrap; line-height: 1.6;
}
.quote {
  border-left: 3px solid var(--sage); padding: 4px 0 4px 14px; margin: 0 0 14px;
  font-family: var(--display); font-style: italic; font-size: 20px; line-height: 1.35;
}
.quote cite { display: block; font-family: var(--body); font-style: normal; font-size: 13px; color: var(--ink-soft); margin-top: 4px; }
.quote-row { display: flex; gap: 8px; align-items: flex-start; }
.quote-row .quote { flex: 1; }
.icon-btn { border: 0; background: none; padding: 6px; cursor: pointer; color: var(--ink-soft); border-radius: 50%; }
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; display: block; }

.progress-edit { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.progress-edit input { width: 100px; }

/* ---------- stats ---------- */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.tile .num { font-family: var(--display); font-weight: 600; font-size: 32px; line-height: 1; }
.tile .lbl { font-size: 14px; color: var(--ink-soft); margin-top: 4px; }
.genre-bars { display: flex; flex-direction: column; gap: 9px; }
.genre-bar .top { display: flex; justify-content: space-between; font-size: 15px; }
.genre-bar .top span:last-child { color: var(--ink-soft); }
.genre-bar .track { height: 9px; border-radius: 9px; background: var(--paper); overflow: hidden; margin-top: 3px; }
.genre-bar .track i { display: block; height: 100%; border-radius: 9px; }
.genre-stack { display: flex; height: 22px; border-radius: 6px; overflow: hidden; margin-bottom: 14px; }
.genre-stack i { display: block; height: 100%; }

.map-wrap { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px; }
.map-wrap svg { width: 100%; height: auto; display: block; }
.map-wrap path.land { fill: var(--paper); stroke: var(--card); stroke-width: .4; }
.map-wrap path.sphere { fill: #E9EEEA; stroke: none; }
.country-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.country-list .chip { cursor: default; font-size: 14px; }
.legend { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink-soft); margin-top: 8px; }
.legend i { display: inline-block; width: 18px; height: 10px; border-radius: 2px; }

.months { display: grid; grid-template-columns: repeat(12, 1fr); gap: 4px; align-items: end; height: 110px; }
.months .m { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 4px; }
.months .m i { display: block; width: 100%; background: var(--slate); border-radius: 3px 3px 0 0; min-height: 2px; }
.months .m i.cur { background: var(--mustard); }
.months .m span { font-size: 11px; color: var(--ink-soft); }
.months .m b { font-size: 11px; font-weight: 500; }
.superlatives { display: flex; flex-direction: column; gap: 8px; }

/* ---------- sheets / modal ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(40, 48, 56, .45); z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .2s ease;
}
.sheet {
  background: var(--cream); width: 100%; max-width: 560px; max-height: 88vh; overflow-y: auto;
  border-radius: 18px 18px 0 0; padding: 10px 18px calc(var(--safe-bottom) + 20px);
  animation: rise .25s ease;
}
.sheet .grabber { width: 40px; height: 5px; border-radius: 5px; background: var(--paper-deep); margin: 0 auto 10px; }
.sheet h3 { font-family: var(--display); font-style: italic; font-weight: 500; font-size: 25px; margin: 4px 0 8px; }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(40px); opacity: .4; } }

/* ---------- tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: flex; justify-content: space-around;
  background: rgba(243, 233, 214, .94);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding: 6px 8px calc(var(--safe-bottom) + 4px);
  height: calc(var(--tabbar-h) + var(--safe-bottom));
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  text-decoration: none; font-size: 12px; color: var(--ink-soft);
}
.tabbar svg { width: 25px; height: 25px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.tabbar a.active { color: var(--ink); }
.tabbar a.active svg { stroke: var(--slate-dark); stroke-width: 1.9; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 14px);
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--cream); padding: 9px 18px; border-radius: 999px; font-size: 15px;
  transition: all .25s ease; z-index: 60; white-space: nowrap;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.spinner { width: 22px; height: 22px; border: 2px solid var(--paper-deep); border-top-color: var(--slate); border-radius: 50%; animation: spin .8s linear infinite; margin: 24px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

.divider { height: 1px; background: var(--line); margin: 26px 0 0; }
.muted { color: var(--ink-soft); }
.small { font-size: 14px; }
.center { text-align: center; }
.mt { margin-top: 16px; }

@media (min-width: 420px) {
  .book-tile { flex-basis: calc((100% - 36px) / 4); }
}
