/* SaFatKhan Portal UI v4 (Flush Grid Alignment + Consistent View Modes + Baseline Polish) */
:root {
  --portal-accent: var(--design-accent, #1f5143);
  --portal-accent-deep: #14362c;
  --portal-gold: #c89b3c;
  --portal-gold-light: #e7c26d;
  --portal-gold-soft: rgba(200, 155, 60, 0.16);
  --portal-surface: var(--paper, #ffffff);
  --portal-surface-alt: #f5f7f4;
  --portal-border: var(--line, #e1e6e0);
  --portal-shadow: 0 4px 16px rgba(17, 34, 28, 0.06);
  --portal-shadow-hover: 0 10px 24px rgba(17, 34, 28, 0.13);
  --portal-radius: 14px;
}

html[data-theme="dark"] {
  --portal-accent: var(--design-accent, #2e7661);
  --portal-accent-deep: #102620;
  --portal-gold: #e0b354;
  --portal-gold-light: #f0ca75;
  --portal-gold-soft: rgba(224, 179, 84, 0.18);
  --portal-surface: #1a211f;
  --portal-surface-alt: #222b28;
  --portal-border: rgba(255, 255, 255, 0.1);
  --portal-shadow: 0 4px 18px rgba(0, 0, 0, 0.3);
  --portal-shadow-hover: 0 10px 26px rgba(0, 0, 0, 0.45);
}

/* =========================================================
   1. UNIFIED EMERALD & GOLD HEADER (HOME & SUB PAGES)
   ========================================================= */
body.portal-site > .top {
  background: linear-gradient(135deg, var(--portal-accent) 0%, var(--portal-accent-deep) 100%) !important;
  color: #f6f9f7 !important;
  border-bottom: 3px solid var(--portal-gold) !important;
  box-shadow: 0 4px 18px rgba(14, 34, 28, 0.18);
}

body.portal-site > .top .top-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: nowrap !important;
  min-height: 64px;
  gap: 12px;
}

body.portal-site > .top .brand {
  color: #ffffff !important;
  font-weight: 800;
  font-size: 1.16rem;
  letter-spacing: -0.01em;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  flex: none;
}

body.portal-site > .top .brand .mark {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(231, 194, 109, 0.45);
  color: var(--portal-gold-light) !important;
  font-size: 1.15rem;
}

body.portal-site > .top [data-appearance-menu-toggle] {
  display: none !important;
}

body.portal-site > .top [data-appearance-menu] {
  margin-inline-start: auto;
  margin-inline-end: 8px;
  display: flex;
  align-items: center;
  gap: 6px 10px !important;
}

body.portal-site > .top .design-public-menu > * {
  border-inline-start: 0 !important;
}

body.portal-site > .top .design-public-menu > details {
  padding-inline: 0 !important;
}

body.portal-site > .top .design-public-menu a,
body.portal-site > .top .design-public-menu summary {
  color: rgba(246, 249, 247, 0.92) !important;
  font-size: 0.92rem;
  font-weight: 600;
  padding: 7px 14px !important;
  border-radius: 999px;
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.16s ease, color 0.16s ease;
}

body.portal-site > .top .design-public-menu a:hover,
body.portal-site > .top .design-public-menu summary:hover {
  background: rgba(255, 255, 255, 0.14);
  color: var(--portal-gold-light) !important;
}

body.portal-site > .top .design-submenu {
  background: var(--portal-surface);
  color: var(--ink);
  border: 1px solid var(--portal-border);
}

body.portal-site > .top .design-submenu a {
  color: inherit !important;
  border-radius: 6px;
}

body.portal-site > .top .design-submenu a:hover {
  background: var(--portal-surface-alt);
  color: var(--portal-accent) !important;
}

body.portal-site > .top #theme {
  background: rgba(255, 255, 255, 0.13) !important;
  color: #ffffff !important;
  border: 1px solid rgba(255, 255, 255, 0.24) !important;
  border-radius: 999px;
  min-width: 38px;
  width: 38px;
  height: 38px;
  padding: 0;
  flex: none;
  display: inline-grid;
  place-items: center;
  transition: background 0.16s ease, border-color 0.16s ease;
}

body.portal-site > .top #theme:hover {
  background: rgba(255, 255, 255, 0.24) !important;
  border-color: var(--portal-gold-light) !important;
}

body.portal-site > .top .design-tagline {
  color: rgba(246, 249, 247, 0.82);
}

@media (max-width: 979px) {
  body.portal-site > .top [data-appearance-menu] {
    display: none !important;
  }
  body.portal-site > .top .brand::after {
    content: "▾";
    font-size: 0.78rem;
    opacity: 0.85;
    margin-inline-start: -3px;
  }
}

/* Left Slide-out Drawer for Mobile & Tablet */
.portal-drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(8, 16, 13, 0.56);
  backdrop-filter: blur(2px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.portal-drawer-backdrop.is-open {
  opacity: 1;
  pointer-events: auto;
}

.portal-drawer {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 100;
  width: min(290px, 82vw);
  background: var(--portal-surface);
  color: var(--ink);
  border-right: 1px solid var(--portal-border);
  box-shadow: 6px 0 28px rgba(0, 0, 0, 0.28);
  transform: translateX(-100%);
  transition: transform 0.24s cubic-bezier(0.22, 1, 0.36, 1);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.portal-drawer.is-open {
  transform: translateX(0);
}

.portal-drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  background: linear-gradient(135deg, var(--portal-accent) 0%, var(--portal-accent-deep) 100%);
  color: #ffffff;
  border-bottom: 2px solid var(--portal-gold);
}

.portal-drawer-head strong {
  font-size: 1.05rem;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.portal-drawer-close {
  background: rgba(255, 255, 255, 0.16);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 8px;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
}

.portal-drawer-nav {
  display: grid;
  gap: 6px;
  padding: 14px;
}

.portal-drawer-nav a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 14px;
  border-radius: 10px;
  background: var(--portal-surface-alt);
  border: 1px solid var(--portal-border);
  color: inherit;
  text-decoration: none;
  font-weight: 600;
  font-size: 0.95rem;
}

.portal-drawer-nav a:hover,
.portal-drawer-nav a[aria-current="page"] {
  border-color: var(--portal-accent);
  background: color-mix(in srgb, var(--portal-accent) 10%, var(--portal-surface-alt));
  color: var(--portal-accent);
}

html[data-theme="dark"] .portal-drawer-nav a:hover,
html[data-theme="dark"] .portal-drawer-nav a[aria-current="page"] {
  color: var(--portal-gold-light);
}

/* =========================================================
   2. ICON VIEW SWITCH (PIXEL-ALIGNED HEIGHT WITH PILLS)
   ========================================================= */
.icon-view-switch {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  height: 34px;
  padding: 2px;
  border-radius: 9px;
  background: var(--portal-surface-alt);
  border: 1px solid var(--portal-border);
}

.icon-view-switch button {
  width: 30px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  opacity: 0.68;
  display: inline-grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, opacity 0.15s ease;
}

.icon-view-switch button:hover {
  opacity: 1;
}

.icon-view-switch button[aria-pressed="true"] {
  background: var(--portal-accent);
  color: #ffffff;
  opacity: 1;
}

.icon-view-switch button:focus-visible {
  outline: 2px solid var(--portal-gold);
  outline-offset: 1px;
}

/* =========================================================
   3. MAIN PORTAL GRID CONTAINER (HOME PAGE — FLUSH TOP ALIGNMENT)
   ========================================================= */
body[data-design-home="true"] #shelf.portal-active {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 20px;
  align-items: start;
  padding-top: 20px;
  padding-bottom: 44px;
}

/* Prevent legacy margins from shifting grid items vertically */
#shelf.portal-active > section,
#shelf.portal-active > aside {
  margin: 0 !important;
}

/* Hide visually-hidden h1 from occupying a phantom grid row */
#shelf.portal-active > h1.visually-hidden,
#shelf.portal-active > #home-section-library[hidden],
#shelf.portal-active > #uploaded-sections {
  display: none !important;
}

@media (max-width: 979px) {
  #shelf.portal-active > #portal-sidebar {
    order: 99;
  }
}

@media (min-width: 980px) {
  html:not([data-home-template="stacked"]) body[data-design-home="true"] #shelf.portal-active {
    grid-template-columns: repeat(12, minmax(0, 1fr));
    grid-auto-flow: dense;
    gap: 20px;
  }

  html:not([data-home-template="stacked"]) #shelf.portal-active > * {
    grid-column: 1 / -1;
  }

  /* Row 1: 60/40 Split Hero + Continue Reading */
  html:not([data-home-template="stacked"]) #shelf.portal-active > [data-home-section="hero"] {
    grid-column: 1 / 8;
  }

  html:not([data-home-template="stacked"]) #shelf.portal-active:has(> [data-home-section="continue"][hidden]) > [data-home-section="hero"] {
    grid-column: 1 / -1;
  }

  html:not([data-home-template="stacked"]) #shelf.portal-active > [data-home-section="continue"] {
    grid-column: 8 / 13;
    height: 100%;
    display: flex;
    flex-direction: column;
  }

  html:not([data-home-template="stacked"]) #shelf.portal-active:has(> [data-home-section="hero"][hidden]) > [data-home-section="continue"] {
    grid-column: 1 / -1;
  }

  /* Row 2: Trending Strip (Full Width) */
  html:not([data-home-template="stacked"]) #shelf.portal-active > #portal-trending {
    grid-column: 1 / -1;
  }

  /* Row 3+: 70/30 Split Main Column (Recent + Section Shelves) & Sticky Sidebar (Flush Top!) */
  html:not([data-home-template="stacked"]) #shelf.portal-active > [data-home-section="recent"],
  html:not([data-home-template="stacked"]) #shelf.portal-active > [data-section-teaser] {
    grid-column: 1 / 9;
  }

  html:not([data-home-template="stacked"]) #shelf.portal-active > #portal-sidebar {
    grid-column: 9 / 13;
    grid-row: span 12;
    position: sticky;
    top: calc(var(--appearance-header-height, 68px) + 16px);
  }
}

/* =========================================================
   4. HERO CAROUSEL & CONTINUE READING (LIST VIEW ONLY)
   ========================================================= */
#shelf.portal-active > [data-home-section="hero"] {
  background: var(--portal-surface);
  border: 1px solid var(--portal-border);
  border-radius: var(--portal-radius);
  padding: 10px;
  box-shadow: var(--portal-shadow);
  overflow: hidden;
}

#shelf.portal-active > [data-home-section="hero"] .book-heroes {
  border-radius: calc(var(--portal-radius) - 4px);
}

#shelf.portal-active > [data-home-section="hero"] .book-hero {
  min-height: 295px;
}

#shelf.portal-active > [data-home-section="hero"] .book-highlight {
  background: var(--portal-gold);
  color: #141c19;
  border-color: transparent;
  font-weight: 700;
  border-radius: 999px;
  padding: 8px 18px;
}

#shelf.portal-active > [data-home-section="hero"] .book-highlight:hover {
  filter: brightness(1.07);
}

#shelf.portal-active > [data-home-section="continue"] {
  background: var(--portal-surface);
  border: 1px solid var(--portal-border);
  border-top: 3px solid var(--portal-gold);
  border-radius: var(--portal-radius);
  padding: 16px 18px;
  box-shadow: var(--portal-shadow);
}

#shelf.portal-active > [data-home-section="continue"] .home-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--portal-border);
}

#shelf.portal-active > [data-home-section="continue"] #continue-title-views {
  display: none !important;
}

#shelf.portal-active > [data-home-section="continue"] .home-section-header::after {
  content: "ဖတ်လက်စ";
  font-size: 0.76rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--portal-gold-soft);
  color: var(--portal-accent);
}

html[data-theme="dark"] #shelf.portal-active > [data-home-section="continue"] .home-section-header::after {
  color: var(--portal-gold-light);
}

#shelf.portal-active > [data-home-section="continue"] #continue-title {
  margin: 0;
  font-size: 1.06rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

#shelf.portal-active > [data-home-section="continue"] #continue-title::before {
  content: "";
  width: 4px;
  height: 18px;
  border-radius: 4px;
  background: var(--portal-gold);
  display: inline-block;
}

#shelf.portal-active > [data-home-section="continue"] #continue-list {
  display: grid !important;
  grid-template-columns: 1fr !important;
  gap: 11px;
  flex: 1;
  align-content: start;
}

#shelf.portal-active > [data-home-section="continue"] .continue-card {
  display: flex !important;
  align-items: center;
  gap: 13px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--portal-surface-alt);
  border: 1px solid var(--portal-border);
  text-decoration: none;
  color: inherit;
  transition: transform 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease;
}

#shelf.portal-active > [data-home-section="continue"] .continue-card:hover {
  transform: translateY(-2px);
  border-color: var(--portal-accent);
  box-shadow: 0 6px 14px rgba(17, 34, 28, 0.08);
}

#shelf.portal-active > [data-home-section="continue"] .continue-cover-frame {
  width: 52px !important;
  height: 74px !important;
  flex: none;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--portal-border);
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.15);
}

#shelf.portal-active > [data-home-section="continue"] .continue-cover {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

#shelf.portal-active > [data-home-section="continue"] .continue-copy {
  flex: 1;
  min-width: 0;
  display: grid;
  gap: 4px;
}

#shelf.portal-active > [data-home-section="continue"] .continue-copy strong {
  font-size: 0.94rem;
  font-weight: 700;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#shelf.portal-active > [data-home-section="continue"] .continue-copy small {
  font-size: 0.8rem;
  opacity: 0.76;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#shelf.portal-active > [data-home-section="continue"] .continue-copy::after {
  content: "";
  display: block;
  height: 4px;
  width: 100%;
  margin-top: 3px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--portal-accent) 0%, var(--portal-gold) 68%, var(--portal-border) 68%);
}

#shelf.portal-active > [data-home-section="continue"] .continue-arrow {
  width: 32px;
  height: 32px;
  flex: none;
  border-radius: 999px;
  display: grid;
  place-items: center;
  font-size: 0.95rem;
  font-weight: 700;
  background: color-mix(in srgb, var(--portal-accent) 12%, transparent);
  color: var(--portal-accent);
  transition: background 0.16s ease, color 0.16s ease, transform 0.16s ease;
}

html[data-theme="dark"] #shelf.portal-active > [data-home-section="continue"] .continue-arrow {
  background: rgba(224, 179, 84, 0.16);
  color: var(--portal-gold-light);
}

#shelf.portal-active > [data-home-section="continue"] .continue-card:hover .continue-arrow {
  background: var(--portal-accent);
  color: #ffffff;
  transform: translateX(2px);
}

/* =========================================================
   5. PORTAL TRENDING ROW (BASELINE ALIGNED)
   ========================================================= */
.portal-trending {
  background: var(--portal-surface);
  border: 1px solid var(--portal-border);
  border-radius: var(--portal-radius);
  padding: 16px 18px 20px;
  box-shadow: var(--portal-shadow);
}

.portal-section-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--portal-border);
}

.portal-section-bar h2 {
  margin: 0;
  font-size: 1.08rem;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.portal-section-bar h2::before {
  content: "";
  width: 4px;
  height: 18px;
  border-radius: 4px;
  background: var(--portal-accent);
  display: inline-block;
}

.portal-bar-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.portal-more-link {
  display: inline-flex;
  align-items: center;
  height: 34px;
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--portal-accent);
  padding: 0 13px;
  border-radius: 9px;
  background: color-mix(in srgb, var(--portal-accent) 10%, transparent);
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.15s ease, color 0.15s ease;
}

html[data-theme="dark"] .portal-more-link {
  color: var(--portal-gold-light);
  background: rgba(224, 179, 84, 0.14);
}

.portal-more-link:hover {
  background: var(--portal-accent);
  color: #ffffff;
}

.portal-trending-grid {
  display: grid;
  grid-template-columns: repeat(var(--portal-trend-cols, 5), minmax(0, 1fr));
  gap: 16px;
}

@media (max-width: 960px) {
  .portal-trending-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 520px) {
  .portal-trending-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }
}

.portal-trend-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-decoration: none;
  color: inherit;
  height: 100%;
}

.portal-trend-thumb {
  position: relative;
  aspect-ratio: 2 / 3;
  border-radius: 10px;
  overflow: hidden;
  background: var(--portal-surface-alt);
  border: 1px solid var(--portal-border);
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.08);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.portal-trend-card:hover .portal-trend-thumb {
  transform: translateY(-3px);
  box-shadow: var(--portal-shadow-hover);
}

.portal-trend-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.portal-badge {
  position: absolute;
  top: 7px;
  left: 7px;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 6px;
  background: rgba(20, 38, 32, 0.86);
  color: #f6e7c1;
  backdrop-filter: blur(4px);
}

.portal-trend-title {
  font-size: 0.92rem;
  font-weight: 700;
  line-height: 1.38;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.portal-trend-meta {
  margin-top: auto;
  font-size: 0.78rem;
  opacity: 0.72;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* =========================================================
   6. RECENT UPDATES & HOME SECTION SHELVES (CONSISTENT GRID vs LIST)
   ========================================================= */
#shelf.portal-active > [data-home-section="recent"] {
  background: var(--portal-surface);
  border: 1px solid var(--portal-border);
  border-top: 3px solid var(--portal-accent);
  border-radius: var(--portal-radius);
  padding: 16px 18px 18px;
  box-shadow: var(--portal-shadow);
}

#shelf.portal-active > [data-home-section="recent"] .home-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--portal-border);
}

#shelf.portal-active > [data-home-section="recent"] #new-books-title {
  margin: 0;
  font-size: 1.08rem;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

#shelf.portal-active > [data-home-section="recent"] #new-books-title::before {
  content: "";
  width: 4px;
  height: 18px;
  border-radius: 4px;
  background: var(--portal-accent);
  display: inline-block;
}

/* --- LIST VIEW (2-Column Compact Horizontal Cards) --- */
#shelf.portal-active > [data-home-section="recent"] #new-books-list.home-list-view,
#shelf.portal-active > .section-card-shelf.is-list-view .section-preview-grid {
  display: grid !important;
  grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  gap: 12px !important;
}

@media (max-width: 600px) {
  #shelf.portal-active > [data-home-section="recent"] #new-books-list.home-list-view,
  #shelf.portal-active > .section-card-shelf.is-list-view .section-preview-grid {
    grid-template-columns: 1fr !important;
  }
}

#shelf.portal-active > [data-home-section="recent"] #new-books-list.home-list-view .continue-card,
#shelf.portal-active > .section-card-shelf.is-list-view .section-preview-grid .continue-card {
  display: flex !important;
  flex-direction: row !important;
  align-items: center;
  gap: 12px;
  padding: 9px 11px !important;
  border-radius: 10px;
  background: var(--portal-surface-alt) !important;
  border: 1px solid var(--portal-border) !important;
  transition: border-color 0.15s ease, transform 0.15s ease;
}

#shelf.portal-active > [data-home-section="recent"] #new-books-list.home-list-view .continue-card:hover,
#shelf.portal-active > .section-card-shelf.is-list-view .section-preview-grid .continue-card:hover {
  border-color: var(--portal-accent) !important;
  transform: translateY(-1px);
}

#shelf.portal-active > [data-home-section="recent"] #new-books-list.home-list-view .continue-cover-frame,
#shelf.portal-active > .section-card-shelf.is-list-view .section-preview-grid .continue-cover-frame {
  width: 52px !important;
  height: 74px !important;
  aspect-ratio: auto !important;
  flex: none;
  border-radius: 7px;
  overflow: hidden;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
}

#shelf.portal-active > [data-home-section="recent"] #new-books-list.home-list-view .continue-copy,
#shelf.portal-active > .section-card-shelf.is-list-view .section-preview-grid .continue-copy {
  min-width: 0;
  flex: 1;
}

/* --- THUMBNAIL VIEW (Portrait Cover Grid for Recent & Sections) --- */
#shelf.portal-active > [data-home-section="recent"] #new-books-list:not(.home-list-view),
#shelf.portal-active > .section-card-shelf:not(.is-list-view) .section-preview-grid {
  display: grid !important;
  grid-template-columns: repeat(5, minmax(0, 1fr)) !important;
  gap: 14px !important;
}

@media (max-width: 780px) {
  #shelf.portal-active > [data-home-section="recent"] #new-books-list:not(.home-list-view):not(:has(.continue-empty)),
  #shelf.portal-active > .section-card-shelf:not(.is-list-view) .section-preview-grid:not(:has(.continue-empty)) {
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
  }
}

@media (max-width: 480px) {
  #shelf.portal-active > [data-home-section="recent"] #new-books-list:not(.home-list-view):not(:has(.continue-empty)),
  #shelf.portal-active > .section-card-shelf:not(.is-list-view) .section-preview-grid:not(:has(.continue-empty)) {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 10px !important;
  }
}

#shelf.portal-active > [data-home-section="recent"] #new-books-list:not(.home-list-view) .continue-card,
#shelf.portal-active > .section-card-shelf:not(.is-list-view) .continue-card {
  display: flex !important;
  flex-direction: column !important;
  align-items: stretch !important;
  gap: 8px;
  padding: 0 !important;
  background: transparent !important;
  border: 0 !important;
  box-shadow: none !important;
}

#shelf.portal-active > [data-home-section="recent"] #new-books-list:not(.home-list-view) .continue-cover-frame,
#shelf.portal-active > .section-card-shelf:not(.is-list-view) .continue-cover-frame {
  width: 100% !important;
  aspect-ratio: 2 / 3 !important;
  height: auto !important;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--portal-border);
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.08);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

#shelf.portal-active > [data-home-section="recent"] #new-books-list:not(.home-list-view) .continue-card:hover .continue-cover-frame,
#shelf.portal-active > .section-card-shelf:not(.is-list-view) .continue-card:hover .continue-cover-frame {
  transform: translateY(-3px);
  box-shadow: var(--portal-shadow-hover);
}

#shelf.portal-active > [data-home-section="recent"] .continue-cover,
#shelf.portal-active > .section-card-shelf .continue-cover {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

#shelf.portal-active > [data-home-section="recent"] .continue-copy strong,
#shelf.portal-active > .section-card-shelf .continue-copy strong {
  font-size: 0.9rem;
  line-height: 1.38;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

#shelf.portal-active > [data-home-section="recent"] .continue-copy small,
#shelf.portal-active > .section-card-shelf .continue-copy small {
  font-size: 0.78rem;
  opacity: 0.72;
}

#shelf.portal-active > .section-card-shelf {
  background: var(--portal-surface);
  border: 1px solid var(--portal-border);
  border-radius: var(--portal-radius);
  padding: 16px 18px 20px;
  box-shadow: var(--portal-shadow);
}

/* =========================================================
   7. RIGHT PORTAL SIDEBAR (FLUSH WITH RECENT UPDATES)
   ========================================================= */
.portal-sidebar {
  display: grid;
  gap: 18px;
  align-content: start;
}

.portal-widget {
  background: var(--portal-surface);
  border: 1px solid var(--portal-border);
  border-radius: var(--portal-radius);
  padding: 15px 16px;
  box-shadow: var(--portal-shadow);
}

.portal-widget-title {
  margin: 0 0 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--portal-border);
  font-size: 0.98rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

.portal-widget-title::before {
  content: "";
  width: 4px;
  height: 16px;
  border-radius: 4px;
  background: var(--portal-gold);
  display: inline-block;
}

.portal-search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 11px;
  border-radius: 10px;
  border: 1px solid var(--portal-border);
  background: var(--portal-surface-alt);
}

.portal-search-box:focus-within {
  border-color: var(--portal-accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--portal-accent) 16%, transparent);
}

.portal-search-box input {
  width: 100%;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 0.92rem;
  outline: none;
}

.portal-search-results {
  margin-top: 10px;
  display: grid;
  gap: 8px;
  max-height: 290px;
  overflow-y: auto;
}

.portal-search-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border-radius: 8px;
  background: var(--portal-surface-alt);
  text-decoration: none;
  color: inherit;
  border: 1px solid transparent;
}

.portal-search-item:hover {
  border-color: var(--portal-accent);
}

.portal-search-item img {
  width: 34px;
  height: 48px;
  border-radius: 5px;
  object-fit: cover;
  flex: none;
}

.portal-search-item span {
  min-width: 0;
  display: grid;
}

.portal-search-item strong {
  font-size: 0.86rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.portal-search-item small {
  font-size: 0.76rem;
  opacity: 0.72;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.portal-search-empty {
  margin: 8px 0 0;
  font-size: 0.85rem;
  opacity: 0.72;
}

.portal-section-pills {
  display: grid;
  gap: 8px;
}

.portal-section-pill {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 11px;
  border-radius: 9px;
  background: var(--portal-surface-alt);
  border: 1px solid var(--portal-border);
  text-decoration: none;
  color: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.portal-section-pill:hover {
  border-color: var(--portal-accent);
  background: color-mix(in srgb, var(--portal-accent) 8%, var(--portal-surface-alt));
}

.portal-section-pill b {
  font-size: 0.78rem;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--portal-gold-soft);
  color: var(--portal-accent);
}

html[data-theme="dark"] .portal-section-pill b {
  color: var(--portal-gold-light);
}

.portal-rank-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
}

.portal-rank-item a {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: inherit;
  padding: 6px;
  border-radius: 9px;
  transition: background 0.15s ease;
}

.portal-rank-item a:hover {
  background: var(--portal-surface-alt);
}

.portal-rank-num {
  width: 24px;
  height: 24px;
  border-radius: 7px;
  display: grid;
  place-items: center;
  font-size: 0.8rem;
  font-weight: 800;
  flex: none;
  background: var(--portal-surface-alt);
  border: 1px solid var(--portal-border);
}

.portal-rank-item:nth-child(1) .portal-rank-num {
  background: var(--portal-gold);
  color: #161d1a;
  border-color: transparent;
}

.portal-rank-item:nth-child(2) .portal-rank-num {
  background: var(--portal-accent);
  color: #ffffff;
  border-color: transparent;
}

.portal-rank-item:nth-child(3) .portal-rank-num {
  background: color-mix(in srgb, var(--portal-accent) 22%, var(--portal-surface-alt));
  color: var(--portal-accent);
  border-color: transparent;
}

.portal-rank-item img {
  width: 40px;
  height: 56px;
  border-radius: 6px;
  object-fit: cover;
  flex: none;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
}

.portal-rank-copy {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.portal-rank-copy strong {
  font-size: 0.88rem;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.portal-rank-copy small {
  font-size: 0.76rem;
  opacity: 0.72;
}

/* =========================================================
   8. SUB PAGE (/sections/) TOOLBAR, GROUP GRID & SERIES DETAIL UI
   ========================================================= */
.section-toolbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-block: 16px 20px;
}

.portal-inline-search {
  flex: 1;
  max-width: 440px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 13px;
  border-radius: 10px;
  border: 1px solid var(--portal-border);
  background: var(--portal-surface);
  margin: 0 !important;
}

.portal-inline-search:focus-within {
  border-color: var(--portal-accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--portal-accent) 16%, transparent);
}

.portal-inline-search input {
  width: 100%;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  outline: none;
}

.section-groups-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 18px;
}

@media (max-width: 900px) {
  .section-groups-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 520px) {
  .section-groups-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
  }
}

.section-group-card {
  display: flex;
  flex-direction: column;
  gap: 9px;
  padding: 10px;
  border-radius: var(--portal-radius);
  background: var(--portal-surface);
  border: 1px solid var(--portal-border);
  box-shadow: var(--portal-shadow);
  text-decoration: none;
  color: inherit;
  transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
}

.section-group-card:hover {
  transform: translateY(-3px);
  border-color: var(--portal-accent);
  box-shadow: var(--portal-shadow-hover);
}

.section-group-thumb {
  position: relative;
  aspect-ratio: 2 / 3;
  border-radius: 9px;
  overflow: hidden;
  background: var(--portal-surface-alt);
}

.section-group-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.section-group-copy {
  display: grid;
  gap: 3px;
}

.section-group-copy strong {
  font-size: 0.94rem;
  line-height: 1.38;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.section-group-copy small {
  font-size: 0.8rem;
  opacity: 0.74;
}

#section-page.section-list-view .section-groups-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

@media (max-width: 680px) {
  #section-page.section-list-view .section-groups-grid {
    grid-template-columns: 1fr;
  }
}

#section-page.section-list-view .section-group-card {
  flex-direction: row;
  align-items: center;
  gap: 14px;
  padding: 10px 14px;
}

#section-page.section-list-view .section-group-thumb {
  width: 56px;
  height: 80px;
  aspect-ratio: auto;
  flex: none;
}

.series-detail-header {
  background: var(--portal-surface);
  border: 1px solid var(--portal-border);
  border-top: 3px solid var(--portal-gold);
  border-radius: var(--portal-radius);
  padding: 22px;
  margin-bottom: 18px;
  box-shadow: var(--portal-shadow);
  display: grid;
  grid-template-columns: 168px minmax(0, 1fr);
  gap: 24px;
  align-items: center;
}

@media (max-width: 640px) {
  .series-detail-header {
    grid-template-columns: 1fr;
    text-align: center;
    justify-items: center;
    padding: 18px;
    gap: 16px;
  }
}

.series-detail-cover {
  width: 168px;
  aspect-ratio: 2 / 3;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--portal-border);
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.22);
}

.series-detail-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.series-detail-info {
  display: grid;
  gap: 12px;
}

.series-detail-breadcrumb {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--portal-accent);
  text-decoration: none;
}

html[data-theme="dark"] .series-detail-breadcrumb {
  color: var(--portal-gold-light);
}

.series-detail-info h2 {
  margin: 0;
  font-size: clamp(1.3rem, 2.5vw, 1.75rem);
  line-height: 1.3;
}

.series-detail-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

@media (max-width: 640px) {
  .series-detail-badges,
  .series-detail-actions {
    justify-content: center;
  }
}

.series-detail-badges span {
  font-size: 0.8rem;
  font-weight: 700;
  padding: 4px 11px;
  border-radius: 999px;
  background: var(--portal-surface-alt);
  border: 1px solid var(--portal-border);
}

.series-detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 4px;
}

.series-btn-primary,
.series-btn-secondary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 700;
  text-decoration: none;
  transition: transform 0.15s ease, filter 0.15s ease;
}

.series-btn-primary {
  background: var(--portal-gold);
  color: #141c19;
}

.series-btn-secondary {
  background: var(--portal-accent);
  color: #ffffff;
}

.series-btn-primary:hover,
.series-btn-secondary:hover {
  transform: translateY(-1px);
  filter: brightness(1.07);
}

.series-volumes-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 14px;
}

@media (max-width: 900px) {
  .series-volumes-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 520px) {
  .series-volumes-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }
}

.series-volumes-grid .continue-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 9px;
  border-radius: 11px;
  background: var(--portal-surface);
  border: 1px solid var(--portal-border);
  text-decoration: none;
  color: inherit;
  transition: transform 0.16s ease, border-color 0.16s ease;
}

.series-volumes-grid .continue-card:hover {
  transform: translateY(-2px);
  border-color: var(--portal-accent);
}

.series-volumes-grid .continue-cover-frame {
  width: 100%;
  aspect-ratio: 2 / 3;
  border-radius: 8px;
  overflow: hidden;
}

.series-volumes-grid .continue-cover {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#section-page.section-list-view .series-volumes-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

@media (max-width: 820px) {
  #section-page.section-list-view .series-volumes-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 520px) {
  #section-page.section-list-view .series-volumes-grid {
    grid-template-columns: 1fr;
  }
}

#section-page.section-list-view .series-volumes-grid .continue-card {
  flex-direction: row;
  align-items: center;
  gap: 11px;
  padding: 8px 11px;
}

#section-page.section-list-view .series-volumes-grid .continue-cover-frame {
  width: 42px;
  height: 58px;
  aspect-ratio: auto;
  flex: none;
}


/* =========================================================
   9. DETAILED LAYOUT & APPEARANCE CONTROLS (FROM ADMIN PRO)
   ========================================================= */
:root {
  --portal-gold: var(--design-accent-gold, #c89b3c);
}
html[data-theme="dark"] {
  --portal-gold: var(--design-accent-gold, #e0b354);
}
html[data-show-trending="false"] #portal-trending {
  display: none !important;
}
html[data-show-sidebar="false"] #portal-sidebar {
  display: none !important;
}
@media (min-width: 980px) {
  html[data-show-sidebar="false"] #shelf.portal-active > [data-home-section="recent"],
  html[data-show-sidebar="false"] #shelf.portal-active > [data-section-teaser] {
    grid-column: 1 / -1 !important;
  }
  html[data-sidebar-side="left"]:not([data-show-sidebar="false"]) #shelf.portal-active > #portal-sidebar {
    grid-column: 1 / 5 !important;
  }
  html[data-sidebar-side="left"]:not([data-show-sidebar="false"]) #shelf.portal-active > [data-home-section="recent"],
  html[data-sidebar-side="left"]:not([data-show-sidebar="false"]) #shelf.portal-active > [data-section-teaser] {
    grid-column: 5 / 13 !important;
  }
}
html[data-header-style="solid"] body.portal-site > .top {
  background: var(--portal-accent) !important;
}
html[data-header-style="glass"] body.portal-site > .top {
  background: color-mix(in srgb, var(--portal-accent-deep) 82%, transparent) !important;
  backdrop-filter: blur(14px);
}
html[data-header-style="minimal"] body.portal-site > .top {
  background: var(--portal-surface) !important;
  color: var(--ink) !important;
  border-bottom: 1px solid var(--portal-border) !important;
}
html[data-header-style="minimal"] body.portal-site > .top .brand,
html[data-header-style="minimal"] body.portal-site > .top .design-public-menu a,
html[data-header-style="minimal"] body.portal-site > .top .design-public-menu summary,
html[data-header-style="minimal"] body.portal-site > .top #theme {
  color: var(--ink) !important;
}
html[data-header-height="compact"] body.portal-site > .top .top-inner {
  min-height: 52px;
}
html[data-header-height="tall"] body.portal-site > .top .top-inner {
  min-height: 78px;
}
html[data-card-shadow="none"] {
  --portal-shadow: none;
  --portal-shadow-hover: 0 2px 8px rgba(0,0,0,0.08);
}
html[data-card-shadow="elevated"] {
  --portal-shadow: 0 10px 28px rgba(14, 34, 28, 0.14);
  --portal-shadow-hover: 0 16px 36px rgba(14, 34, 28, 0.22);
}
#shelf.portal-active > [data-home-section="recent"] #new-books-list:not(.home-list-view),
#shelf.portal-active > .section-card-shelf:not(.is-list-view) .section-preview-grid {
  grid-template-columns: repeat(var(--portal-home-cols, 5), minmax(0, 1fr)) !important;
}
.portal-trend-thumb,
#shelf.portal-active > .section-card-shelf:not(.is-list-view) .continue-cover-frame,
.section-group-thumb,
.series-volumes-grid .continue-cover-frame {
  aspect-ratio: var(--portal-card-ratio, 2 / 3) !important;
}
