/* ==========================================================
   Kurasa — an eye-comfortable reading palette
   Warm paper tones, soft ink, muted forest green + clay.
   No pure white / pure black, gentle contrast, no harsh blues.
   ========================================================== */
:root, [data-theme="paper"] {
  --paper: #f6f1e6;
  --paper-2: #efe7d6;
  --card: #fcf9f1;
  --ink: #2f2a24;
  --muted: #6e6558;
  --line: #e1d8c4;
  --accent: #3f6b57;
  --accent-ink: #f6f1e6;
  --accent-hover: #345a49;
  --clay: #b5653a;
  --gold: #c58d1c;
  --shadow: 0 6px 22px rgba(70, 52, 24, .10);
  --bs-body-bg: var(--paper);
  --bs-body-color: var(--ink);
  --bs-border-color: var(--line);
  --bs-link-color: var(--accent);
  --bs-link-hover-color: var(--accent-hover);
}
[data-theme="sepia"] {
  --paper: #efe3c8; --paper-2: #e6d7b5; --card: #f5ebd3; --ink: #3b3024; --muted: #75664f; --line: #d8c7a0;
  --accent: #4d6b4f; --accent-hover: #3e5740; --clay: #a85a2f; --shadow: 0 6px 22px rgba(80, 55, 20, .14);
}
[data-theme="night"] {
  --paper: #1d1a16; --paper-2: #25211c; --card: #2a2620; --ink: #e8dfcd; --muted: #a3988a; --line: #3b352c;
  --accent: #8fbfa5; --accent-ink: #17201b; --accent-hover: #a6d1b9; --clay: #e0a07a; --gold: #e0b250; --shadow: 0 6px 22px rgba(0, 0, 0, .35);
}

html { scroll-behavior: smooth; }
body {
  background: var(--paper); color: var(--ink);
  font-family: 'Nunito Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 1.02rem; line-height: 1.6; letter-spacing: .005em;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4, .display-6, .brand-font { font-family: 'Literata', Georgia, 'Times New Roman', serif; letter-spacing: -.005em; color: var(--ink); }
a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { color: var(--accent-hover); }
.text-muted, .form-text { color: var(--muted) !important; }
::selection { background: color-mix(in srgb, var(--accent) 30%, transparent); }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 2px; }

/* Buttons & inputs */
.btn-brand { background: var(--accent); color: var(--accent-ink); border: 1px solid var(--accent); font-weight: 700; border-radius: 12px; }
.btn-brand:hover, .btn-brand:focus { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--accent-ink); }
.btn-outline-brand { color: var(--accent); border: 1.5px solid var(--accent); border-radius: 12px; font-weight: 700; background: transparent; }
.btn-outline-brand:hover { background: var(--accent); color: var(--accent-ink); }
.btn-clay { background: var(--clay); color: #fff8ef; border: 0; border-radius: 12px; font-weight: 700; }
.btn-clay:hover { filter: brightness(.93); color: #fff8ef; }
.btn { border-radius: 12px; }
.btn-icon { border: 0; background: transparent; color: var(--ink); font-size: 1.2rem; border-radius: 50%; width: 42px; height: 42px; display: inline-flex; align-items: center; justify-content: center; }
.btn-icon:hover { background: var(--paper-2); }
.form-control, .form-select { background-color: var(--card); color: var(--ink); border: 1px solid var(--line); border-radius: 12px; }
.form-control:focus, .form-select:focus { background-color: var(--card); color: var(--ink); border-color: var(--accent); box-shadow: 0 0 0 .22rem color-mix(in srgb, var(--accent) 22%, transparent); }
.form-control::placeholder { color: color-mix(in srgb, var(--muted) 75%, transparent); }
.form-check-input:checked { background-color: var(--accent); border-color: var(--accent); }
.form-label { font-weight: 700; font-size: .92rem; }
.alert { border-radius: 14px; border: 1px solid var(--line); }
.dropdown-menu { background: var(--card); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); }
.dropdown-item { color: var(--ink); } .dropdown-item:hover { background: var(--paper-2); color: var(--ink); }
.modal-content { background: var(--card); border: 1px solid var(--line); border-radius: 20px; }
.table { --bs-table-bg: transparent; --bs-table-color: var(--ink); --bs-table-border-color: var(--line); }
.nav-tabs { border-color: var(--line); } .nav-tabs .nav-link { color: var(--muted); border-radius: 12px 12px 0 0; }
.nav-tabs .nav-link.active { background: var(--card); color: var(--ink); border-color: var(--line) var(--line) var(--card); font-weight: 700; }
.pagination .page-link { background: var(--card); color: var(--ink); border-color: var(--line); }
.pagination .active .page-link { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

/* Navbar */
.site-nav { background: color-mix(in srgb, var(--paper) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.site-nav .navbar-brand { font-family: 'Literata', Georgia, serif; font-weight: 700; font-size: 1.4rem; color: var(--accent); }
.site-nav .nav-link { color: var(--ink); font-weight: 600; border-radius: 10px; padding: .5rem .8rem; }
.site-nav .nav-link:hover, .site-nav .nav-link.active { background: var(--paper-2); }
.site-nav .navbar-toggler { border: 0; color: var(--ink); box-shadow: none; padding: .2rem .4rem; }
.brand-mark { color: var(--accent); }
.search-form i.bi-search { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search-form .form-control { padding-left: 2.4rem; border-radius: 999px; }
.badge-dot { position: absolute; top: 4px; right: 2px; min-width: 18px; height: 18px; padding: 0 4px; border-radius: 9px; background: var(--clay); color: #fff8ef; font-size: .7rem; font-weight: 700; display: flex; align-items: center; justify-content: center; }
.suggest { position: absolute; left: 0; right: 0; top: calc(100% + 6px); background: var(--card); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); z-index: 1050; overflow: hidden; }
.suggest a { display: block; padding: .55rem 1rem; color: var(--ink); text-decoration: none; }
.suggest a:hover { background: var(--paper-2); }
.suggest small { color: var(--muted); }

/* Surfaces */
.paper-card { background: var(--card); border: 1px solid var(--line); border-radius: 20px; box-shadow: var(--shadow); }
.site-footer { border-top: 1px solid var(--line); background: var(--paper-2); }

/* Hero */
.hero { background: radial-gradient(1200px 400px at 85% -10%, color-mix(in srgb, var(--clay) 14%, transparent), transparent 60%),
        radial-gradient(900px 400px at 0% 120%, color-mix(in srgb, var(--accent) 16%, transparent), transparent 60%), var(--paper-2);
        border: 1px solid var(--line); border-radius: 28px; padding: clamp(1.5rem, 5vw, 3.5rem); }
.hero h1 { font-size: clamp(1.9rem, 5vw, 3.2rem); font-weight: 700; line-height: 1.12; }
.hero .lead { color: var(--muted); max-width: 40rem; }
.hero-search .form-control { border-radius: 999px 0 0 999px; padding: .9rem 1.3rem; }
.hero-search .btn { border-radius: 0 999px 999px 0; padding-inline: 1.5rem; }
.chip { display: inline-flex; align-items: center; gap: .35rem; padding: .35rem .85rem; border-radius: 999px; background: var(--card); border: 1px solid var(--line); color: var(--ink); text-decoration: none; font-weight: 600; font-size: .9rem; }
.chip:hover, .chip.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.section-title { font-size: 1.45rem; font-weight: 700; display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; }
.section-title a { font-family: 'Nunito Sans', sans-serif; font-size: .95rem; font-weight: 700; }

/* Book cards */
.book-card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; transition: transform .18s ease, box-shadow .18s ease; }
.book-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.cover-wrap { position: relative; aspect-ratio: 2 / 3; background: var(--paper-2); }
.cover-wrap img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cover-wrap .tags { position: absolute; left: 8px; top: 8px; display: flex; flex-direction: column; gap: 4px; align-items: flex-start; }
.tag { font-size: .7rem; font-weight: 800; letter-spacing: .03em; text-transform: uppercase; padding: .2rem .5rem; border-radius: 8px; }
.tag-free { background: var(--accent); color: var(--accent-ink); }
.tag-preview { background: #e9d9a6; color: #5b4a12; }
.tag-offer { background: var(--clay); color: #fff8ef; }
[data-theme="night"] .tag-preview { background: #5a4d22; color: #f1e2ae; }
.bm-btn { position: absolute; right: 8px; top: 8px; width: 36px; height: 36px; border-radius: 50%; border: 0; background: color-mix(in srgb, var(--card) 92%, transparent); color: var(--ink); display: flex; align-items: center; justify-content: center; box-shadow: 0 2px 8px rgba(0,0,0,.15); }
.bm-btn.on { color: var(--clay); }
.book-title { font-size: .98rem; font-weight: 700; line-height: 1.3; margin: 0; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.book-title a { color: var(--ink); text-decoration: none; }
.book-author { color: var(--muted); font-size: .86rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.price { font-weight: 800; font-size: .92rem; } .price-free { color: var(--accent); } .price-old { color: var(--muted); font-size: .8rem; font-weight: 600; }
.stars { color: var(--gold); white-space: nowrap; } .stars-sm { font-size: .78rem; letter-spacing: 1px; }
.stars-lg { font-size: 1.35rem; }

/* Horizontal shelf on mobile */
.shelf { display: flex; gap: .9rem; overflow-x: auto; scroll-snap-type: x mandatory; padding: .25rem .25rem 1rem; margin: 0 -.25rem; }
.shelf > * { flex: 0 0 150px; scroll-snap-align: start; max-width: none; padding: 0; width: auto; }
@media (min-width: 768px) { .shelf > * { flex-basis: 175px; } }
.shelf::-webkit-scrollbar { height: 8px; } .shelf::-webkit-scrollbar-thumb { background: var(--line); border-radius: 8px; }

/* Book page */
.book-hero-cover { border-radius: 14px; box-shadow: 0 14px 34px rgba(60, 42, 16, .25); width: 100%; max-width: 320px; aspect-ratio: 2/3; object-fit: cover; background: var(--paper-2); }
.meta-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .75rem 1.25rem; }
.meta-list dt { font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; margin: 0; }
.meta-list dd { margin: 0; font-weight: 600; }
.rate-widget button { background: none; border: 0; padding: 0 .1rem; font-size: 1.7rem; color: var(--gold); line-height: 1; }
.rate-widget button:hover { transform: scale(1.15); }
.price-big { font-family: 'Literata', serif; font-size: 2rem; font-weight: 700; }
.desc { white-space: pre-line; max-width: 46rem; }

/* Reader */
body.reader-body { overflow: hidden; background: var(--paper-2); }
.reader-bar { background: var(--card); border-bottom: 1px solid var(--line); height: 56px; display: flex; align-items: center; gap: .5rem; padding: 0 .75rem; position: relative; z-index: 20; }
.reader-bar .title { font-family: 'Literata', serif; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; font-size: .98rem; }
.reader-stage { height: calc(100vh - 56px - 62px); height: calc(100dvh - 56px - 62px); display: flex; align-items: center; justify-content: center; position: relative; padding: 8px; }
#flipbook { margin: 0 auto; }
.reader-foot { height: 62px; background: var(--card); border-top: 1px solid var(--line); display: flex; align-items: center; gap: .75rem; padding: 0 .9rem; }
.reader-foot input[type=range] { flex: 1; accent-color: var(--accent); }
.reader-foot .pg { min-width: 84px; text-align: center; font-weight: 700; font-size: .9rem; font-variant-numeric: tabular-nums; }
.stf__parent { margin: 0 auto; }
.rpage { background: #fbf8f0; overflow: hidden; position: relative; }
.rpage canvas { width: 100%; height: 100%; display: block; }
.rpage .pno { position: absolute; bottom: 4px; width: 100%; text-align: center; font-size: 10px; color: #8a7f6c; pointer-events: none; }
.rpage.gutter-l { box-shadow: inset -22px 0 24px -22px rgba(60,40,10,.35); }
.rpage.gutter-r { box-shadow: inset 22px 0 24px -22px rgba(60,40,10,.35); }
.rpage .spin { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #9b907b; }
[data-theme="paper"] .rpage canvas { filter: sepia(.14) brightness(.97) contrast(.97); }
[data-theme="sepia"] .rpage { background: #f2e6c9; } [data-theme="sepia"] .rpage canvas { filter: sepia(.45) brightness(.95) contrast(.95); }
[data-theme="night"] .rpage { background: #1c1915; } [data-theme="night"] .rpage canvas { filter: invert(.9) hue-rotate(180deg) sepia(.25) brightness(.92) contrast(.92); }
.rpage.locked { background: var(--card); display: flex; align-items: center; justify-content: center; text-align: center; padding: 1.5rem; color: var(--ink); }
.read-panel { position: absolute; right: 12px; top: 8px; width: min(340px, calc(100% - 24px)); z-index: 15; }
.read-panel .paper-card { padding: 1rem; }
.reader-hint { position: absolute; bottom: 8px; left: 50%; transform: translateX(-50%); font-size: .8rem; color: var(--muted); pointer-events: none; opacity: .9; }
.reader-nav { position: absolute; top: 50%; transform: translateY(-50%); width: 44px; height: 70px; border: 0; border-radius: 12px; background: color-mix(in srgb, var(--card) 85%, transparent); color: var(--ink); z-index: 10; font-size: 1.4rem; box-shadow: var(--shadow); }
.reader-nav.prev { left: 8px; } .reader-nav.next { right: 8px; }
@media (max-width: 767px) { .reader-nav { display: none; } }

/* Admin */
.admin-wrap { display: flex; min-height: 100vh; }
.admin-side { width: 250px; background: var(--paper-2); border-right: 1px solid var(--line); padding: 1.1rem .9rem; flex-shrink: 0; }
.admin-side .brand { font-family: 'Literata', serif; font-weight: 700; font-size: 1.3rem; color: var(--accent); text-decoration: none; display: flex; gap: .5rem; align-items: center; margin-bottom: 1.2rem; }
.admin-side a.item { display: flex; align-items: center; gap: .65rem; padding: .6rem .8rem; border-radius: 12px; color: var(--ink); text-decoration: none; font-weight: 600; margin-bottom: 2px; }
.admin-side a.item:hover { background: var(--card); }
.admin-side a.item.active { background: var(--accent); color: var(--accent-ink); }
.admin-main { flex: 1; min-width: 0; padding: 1.25rem; }
.admin-top { display: none; }
@media (max-width: 991px) { .admin-side { display: none; } .admin-top { display: flex; align-items: center; justify-content: space-between; padding: .6rem 1rem; background: var(--paper-2); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 30; } .admin-wrap { display: block; } .admin-main { padding: 1rem; } }
.stat-card { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 1.1rem 1.25rem; height: 100%; }
.stat-card .num { font-family: 'Literata', serif; font-size: 1.9rem; font-weight: 700; line-height: 1.1; }
.stat-card .lbl { color: var(--muted); font-size: .85rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; }
.thumb { width: 44px; height: 64px; object-fit: cover; border-radius: 6px; background: var(--paper-2); }
.bar-row { display: flex; align-items: flex-end; gap: 6px; height: 120px; }
.bar-row .b { flex: 1; background: color-mix(in srgb, var(--accent) 70%, transparent); border-radius: 6px 6px 0 0; min-height: 3px; position: relative; }
.bar-row .b:hover { background: var(--accent); }
.status-pill { padding: .15rem .6rem; border-radius: 999px; font-size: .78rem; font-weight: 800; text-transform: capitalize; }
.st-completed, .st-fulfilled { background: #d7e7dc; color: #1f4a35; } .st-pending { background: #f2e4b8; color: #6a4f08; }
.st-failed, .st-declined, .st-cancelled { background: #f1d4cb; color: #7a2e17; }
[data-theme="night"] .st-completed, [data-theme="night"] .st-fulfilled { background: #29443a; color: #bfe3cf; }
[data-theme="night"] .st-pending { background: #4c4020; color: #f0dc9a; }
[data-theme="night"] .st-failed, [data-theme="night"] .st-declined, [data-theme="night"] .st-cancelled { background: #512d24; color: #f2c5b6; }
.medal { display: inline-flex; width: 30px; height: 30px; border-radius: 50%; align-items: center; justify-content: center; font-weight: 800; background: var(--paper-2); }
.medal.m1 { background: #f0d98a; color: #5a4300; } .medal.m2 { background: #d9d9d2; color: #444; } .medal.m3 { background: #e5b99a; color: #5a2d10; }

/* Notifications */
.notif { border-left: 4px solid transparent; }
.notif.unread { border-left-color: var(--clay); background: color-mix(in srgb, var(--clay) 7%, var(--card)); }

/* Misc */
.empty { text-align: center; padding: 3rem 1rem; color: var(--muted); }
.empty i { font-size: 2.6rem; color: var(--line); display: block; margin-bottom: .5rem; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; scroll-behavior: auto !important; } }
@media print { .site-nav, .site-footer { display: none; } }
