/* =========================================================================
   Rumah Bambu Digital Library — Stylesheet
   Design language: Material Design 3 (M3), mobile-first
   Palette: "Alami Bambu" — natural earth-tones (sage green, bamboo brown,
   warm cream), inspired by real bamboo stalks, wood, and paper — no
   saturated/neon colors. Rounded cards, soft shadows.
   ========================================================================= */

/* -------------------------------------------------------------------------
   1. Design tokens (CSS custom properties)
   Everything visual is driven from these variables so Dark Mode is just a
   matter of swapping the values on <html data-theme="dark">.
   ------------------------------------------------------------------------- */
:root {
  /* Natural bamboo palette: muted sage green + warm wood-brown */
  --color-primary: #6b8e5a;
  --color-primary-dark: #435c37;
  --color-primary-light: #a8bd97;
  --color-primary-container: #e7ecdd;
  --color-secondary: #8a6d4c;
  --color-accent: #c7a978;

  /* Surfaces — warm cream/paper tones instead of stark white */
  --color-bg: #faf6ec;
  --color-surface: #fffdf8;
  --color-surface-alt: #f1ead9;
  --color-outline: #e1d7bf;

  /* Text */
  --color-text: #2f2b22;
  --color-text-muted: #6e6353;
  --color-on-primary: #ffffff;

  /* Feedback */
  --color-success: #6b8e5a;
  --color-warning: #b5701e;
  --color-danger: #a63b2c;
  --color-whatsapp: #25d366;

  /* Shape */
  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --radius-pill: 999px;

  /* Elevation */
  --shadow-1: 0 1px 3px rgba(61, 51, 30, 0.12), 0 1px 2px rgba(61, 51, 30, 0.08);
  --shadow-2: 0 4px 12px rgba(61, 51, 30, 0.14);
  --shadow-3: 0 10px 28px rgba(61, 51, 30, 0.18);

  /* Motion */
  --ease-standard: cubic-bezier(0.2, 0, 0, 1);
  --dur-fast: 150ms;
  --dur-med: 260ms;
  --dur-slow: 420ms;

  /* Layout */
  --app-bar-h: 64px;
  --bottom-nav-h: 64px;
  --max-width: 960px;

  color-scheme: light;
}

[data-theme="dark"] {
  --color-primary: #9cbf87;
  --color-primary-dark: #7a9c68;
  --color-primary-light: #435c37;
  --color-primary-container: #2c3524;
  --color-secondary: #c7a978;
  --color-accent: #4a3e2c;

  --color-bg: #1c1a15;
  --color-surface: #262319;
  --color-surface-alt: #2e2a1e;
  --color-outline: #3a3527;

  --color-text: #f1ecdd;
  --color-text-muted: #b8ae98;
  --color-on-primary: #14160f;

  color-scheme: dark;
}

/* -------------------------------------------------------------------------
   2. Reset & base
   ------------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
}

body {
  font-family: "Poppins", "Segoe UI", Roboto, system-ui, -apple-system, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: contain;
  transition: background var(--dur-med) var(--ease-standard), color var(--dur-med) var(--ease-standard);
  padding-top: env(safe-area-inset-top);
}

h1, h2, h3, h4 { font-family: "Poppins", "Segoe UI", sans-serif; font-weight: 600; line-height: 1.25; margin: 0 0 8px; }
p { line-height: 1.6; color: var(--color-text-muted); margin: 0 0 12px; }
a { color: var(--color-primary-dark); text-decoration: none; }
img { max-width: 100%; display: block; }
button { font-family: inherit; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); white-space: nowrap; border: 0; padding: 0;
}

/* Skip link for accessibility */
.skip-link {
  position: absolute; left: 8px; top: -48px;
  background: var(--color-primary); color: var(--color-on-primary);
  padding: 10px 16px; border-radius: var(--radius-sm); z-index: 999;
  transition: top var(--dur-fast) var(--ease-standard);
}
.skip-link:focus { top: 8px; }

/* -------------------------------------------------------------------------
   3. App shell layout
   ------------------------------------------------------------------------- */
#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.app-bar {
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--app-bar-h);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 8px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-outline);
  backdrop-filter: saturate(180%) blur(8px);
}

.app-bar__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

.app-bar__logo { width: 36px; height: 36px; border-radius: var(--radius-sm); }

.app-bar__title {
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.app-bar__subtitle { font-size: 11px; color: var(--color-text-muted); }

.icon-btn {
  width: 40px; height: 40px;
  display: inline-flex; align-items: center; justify-content: center;
  border: none; background: transparent; color: var(--color-text);
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease-standard), transform var(--dur-fast);
}
.icon-btn:hover { background: var(--color-primary-container); }
.icon-btn:active { transform: scale(0.92); }
.icon-btn svg { width: 22px; height: 22px; fill: currentColor; }

/* Main scroll region */
main#view-root {
  flex: 1;
  max-width: var(--max-width);
  width: 100%;
  margin: 0 auto;
  padding: 16px 16px calc(var(--bottom-nav-h) + 32px);
}

/* Pull-to-refresh indicator */
#ptr-indicator {
  display: flex; align-items: center; justify-content: center;
  height: 0; overflow: hidden;
  color: var(--color-primary);
  transition: height var(--dur-fast) var(--ease-standard);
}
#ptr-indicator.active { height: 48px; }
.ptr-spinner {
  width: 22px; height: 22px; border-radius: 50%;
  border: 3px solid var(--color-primary-container);
  border-top-color: var(--color-primary);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* -------------------------------------------------------------------------
   4. Bottom navigation (Material 3 style)
   ------------------------------------------------------------------------- */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  height: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--color-surface);
  border-top: 1px solid var(--color-outline);
  display: flex;
  justify-content: space-around;
  box-shadow: 0 -2px 12px rgba(0,0,0,0.06);
}

.bottom-nav__item {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px;
  border: none; background: transparent; color: var(--color-text-muted);
  font-size: 11px; cursor: pointer; padding: 6px 2px;
  transition: color var(--dur-fast) var(--ease-standard);
}
.bottom-nav__item svg { width: 22px; height: 22px; fill: currentColor; transition: transform var(--dur-fast) var(--ease-standard); }
.bottom-nav__item.active { color: var(--color-primary-dark); font-weight: 600; }
.bottom-nav__item.active svg { transform: translateY(-2px); }
.bottom-nav__item:active svg { transform: scale(0.88); }

/* -------------------------------------------------------------------------
   5. Cards, buttons, chips (M3-inspired)
   ------------------------------------------------------------------------- */
.card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
  padding: 16px;
  transition: box-shadow var(--dur-med) var(--ease-standard), transform var(--dur-med) var(--ease-standard);
}
.card:hover { box-shadow: var(--shadow-2); }

.hero {
  position: relative;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: linear-gradient(160deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
  color: #fff;
  padding: 28px 22px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-2);
}
.hero::after {
  content: "";
  position: absolute; inset: 0;
  background: radial-gradient(circle at 85% 20%, rgba(255,255,255,0.16), transparent 55%);
}
.hero h1 { font-size: 22px; margin-bottom: 6px; position: relative; }
.hero p { color: rgba(255,255,255,0.9); font-size: 14px; max-width: 46ch; position: relative; }
.hero .tagline { font-style: italic; opacity: 0.85; font-size: 13px; margin-top: 10px; position: relative; }

.section-title {
  display: flex; align-items: baseline; justify-content: space-between;
  margin: 24px 0 12px;
}
.section-title h2 { font-size: 16px; }
.section-title .link-more { font-size: 12px; color: var(--color-primary-dark); font-weight: 600; }

.quick-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
@media (min-width: 480px) {
  .quick-grid { grid-template-columns: repeat(4, 1fr); }
}

.quick-tile {
  background: var(--color-surface);
  border: 1px solid var(--color-outline);
  border-radius: var(--radius-md);
  padding: 14px 8px;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  text-align: center;
  cursor: pointer;
  transition: transform var(--dur-fast) var(--ease-standard), box-shadow var(--dur-fast) var(--ease-standard), background var(--dur-fast);
}
.quick-tile:hover { box-shadow: var(--shadow-1); transform: translateY(-2px); }
.quick-tile:active { transform: scale(0.96); }
.quick-tile .quick-tile__icon {
  width: 42px; height: 42px; border-radius: var(--radius-pill);
  background: var(--color-primary-container);
  display: flex; align-items: center; justify-content: center;
  color: var(--color-primary-dark);
}
.quick-tile .quick-tile__icon svg { width: 22px; height: 22px; fill: currentColor; }
.quick-tile__label { font-size: 11.5px; font-weight: 600; color: var(--color-text); }

.book-scroll {
  display: flex; gap: 12px; overflow-x: auto; padding-bottom: 6px;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
}
.book-scroll::-webkit-scrollbar { height: 6px; }
.book-scroll::-webkit-scrollbar-thumb { background: var(--color-outline); border-radius: var(--radius-pill); }

.book-card {
  scroll-snap-align: start;
  flex: 0 0 150px;
  background: var(--color-surface);
  border-radius: var(--radius-md);
  border: 1px solid var(--color-outline);
  overflow: hidden;
  cursor: pointer;
  transition: transform var(--dur-fast) var(--ease-standard);
}
.book-card:hover { transform: translateY(-3px); }
.book-card__cover {
  height: 100px;
  background: linear-gradient(135deg, var(--color-primary-light), var(--color-primary));
  display: flex; align-items: center; justify-content: center; color: #fff; font-size: 26px;
}
.book-card__body { padding: 10px; }
.book-card__title { font-size: 12.5px; font-weight: 700; margin-bottom: 2px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.book-card__meta { font-size: 10.5px; color: var(--color-text-muted); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: none; border-radius: var(--radius-pill);
  padding: 12px 22px; font-weight: 600; font-size: 14px;
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease-standard), box-shadow var(--dur-fast) var(--ease-standard), transform var(--dur-fast);
}
.btn:active { transform: scale(0.97); }
.btn--filled { background: var(--color-primary); color: var(--color-on-primary); box-shadow: var(--shadow-1); }
.btn--filled:hover { box-shadow: var(--shadow-2); }
.btn--tonal { background: var(--color-primary-container); color: var(--color-primary-dark); }
.btn--outline { background: transparent; border: 1.5px solid var(--color-outline); color: var(--color-text); }
.btn--block { width: 100%; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 14px; border-radius: var(--radius-pill);
  background: var(--color-surface-alt); border: 1px solid var(--color-outline);
  font-size: 12.5px; color: var(--color-text); cursor: pointer;
  white-space: nowrap;
}
.chip.active { background: var(--color-primary); color: var(--color-on-primary); border-color: var(--color-primary); }
.chip-row { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 4px; }

/* -------------------------------------------------------------------------
   6. Views / routing
   ------------------------------------------------------------------------- */
.view { display: none; animation: fadeUp var(--dur-slow) var(--ease-standard); }
.view.active { display: block; }
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.page-header { margin-bottom: 16px; }
.page-header h1 { font-size: 20px; }
.page-header p { font-size: 13px; }

/* Embedded content frame (for live WordPress pages) */
.embed-wrap {
  position: relative;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--color-surface);
  box-shadow: var(--shadow-1);
  min-height: 60vh;
}
.embed-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 10px 14px;
  background: var(--color-surface-alt);
  border-bottom: 1px solid var(--color-outline);
  font-size: 12px; color: var(--color-text-muted);
}
.embed-toolbar__status { display: flex; align-items: center; gap: 6px; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--color-success); }
.embed-wrap iframe {
  width: 100%; height: 72vh; border: none; background: var(--color-surface);
}
.embed-fallback {
  padding: 32px 20px; text-align: center; display: none;
}
.embed-fallback.show { display: block; }

/* Search */
.search-bar {
  display: flex; align-items: center; gap: 8px;
  background: var(--color-surface); border: 1.5px solid var(--color-outline);
  border-radius: var(--radius-pill); padding: 6px 6px 6px 16px;
  margin-bottom: 16px;
}
.search-bar input {
  flex: 1; border: none; outline: none; background: transparent;
  font-size: 14px; color: var(--color-text); padding: 8px 0;
}
.search-bar .icon-btn { background: var(--color-primary); color: #fff; }
.search-bar .icon-btn:hover { background: var(--color-primary-dark); }

/* Contact */
.contact-list { display: flex; flex-direction: column; gap: 12px; }
.contact-item {
  display: flex; align-items: center; gap: 14px;
  background: var(--color-surface); border-radius: var(--radius-md);
  border: 1px solid var(--color-outline); padding: 14px;
}
.contact-item__icon {
  width: 42px; height: 42px; flex: none; border-radius: var(--radius-pill);
  background: var(--color-primary-container); color: var(--color-primary-dark);
  display: flex; align-items: center; justify-content: center;
}
.contact-item__icon svg { width: 20px; height: 20px; fill: currentColor; }
.contact-item h3 { font-size: 13.5px; margin-bottom: 2px; }
.contact-item p { font-size: 12.5px; margin: 0; }
.map-embed {
  border-radius: var(--radius-md); overflow: hidden; border: 1px solid var(--color-outline);
  margin-top: 14px; height: 220px;
}
.map-embed iframe { width: 100%; height: 100%; border: none; }

/* Gallery */
.gallery-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px;
}
@media (min-width: 480px) { .gallery-grid { grid-template-columns: repeat(3, 1fr); } }
.gallery-item {
  border-radius: var(--radius-md); overflow: hidden; aspect-ratio: 1/1;
  background: var(--color-surface-alt); border: 1px solid var(--color-outline);
  cursor: pointer;
}
.gallery-item img { width: 100%; height: 100%; object-fit: cover; transition: transform var(--dur-med) var(--ease-standard); }
.gallery-item:hover img { transform: scale(1.06); }

/* QR page */
.qr-box {
  display: flex; flex-direction: column; align-items: center; gap: 16px;
  background: var(--color-surface); border-radius: var(--radius-lg);
  padding: 28px 20px; box-shadow: var(--shadow-1); text-align: center;
}
.qr-box img { width: 220px; height: 220px; border-radius: var(--radius-md); background: #fff; padding: 10px; border: 1px solid var(--color-outline); }

/* Floating WhatsApp button */
.fab-whatsapp {
  position: fixed; right: 16px; bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom) + 16px);
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--color-whatsapp); color: #fff; border: none;
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-3); cursor: pointer; z-index: 45;
  transition: transform var(--dur-fast) var(--ease-standard);
}
.fab-whatsapp:hover { transform: scale(1.06); }
.fab-whatsapp:active { transform: scale(0.94); }
.fab-whatsapp svg { width: 28px; height: 28px; fill: currentColor; }

/* Install banner */
.install-banner {
  position: fixed; left: 12px; right: 12px; bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom) + 12px);
  max-width: calc(var(--max-width) - 24px); margin: 0 auto;
  background: var(--color-primary-dark); color: #fff;
  border-radius: var(--radius-lg); padding: 14px 16px;
  display: flex; align-items: center; gap: 12px;
  box-shadow: var(--shadow-3); z-index: 60;
  transform: translateY(140%); transition: transform var(--dur-slow) var(--ease-standard);
}
.install-banner.show { transform: translateY(0); }
.install-banner img { width: 40px; height: 40px; border-radius: var(--radius-sm); background: #fff; }
.install-banner__text { flex: 1; }
.install-banner__text strong { display: block; font-size: 13.5px; }
.install-banner__text span { font-size: 11.5px; opacity: 0.85; }
.install-banner__actions { display: flex; gap: 6px; }
.install-banner__actions button {
  border: none; border-radius: var(--radius-pill); padding: 8px 12px; font-size: 12px; font-weight: 700; cursor: pointer;
}
.install-banner__actions .install-yes { background: #fff; color: var(--color-primary-dark); }
.install-banner__actions .install-no { background: rgba(255,255,255,0.15); color: #fff; }

/* Toast / update snackbar */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom) + 12px);
  transform: translate(-50%, 140%);
  background: #2f2b22; color: #fff; padding: 12px 18px; border-radius: var(--radius-pill);
  font-size: 13px; display: flex; align-items: center; gap: 12px;
  box-shadow: var(--shadow-3); z-index: 70; transition: transform var(--dur-med) var(--ease-standard);
  white-space: nowrap;
}
.toast.show { transform: translate(-50%, 0); }
.toast button { background: var(--color-primary-light); border: none; color: #14160f; font-weight: 700; padding: 6px 12px; border-radius: var(--radius-pill); cursor: pointer; }

/* Offline pill in app bar */
.offline-pill {
  display: none; align-items: center; gap: 6px; font-size: 11px; font-weight: 700;
  background: #fdecea; color: var(--color-danger); border-radius: var(--radius-pill);
  padding: 4px 10px; margin-right: 4px;
}
.offline-pill.show { display: inline-flex; }
[data-theme="dark"] .offline-pill { background: #3a1f1f; }

/* Skeleton loading */
.skeleton {
  background: linear-gradient(90deg, var(--color-surface-alt) 25%, var(--color-outline) 37%, var(--color-surface-alt) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
  border-radius: var(--radius-md);
}
@keyframes shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* Footer */
.app-footer {
  text-align: center; padding: 28px 16px 12px; font-size: 11.5px; color: var(--color-text-muted);
}

/* Splash (in-app, shown briefly on cold start) */
#app-splash {
  position: fixed; inset: 0; z-index: 999;
  background: linear-gradient(160deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  color: #fff;
  transition: opacity var(--dur-slow) var(--ease-standard), visibility var(--dur-slow);
}
#app-splash img { width: 96px; height: 96px; border-radius: var(--radius-lg); box-shadow: var(--shadow-3); }
#app-splash .brand { font-size: 17px; font-weight: 700; letter-spacing: 0.3px; }
#app-splash .tagline { font-size: 12px; opacity: 0.85; font-style: italic; }
#app-splash.hide { opacity: 0; visibility: hidden; pointer-events: none; }

/* Larger screens: constrain + polish */
@media (min-width: 720px) {
  .bottom-nav { display: none; }
  main#view-root { padding-bottom: 40px; }
  .fab-whatsapp, .install-banner, .toast { bot