:root{
  --bg: #02120B;
  --bg-top: #05170F;
  --bg-end: #010402;
  --surface: #0D1F16;
  --surface-2: #12291E;
  --fg: #E6F4EF;
  --muted: #8AA69C;
  --subtle: #5C7A6E;
  --border: #1E332B;
  --accent: #00A491;
  --accent-2: #00C2A8;
  --warm: #2FBF8F;
  --danger: #E5534B;
  --accent-gradient: linear-gradient(135deg, #00A491, #00C2A8);
  --accent-alpha-08: rgba(0,164,145,0.08);
  --accent-alpha-12: rgba(0,164,145,0.12);
  --accent-alpha-14: rgba(0,164,145,0.14);
  --accent-alpha-16: oklch(75% 0.155 162 / 0.16);
  --accent-alpha-22: rgba(0,164,145,0.22);
  --accent-alpha-34: rgba(0,164,145,0.34);
  --accent-alpha-48: rgba(0,164,145,0.48);
  --accent-2-alpha-14: rgba(0,194,168,0.14);
  --subtle-alpha-14: rgba(92,122,110,0.14);
  --danger-alpha-12: oklch(66% 0.158 35 / 0.12);
  --danger-alpha-14: oklch(66% 0.158 35 / 0.14);
  --danger-alpha-20: oklch(66% 0.158 35 / 0.2);
  --danger-alpha-30: oklch(66% 0.158 35 / 0.3);
  --header-bg: rgba(2,18,11,0.78);
  --grid-line-strong: rgba(0,164,145,0.055);
  --grid-line-soft: oklch(100% 0 0 / 0.026);
  --grid-wash: rgba(0,164,145,0.07);
  --radius-sm:10px; --radius-md:14px; --radius-lg:18px;
  --font:'Vazirmatn', system-ui, -apple-system, 'Segoe UI', Tahoma, sans-serif;
  --font-mono:'Geist Mono','Vazirmatn', ui-monospace, Menlo, monospace;
  --ease: cubic-bezier(0.2,0.8,0.2,1);
}
*{box-sizing:border-box;}
html,body{height:100%;}
body{
  margin:0; font-family:var(--font); font-size:13.5px; background:linear-gradient(180deg, var(--bg-top), var(--bg) 36rem); color:var(--fg);
  min-height:100dvh; line-height:1.55; padding-bottom:88px; position:relative; overflow-x:hidden;
}
body.no-nav{ padding-bottom:100px; }
body::before{
  content:""; position:fixed; inset:0; z-index:-2; pointer-events:none;
  background-image:
    linear-gradient(var(--grid-line-soft) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line-soft) 1px, transparent 1px),
    linear-gradient(var(--grid-line-strong) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line-strong) 1px, transparent 1px),
    radial-gradient(circle at 50% 0%, var(--grid-wash), transparent 34rem);
  background-size:32px 32px,32px 32px,128px 128px,128px 128px,100% 100%;
  opacity:.9;
}
body::after{
  content:""; position:fixed; inset:0; z-index:-1; pointer-events:none;
  background:linear-gradient(180deg, transparent, var(--bg-end) 72%);
}
::selection{ background:var(--accent-alpha-34); color:oklch(98% 0.014 220); }
a{ color:inherit; text-decoration:none; }
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible{ outline:2px solid var(--accent); outline-offset:3px; }

/* ---------- topbar (shared chrome) ---------- */
header.topbar{
  position:sticky; top:0; z-index:10; background:var(--header-bg); backdrop-filter:blur(18px); -webkit-backdrop-filter:blur(18px);
  border-bottom:1px solid oklch(100% 0 0 / 0.08); padding:16px 16px 12px;
}
header.topbar.simple{ padding:14px 16px; display:flex; align-items:center; gap:12px; }
.topbar-row{ display:flex; align-items:center; justify-content:space-between; margin-bottom:14px; }
.topbar-row h1{ font-size:20px; font-weight:700; margin:0; }
.topbar-row .count{ font-size:13px; color:var(--muted); font-family:var(--font-mono); font-variant-numeric:tabular-nums; }
header.topbar.simple h1{ font-size:20px; margin:0; font-weight:700; }
header.topbar.simple h2{ font-size:15px; margin:0; color:var(--muted); font-weight:500; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }

.back-btn{
  width:38px; height:38px; border-radius:12px; background:var(--surface-2); border:1px solid var(--border);
  display:flex; align-items:center; justify-content:center; flex-shrink:0; transition:border-color .16s var(--ease);
}
.back-btn:hover{ border-color:var(--accent-alpha-34); }
.back-btn svg{ width:19px; height:19px; stroke:var(--fg); }

.search{ position:relative; margin-bottom:12px; }
.search svg{ position:absolute; inset-inline-start:14px; top:50%; transform:translateY(-50%); width:18px; height:18px; stroke:var(--subtle); }
.search input{
  width:100%; background:var(--surface-2); border:1.5px solid var(--border); border-radius:var(--radius-md);
  padding:12px 44px 12px 16px; font-size:15px; color:var(--fg); font-family:inherit; min-height:46px;
  transition:border-color .15s var(--ease), box-shadow .15s var(--ease);
}
.search input::placeholder{ color:var(--subtle); }
.search input:focus{ outline:none; border-color:var(--accent); box-shadow:0 0 0 4px var(--accent-alpha-14); }
.filters{ display:flex; gap:8px; overflow-x:auto; padding-bottom:2px; scrollbar-width:none; }
.filters::-webkit-scrollbar{ display:none; }
.chip{
  flex:0 0 auto; display:flex; align-items:center; gap:6px; padding:8px 14px; border-radius:999px;
  border:1px solid oklch(100% 0 0 / 0.1); background:oklch(100% 0 0 / 0.035); color:var(--muted); font-size:13.5px;
  font-family:inherit; cursor:pointer; min-height:38px; white-space:nowrap; transition:background .16s var(--ease), color .16s var(--ease), transform .16s var(--ease);
}
.chip.active{ background:var(--accent); border-color:transparent; color:var(--bg); font-weight:600; transform:translateY(-1px); }
select.chip{ appearance:none; padding-inline-end:30px; background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23A9C9BC' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E"); background-repeat:no-repeat; background-position:left 10px center; border:none; }

main{ padding:14px 16px 8px; max-width:640px; margin:0 auto; position:relative; z-index:1; }

/* ---------- flash banner ---------- */
.flash-wrap{ max-width:640px; margin:12px auto 0; padding:0 16px; position:relative; z-index:1; }
.flash-banner{ background:var(--accent-alpha-14); color:var(--accent-2); border:1px solid var(--accent-alpha-34); border-radius:var(--radius-sm); padding:12px 16px; font-size:13.5px; text-align:center; }

/* ---------- books list ---------- */
.sort-row{ display:flex; align-items:center; justify-content:space-between; margin:4px 2px 14px; font-size:13px; color:var(--subtle); }
.sort-row span{ font-family:var(--font-mono); font-variant-numeric:tabular-nums; }

.list{ display:flex; flex-direction:column; gap:10px; }
.book-card{
  background:var(--surface); border:1px solid var(--border); border-radius:var(--radius-md);
  padding:14px; display:flex; flex-direction:column; gap:10px; transition:background .18s var(--ease), border-color .18s var(--ease), transform .18s var(--ease);
}
.book-card:hover{ background:var(--surface-2); border-color:var(--accent-alpha-34); transform:translateY(-1px); }
.book-top{ display:flex; justify-content:space-between; gap:12px; align-items:flex-start; }
.book-title-link{ font-size:16.5px; font-weight:700; line-height:1.4; }
.book-title-link:hover{ color:var(--accent); }
.book-meta{ font-size:13px; color:var(--muted); margin-top:4px; }
.badges{ display:flex; gap:6px; flex-wrap:wrap; }
.badge{ display:inline-flex; align-items:center; gap:5px; font-size:11.5px; font-weight:600; padding:4px 9px; border-radius:999px; white-space:nowrap; }
.badge svg{ width:11px; height:11px; }
.badge.status-unread{ background:var(--subtle-alpha-14); color:var(--muted); }
.badge.status-reading{ background:var(--accent-2-alpha-14); color:var(--accent-2); }
.badge.status-read{ background:var(--accent-alpha-14); color:var(--accent); }
.badge.location{ background:var(--surface-2); color:var(--subtle); border:1px solid var(--border); }

.book-bottom{ display:flex; align-items:center; justify-content:space-between; gap:10px; padding-top:10px; border-top:1px solid var(--border); }
.genre-tags{ display:flex; gap:6px; flex-wrap:wrap; }
.genre-tags .tag{ font-size:11px; color:var(--subtle); background:var(--surface-2); padding:3px 8px; border-radius:6px; }
.book-bottom .status-toggle{ display:flex; background:var(--surface-2); border-radius:999px; padding:3px; gap:2px; border:1px solid var(--border); flex-shrink:0; }
.book-bottom .status-toggle button{
  appearance:none; border:none; background:none; width:32px; height:32px; border-radius:999px; display:flex;
  align-items:center; justify-content:center; cursor:pointer; color:var(--subtle);
}
.book-bottom .status-toggle svg{ width:15px; height:15px; stroke:currentColor; }
.book-bottom .status-toggle button.current{ background:var(--surface); color:var(--accent); box-shadow:0 1px 3px oklch(0% 0 0 / .4); }
.book-bottom .status-toggle button.current.st-reading{ color:var(--accent-2); }

.empty-state{ text-align:center; padding:48px 16px; color:var(--subtle); font-size:14px; }

.fab{
  position:fixed; inset-inline-end:20px; bottom:88px; width:56px; height:56px; border-radius:18px;
  background:var(--accent-gradient); color:var(--bg); display:flex; align-items:center; justify-content:center;
  border:1px solid oklch(100% 0 0 / 0.16);
  box-shadow:0 10px 28px -6px var(--accent-alpha-34); z-index:20; transition:transform .18s var(--ease), box-shadow .18s var(--ease);
}
.fab:hover{ transform:translateY(-2px); box-shadow:0 14px 34px -6px var(--accent-alpha-48); }
.fab svg{ width:26px; height:26px; stroke:currentColor; stroke-width:2.2; }

nav.bottomnav{
  position:fixed; bottom:0; inset-inline:0; z-index:20; background:var(--header-bg); backdrop-filter:blur(18px); -webkit-backdrop-filter:blur(18px);
  border-top:1px solid oklch(100% 0 0 / 0.08); display:flex; padding:8px 8px calc(8px + env(safe-area-inset-bottom));
}
nav.bottomnav a{
  flex:1; display:flex; flex-direction:column; align-items:center; gap:4px; padding:6px 4px; border-radius:12px;
  font-size:11px; color:var(--subtle); min-height:48px; justify-content:center; transition:color .16s var(--ease);
  background:none; border:none; font-family:inherit; cursor:pointer;
}
nav.bottomnav a svg{ width:21px; height:21px; stroke:currentColor; stroke-width:1.8; }
nav.bottomnav a.active{ color:var(--accent); font-weight:600; }

/* ---------- book detail ---------- */
.hero{
  background:linear-gradient(160deg, var(--accent-alpha-14), transparent 70%), var(--surface);
  border:1px solid var(--border); border-radius:var(--radius-lg); padding:24px 20px; margin-bottom:18px;
  display:flex; gap:16px; align-items:flex-start;
}
.cover{
  flex-shrink:0; width:72px; height:100px; border-radius:10px;
  background:var(--accent-gradient); border:1px solid oklch(100% 0 0 / 0.16);
  display:flex; align-items:center; justify-content:center;
  box-shadow:0 12px 24px -8px var(--accent-alpha-34);
}
.cover svg{ width:28px; height:28px; stroke:var(--bg); opacity:.9; }
.hero-text{ flex:1; min-width:0; }
.hero-text h1{ margin:0 0 6px; font-size:23px; font-weight:700; line-height:1.4; }
.hero-text .en-title{ font-size:14px; color:var(--subtle); font-style:italic; margin:0 0 10px; font-family:var(--font-mono); }
.hero-text .author-line{ font-size:14.5px; color:var(--muted); margin:0; }
.hero-text .author-line strong{ color:var(--fg); font-weight:600; }

.tags{ display:flex; gap:8px; flex-wrap:wrap; margin:16px 0 20px; }
.tags .tag{ font-size:12.5px; background:oklch(100% 0 0 / 0.035); color:var(--muted); border:1px solid oklch(100% 0 0 / 0.1); padding:5px 12px; border-radius:999px; }

.section-title{ font-size:13px; font-weight:700; color:var(--subtle); text-transform:uppercase; letter-spacing:.04em; margin:0 0 10px; font-family:var(--font-mono); }

.status-row{ margin-bottom:20px; }
.status-row .status-toggle{ display:flex; background:var(--surface); border:1px solid var(--border); border-radius:var(--radius-md); padding:5px; gap:4px; }
.status-row .status-toggle button{
  flex:1; appearance:none; border:none; background:none; font-family:inherit; font-size:13.5px; font-weight:600;
  padding:11px 6px; border-radius:12px; display:flex; align-items:center; justify-content:center; gap:6px;
  color:var(--subtle); cursor:pointer; min-height:44px; transition:background .16s var(--ease), color .16s var(--ease);
}
.status-row .status-toggle svg{ width:16px; height:16px; stroke:currentColor; }
.status-row .status-toggle button.active{ background:var(--accent-2-alpha-14); color:var(--accent-2); }
.status-row .status-toggle button.active.st-read{ background:var(--accent-alpha-14); color:var(--accent); }

.meta-card{ background:var(--surface); border:1px solid var(--border); border-radius:var(--radius-md); margin-bottom:20px; overflow:hidden; }
.meta-row{ display:flex; align-items:center; gap:12px; padding:14px 16px; border-bottom:1px solid var(--border); }
.meta-row:last-child{ border-bottom:none; }
.meta-row .icon{ width:34px; height:34px; border-radius:10px; background:var(--surface-2); display:flex; align-items:center; justify-content:center; flex-shrink:0; }
.meta-row .icon svg{ width:16px; height:16px; stroke:var(--muted); }
.meta-row .label{ font-size:12px; color:var(--subtle); margin:0 0 2px; }
.meta-row .value{ font-size:14.5px; color:var(--fg); font-weight:500; margin:0; }

.notes-card{ background:var(--surface); border:1px solid var(--border); border-radius:var(--radius-md); padding:16px; margin-bottom:24px; }
.notes-card p{ margin:0; font-size:14.5px; color:var(--muted); font-family:var(--font-mono); white-space:pre-wrap; }

.summary-card{ background:var(--surface); border:1px solid var(--border); border-radius:var(--radius-md); padding:16px; margin-bottom:24px; }
.summary-card p{ margin:0; font-size:14.5px; line-height:1.9; color:var(--fg); }

.actions{ display:flex; gap:10px; }
.actions form{ flex:1; display:flex; }
.btn{
  flex:1; min-height:50px; border-radius:999px; font-family:inherit; font-size:15px; font-weight:700;
  display:flex; align-items:center; justify-content:center; gap:8px; cursor:pointer; border:1.5px solid transparent;
  transition:transform .18s var(--ease), box-shadow .18s var(--ease), background .18s var(--ease), border-color .18s var(--ease);
}
.btn svg{ width:17px; height:17px; stroke:currentColor; }
.btn-primary{ background:var(--accent-gradient); color:var(--bg); }
.btn-primary:hover{ transform:translateY(-2px); box-shadow:0 10px 28px -6px var(--accent-alpha-34); }
.btn-danger{ background:var(--danger-alpha-12); color:var(--danger); border-color:var(--danger-alpha-30); }
.btn-danger:hover{ background:var(--danger-alpha-20); }
.btn-ghost{ background:var(--surface-2); color:var(--muted); border-color:var(--border); flex:0 0 110px; }
.btn-ghost:hover{ border-color:var(--accent-alpha-34); }

/* ---------- book form ---------- */
fieldset{ border:none; margin:0 0 22px; padding:0; }
legend.section-title{ font-size:13px; font-weight:700; color:var(--subtle); text-transform:uppercase; letter-spacing:.04em; margin:0 0 12px; padding:0; font-family:var(--font-mono); }

.field{ margin-bottom:16px; }
.field label{ display:block; font-size:13.5px; font-weight:500; color:var(--muted); margin-bottom:7px; }
.field label .req{ color:var(--accent); margin-inline-start:2px; }
.field .hint{ font-size:12px; color:var(--subtle); margin-top:6px; }

input[type="text"], input[type="number"], input[type="password"], select, textarea{
  width:100%; background:var(--surface-2); border:1.5px solid var(--border); border-radius:var(--radius-sm);
  padding:13px 14px; font-size:15px; color:var(--fg); font-family:inherit; min-height:48px;
  transition:border-color .15s var(--ease), box-shadow .15s var(--ease);
}
input::placeholder, textarea::placeholder{ color:var(--subtle); }
input:focus, select:focus, textarea:focus{ outline:none; border-color:var(--accent); box-shadow:0 0 0 4px var(--accent-alpha-14); }
textarea{ min-height:96px; resize:vertical; line-height:1.6; }

select{ appearance:none; background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23A9C9BC' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E"); background-repeat:no-repeat; background-position:left 14px center; }

.field.invalid input{ border-color:var(--danger); box-shadow:0 0 0 4px var(--danger-alpha-14); }
.error-text{ display:flex; align-items:center; gap:6px; font-size:12.5px; color:var(--danger); margin-top:7px; }
.error-text svg{ width:14px; height:14px; stroke:var(--danger); flex-shrink:0; }

.row-2{ display:grid; grid-template-columns:1fr 1fr; gap:12px; }
@media (max-width:420px){ .row-2{ grid-template-columns:1fr; } }

.segmented{ display:flex; background:var(--surface-2); border:1.5px solid var(--border); border-radius:var(--radius-sm); padding:4px; gap:4px; }
.segmented input{ display:none; }
.segmented label{
  flex:1; text-align:center; margin:0; padding:11px 6px; border-radius:8px; font-size:13.5px; font-weight:600;
  color:var(--subtle); cursor:pointer; min-height:44px; display:flex; align-items:center; justify-content:center;
  transition:background .16s var(--ease), color .16s var(--ease);
}
.segmented input:checked + label{ background:var(--surface); color:var(--accent); box-shadow:0 1px 3px oklch(0% 0 0 / .4); }

.sticky-actions{
  position:fixed; bottom:0; inset-inline:0; background:var(--header-bg); backdrop-filter:blur(18px); -webkit-backdrop-filter:blur(18px);
  border-top:1px solid oklch(100% 0 0 / 0.08); padding:12px 16px calc(12px + env(safe-area-inset-bottom));
  display:flex; gap:10px; z-index:20;
}

/* ---------- home ---------- */
.section-grid{ display:grid; grid-template-columns:repeat(2,1fr); gap:10px; }
.section-card{
  background:var(--surface); border:1px solid var(--border); border-radius:var(--radius-md);
  padding:20px 16px; display:flex; flex-direction:column; align-items:flex-start; gap:10px;
  transition:background .18s var(--ease), border-color .18s var(--ease), transform .18s var(--ease);
}
a.section-card:hover{ background:var(--surface-2); border-color:var(--accent-alpha-34); transform:translateY(-1px); }
.section-card.disabled{ opacity:.55; }
.section-icon{ width:40px; height:40px; border-radius:12px; background:var(--surface-2); display:flex; align-items:center; justify-content:center; }
.section-card:not(.disabled) .section-icon{ background:var(--accent-alpha-14); }
.section-icon svg{ width:19px; height:19px; stroke:var(--muted); }
.section-card:not(.disabled) .section-icon svg{ stroke:var(--accent); }
.section-label{ font-size:14.5px; font-weight:700; color:var(--fg); }
.section-sub{ font-size:12px; color:var(--subtle); font-family:var(--font-mono); font-variant-numeric:tabular-nums; }
.badge-soon{ font-family:var(--font); background:var(--subtle-alpha-14); color:var(--subtle); padding:3px 9px; border-radius:999px; font-weight:600; }

/* ---------- stats ---------- */
.hero-total{
  background:linear-gradient(160deg, var(--accent-alpha-16), transparent 70%), var(--surface);
  border:1px solid var(--border); border-radius:var(--radius-lg); padding:26px 22px; margin-bottom:20px;
  display:flex; align-items:center; justify-content:space-between;
}
.hero-total .num{ font-size:40px; font-weight:800; color:var(--accent); line-height:1; font-variant-numeric:tabular-nums; font-family:var(--font-mono); }
.hero-total .label{ font-size:14px; color:var(--muted); margin-top:6px; }
.hero-total .icon{ width:56px; height:56px; border-radius:16px; background:var(--accent-alpha-16); display:flex; align-items:center; justify-content:center; }
.hero-total .icon svg{ width:26px; height:26px; stroke:var(--accent); }

.stats-title{ margin:26px 2px 12px; }
.stats-title:first-of-type{ margin-top:0; }

.status-grid{ display:grid; grid-template-columns:repeat(3,1fr); gap:10px; }
.stat-card{ background:var(--surface); border:1px solid var(--border); border-radius:var(--radius-md); padding:16px 12px; text-align:center; }
.stat-card .num{ font-size:24px; font-weight:800; font-variant-numeric:tabular-nums; margin-bottom:4px; font-family:var(--font-mono); }
.stat-card .lbl{ font-size:12.5px; color:var(--muted); }
.stat-card.unread .num{ color:var(--subtle); }
.stat-card.reading .num{ color:var(--accent-2); }
.stat-card.read .num{ color:var(--accent); }

.loc-grid{ display:grid; grid-template-columns:repeat(3,1fr); gap:10px; }
.loc-card{ background:var(--surface); border:1px solid var(--border); border-radius:var(--radius-md); padding:14px 10px; text-align:center; }
.loc-card .num{ font-size:20px; font-weight:800; font-variant-numeric:tabular-nums; color:var(--fg); font-family:var(--font-mono); }
.loc-card .lbl{ font-size:11.5px; color:var(--subtle); margin-top:3px; }

.bar-list{ background:var(--surface); border:1px solid var(--border); border-radius:var(--radius-md); padding:16px; display:flex; flex-direction:column; gap:14px; }
.bar-row .bar-top{ display:flex; justify-content:space-between; font-size:13.5px; margin-bottom:6px; }
.bar-row .bar-top .name{ color:var(--fg); font-weight:500; }
.bar-row .bar-top .val{ color:var(--muted); font-variant-numeric:tabular-nums; font-family:var(--font-mono); }
.bar-track{ height:8px; border-radius:999px; background:var(--surface-2); overflow:hidden; }
.bar-fill{ height:100%; border-radius:999px; background:var(--accent-gradient); }

.export-row{ display:flex; align-items:center; justify-content:space-between; gap:12px; background:var(--surface); border:1px solid var(--border); border-radius:var(--radius-md); padding:14px 16px; margin-top:26px; }
.export-row p{ margin:0; font-size:13px; color:var(--muted); }
.export-row button{
  appearance:none; border:1.5px solid var(--border); background:var(--surface-2); color:var(--fg); font-family:inherit;
  font-size:13.5px; font-weight:600; padding:10px 18px; border-radius:999px; cursor:pointer; flex-shrink:0;
  transition:border-color .16s var(--ease);
}
.export-row button:hover{ border-color:var(--accent-alpha-34); }

@media (prefers-reduced-motion:no-preference){
  .book-card{ animation:fadein .35s ease both; }
  .card{ animation:rise .4s var(--ease); }
  @keyframes fadein{ from{opacity:0; transform:translateY(8px);} to{opacity:1; transform:none;} }
  @keyframes rise{ from{opacity:0; transform:translateY(14px);} to{opacity:1; transform:none;} }
}
