/* ==========================================================
   Magazine Reader
   Self-contained styles for pages/magazines/read.php
   ========================================================== */

:root {
  --mr-bg: #0b0f17;
  --mr-chrome: rgba(10, 14, 22, 0.82);
  --mr-line: rgba(148, 163, 184, 0.16);
  --mr-text: #f1f5f9;
  --mr-muted: #94a3b8;
  --mr-accent: #2563eb;
  --mr-paper: #eae7df;
  --mr-bar-top: 3.5rem;
  --mr-bar-bottom: 3.25rem;
  --mr-ease: cubic-bezier(0.22, 1, 0.36, 1);
  --mr-turn: 720ms;
  --page-w: 300px;
  --page-h: 420px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

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

body.mr-body {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--mr-bg);
  color: var(--mr-text);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

button,
input,
a {
  font: inherit;
  color: inherit;
}

img {
  display: block;
}

[hidden] {
  display: none !important;
}

:focus-visible {
  outline: 2px solid #60a5fa;
  outline-offset: 2px;
}

.mr {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

/* ---------- Chrome bars ---------- */
.mr-bar {
  flex: 0 0 auto;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.85rem;
  background: var(--mr-chrome);
  backdrop-filter: blur(18px) saturate(1.3);
  -webkit-backdrop-filter: blur(18px) saturate(1.3);
}

.mr-bar--top {
  min-height: var(--mr-bar-top);
  justify-content: space-between;
  border-bottom: 1px solid var(--mr-line);
}

.mr-bar--bottom {
  min-height: var(--mr-bar-bottom);
  justify-content: center;
  gap: 0.85rem;
  border-top: 1px solid var(--mr-line);
}

.mr-bar__group {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  min-width: 0;
}

.mr-bar__group--start {
  flex: 1 1 auto;
}

.mr-bar__group--end {
  flex: 0 0 auto;
}

.mr-heading {
  min-width: 0;
  padding-left: 0.2rem;
}

.mr-heading__title {
  margin: 0;
  font-size: 0.875rem;
  font-weight: 600;
  letter-spacing: -0.012em;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: min(40vw, 30rem);
}

.mr-heading__meta {
  margin: 0.12rem 0 0;
  font-size: 0.7rem;
  color: var(--mr-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mr-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  height: 2.3rem;
  min-width: 2.3rem;
  padding: 0 0.55rem;
  border: 1px solid var(--mr-line);
  border-radius: 0.5rem;
  background: rgba(148, 163, 184, 0.06);
  color: var(--mr-text);
  text-decoration: none;
  cursor: pointer;
  transition: background 160ms ease, border-color 160ms ease, opacity 160ms ease;
}

.mr-btn:hover {
  background: rgba(37, 99, 235, 0.24);
  border-color: rgba(96, 165, 250, 0.42);
}

.mr-btn[disabled] {
  opacity: 0.35;
  cursor: default;
  background: rgba(148, 163, 184, 0.06);
  border-color: var(--mr-line);
}

.mr-btn svg {
  width: 1.05rem;
  height: 1.05rem;
  flex: 0 0 auto;
}

.mr-btn__text {
  font-size: 0.78rem;
  font-weight: 550;
}

.mr-count {
  padding: 0 0.6rem;
  font-size: 0.76rem;
  font-variant-numeric: tabular-nums;
  color: var(--mr-muted);
  white-space: nowrap;
}

.mr-range {
  flex: 1 1 auto;
  max-width: 32rem;
  height: 1.5rem;
  accent-color: var(--mr-accent);
  cursor: pointer;
  background: transparent;
}

/* ---------- Stage ---------- */
.mr-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  padding: 1rem;
  background:
    radial-gradient(ellipse 60% 50% at 50% 40%, rgba(37, 99, 235, 0.16), transparent 65%),
    radial-gradient(ellipse 50% 40% at 50% 100%, rgba(2, 6, 23, 0.9), transparent 60%),
    var(--mr-bg);
}

.mr-stage.is-zoomed {
  overflow: auto;
}

.mr-canvas {
  position: relative;
  margin: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.1rem;
  flex: 0 0 auto;
  min-width: 0;
}

/* ---------- Book ---------- */
.mr-book {
  position: relative;
  flex: 0 0 auto;
  width: calc(var(--page-w) * 2);
  height: var(--page-h);
  transform-style: preserve-3d;
  perspective: 2600px;
  transition: width 420ms var(--mr-ease), height 220ms var(--mr-ease);
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
}

.mr-book.is-single {
  width: var(--page-w);
}

.mr-book.is-cover {
  cursor: pointer;
}

/* Page slots */
.mr-slot {
  position: absolute;
  top: 0;
  width: var(--page-w);
  height: var(--page-h);
  overflow: hidden;
  background: var(--mr-paper);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
}

.mr-slot--left {
  left: 0;
  border-radius: 3px 0 0 3px;
}

.mr-slot--right {
  right: 0;
  border-radius: 0 3px 3px 0;
}

/* Keep pages a fixed size while the frame animates open / closed */
.mr-book.is-single .mr-slot {
  left: 50%;
  right: auto;
  width: var(--page-w);
  margin-left: calc(var(--page-w) / -2);
  border-radius: 3px;
}

.mr-book.is-single .mr-slot.is-empty {
  display: none;
}

/* Empty side = inner board of the book, never a white gap */
.mr-slot.is-empty {
  background:
    linear-gradient(115deg, rgba(2, 6, 23, 0.96), rgba(15, 23, 42, 0.88));
  box-shadow: inset 0 0 60px rgba(0, 0, 0, 0.6);
}

.mr-slot img {
  width: 100%;
  height: 100%;
  object-fit: fill;
  pointer-events: none;
  -webkit-user-drag: none;
}

/* Inner shadow along the spine */
.mr-slot--left::after,
.mr-slot--right::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  width: 9%;
  pointer-events: none;
}

.mr-slot--left::after {
  right: 0;
  background: linear-gradient(to left, rgba(0, 0, 0, 0.26), transparent);
}

.mr-slot--right::after {
  left: 0;
  background: linear-gradient(to right, rgba(0, 0, 0, 0.26), transparent);
}

.mr-book.is-single .mr-slot::after {
  display: none;
}

.mr-gutter {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 2px;
  transform: translateX(-1px);
  background: rgba(0, 0, 0, 0.45);
  pointer-events: none;
  opacity: 1;
  transition: opacity 200ms ease;
}

.mr-book.is-single .mr-gutter {
  opacity: 0;
}

/* Turning sheet */
.mr-sheet {
  position: absolute;
  top: 0;
  left: var(--page-w);
  width: var(--page-w);
  height: var(--page-h);
  z-index: 6;
  transform-style: preserve-3d;
  transform-origin: left center;
  transform: rotateY(0deg);
  transition: transform var(--mr-turn) cubic-bezier(0.42, 0.05, 0.24, 1);
  will-change: transform;
}

.mr-book.is-single .mr-sheet {
  left: 0;
}

.mr-sheet.is-turned {
  transform: rotateY(-180deg);
}

.mr-sheet__face {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: var(--mr-paper);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}

.mr-sheet__face--back {
  transform: rotateY(180deg);
}

.mr-sheet__face img {
  width: 100%;
  height: 100%;
  object-fit: fill;
  pointer-events: none;
}

/* Edge navigation */
.mr-edge {
  position: absolute;
  top: 50%;
  z-index: 12;
  width: 2.9rem;
  height: 2.9rem;
  margin-top: -1.45rem;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.62);
  backdrop-filter: blur(10px);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 160ms ease, transform 160ms ease, opacity 160ms ease;
}

.mr-edge svg {
  width: 1.4rem;
  height: 1.4rem;
}

.mr-edge:hover {
  background: rgba(37, 99, 235, 0.7);
  transform: scale(1.06);
}

.mr-edge[disabled] {
  opacity: 0;
  pointer-events: none;
}

.mr-edge--prev {
  left: 0.85rem;
}

.mr-edge--next {
  right: 0.85rem;
}

/* Open magazine call to action */
.mr-open {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  height: 2.85rem;
  padding: 0 1.5rem;
  border: 0;
  border-radius: 0.55rem;
  background: var(--mr-accent);
  color: #fff;
  font-size: 0.875rem;
  font-weight: 650;
  cursor: pointer;
  box-shadow: 0 16px 34px rgba(37, 99, 235, 0.35);
  transition: background 160ms ease, transform 160ms ease;
}

.mr-open:hover {
  background: #1d4ed8;
  transform: translateY(-1px);
}

.mr-open svg {
  width: 1.05rem;
  height: 1.05rem;
}

/* ---------- Overlays ---------- */
.mr-overlay {
  position: absolute;
  inset: 0;
  z-index: 25;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: rgba(8, 12, 20, 0.97);
  transition: opacity 320ms ease;
}

.mr-overlay.is-hiding {
  opacity: 0;
  pointer-events: none;
}

.mr-overlay__card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  max-width: 21rem;
}

.mr-overlay__cover {
  width: 8.75rem;
  aspect-ratio: 3 / 4;
  overflow: hidden;
  margin-bottom: 1.25rem;
  border-radius: 2px;
  background: #111827;
  box-shadow: 0 26px 56px rgba(0, 0, 0, 0.6);
}

.mr-overlay__cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.mr-overlay__icon {
  width: 2rem;
  height: 2rem;
  color: #f87171;
  margin-bottom: 0.75rem;
}

.mr-overlay__title {
  margin: 0.85rem 0 0;
  font-size: 1rem;
  font-weight: 650;
  line-height: 1.4;
}

.mr-overlay__text {
  margin: 0.4rem 0 0;
  font-size: 0.8125rem;
  color: var(--mr-muted);
}

.mr-overlay__link {
  margin-top: 1.1rem;
  font-size: 0.8125rem;
  font-weight: 600;
  color: #93c5fd;
}

.mr-progress {
  margin-top: 1.1rem;
  width: 11rem;
  height: 0.25rem;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.2);
  overflow: hidden;
}

.mr-progress span {
  display: block;
  width: 6%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--mr-accent), #93c5fd);
  transition: width 280ms ease;
}

.mr-spinner {
  width: 2rem;
  height: 2rem;
  border: 2.5px solid rgba(148, 163, 184, 0.22);
  border-top-color: #93c5fd;
  border-radius: 50%;
  animation: mr-spin 0.8s linear infinite;
}

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

/* ---------- Contents drawer ---------- */
.mr-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  width: min(22rem, 90vw);
  display: flex;
  flex-direction: column;
  background: #0d1220;
  border-left: 1px solid var(--mr-line);
  box-shadow: -24px 0 60px rgba(0, 0, 0, 0.5);
  animation: mr-slide-in 260ms var(--mr-ease);
}

@keyframes mr-slide-in {
  from {
    transform: translateX(100%);
  }
}

.mr-drawer__head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--mr-line);
}

.mr-drawer__title {
  margin: 0;
  font-size: 0.8125rem;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--mr-muted);
}

.mr-thumbs {
  flex: 1 1 auto;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
  padding: 1rem;
}

.mr-thumb {
  border: 1px solid var(--mr-line);
  border-radius: 0.35rem;
  background: rgba(148, 163, 184, 0.06);
  padding: 0;
  cursor: pointer;
  overflow: hidden;
  transition: border-color 160ms ease, transform 160ms ease;
}

.mr-thumb:hover {
  border-color: rgba(96, 165, 250, 0.5);
  transform: translateY(-2px);
}

.mr-thumb.is-active {
  border-color: var(--mr-accent);
  box-shadow: 0 0 0 1px var(--mr-accent);
}

.mr-thumb__media {
  aspect-ratio: 3 / 4;
  background: #111827;
  overflow: hidden;
}

.mr-thumb__media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.mr-thumb__label {
  display: block;
  padding: 0.35rem 0.4rem;
  font-size: 0.7rem;
  font-variant-numeric: tabular-nums;
  color: var(--mr-muted);
}

.mr-scrim {
  position: fixed;
  inset: 0;
  z-index: 45;
  background: rgba(2, 6, 23, 0.6);
  border: 0;
}

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .mr-btn__text {
    display: none;
  }
}

@media (max-width: 900px) {
  .mr-edge {
    width: 2.5rem;
    height: 2.5rem;
    margin-top: -1.25rem;
  }

  .mr-edge--prev {
    left: 0.35rem;
  }

  .mr-edge--next {
    right: 0.35rem;
  }
}

@media (max-width: 767px) {
  .mr-bar {
    padding: 0.45rem 0.6rem;
  }

  .mr-heading__title {
    max-width: 46vw;
    font-size: 0.8125rem;
  }

  .mr-heading__meta {
    display: none;
  }

  .mr-count {
    display: none;
  }

  .mr-btn {
    height: 2.2rem;
    min-width: 2.2rem;
    padding: 0 0.45rem;
  }

  .mr-stage {
    padding: 0.6rem;
  }

  .mr-edge {
    display: none;
  }

  .mr-thumbs {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 420px) {
  .mr-heading__title {
    max-width: 38vw;
  }

  .mr-thumbs {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (prefers-reduced-motion: reduce) {
  .mr-sheet {
    transition-duration: 1ms;
  }

  .mr-book {
    transition: none;
  }

  .mr-drawer {
    animation: none;
  }
}
