/* ===== CSS VARIABLES ===== */
:root {
  --bg:            #0a0a0a;
  --surface:       #141414;
  --surface-hover: #1a1a1a;
  --border:        #1e1e1e;
  --text:          #f0f0f0;
  --text-muted:    #888888;
  --accent:        #e8c468; /* overridden per domain by JS */
  --accent-dark:   #c9a84c;
  --radius:        6px;
  --max-width:     800px;
  --header-h:      52px;
  /* Minimum tap target size per iOS HIG / WCAG */
  --tap-min:       44px;
}

/* ===== RESET ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html  { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body  {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;        /* 16px base prevents iOS auto-zoom on inputs */
  line-height: 1.5;
  min-height: 100vh;
  /* Prevent horizontal overflow on mobile */
  overflow-x: hidden;
}
a      { color: inherit; text-decoration: none; }
button { cursor: pointer; border: none; background: none; color: inherit; font: inherit;
         /* Ensure tappable area */
         min-height: var(--tap-min); }
img    { display: block; max-width: 100%; }
ul     { list-style: none; }

/* ===== SHARED HEADER ===== */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  /* Mobile: tight padding */
  padding: 0 16px;
}

.site-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

/* Square badge — rendered in CSS, no image asset needed */
.logo-mark {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 900;
  background: var(--accent);
  color: #0a0a0a;
  flex-shrink: 0;
  user-select: none;
}

/* Mobile: hide site name to save space; show from tablet up */
.site-logo__name { display: none; }

/* ===== HOMEPAGE — CHAPTER LIST ===== */
.page-main {
  max-width: var(--max-width);
  margin: 0 auto;
  /* Mobile: smaller vertical padding, leave room for sticky ad */
  padding: 16px 0 80px;
}

/* "Continue reading" banner */
.continue-reading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin: 0 16px 16px;
}
.continue-reading__label   { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }
.continue-reading__chapter { font-weight: 600; font-size: 14px; margin-top: 2px; }
.continue-reading__btn {
  background: var(--accent);
  color: #0a0a0a;
  padding: 0 16px;
  height: var(--tap-min);
  border-radius: var(--radius);
  font-weight: 700;
  font-size: 13px;
  white-space: nowrap;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  transition: background 0.15s;
}
.continue-reading__btn:hover { background: var(--accent-dark); }

/* Chapter list rows */
.chapter-list { margin-bottom: 4px; }

.chapter-item {
  display: flex;
  align-items: center;
  /* Mobile: generous tap target height */
  min-height: var(--tap-min);
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  /* Smooth press feedback on mobile */
  -webkit-tap-highlight-color: transparent;
  transition: background 0.1s;
}
.chapter-item:first-child { border-top: 1px solid var(--border); }
.chapter-item:hover,
.chapter-item:active       { background: var(--surface-hover); }

.chapter-item__num {
  color: var(--accent);
  font-weight: 700;
  font-size: 14px;
  min-width: 56px;
  flex-shrink: 0;
}
.chapter-item__title {
  flex: 1;
  font-size: 15px;
  /* Truncate long titles on small screens */
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  padding-right: 8px;
}
.chapter-item__arrow { color: var(--text-muted); font-size: 20px; flex-shrink: 0; }

/* Infinite-scroll sentinel & loader */
.sentinel { height: 1px; }
.loading-indicator {
  text-align: center;
  color: var(--text-muted);
  padding: 24px;
  font-size: 14px;
}

/* ===== AD SLOTS ===== */
.ad-slot {
  min-height: 0;       /* collapses when empty */
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 12px 0;
}

/* Sticky bottom banner (mobile-optimised 320×50) */
.ad-slot--sticky {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 200;
  margin: 0;
  background: transparent;
  pointer-events: none;
}
.ad-slot--sticky > * { pointer-events: all; }

/* ===== READER — HEADER ===== */
.reader-header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  /* Mobile: tight, no wasted space */
  padding: 0 8px;
  gap: 6px;
}

.back-btn {
  color: var(--text-muted);
  font-size: 13px;
  padding: 0 8px;
  height: var(--tap-min);
  border-radius: var(--radius);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.1s, background 0.1s;
  white-space: nowrap;
}
.back-btn:hover,
.back-btn:active { color: var(--text); background: var(--surface-hover); }

.reader-nav {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  justify-content: center;
  min-width: 0;
}

.nav-btn {
  width: var(--tap-min);
  height: var(--tap-min);
  background: var(--surface-hover);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s, color 0.15s;
}
.nav-btn:hover,
.nav-btn:active             { background: var(--accent); color: #0a0a0a; }
.nav-btn:disabled           { opacity: 0.35; cursor: not-allowed; }
.nav-btn:disabled:hover,
.nav-btn:disabled:active    { background: var(--surface-hover); color: inherit; }

/* Mobile: compact select; expands on larger screens */
.chapter-select {
  background: var(--surface-hover);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 0 8px;
  height: var(--tap-min);
  font-size: 13px;
  /* Constrain on mobile so it doesn't overflow */
  max-width: 160px;
  min-width: 0;
  flex: 1;
  cursor: pointer;
  /* Prevent default iOS styling */
  -webkit-appearance: none;
  appearance: none;
}
.chapter-select:focus { outline: 1px solid var(--accent); }

/* ===== READER — SCROLL PROGRESS ===== */
.scroll-progress {
  position: fixed;
  top: var(--header-h);
  left: 0;
  height: 2px;
  background: var(--accent);
  width: 0%;
  z-index: 99;
  transition: width 0.08s linear;
  pointer-events: none;
}

/* ===== READER — CONTENT ===== */
.reader-main {
  max-width: var(--max-width);
  margin: 0 auto;
  /* Mobile: no side padding — images go edge-to-edge */
  padding: 0 0 80px;
}

.chapter-info {
  text-align: center;
  padding: 20px 16px 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}
.chapter-info__num   { font-size: 12px; color: var(--text-muted); margin-bottom: 4px; letter-spacing: 0.3px; }
.chapter-info__title { font-size: 18px; font-weight: 700; }

/* Pages — column layout, images are full-width on mobile */
.pages-container { display: flex; flex-direction: column; }

.page-wrapper {
  position: relative;
  background: var(--surface);
  line-height: 0;
}

.page-img {
  width: 100%;
  height: auto;
  display: none; /* shown via JS after load */
}

/* Skeleton placeholder — aspect ratio approximates manga page */
.page-placeholder {
  width: 100%;
  /* Use aspect-ratio to avoid layout jump while loading */
  aspect-ratio: 2 / 3;
  min-height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 13px;
  background: var(--surface);
}

/* Bottom chapter navigation — stacked on mobile */
.chapter-end-nav {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 24px 16px;
}
.nav-btn-large {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0 24px;
  height: var(--tap-min);
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.15s, color 0.15s;
}
.nav-btn-large:hover,
.nav-btn-large:active         { border-color: var(--accent); color: var(--accent); }
.nav-btn-large:disabled       { opacity: 0.35; cursor: not-allowed; }
.nav-btn-large:disabled:hover,
.nav-btn-large:disabled:active { border-color: var(--border); color: inherit; }

/* ===== UTILITIES ===== */
.hidden { display: none !important; }

/* ===== TABLET (≥ 600px) ===== */
@media (min-width: 600px) {
  body { font-size: 15px; }

  .site-header    { padding: 0 20px; }
  .site-logo      { font-size: 18px; }
  .site-logo__name { display: inline; }  /* show site name */

  .page-main      { padding: 24px 20px 80px; }

  .continue-reading       { margin: 0 0 24px; padding: 14px 18px; }
  .continue-reading__chapter { font-size: 15px; }

  .chapter-item           { padding: 14px 16px; }
  .chapter-item__num      { min-width: 64px; }
  .chapter-item__title    { white-space: normal; }  /* allow wrapping on larger screens */

  .reader-header  { padding: 0 16px; gap: 12px; }
  .back-btn       { font-size: 14px; padding: 0 10px; }
  .reader-nav     { gap: 8px; }
  .chapter-select { font-size: 14px; max-width: 220px; }

  .chapter-info           { padding: 28px 20px 20px; }
  .chapter-info__title    { font-size: 20px; }

  .chapter-end-nav        { flex-direction: row; justify-content: center; padding: 32px 20px; gap: 12px; }
  .nav-btn-large          { width: auto; }
}

/* ===== DESKTOP (≥ 900px) ===== */
@media (min-width: 900px) {
  .chapter-item:hover { background: var(--surface-hover); }
}
