*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --green: #059669;
  --green-dark: #047857;
  --green-light: #10B981;
  --green-bg: #ECFDF5;
  --orange: #F97316;
  --orange-dark: #EA580C;
  --gray-dark: #1F2937;
  --gray-mid: #6B7280;
  --gray-line: #E5E7EB;
  --gray-light: #F9FAFB;
  --white: #FFFFFF;
  --radius: 16px;
  --shadow: 0 6px 28px rgba(0,0,0,0.10);
  --topbar-h: 56px;
}

html, body { height: 100%; }
body {
  font-family: 'Inter', sans-serif;
  background: var(--gray-light);
  color: var(--gray-dark);
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

/* ===== TOP BAR ===== */
.topbar {
  position: sticky; top: 0; z-index: 30;
  height: var(--topbar-h);
  background: var(--green);
  display: flex; align-items: center; gap: 10px;
  padding: 0 12px;
  box-shadow: 0 2px 10px rgba(5,150,105,0.30);
}
.tb-btn {
  background: transparent; border: none; cursor: pointer;
  color: #fff; font-size: 22px; line-height: 1;
  width: 40px; height: 40px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.tb-btn:active { background: rgba(255,255,255,0.15); }
.tb-logo { width: 30px; height: 30px; border-radius: 8px; object-fit: cover; }
.tb-title {
  flex: 1; color: #fff; font-weight: 800; font-size: 16px; letter-spacing: -0.3px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tb-title span { color: #A7F3D0; font-weight: 700; }

/* ===== SCREENS ===== */
.screen { display: none; }
.screen.active { display: flex; }

/* ===== COVER ===== */
.cover {
  flex-direction: column; align-items: center;
  min-height: calc(100vh - var(--topbar-h));
  padding: 28px 20px 40px;
}
.cover-inner { width: 100%; max-width: 460px; text-align: center; }
.cover-logo {
  width: 86px; height: 86px; border-radius: 22px; object-fit: cover;
  box-shadow: var(--shadow); margin-bottom: 18px;
}
.cover h1 {
  font-size: 30px; font-weight: 800; color: var(--green); line-height: 1.2;
  margin-bottom: 12px; letter-spacing: -0.5px;
}
.cover p {
  font-size: 15px; color: var(--gray-mid); line-height: 1.65; margin-bottom: 24px;
}
.cover-note { font-size: 12.5px; color: var(--gray-mid); margin-top: 26px; margin-bottom: 0; }

/* ===== BUTTONS ===== */
.btn-primary {
  background: var(--orange); color: #fff; border: none; border-radius: 50px;
  padding: 15px 28px; font-size: 17px; font-weight: 700; cursor: pointer;
  width: 100%; font-family: inherit; transition: background .2s, transform .1s;
  box-shadow: 0 6px 18px rgba(249,115,22,0.35);
}
.btn-primary:hover { background: var(--orange-dark); }
.btn-primary:active { transform: scale(.97); }
.btn-ghost {
  margin-top: 12px; background: transparent; color: var(--green);
  border: 2px solid var(--green); border-radius: 50px;
  padding: 12px 24px; font-size: 15px; font-weight: 700; cursor: pointer;
  width: 100%; font-family: inherit; transition: background .2s;
}
.btn-ghost:active { background: var(--green-bg); }

/* ===== COVER SECTION LIST ===== */
.cover-sections { margin-top: 30px; text-align: left; display: grid; gap: 12px; }
.cs-card {
  background: #fff; border: 1px solid var(--gray-line); border-radius: var(--radius);
  padding: 16px; display: flex; align-items: center; gap: 14px; cursor: pointer;
  transition: transform .1s, box-shadow .15s, border-color .15s;
}
.cs-card:hover { box-shadow: var(--shadow); border-color: var(--green-light); }
.cs-card:active { transform: scale(.98); }
.cs-icon {
  flex: none; width: 46px; height: 46px; border-radius: 12px; background: var(--green-bg);
  display: flex; align-items: center; justify-content: center; font-size: 24px;
}
.cs-text { flex: 1; min-width: 0; }
.cs-text b { display: block; font-size: 15.5px; font-weight: 700; color: var(--gray-dark); }
.cs-text small { color: var(--gray-mid); font-size: 12.5px; }
.cs-arrow { color: var(--gray-mid); font-size: 20px; }

/* ===== READER ===== */
.reader { flex-direction: column; height: calc(100vh - var(--topbar-h)); height: calc(100dvh - var(--topbar-h)); }
.reader-label {
  padding: 10px 16px 8px; text-align: center; border-bottom: 1px solid var(--gray-line);
  background: #fff;
}
.rl-section {
  display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: .5px;
  text-transform: uppercase; color: var(--green); background: var(--green-bg);
  padding: 3px 10px; border-radius: 20px; margin-bottom: 5px;
}
.rl-title { display: block; font-size: 17px; font-weight: 800; color: var(--gray-dark); }

.stage {
  position: relative; flex: 1; min-height: 0; background: var(--gray-light);
  display: flex; align-items: center; justify-content: center; overflow: hidden;
  padding: 12px;
}
.page-img {
  max-width: 100%; max-height: 100%; object-fit: contain; cursor: zoom-in;
  border-radius: 10px; box-shadow: var(--shadow); background: #fff;
  opacity: 0; transition: opacity .2s;
}
.page-img.loaded { opacity: 1; }

.stage-spinner {
  position: absolute; width: 38px; height: 38px; border-radius: 50%;
  border: 4px solid var(--green-bg); border-top-color: var(--green);
  animation: spin .8s linear infinite; display: none;
}
.stage-spinner.show { display: block; }
@keyframes spin { to { transform: rotate(360deg); } }

.edge {
  position: absolute; top: 0; bottom: 0; width: 22%; border: none;
  background: transparent; color: rgba(5,150,105,0); font-size: 40px; font-weight: 700;
  cursor: pointer; display: flex; align-items: center; transition: color .15s, background .15s;
}
.edge-prev { left: 0; justify-content: flex-start; padding-left: 6px; }
.edge-next { right: 0; justify-content: flex-end; padding-right: 6px; }
.edge:hover { color: rgba(5,150,105,0.55); background: linear-gradient(90deg, rgba(5,150,105,0.06), transparent); }
.edge-next:hover { background: linear-gradient(270deg, rgba(5,150,105,0.06), transparent); }
.edge:disabled { opacity: 0; pointer-events: none; }

.reader-bar {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px;
  background: #fff; border-top: 1px solid var(--gray-line);
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
}
.rb-btn {
  flex: 1; background: var(--green-bg); color: var(--green-dark); border: none;
  border-radius: 12px; padding: 12px 8px; font-size: 14.5px; font-weight: 700;
  cursor: pointer; font-family: inherit; transition: background .15s, opacity .15s;
}
.rb-btn:hover { background: #D1FAE5; }
.rb-btn:active { transform: scale(.97); }
.rb-btn:disabled { opacity: .4; pointer-events: none; }
.rb-counter { flex: none; font-size: 14px; font-weight: 700; color: var(--gray-mid); min-width: 62px; text-align: center; }

/* ===== DRAWER ===== */
.drawer-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 40;
  opacity: 0; pointer-events: none; transition: opacity .25s;
}
.drawer-overlay.open { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(340px, 86vw); z-index: 50;
  background: #fff; box-shadow: -8px 0 30px rgba(0,0,0,0.18);
  transform: translateX(100%); transition: transform .28s cubic-bezier(.4,0,.2,1);
  display: flex; flex-direction: column;
}
.drawer.open { transform: translateX(0); }
.drawer-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px; background: var(--green); color: #fff;
  font-weight: 800; font-size: 17px; flex: none;
}
.drawer-close {
  background: transparent; border: none; color: #fff; font-size: 20px; cursor: pointer;
  width: 34px; height: 34px; border-radius: 8px;
}
.drawer-close:active { background: rgba(255,255,255,0.15); }
.drawer-body { flex: 1; overflow-y: auto; padding: 8px 0 24px; -webkit-overflow-scrolling: touch; }

.dg-head {
  padding: 14px 18px 6px; font-size: 12px; font-weight: 800; letter-spacing: .6px;
  text-transform: uppercase; color: var(--green); position: sticky; top: 0;
  background: #fff; z-index: 1;
}
.dg-item {
  display: flex; align-items: center; gap: 12px; padding: 11px 18px; cursor: pointer;
  border-left: 3px solid transparent; transition: background .12s;
}
.dg-item:hover { background: var(--gray-light); }
.dg-item.current { background: var(--green-bg); border-left-color: var(--green); }
.dg-num {
  flex: none; width: 30px; height: 30px; border-radius: 8px; background: var(--gray-light);
  display: flex; align-items: center; justify-content: center; font-size: 12.5px;
  font-weight: 700; color: var(--gray-mid);
}
.dg-item.current .dg-num { background: var(--green); color: #fff; }
.dg-txt { flex: 1; min-width: 0; }
.dg-txt b { display: block; font-size: 14.5px; font-weight: 600; color: var(--gray-dark); }
.dg-ar { flex: none; font-size: 20px; color: var(--gray-dark); }

/* ===== LIGHTBOX ===== */
.lightbox {
  position: fixed; inset: 0; z-index: 60; background: rgba(17,24,39,0.96);
  display: none; flex-direction: column;
}
.lightbox.open { display: flex; }
.lb-close {
  position: absolute; top: 12px; right: 12px; z-index: 2;
  width: 44px; height: 44px; border-radius: 50%; border: none; cursor: pointer;
  background: rgba(255,255,255,0.15); color: #fff; font-size: 20px;
}
.lb-scroll { flex: 1; overflow: auto; display: flex; align-items: flex-start; justify-content: center; -webkit-overflow-scrolling: touch; touch-action: pinch-zoom; }
.lb-scroll img { width: 100%; max-width: 900px; height: auto; display: block; }
.lb-hint { text-align: center; color: rgba(255,255,255,0.6); font-size: 12.5px; padding: 10px; flex: none; }

@media (min-width: 700px) {
  .stage { padding: 22px; }
  .page-img { max-width: 640px; }
}
