/* ==========================================================================
   Tibbiy Biokimyo Darsligi — mobil ilova uslubi
   ========================================================================== */

:root{
  --ink:            #16231c;
  --ink-soft:       #3c483f;
  --paper:          #f4f6f3;
  --paper-raised:   #ffffff;
  --line:           #dde3dd;
  --accent:         #2e6f5e;
  --accent-dark:    #1f4d41;
  --accent-tint:    #e4efe9;
  --brick:          #a6432e;
  --brick-tint:     #f6e6e1;
  --shadow:         0 2px 14px rgba(20, 35, 28, .08);
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: Georgia, "Iowan Old Style", "Palatino Linotype", "Times New Roman", serif;
  --radius: 10px;
  --topbar-h: 56px;
  --footer-h: 34px;
}

html.dark{
  --ink:            #eef2ee;
  --ink-soft:       #b7c2b9;
  --paper:          #121814;
  --paper-raised:   #1a221c;
  --line:           #2a352c;
  --accent:         #57b79a;
  --accent-dark:    #7fd0b6;
  --accent-tint:    #1b2b25;
  --brick:          #d98066;
  --brick-tint:     #2c1e1a;
  --shadow:         0 2px 14px rgba(0, 0, 0, .4);
}

*{ box-sizing: border-box; }
html, body{ height: 100%; }
body{
  margin: 0;
  font-family: var(--sans);
  background: var(--paper);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

#app{
  display: flex;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* ---------- Top bar ---------- */
.topbar{
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  background: var(--paper-raised);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 6px;
  z-index: 40;
}
.icon-btn{
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  background: none; border: none;
  color: var(--ink);
  border-radius: 8px;
  flex: none;
  cursor: pointer;
}
.icon-btn:active{ background: var(--accent-tint); }
.icon-btn svg{ width: 22px; height: 22px; }

.topbar-title{
  flex: 1;
  min-width: 0;
  font-family: var(--serif);
  font-size: 15px;
  line-height: 1.25;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 0 4px;
}
.topbar-title small{
  display: block;
  font-family: var(--sans);
  font-size: 10.5px;
  letter-spacing: .02em;
  color: var(--accent);
  font-weight: 600;
}

/* ---------- Sidebar (drawer) ---------- */
.scrim{
  position: fixed; inset: 0;
  background: rgba(10, 16, 12, .45);
  z-index: 45;
  opacity: 0;
  pointer-events: none;
  transition: opacity .22s ease;
}
.scrim.open{ opacity: 1; pointer-events: auto; }

.sidebar{
  position: fixed;
  top: 0; bottom: 0; left: 0;
  width: min(86vw, 340px);
  background: var(--paper-raised);
  border-right: 1px solid var(--line);
  z-index: 50;
  transform: translateX(-100%);
  transition: transform .25s cubic-bezier(.2,.8,.2,1);
  display: flex;
  flex-direction: column;
}
.sidebar.open{ transform: translateX(0); }

.sidebar-head{
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--accent-dark);
  color: #fff;
}
.sidebar-head .book-name{
  font-family: var(--serif);
  font-size: 19px;
  line-height: 1.3;
  margin: 0 0 3px;
}
.sidebar-head .book-sub{
  font-size: 11.5px;
  opacity: .85;
  margin: 0;
}

.sidebar-scroll{
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 6px 0 18px;
}

.toc-chapter{ border-bottom: 1px solid var(--line); }
.toc-chapter-btn{
  width: 100%;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 16px;
  background: none;
  border: none;
  text-align: left;
  font-family: var(--sans);
  color: var(--ink);
  cursor: pointer;
}
.toc-chapter-btn.active{ background: var(--accent-tint); }
.toc-chapter-btn .num{
  flex: none;
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--accent-tint);
  color: var(--accent-dark);
  font-size: 11.5px;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.toc-chapter-btn.active .num{ background: var(--accent); color: #fff; }
.toc-chapter-btn .label{
  flex: 1;
  font-size: 13.5px;
  line-height: 1.35;
  padding-top: 3px;
}
.toc-chapter-btn .chev{
  flex: none;
  width: 18px; height: 18px;
  margin-top: 4px;
  transition: transform .2s ease;
  color: var(--ink-soft);
}
.toc-chapter.expanded .toc-chapter-btn .chev{ transform: rotate(90deg); }

.toc-sections{
  display: none;
  padding: 0 16px 10px 52px;
}
.toc-chapter.expanded .toc-sections{ display: block; }
.toc-sec-link{
  display: block;
  padding: 6px 0;
  font-size: 12.5px;
  color: var(--ink-soft);
  text-decoration: none;
  border-bottom: 1px dashed var(--line);
}
.toc-sec-link.lvl3{ padding-left: 12px; color: var(--ink-soft); font-size: 12px; }
.toc-sec-link:active{ color: var(--accent); }

/* ---------- Main content ---------- */
.main{
  flex: 1;
  min-width: 0;
  padding-top: var(--topbar-h);
  padding-bottom: var(--footer-h);
  height: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

#reader{
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 18px 18px 60px;
  scroll-behavior: smooth;
}

.chapter-eyebrow{
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: .03em;
  color: var(--accent);
  margin: 0 0 6px;
}
.chapter-title{
  font-family: var(--serif);
  font-size: 25px;
  line-height: 1.28;
  margin: 0 0 18px;
  color: var(--ink);
  padding-bottom: 14px;
  border-bottom: 2px solid var(--accent);
}

#reader h2{
  font-family: var(--serif);
  font-size: 19px;
  line-height: 1.35;
  color: var(--accent-dark);
  margin: 30px 0 12px;
  padding-top: 6px;
  scroll-margin-top: 12px;
}
#reader h3{
  font-family: var(--serif);
  font-size: 16px;
  line-height: 1.35;
  color: var(--ink);
  margin: 20px 0 8px;
  scroll-margin-top: 12px;
}
#reader p{
  font-family: var(--serif);
  font-size: 16px;
  line-height: 1.68;
  color: var(--ink);
  margin: 0 0 14px;
  text-align: left;
}
#reader strong{ color: var(--ink); }
#reader ul, #reader ol{
  font-family: var(--serif);
  font-size: 16px;
  line-height: 1.62;
  padding-left: 22px;
  margin: 0 0 14px;
}
#reader li{ margin-bottom: 6px; }
#reader em{ color: var(--ink-soft); }

#reader img{
  max-width: 100%;
  height: auto;
  display: block;
  margin: 16px auto;
  border-radius: 8px;
  border: 1px solid var(--line);
}

#reader table{
  width: 100%;
  border-collapse: collapse;
  margin: 18px 0;
  font-size: 13px;
  display: block;
  overflow-x: auto;
  white-space: nowrap;
  border: 1px solid var(--line);
  border-radius: 8px;
}
#reader table thead{ background: var(--accent-tint); }
#reader th, #reader td{
  border: 1px solid var(--line);
  padding: 8px 10px;
  text-align: left;
  white-space: normal;
  vertical-align: top;
}
#reader th{ color: var(--accent-dark); font-weight: 700; }
#reader tbody tr:nth-child(even){ background: rgba(0,0,0,.015); }

.chapter-attribution-inline{
  margin-top: 40px;
  padding-top: 14px;
  border-top: 1px dashed var(--line);
  font-family: var(--sans);
  font-size: 11px;
  color: var(--ink-soft);
  text-align: center;
}

/* ---------- Chapter nav (prev/next) ---------- */
.chapter-nav{
  display: flex;
  gap: 10px;
  margin-top: 30px;
  padding-top: 16px;
}
.nav-btn{
  flex: 1;
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--paper-raised);
  font-family: var(--sans);
  color: var(--ink);
  cursor: pointer;
  text-align: left;
}
.nav-btn .nav-dir{
  display: block;
  font-size: 10.5px;
  color: var(--accent);
  font-weight: 700;
  margin-bottom: 2px;
}
.nav-btn .nav-label{
  display: block;
  font-size: 12.5px;
  line-height: 1.3;
}
.nav-btn.next{ text-align: right; }
.nav-btn:disabled{ opacity: .35; }

/* ---------- Footer attribution bar (persistent, every screen) ---------- */
.footer-bar{
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: var(--footer-h);
  background: var(--accent-dark);
  color: #eaf3ef;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10.5px;
  letter-spacing: .01em;
  font-family: var(--sans);
  z-index: 30;
  padding: 0 10px;
  text-align: center;
}

/* ---------- Search overlay ---------- */
.search-panel{
  position: fixed;
  inset: 0;
  background: var(--paper);
  z-index: 60;
  display: flex;
  flex-direction: column;
  transform: translateY(-100%);
  transition: transform .22s ease;
}
.search-panel.open{ transform: translateY(0); }
.search-head{
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  background: var(--paper-raised);
}
.search-input{
  flex: 1;
  height: 40px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  padding: 0 12px;
  font-size: 15px;
  font-family: var(--sans);
}
.search-results{
  flex: 1;
  overflow-y: auto;
  padding: 6px 4px 30px;
}
.search-hint{
  padding: 30px 20px;
  text-align: center;
  color: var(--ink-soft);
  font-size: 13px;
}
.search-item{
  display: block;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-decoration: none;
  color: var(--ink);
}
.search-item .sr-chapter{
  font-size: 10.5px;
  color: var(--accent);
  font-weight: 700;
  margin-bottom: 3px;
}
.search-item .sr-title{
  font-size: 14px;
  font-family: var(--serif);
  margin-bottom: 3px;
}
.search-item .sr-snippet{
  font-size: 12px;
  color: var(--ink-soft);
  line-height: 1.4;
}
.search-item mark{
  background: var(--accent-tint);
  color: var(--accent-dark);
  border-radius: 2px;
}

/* ---------- Cover / welcome screen ---------- */
.cover{
  padding: 40px 26px 30px;
  text-align: center;
}
.cover-badge{
  display: inline-block;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--accent-tint);
  color: var(--accent-dark);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .03em;
  margin-bottom: 18px;
}
.cover h1{
  font-family: var(--serif);
  font-size: 28px;
  line-height: 1.25;
  margin: 0 0 10px;
}
.cover p.lead{
  font-family: var(--serif);
  font-size: 15px;
  color: var(--ink-soft);
  line-height: 1.55;
  margin: 0 0 26px;
}
.cover-start{
  display: inline-block;
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 14px 30px;
  border-radius: 999px;
  font-family: var(--sans);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.cover-grid{
  margin-top: 34px;
  text-align: left;
  display: grid;
  gap: 10px;
}
.cover-chip{
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper-raised);
  cursor: pointer;
}
.cover-chip .num{
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--accent-tint);
  color: var(--accent-dark);
  font-weight: 700;
  font-size: 12px;
  display: flex; align-items: center; justify-content: center;
  flex: none;
}
.cover-chip .txt{ font-size: 13px; line-height: 1.35; }
.cover-author{
  margin-top: 30px;
  font-size: 11.5px;
  color: var(--ink-soft);
}

/* ---------- Scrollbar (desktop preview) ---------- */
#reader::-webkit-scrollbar, .sidebar-scroll::-webkit-scrollbar{ width: 6px; }
#reader::-webkit-scrollbar-thumb, .sidebar-scroll::-webkit-scrollbar-thumb{
  background: var(--line); border-radius: 3px;
}

@media (min-width: 860px){
  .sidebar{
    position: relative;
    transform: none !important;
    box-shadow: none;
  }
  .scrim{ display: none; }
  #menu-toggle{ display: none; }
  .main{ border-left: 1px solid var(--line); }
  #reader{ padding-left: 40px; padding-right: 40px; max-width: 760px; margin: 0 auto; width: 100%; }
  .chapter-title{ font-size: 30px; }
}
