/* ============================================================
   Ironshelf — CBZ/Comic Reader Styles
   ============================================================ */

/* --- Container --- */
.cbz-reader-container {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  background: #1a1a1a;
  color: #e8e4da;
  font-family: 'Inter', sans-serif;
}

/* --- Toolbar --- */
.cbz-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  background: rgba(15, 17, 21, 0.97);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 10;
  flex-shrink: 0;
  gap: 8px;
}

.cbz-toolbar-left,
.cbz-toolbar-center,
.cbz-toolbar-right {
  display: flex;
  align-items: center;
  gap: 4px;
}

.cbz-toolbar-left {
  flex: 1;
  min-width: 0;
}

.cbz-toolbar-center {
  flex-shrink: 0;
}

.cbz-toolbar-right {
  flex: 1;
  justify-content: flex-end;
  gap: 6px;
}

.cbz-title {
  font-size: 13px;
  font-weight: 500;
  color: rgba(232, 228, 218, 0.8);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-left: 8px;
  min-width: 0;
}

/* --- Buttons --- */
.cbz-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: rgba(232, 228, 218, 0.85);
  cursor: pointer;
  transition: background 150ms ease, color 150ms ease;
  flex-shrink: 0;
  padding: 0;
}

.cbz-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #e8e4da;
}

.cbz-btn:focus-visible {
  outline: 2px solid #3BB3C9;
  outline-offset: 2px;
}

.cbz-btn svg {
  width: 18px;
  height: 18px;
}

.cbz-btn-active {
  background: rgba(59, 179, 201, 0.15);
  color: #3BB3C9;
}

.cbz-btn-active:hover {
  background: rgba(59, 179, 201, 0.25);
}

/* --- Select dropdowns --- */
.cbz-select {
  height: 28px;
  padding: 0 8px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.06);
  color: #e8e4da;
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23999' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 6px center;
  padding-right: 22px;
}

.cbz-select:focus {
  outline: none;
  border-color: #3BB3C9;
}

.cbz-select option {
  background: #1a1a1a;
  color: #e8e4da;
}

/* --- Page Navigation Input --- */
.cbz-page-nav {
  display: flex;
  align-items: center;
  gap: 4px;
}

.cbz-page-input {
  width: 48px;
  height: 28px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.06);
  color: #e8e4da;
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  text-align: center;
  padding: 0 4px;
  -moz-appearance: textfield;
}

.cbz-page-input::-webkit-inner-spin-button,
.cbz-page-input::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.cbz-page-input:focus {
  outline: none;
  border-color: #3BB3C9;
}

.cbz-page-total {
  font-size: 13px;
  color: rgba(232, 228, 218, 0.6);
  white-space: nowrap;
}

/* --- Body --- */
.cbz-body {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  position: relative;
}

/* --- Viewport --- */
.cbz-viewport {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  outline: none;
  -webkit-overflow-scrolling: touch;
}

/* --- Page Display --- */
.cbz-page-display {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100%;
  padding: 8px;
}

/* Continuous mode: stack pages vertically */
.cbz-page-display.cbz-display-continuous {
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 0;
}

.cbz-continuous-page {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
}

/* --- Image Fit Modes --- */
.cbz-page-image {
  display: block;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
}

/* Fit Width */
.cbz-fit-fit-width .cbz-page-image {
  width: 100%;
  max-height: none;
  object-fit: contain;
}

.cbz-fit-fit-width.cbz-display-continuous .cbz-page-image {
  width: 100%;
  max-height: none;
}

/* Fit Height */
.cbz-fit-fit-height .cbz-page-image {
  height: calc(100vh - 130px); /* toolbar + thumbnail strip */
  width: auto;
  max-width: 100%;
}

.cbz-fit-fit-height.cbz-display-continuous .cbz-page-image {
  height: auto;
  max-height: 100vh;
  width: auto;
}

/* Original size */
.cbz-fit-original .cbz-page-image {
  max-width: none;
  max-height: none;
  width: auto;
  height: auto;
}

/* --- Double Page Spread --- */
.cbz-spread {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  max-height: 100%;
}

.cbz-spread .cbz-page-image {
  max-width: 50%;
}

.cbz-spread-rtl {
  flex-direction: row-reverse;
}

/* Fit adjustments for double page */
.cbz-fit-fit-width .cbz-spread .cbz-page-image {
  width: 50%;
  max-width: 50%;
}

.cbz-fit-fit-height .cbz-spread .cbz-page-image {
  height: calc(100vh - 130px);
  max-width: 50%;
  width: auto;
}

/* --- Navigation Arrows --- */
.cbz-nav-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 48px;
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 8px;
  background: rgba(15, 17, 21, 0.6);
  color: rgba(232, 228, 218, 0.7);
  cursor: pointer;
  opacity: 0;
  transition: opacity 200ms ease, background 150ms ease;
  z-index: 5;
}

.cbz-nav-arrow:hover {
  background: rgba(15, 17, 21, 0.85);
  color: #e8e4da;
}

.cbz-nav-arrow:focus-visible {
  outline: 2px solid #3BB3C9;
  outline-offset: 2px;
  opacity: 1;
}

.cbz-nav-arrow svg {
  width: 24px;
  height: 24px;
}

.cbz-nav-arrow-left {
  left: 8px;
}

.cbz-nav-arrow-right {
  right: 8px;
}

.cbz-viewport:hover .cbz-nav-arrow {
  opacity: 1;
}

/* Hide arrows in continuous mode */
.cbz-display-continuous ~ .cbz-nav-arrow-left,
.cbz-display-continuous ~ .cbz-nav-arrow-right {
  display: none;
}

/* --- Thumbnail Strip (Bottom) --- */
.cbz-thumbnail-strip {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 8px;
  background: rgba(15, 17, 21, 0.95);
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  overflow-x: auto;
  overflow-y: hidden;
  flex-shrink: 0;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.15) transparent;
}

.cbz-thumbnail-strip::-webkit-scrollbar {
  height: 4px;
}

.cbz-thumbnail-strip::-webkit-scrollbar-track {
  background: transparent;
}

.cbz-thumbnail-strip::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 2px;
}

.cbz-thumbnail {
  flex-shrink: 0;
  width: 56px;
  height: 72px;
  padding: 2px;
  border: 2px solid transparent;
  border-radius: 4px;
  background: transparent;
  cursor: pointer;
  transition: border-color 150ms ease, opacity 150ms ease;
  overflow: hidden;
}

.cbz-thumbnail:hover {
  border-color: rgba(255, 255, 255, 0.2);
}

.cbz-thumbnail:focus-visible {
  outline: 2px solid #3BB3C9;
  outline-offset: 1px;
}

.cbz-thumbnail-active {
  border-color: #3BB3C9;
}

.cbz-thumbnail img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  border-radius: 2px;
}

/* --- Loading --- */
.cbz-loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: #1a1a1a;
  z-index: 20;
}

.cbz-loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(59, 179, 201, 0.2);
  border-top-color: #3BB3C9;
  border-radius: 50%;
  animation: cbz-spin 0.8s linear infinite;
}

@keyframes cbz-spin {
  to { transform: rotate(360deg); }
}

.cbz-loading-text {
  font-size: 14px;
  color: rgba(232, 228, 218, 0.7);
}

.cbz-loading-progress {
  font-size: 12px;
  color: rgba(232, 228, 218, 0.5);
}

/* --- Error --- */
.cbz-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  text-align: center;
  padding: 24px;
}

.cbz-error-icon {
  width: 48px;
  height: 48px;
  color: #ef4444;
}

.cbz-error-icon svg {
  width: 100%;
  height: 100%;
}

.cbz-error-title {
  font-size: 16px;
  font-weight: 600;
  color: #e8e4da;
}

.cbz-error-message {
  font-size: 13px;
  color: rgba(232, 228, 218, 0.6);
  max-width: 400px;
}

.cbz-error-btn {
  margin-top: 8px;
  padding: 8px 20px;
  border: none;
  border-radius: 8px;
  background: #3BB3C9;
  color: #fff;
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 150ms ease;
}

.cbz-error-btn:hover {
  opacity: 0.85;
}

/* --- Responsive --- */
@media (max-width: 768px) {
  .cbz-toolbar {
    padding: 4px 8px;
    flex-wrap: wrap;
    gap: 4px;
  }

  .cbz-toolbar-left {
    order: 1;
  }

  .cbz-toolbar-center {
    order: 3;
    flex: 1;
    justify-content: center;
  }

  .cbz-toolbar-right {
    order: 2;
    flex: 0;
  }

  .cbz-title {
    display: none;
  }

  .cbz-select {
    display: none;
  }

  .cbz-nav-arrow {
    display: none;
  }

  .cbz-btn {
    width: 36px;
    height: 36px;
  }

  .cbz-thumbnail {
    width: 44px;
    height: 58px;
  }

  .cbz-thumbnail-strip {
    padding: 4px 6px;
  }
}

@media (max-width: 480px) {
  .cbz-thumbnail-strip {
    gap: 2px;
  }

  .cbz-thumbnail {
    width: 36px;
    height: 48px;
  }
}

/* --- Fullscreen --- */
.cbz-reader-container:fullscreen,
.cbz-reader-container:-webkit-full-screen {
  background: #000;
}

.cbz-reader-container:fullscreen .cbz-viewport,
.cbz-reader-container:-webkit-full-screen .cbz-viewport {
  background: #000;
}
