/* Reading Life — app styles.
   Palette (from the printed system): deep aubergine #4A2440, muted mauve
   #86647C, brass #C9A227, cream #F4EEE9 / paper #FBF7F1, rule #C9B2C4.
   The brass accent is a CSS variable so a creator edition can override
   it from config (edition.accent) without touching this file. */
:root {
  --plum: #4a2440;
  --plum-dark: #33182c;
  --mauve: #86647c;
  --accent: #c9a227;
  --cream: #f4eee9;
  --paper: #fbf7f1;
  --card: #fffdf9;
  --ink: #2a1e26;
  --grey: #6b5a66;
  --rule: #c9b2c4;
  --danger: #9c2b2e;
  --ok: #3d6b35;
  --serif: Georgia, "Iowan Old Style", "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--cream); color: var(--ink);
  font-family: var(--sans); font-size: 16px; line-height: 1.45;
  padding-bottom: calc(64px + env(safe-area-inset-bottom));
}
h1, h2, h3 { font-family: var(--serif); color: var(--plum); margin: 0 0 .4em; }
h1 { font-size: 1.55rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.02rem; }
a { color: var(--plum); }
button { font-family: inherit; cursor: pointer; }

/* ---------- header ---------- */
#topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--plum-dark); color: var(--paper);
  padding: 10px 14px calc(10px + env(safe-area-inset-top) * 0) 14px;
  padding-top: calc(10px + env(safe-area-inset-top));
}
.brand { display: flex; flex-direction: column; min-width: 0; }
.brand-name { font-family: var(--serif); font-size: 1.25rem; color: #fff; line-height: 1.1; }
.brand-tag { font-size: .78rem; color: var(--rule); }
.brand-edition { font-size: .78rem; color: var(--accent); font-style: italic; }
.top-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.lang-toggle { display: flex; border: 1px solid var(--mauve); border-radius: 999px; overflow: hidden; }
.lang-btn {
  min-height: 44px; min-width: 48px; padding: 0 12px;
  background: transparent; color: var(--rule); border: 0; font-weight: 600;
}
.lang-btn.active { background: var(--accent); color: var(--plum-dark); }
.ghost-btn {
  min-height: 44px; padding: 0 14px; border-radius: 10px;
  border: 1px solid var(--mauve); background: transparent; color: inherit; font-size: .95rem;
}
#topbar .ghost-btn { color: var(--paper); }

/* ---------- layout / views ---------- */
#view { max-width: 880px; margin: 0 auto; padding: 16px 14px 28px; }
.view-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.view-head h1 { margin-bottom: .1em; }
.hero {
  border-radius: 16px; overflow: hidden; margin-bottom: 16px;
  border: 1px solid var(--rule); background: var(--plum-dark);
}
.hero img { display: block; width: 100%; height: 190px; object-fit: cover; }
.hero .hero-cap { padding: 12px 16px; color: var(--paper); }
.hero .hero-cap h1 { color: #fff; margin: 0; }
.hero .hero-cap p { margin: .25em 0 0; color: var(--rule); font-size: .92rem; }
.section-art { width: 100%; height: 130px; object-fit: cover; border-radius: 14px; border: 1px solid var(--rule); margin-bottom: 14px; }
.card {
  background: var(--card); border: 1px solid var(--rule); border-radius: 14px;
  padding: 14px 16px; margin-bottom: 14px;
}
.banner {
  background: #fdf3d8; border: 1px solid var(--accent); color: #5c4a08;
  border-radius: 12px; padding: 10px 14px; margin-bottom: 14px; font-size: .92rem;
}

/* ---------- stats ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
@media (min-width: 640px) { .stat-grid { grid-template-columns: repeat(3, 1fr); } }
.stat {
  background: var(--card); border: 1px solid var(--rule); border-radius: 14px; padding: 12px 14px;
}
.stat .stat-num { font-family: var(--serif); font-size: 1.6rem; color: var(--plum); line-height: 1.1; }
.stat .stat-label { font-size: .82rem; color: var(--grey); }
.bar { height: 12px; background: var(--cream); border: 1px solid var(--rule); border-radius: 999px; overflow: hidden; }
.bar > div { height: 100%; background: var(--accent); width: 0; transition: width .3s; }
.genre-row { display: flex; align-items: center; gap: 10px; margin: 6px 0; }
.genre-row .g-name { width: 110px; flex-shrink: 0; font-size: .92rem; }
.genre-row .bar { flex: 1; }
.genre-row .g-count { width: 28px; text-align: right; font-weight: 600; color: var(--plum); }

/* ---------- lists & items ---------- */
.item {
  background: var(--card); border: 1px solid var(--rule); border-radius: 14px;
  padding: 12px 14px; margin-bottom: 10px;
}
.item .item-title { font-family: var(--serif); font-size: 1.08rem; color: var(--plum); }
.item .item-sub { color: var(--grey); font-size: .9rem; }
.item .item-meta { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 6px; font-size: .88rem; }
.item .item-actions { display: flex; gap: 8px; margin-top: 10px; }
.chip {
  display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .8rem;
  border: 1px solid var(--mauve); color: var(--plum); background: var(--paper);
}
.chip.gold { background: var(--accent); border-color: var(--accent); color: var(--plum-dark); font-weight: 700; }
.chip.red { background: #f9e3e3; border-color: var(--danger); color: var(--danger); font-weight: 700; }
.chip.green { background: #e6f0e2; border-color: var(--ok); color: var(--ok); font-weight: 600; }
.stars { color: var(--accent); letter-spacing: 1px; }
.empty { color: var(--grey); font-style: italic; padding: 12px 2px; }
.small { font-size: .88rem; color: var(--grey); }

/* ---------- buttons & forms ---------- */
.primary-btn {
  min-height: 48px; padding: 0 20px; border-radius: 12px; border: 0;
  background: var(--plum); color: #fff; font-size: 1rem; font-weight: 600;
}
.primary-btn:active { background: var(--plum-dark); }
.mini-btn {
  min-height: 44px; padding: 0 14px; border-radius: 10px; font-size: .92rem;
  border: 1px solid var(--mauve); background: var(--paper); color: var(--plum);
}
.mini-btn.danger { border-color: var(--danger); color: var(--danger); }
.danger-btn {
  min-height: 48px; padding: 0 20px; border-radius: 12px;
  border: 1px solid var(--danger); background: #fff; color: var(--danger); font-weight: 600;
}
input[type="text"], input[type="number"], input[type="date"], input[type="url"],
input[type="search"], select, textarea {
  width: 100%; min-height: 48px; padding: 10px 12px; font-size: 1rem;
  border: 1px solid var(--mauve); border-radius: 10px; background: #fff; color: var(--ink);
  font-family: inherit;
}
textarea { min-height: 84px; resize: vertical; }
label.f { display: block; margin: 12px 0; font-size: .92rem; color: var(--plum); font-weight: 600; }
label.f input, label.f select, label.f textarea { margin-top: 5px; font-weight: 400; }
label.check { display: flex; align-items: center; gap: 10px; min-height: 48px; font-weight: 600; color: var(--plum); }
label.check input { width: 24px; height: 24px; accent-color: var(--plum); }
.search-row { margin-bottom: 12px; }
.form-msg { color: var(--danger); min-height: 1.2em; font-size: .92rem; }

/* ---------- tabs (TBR sub-tabs, bottom nav) ---------- */
.subtabs { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.subtab {
  min-height: 44px; padding: 0 16px; border-radius: 999px;
  border: 1px solid var(--mauve); background: var(--card); color: var(--plum); font-size: .95rem;
}
.subtab.active { background: var(--plum); color: #fff; border-color: var(--plum); }
#tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; background: var(--plum-dark);
  padding-bottom: env(safe-area-inset-bottom);
  box-shadow: 0 -2px 12px rgba(51, 24, 44, .25);
}
#tabbar button {
  flex: 1; min-height: 58px; border: 0; background: transparent; color: var(--rule);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  font-size: .78rem; padding: 6px 2px;
}
#tabbar button .tab-ico { font-size: 1.15rem; line-height: 1; }
#tabbar button.active { color: var(--accent); }

/* ---------- 100-book grid ---------- */
.grid100 { display: grid; grid-template-columns: repeat(10, 1fr); gap: 4px; margin: 10px 0 4px; }
.grid100 .cell {
  aspect-ratio: 1; border-radius: 4px; border: 1px solid var(--rule); background: var(--paper);
  display: flex; align-items: center; justify-content: center; font-size: .62rem; color: var(--grey);
}
.grid100 .cell.on { background: var(--accent); border-color: var(--accent); color: var(--plum-dark); font-weight: 700; }

/* ---------- monthly rows / wrap-ups ---------- */
.month-row {
  display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--cream);
}
.month-row:last-child { border-bottom: 0; }
.month-row .m-name { width: 96px; flex-shrink: 0; font-weight: 600; color: var(--plum); text-transform: capitalize; }
.month-row .m-count { margin-left: auto; font-weight: 700; color: var(--plum); white-space: nowrap; }
.month-row input[type="text"] { flex: 1; min-height: 44px; }
.month-row .m-check { width: 26px; height: 26px; accent-color: var(--plum); flex-shrink: 0; }

/* ---------- more menu ---------- */
.more-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 640px) { .more-grid { grid-template-columns: repeat(3, 1fr); } }
.more-tile {
  min-height: 84px; border-radius: 14px; border: 1px solid var(--rule); background: var(--card);
  color: var(--plum); font-family: var(--serif); font-size: 1.02rem; padding: 12px;
  display: flex; align-items: center; justify-content: center; text-align: center;
}

/* ---------- dialogs, gate, toast, install hint ---------- */
dialog {
  border: 1px solid var(--rule); border-radius: 16px; background: var(--paper);
  max-width: min(560px, calc(100vw - 24px)); width: 100%; max-height: 88vh; overflow: auto;
  padding: 20px;
}
dialog::backdrop { background: rgba(51, 24, 44, .55); }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; }
.form-actions .ghost-btn { color: var(--plum); }
#gate {
  position: fixed; inset: 0; z-index: 60; background: var(--cream);
  display: flex; align-items: flex-start; justify-content: center; overflow: auto; padding: 22px 14px;
}
#gate[hidden] { display: none; }
.gate-card {
  background: var(--card); border: 1px solid var(--rule); border-radius: 18px;
  max-width: 460px; width: 100%; padding: 18px; text-align: left;
}
.gate-art { width: 100%; height: 170px; object-fit: cover; border-radius: 12px; margin-bottom: 12px; }
.gate-card input { margin: 10px 0; }
.gate-card .primary-btn { width: 100%; }
#toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(76px + env(safe-area-inset-bottom));
  background: var(--plum-dark); color: #fff; padding: 10px 18px; border-radius: 999px; z-index: 70;
  font-size: .95rem; box-shadow: 0 4px 16px rgba(0,0,0,.3); max-width: calc(100vw - 32px); text-align: center;
}
#install-hint {
  position: fixed; left: 10px; right: 10px; bottom: calc(70px + env(safe-area-inset-bottom)); z-index: 40;
  background: var(--plum); color: #fff; border-radius: 14px; padding: 12px 14px;
  display: flex; align-items: center; gap: 10px; font-size: .92rem;
}
#install-hint[hidden] { display: none; }
#install-hint .ih-text { flex: 1; }
#install-hint button { min-height: 44px; border-radius: 10px; border: 0; padding: 0 14px; }
#ih-install { background: var(--accent); color: var(--plum-dark); font-weight: 700; }
#ih-close { background: transparent; color: #fff; font-size: 1.3rem; min-width: 44px; }
.file-label { display: inline-block; }
.file-label input[type="file"] { display: none; }
.stack > * { margin-bottom: 10px; }
.series-book { display: flex; gap: 8px; align-items: center; margin: 6px 0; }
.series-book select { width: 128px; flex-shrink: 0; }
.series-book input { flex: 1; }
.series-book .mini-btn { flex-shrink: 0; min-width: 44px; padding: 0 8px; }
