
html,
body {
  margin: 0;
  padding: 0;
  font-family: "Segoe UI", Tahoma, Arial, sans-serif;
  color: var(--text);
  background: linear-gradient(180deg, #edf3fb 0%, #f8fbff 100%);
  min-height: 100%;
}

body {
  min-height: 100vh;
}

a {
  color: inherit;
  text-decoration: none;
}

.hidden {
  display: none !important;
}

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(219, 228, 240, 0.8);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 14px 22px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-logo {
  width: 52px;
  height: 52px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #1d4ed8, #60a5fa);
  color: white;
  font-size: 24px;
  box-shadow: var(--shadow);
}

.brand h1 {
  margin: 0;
  font-size: 1.2rem;
}

.brand p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.main-layout {
  flex: 1;
  padding: 22px;
}

.view {
  display: block;
}

.section-head {
  margin-bottom: 18px;
}

.section-head h2 {
  margin: 0 0 4px;
}

.section-head p {
  margin: 0;
  color: var(--muted);
}

.library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 18px;
}

.book-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.book-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 16px 30px rgba(15, 23, 42, 0.12);
}

.book-thumb {
  height: 260px;
  aspect-ratio: 3 / 4;
  background: linear-gradient(135deg, #dbeafe, #eff6ff);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.book-thumb canvas,
.book-thumb img {
  max-width: 100%;
  max-height: 100%;
  display: block;
}

.book-thumb-placeholder {
  color: #1e40af;
  font-weight: 700;
  text-align: center;
  padding: 16px;
}

.book-info {
  padding: 14px;
}

.book-info h3 {
  margin: 0 0 8px;
  font-size: 1rem;
  line-height: 1.35;
}

.book-info p {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 0.9rem;
  word-break: break-word;
}

.book-links {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.reader-layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 18px;
}

.reader-sidebar,
.reader-main {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.reader-sidebar {
  padding: 18px;
  height: calc(100vh - 118px);
  position: sticky;
  top: 94px;
  overflow: auto;
}

.book-meta {
  display: none !important;
}

.small-link {
  font-size: 0.85rem;
  color: #1d4ed8;
  word-break: break-all;
}

.search-panel label {
  display: block;
  margin-bottom: 8px;
  font-weight: 600;
}

.search-box {
  display: flex;
  gap: 8px;
}

.search-box input {
  flex: 1;
  min-width: 0;
}

.search-actions {
  margin-top: 10px;
}

.search-summary {
  margin-top: 12px;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.5;
}

.search-results {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.search-result-item {
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 14px;
  padding: 12px;
  cursor: pointer;
  transition: 0.16s ease;
}

.search-result-item:hover {
  border-color: #93c5fd;
  background: #eff6ff;
  transform: translateY(-2px);
}

.search-result-item strong {
  display: block;
  margin-bottom: 6px;
}

.search-result-item p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.reader-main {
  position: relative;
  padding: 14px;
  min-height: calc(100vh - 118px);
  display: flex;
  flex-direction: column;
}

.reader-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 6px 4px 12px;
}

.toolbar-left,
.toolbar-center,
.toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-bar {
  font-size: 14px;
  color: #374151;
  padding: 0 4px 12px;
  min-height: 20px;
}

.flipbook-stage {
  position: relative;
  flex: 1;
  min-height: 600px;
  height: calc(100vh - 210px);
  border-radius: 18px;
  overflow: hidden;
  background:
    radial-gradient(circle at top left, rgba(191, 219, 254, 0.8), transparent 28%),
    linear-gradient(180deg, #dfeaf9, #ecf3fc 45%, #e8f0fa);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
}

.flipbook {
  width: 100%;
  height: 100%;
  min-height: 560px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.page {
  background: #fff;
  width: 100%;
  height: 100%;
  overflow: hidden;
  border: none !important;
  outline: none !important;
  box-shadow: none !important;
  position: relative;
  will-change: transform;
  backface-visibility: hidden;
}

.page-inner {
  position: relative;
  width: 100%;
  height: 100%;
  background: #fff;
  margin: 0 !important;
  padding: 0 !important;
  border: none !important;
  outline: none !important;
  box-shadow: none !important;
}

.page-canvas {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: fill;
  margin: 0 !important;
  padding: 0 !important;
  border: none !important;
  outline: none !important;
  box-shadow: none !important;
  position: relative;
  z-index: 1;
}

.text-layer,
.highlight-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.text-layer {
  z-index: 2;
}

.highlight-layer {
  z-index: 3;
}

.text-item {
  position: absolute;
  white-space: pre;
  transform-origin: 0% 0%;
  color: transparent;
  user-select: text;
  pointer-events: none;
}

.highlight-box {
  position: absolute;
  background: var(--highlight);
  border-radius: 2px;
}

.page-badge {
  position: absolute;
  right: 10px;
  bottom: 10px;
  background: rgba(17, 24, 39, 0.75);
  color: #fff;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  z-index: 4;
}

.loading-overlay {
  position: absolute;
  inset: 14px;
  background: rgba(255, 255, 255, 0.75);
  backdrop-filter: blur(5px);
  z-index: 30;
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
  justify-content: center;
}

.spinner {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 4px solid #dbeafe;
  border-top-color: var(--primary);
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.btn {
  border: none;
  background: var(--primary);
  color: #fff;
  padding: 10px 14px;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 600;
  transition: background 0.16s ease, transform 0.16s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn:hover {
  background: var(--primary-dark);
}

.btn-light {
  background: #eef4ff;
  color: #1e3a8a;
  border: 1px solid #cfe0ff;
}

.btn-light:hover {
  background: #dceaff;
}

.btn-ghost {
  background: white;
  color: var(--text);
  border: 1px solid var(--border);
}

input[type="text"],
input[type="number"] {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 0.96rem;
  outline: none;
  background: white;
}

input[type="text"]:focus,
input[type="number"]:focus {
  border-color: #93c5fd;
  box-shadow: 0 0 0 4px rgba(147, 197, 253, 0.2);
}

#pageInput {
  width: 84px;
}

.empty-state,
.error-state {
  padding: 16px;
  border-radius: 14px;
  background: #fff;
  border: 1px dashed var(--border);
  color: var(--muted);
  text-align: center;
  line-height: 1.5;
}

.error-state {
  color: var(--danger);
}

mark {
  background: #fde68a;
  color: inherit;
  padding: 0 2px;
  border-radius: 4px;
}

@media (max-width: 1100px) {
  .reader-layout {
    grid-template-columns: 1fr;
  }

  .reader-sidebar {
    position: static;
    height: auto;
  }

  .reader-main {
    min-height: 720px;
  }
}

@media (max-width: 768px) {
  .main-layout {
    padding: 14px;
  }

  .topbar {
    padding: 12px 14px;
  }

  .book-thumb {
    height: 220px;
  }

  .reader-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .toolbar-left,
  .toolbar-center,
  .toolbar-right {
    justify-content: center;
    flex-wrap: wrap;
  }

  .flipbook {
    min-height: 500px;
  }

  .loading-overlay {
    inset: 8px;
  }
}
.flipbook .stf__parent {
  margin: 0 auto !important;
}

.flipbook .stf__wrapper {
  margin: 0 auto !important;
}

.flipbook .stf__block {
  margin: 0 auto !important;
}
.flipbook.single-page {
  justify-content: flex-start !important;
}

.flipbook.single-page .stf__parent {
  margin-left: 0 !important;
}
.flipbook,
.flipbook .stf__parent,
.flipbook .stf__wrapper,
.flipbook .stf__block,
.flipbook .stf__item {
  margin: 0 !important;
  padding: 0;
  border: none !important;
  outline: none !important;
  box-shadow: none !important;
  background: transparent !important;
}

.flipbook .stf__block {
  gap: 0 !important;
}
.page,
.page-inner,
.page-canvas,
.flipbook,
.flipbook .stf__parent,
.flipbook .stf__wrapper,
.flipbook .stf__block,
.flipbook .stf__item {
  margin: 0 !important;
  padding: 0;
  border: none !important;
  outline: none !important;
  box-shadow: none !important;
}

.page {
  background: #fff;
  overflow: hidden;
}

.page-inner {
  background: #fff;
}

.page-canvas {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: fill;
}

.flipbook .stf__block {
  gap: 0 !important;
}

.flipbook-stage {
  padding: 0 !important;
}

.flipbook-stage::after {
  display: none !important;
  content: none !important;
}

#bookTitle
{
  display: none !important;
}
#bookFileName
{
  display: none !important;
}
.page-blank .blank-page-inner {
  width: 100%;
  height: 100%;
  background: transparent;
  box-shadow: none;
}

.page-blank {
  background: transparent !important;
}

.page-blank canvas,
.page-blank .text-layer,
.page-blank .page-badge {
  display: none !important;
}
.flipbook .page {
  padding: 0 !important;
}

.page-inner {
  margin: 0 !important;
  padding: 0 !important;
}

.page-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.page {
  background: transparent;
}

/* เอาช่องว่างตรงสันหนังสือออก */
.stf__block {
  gap: 0 !important;
}

.stf__item {
  margin: 0 !important;
}
.stf__item {
  box-shadow: none !important;
}
.page-canvas {
  image-rendering: auto;
  border: none;
}
.flipbook .page {
  padding: 0 !important;
  margin: 0 !important;
}

.page-inner {
  padding: 0 !important;
  margin: 0 !important;
}

.page-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* ลบช่องว่างของ StPageFlip */
.stf__block {
  gap: 0 !important;
}

.stf__item {
  margin: 0 !important;
  padding: 0 !important;
}

.page-canvas{
  margin-left:-1px;
  margin-right:-1px;
}
.reader-layout {
  display: flex;
  width: 100%;
  height: calc(100vh - 72px);
  overflow: hidden;
}

.reader-sidebar {
  flex: 0 0 320px;
  max-width: 320px;
  overflow: auto;
}

.reader-main {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
}
#status-bar
{
  display: none !important;
}
.status-bar
{
  display: none !important;
}

