/* ห้องสมุดนิทานภาษาอังกฤษ — ทุกกฎอยู่ภายใต้ #lib-app */

#lib-app,
#lib-app *,
#lib-app *::before,
#lib-app *::after {
  box-sizing: border-box;
}

#lib-app {
  --lib-ink: #2d3748;
  --lib-muted: #5c6b82;
  --lib-paper: #ffffff;
  --lib-line: #e7e1f5;
  --lib-peach: #ff8a5b;
  --lib-peach-deep: #f26b3a;
  --lib-violet: #7c6bf2;
  --lib-violet-deep: #6554e0;
  --lib-shadow: 0 12px 28px rgba(72, 58, 120, 0.1);
  color: var(--lib-ink);
  font-family: 'Mali', 'Fredoka', 'Sarabun', sans-serif;
  width: min(1120px, 100%);
  margin: 0 auto;
}

body#lib-app {
  min-height: 100vh;
  margin: 0;
  padding: 20px 16px 40px;
  background:
    radial-gradient(circle at 8% 10%, rgba(255, 196, 160, 0.45), transparent 26%),
    radial-gradient(circle at 92% 0%, rgba(176, 164, 255, 0.4), transparent 28%),
    linear-gradient(180deg, #fff8f3 0%, #f6f4ff 55%, #f3fbff 100%);
}

#lib-app [hidden] {
  display: none !important;
}

/* pageFadeIn ค้าง transform ไว้ ทำให้ position:fixed ของ modal อิงกับหน้า ไม่ใช่จอ */
#page-library {
  animation: none;
  transform: none;
}

#lib-app .lib-topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}

#lib-app .lib-back {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 14px;
  border-radius: 999px;
  background: #fff;
  color: #9a5b12;
  border: 1.5px solid #f6d7a8;
  text-decoration: none;
  font-weight: 700;
}

#lib-app .lib-back:hover {
  background: #fff7ea;
}

#lib-app .lib-logo {
  width: 52px;
  height: 52px;
  object-fit: contain;
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 4px 12px rgba(80, 90, 130, 0.12);
}

#lib-app .lib-brand {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

#lib-app .lib-brand-th {
  font-weight: 700;
  color: #e11d48;
}

#lib-app .lib-brand-en {
  font-family: 'Fredoka', sans-serif;
  font-weight: 600;
  color: #334155;
}

#lib-app .lib-header {
  text-align: center;
  margin-bottom: 18px;
}

#lib-app .lib-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  background: #fff;
  color: #6d28d9;
  font-weight: 700;
  box-shadow: 0 4px 12px rgba(109, 40, 217, 0.08);
}

#lib-app .lib-title {
  margin: 10px 0 6px;
  font-family: 'Fredoka', 'Mali', sans-serif;
  font-size: clamp(1.7rem, 3vw, 2.4rem);
  line-height: 1.25;
  color: #2a2142;
}

#lib-app .lib-lead {
  max-width: 680px;
  margin: 0 auto;
  color: var(--lib-muted);
  font-size: 1.02rem;
}

#lib-app .lib-monthly-note {
  max-width: 720px;
  margin: 8px auto 0;
  font-family: 'Mali', 'Fredoka', sans-serif;
  font-weight: 800;
  font-size: clamp(1.2rem, 2.6vw, 1.55rem);
  line-height: 1.45;
  background-image: linear-gradient(90deg, #f97316 0%, #ec4899 38%, #8b5cf6 68%, #06b6d4 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

#lib-app .bdd-value-banner {
  margin: 14px 0 0;
  padding: 12px 14px;
  border-radius: 16px;
  text-align: left;
  background: linear-gradient(180deg, #fff8dc 0%, #fff1c2 100%);
  border: 1.5px solid #e8b931;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

#lib-app .bdd-value-banner p {
  margin: 0;
  color: #7a4b08;
  font-weight: 700;
  line-height: 1.55;
}

#lib-app .lib-panel {
  margin-top: 18px;
}

#lib-app .lib-btn:focus-visible,
#lib-app .lib-reader-close:focus-visible,
#lib-app .lib-back:focus-visible {
  outline: 3px solid #7c6bf2;
  outline-offset: 2px;
}

#lib-app .lib-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}

#lib-app .lib-card {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--lib-paper);
  border: 1px solid var(--lib-line);
  border-radius: 24px;
  overflow: hidden;
  box-shadow: var(--lib-shadow);
}

#lib-app .lib-cover-wrap {
  position: relative;
  aspect-ratio: 3 / 4;
  background:
    linear-gradient(160deg, #fff4ea 0%, #efe9ff 100%);
}

#lib-app .lib-cover {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

#lib-app .lib-cover-missing::after {
  content: '📘';
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 3rem;
}

#lib-app .lib-card-vip {
  border-color: #f6d98a;
  box-shadow: 0 12px 28px rgba(180, 130, 32, 0.16);
}

#lib-app .lib-cover-shade {
  position: absolute;
  inset: 0;
  background: rgba(48, 32, 8, 0.34);
}

#lib-app .vip-book-badge {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  padding: 0.28rem 0.65rem;
  border-radius: 999px;
  background: linear-gradient(135deg, #fff4c2 0%, #f5c451 55%, #e8a317 100%);
  color: #7a4b08;
  font-size: 0.78rem;
  font-weight: 800;
  box-shadow: 0 3px 0 #c9890d;
}

#lib-app .lib-btn-vip {
  background: linear-gradient(135deg, #f6d98a 0%, #f5c451 100%);
  color: #7a4b08;
  box-shadow: 0 4px 0 #c9890d;
}

#lib-app .lib-btn-download,
#lib-app #lib-reader-download {
  display: none;
}

#lib-app .lib-vip-modal {
  position: fixed;
  inset: 0;
  z-index: 12000;
  display: grid;
  place-items: center;
  padding: 16px;
}

#lib-app .lib-vip-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(48, 32, 8, 0.48);
}

#lib-app .lib-vip-card {
  position: relative;
  width: min(480px, 100%);
  padding: 26px 22px 20px;
  border-radius: 28px;
  background: linear-gradient(180deg, #fffaf0 0%, #ffffff 40%);
  border: 2px solid #f6d98a;
  box-shadow: 0 24px 60px rgba(72, 46, 8, 0.22);
  text-align: center;
}

#lib-app .lib-vip-kicker {
  margin: 0 0 6px;
  color: #b7791f;
  font-weight: 700;
}

#lib-app .lib-vip-title {
  margin: 0 0 10px;
  font-family: 'Fredoka', 'Mali', sans-serif;
  font-size: 1.4rem;
  line-height: 1.35;
  color: #7a4b08;
}

#lib-app .lib-vip-text {
  margin: 0;
  color: #57534e;
  line-height: 1.6;
}

#lib-app .lib-vip-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 18px;
}

#lib-app .lib-vip-contact {
  color: #fff;
  background: linear-gradient(135deg, #22c55e 0%, #16a34a 48%, #d97706 100%);
  box-shadow: 0 4px 0 #166534;
}

#lib-app .lib-card-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
  padding: 12px 12px 14px;
}

#lib-app .lib-card-title {
  margin: 0;
  font-family: 'Fredoka', 'Mali', sans-serif;
  font-size: 1.05rem;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 2.6em;
}

#lib-app .lib-card-subtitle {
  margin: 0;
  color: var(--lib-muted);
  font-weight: 600;
}

#lib-app .lib-card-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: auto;
  padding-top: 8px;
}

#lib-app .lib-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 12px;
  border-radius: 14px;
  border: 0;
  font: inherit;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}

#lib-app .lib-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#lib-app .lib-btn-read {
  background: linear-gradient(180deg, #ff9a6a 0%, #ff7a45 100%);
  color: #fff;
  box-shadow: 0 4px 0 #e15a28;
}

#lib-app .lib-btn-download {
  background: #efeaff;
  color: #5b21b6;
}

#lib-app .lib-btn-ghost {
  background: #fff;
  color: #475569;
  border: 1.5px solid #e2e8f0;
}

#lib-app .lib-btn-read:hover,
#lib-app .lib-btn-download:hover,
#lib-app .lib-btn-ghost:hover {
  transform: translateY(-1px);
}

#lib-app .lib-live {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

#lib-app .lib-reader-modal {
  position: fixed;
  inset: 0;
  z-index: 12000;
  display: grid;
  place-items: center;
  padding: 16px;
  overflow: auto;
}

#lib-app .lib-reader-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(32, 24, 58, 0.55);
}

#lib-app .lib-reader-title {
  margin: 0;
  font-family: 'Fredoka', 'Mali', sans-serif;
  font-size: 1.45rem;
  line-height: 1.3;
}

#lib-app .lib-reader-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

#lib-app .lib-reader-card {
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(1100px, calc(100vw - 32px));
  height: min(900px, calc(100dvh - 32px));
  max-height: calc(100dvh - 32px);
  border-radius: 24px;
  overflow: hidden;
  background: #1c1730;
  box-shadow: 0 24px 60px rgba(20, 12, 40, 0.4);
}

#lib-app .lib-reader-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  padding: 12px 14px;
  background: #fff;
}

#lib-app .lib-reader-subtitle {
  margin: 2px 0 0;
  color: var(--lib-muted);
  font-weight: 700;
}

#lib-app .lib-reader-close {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 14px;
  background: #fee2e2;
  color: #b91c1c;
  font: inherit;
  font-size: 1.2rem;
  font-weight: 700;
  cursor: pointer;
}

#lib-app .lib-reader-frame {
  flex: 1;
  width: 100%;
  min-height: 0;
  border: 0;
  background: #0f0c1a;
}

#lib-app .lib-reader-fallback {
  margin: 0;
  padding: 8px 14px 12px;
  background: #fff;
  color: var(--lib-muted);
  font-size: 0.92rem;
}

@media (max-width: 720px) {
  #lib-app .lib-reader-card {
    height: 100%;
    border-radius: 16px;
  }

  #lib-app .lib-reader-modal {
    padding: 8px;
  }
}

@media (prefers-reduced-motion: reduce) {
  #lib-app .lib-btn-read:hover,
  #lib-app .lib-btn-download:hover,
  #lib-app .lib-btn-ghost:hover {
    transform: none;
  }
}
