/* ── Reset & base ─────────────────────────────────────────────────────────── */

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

:root {
  --paper:    #f5f1e8;
  --ink:      #1a1a1a;
  --ink-soft: #6b6b6b;
  --red:      #a8201a;
  --border:   #2a2a2a;
  --font-serif: 'Frank Ruhl Libre', Georgia, serif;
  --font-sans:  'Heebo', Arial, sans-serif;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  background-color: var(--paper);
  color: var(--ink);
  min-height: 100dvh;
  direction: rtl;

  /* Subtle newsprint dot texture */
  background-image: radial-gradient(circle, #c8bfa8 1px, transparent 1px);
  background-size: 24px 24px;
}

/* ── Views ────────────────────────────────────────────────────────────────── */

.view {
  width: 100%;
  min-height: calc(100dvh - 120px); /* minus masthead */
}

.hidden { display: none !important; }

/* ── Masthead ─────────────────────────────────────────────────────────────── */

#masthead {
  background-color: var(--paper);
  border-bottom: 3px double var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  padding: 0.75rem 1rem 0.5rem;
}

.masthead-inner {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 1rem;
}

.masthead-center {
  flex: 1;
  text-align: center;
}

.masthead-title {
  font-family: var(--font-serif);
  font-weight: 900;
  font-size: clamp(2rem, 6vw, 3.5rem);
  line-height: 1;
  letter-spacing: -0.02em;
  color: var(--ink);
  cursor: pointer;
  transition: color 0.15s;
}

.masthead-title:hover { color: var(--red); }

.masthead-rules {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 0.35rem 0 0.25rem;
}

.masthead-rule { background: var(--border); }
.masthead-rule.thick { height: 3px; }
.masthead-rule.thin  { height: 1px; }

.masthead-tagline {
  font-family: var(--font-serif);
  font-size: 0.8rem;
  color: var(--ink-soft);
  font-style: italic;
  letter-spacing: 0.05em;
  min-height: 1em;
}

.masthead-side {
  min-width: 90px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.masthead-right { align-items: flex-end; text-align: right; }
.masthead-left  { align-items: flex-start; text-align: left; }

.masthead-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-soft);
  font-family: var(--font-sans);
}

.masthead-value {
  font-family: var(--font-serif);
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--ink);
}

/* ── Loading view ─────────────────────────────────────────────────────────── */

#loading-view {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  min-height: calc(100dvh - 120px);
}

.spinner {
  width: 48px;
  height: 48px;
}

.spinner-ring {
  width: 100%;
  height: 100%;
  border: 3px solid #ddd6c4;
  border-top-color: var(--red);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

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

.loading-label {
  font-family: var(--font-serif);
  font-size: 1rem;
  color: var(--ink-soft);
  letter-spacing: 0.05em;
}

/* ── Archive view ─────────────────────────────────────────────────────────── */

#archive-container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 2rem 1rem 3rem;
}

.year-section { margin-bottom: 3rem; }

.year-heading {
  font-family: var(--font-serif);
  font-weight: 900;
  font-size: 1.6rem;
  color: var(--ink);
  border-bottom: 2px solid var(--border);
  padding-bottom: 0.4rem;
  margin-bottom: 1.25rem;
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
}

.year-heading::after {
  content: '';
  display: block;
  height: 1px;
  background: var(--border);
  flex: 1;
  opacity: 0.3;
  margin-bottom: 2px;
}

.year-count {
  font-family: var(--font-sans);
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--ink-soft);
}

.issues-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 1.25rem;
}

/* ── Issue card ───────────────────────────────────────────────────────────── */

.issue-card {
  cursor: pointer;
  border: 1px solid var(--border);
  background: #fff;
  box-shadow: 2px 2px 0 var(--border);
  transition: transform 0.15s, box-shadow 0.15s;
  text-decoration: none;
  color: inherit;
  display: flex;
  flex-direction: column;
}

.issue-card:hover,
.issue-card:focus-visible {
  transform: translate(-2px, -2px);
  box-shadow: 4px 4px 0 var(--border);
  outline: none;
}

.issue-card:active {
  transform: translate(0, 0);
  box-shadow: 1px 1px 0 var(--border);
}

.card-thumb {
  width: 100%;
  aspect-ratio: 0.707; /* A4 ratio */
  overflow: hidden;
  background: #e8e2d4;
  position: relative;
}

.card-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: opacity 0.3s;
}

.card-thumb img[src=""] { opacity: 0; }

.card-thumb-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-serif);
  font-size: 2rem;
  color: #c0b89a;
  pointer-events: none;
}

.card-info {
  padding: 0.5rem 0.6rem 0.6rem;
  border-top: 1px solid var(--border);
  background: var(--paper);
}

.card-number {
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--red);
  line-height: 1.2;
}

.card-date {
  font-size: 0.72rem;
  color: var(--ink-soft);
  margin-top: 2px;
  font-family: var(--font-sans);
}

.card-pages {
  font-size: 0.68rem;
  color: #a09080;
  margin-top: 1px;
}

/* ── Home / Featured view ─────────────────────────────────────────────────── */

#home-view {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 2.5rem 1rem 1rem;
  min-height: calc(100dvh - 120px);
}

.featured-card {
  display: flex;
  gap: 2.5rem;
  align-items: flex-start;
  background: #fff;
  border: 1px solid var(--border);
  box-shadow: 4px 4px 0 var(--border);
  padding: 2rem;
  max-width: 700px;
  width: 100%;
}

.featured-thumb-wrap {
  flex-shrink: 0;
}

.featured-thumb {
  width: 220px;
  display: block;
  border: 1px solid #ccc;
  box-shadow: 2px 2px 8px rgba(0,0,0,0.15);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}

.featured-thumb:hover {
  transform: translate(-2px, -2px);
  box-shadow: 4px 4px 12px rgba(0,0,0,0.2);
}

.featured-info {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding-top: 0.5rem;
}

.featured-label {
  font-family: var(--font-sans);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--red);
  font-weight: 700;
}

.featured-number {
  font-family: var(--font-serif);
  font-weight: 900;
  font-size: 2.2rem;
  line-height: 1;
  color: var(--ink);
}

.featured-date {
  font-family: var(--font-serif);
  font-size: 1rem;
  color: var(--ink-soft);
}

.featured-pages {
  font-size: 0.8rem;
  color: #a09080;
  margin-bottom: 0.5rem;
}

.featured-read-btn {
  margin-top: auto;
  background: var(--ink);
  color: var(--paper);
  border: none;
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: 1rem;
  padding: 0.65rem 1.5rem;
  cursor: pointer;
  transition: background 0.15s;
  align-self: flex-start;
}

.featured-read-btn:hover { background: var(--red); }

.home-archive-btn-wrap {
  margin-top: 2rem;
}

.archive-link-btn {
  background: transparent;
  border: none;
  font-family: var(--font-sans);
  font-size: 0.9rem;
  color: var(--ink-soft);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
  padding: 0;
  transition: color 0.15s;
}

.archive-link-btn:hover { color: var(--red); }

/* ── Archive topbar ────────────────────────────────────────────────────────── */

.archive-topbar {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem 1rem 0;
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.archive-heading {
  font-family: var(--font-serif);
  font-weight: 900;
  font-size: 1.4rem;
  color: var(--ink);
}

.back-link-btn {
  background: transparent;
  border: none;
  font-family: var(--font-sans);
  font-size: 0.85rem;
  color: var(--ink-soft);
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
  text-underline-offset: 3px;
  transition: color 0.15s;
  white-space: nowrap;
}

.back-link-btn:hover { color: var(--red); }

/* ── Responsive featured ──────────────────────────────────────────────────── */

@media (max-width: 580px) {
  .featured-card {
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 1.25rem;
    gap: 1.25rem;
  }

  .featured-thumb { width: 160px; }

  .featured-info { align-items: center; }

  .featured-read-btn { align-self: center; }

  .archive-topbar { flex-direction: column; align-items: flex-start; gap: 0.5rem; }
}

/* ── Viewer view ──────────────────────────────────────────────────────────── */

#viewer-view {
  display: flex;
  flex-direction: column;
  height: calc(100dvh - 120px);
  overflow: hidden;
  background: #2c2824;
  background-image: radial-gradient(circle, #3a3330 1px, transparent 1px);
  background-size: 20px 20px;
}

#viewer-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 1rem;
  background: rgba(26, 22, 18, 0.92);
  backdrop-filter: blur(4px);
  border-bottom: 1px solid #3a3330;
  flex-shrink: 0;
  gap: 1rem;
  z-index: 10;
}

.viewer-btn {
  background: transparent;
  border: 1px solid #5a5550;
  color: #d4cfc8;
  padding: 0.3rem 0.75rem;
  font-family: var(--font-sans);
  font-size: 0.8rem;
  cursor: pointer;
  border-radius: 2px;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}

.viewer-btn:hover { background: #3a3330; color: #fff; }

.viewer-btn-group { display: flex; gap: 0.5rem; }

.icon-btn { padding: 0.3rem 0.5rem; font-size: 1rem; line-height: 1; }

.page-indicator {
  font-family: var(--font-serif);
  font-size: 0.85rem;
  color: #a0998e;
  text-align: center;
  flex: 1;
  white-space: nowrap;
}

/* ── PDF Spread layout ────────────────────────────────────────────────────── */

#spread-wrap {
  flex: 1;
  position: relative;   /* anchor for absolute nav buttons */
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

#spread-container {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

#canvas-right,
#canvas-left {
  display: block;
  max-width: 100%;
  max-height: 100%;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.7);
  background: #fff;
}

/* ── Navigation buttons — float over the canvas ───────────────────────────── */

.nav-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 5;
  background: rgba(20, 16, 12, 0.5);
  border: 1px solid rgba(200, 190, 175, 0.25);
  color: #d4cfc8;
  width: 2.75rem;
  height: 6rem;
  font-size: 1.2rem;
  cursor: pointer;
  border-radius: 3px;
  transition: background 0.15s, opacity 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.5;
}

.nav-btn-left  { left:  0.4rem; }
.nav-btn-right { right: 0.4rem; }

.nav-btn:hover    { background: rgba(40, 32, 24, 0.9); opacity: 1; }
.nav-btn:disabled { opacity: 0.1; cursor: default; pointer-events: none; }

/* ── Fullscreen ───────────────────────────────────────────────────────────── */

#viewer-view:fullscreen,
#viewer-view:-webkit-full-screen {
  height: 100dvh;
  background: #1a1410;
}

/* ── Error toast ──────────────────────────────────────────────────────────── */

.error-toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: #7a1515;
  color: #fff;
  padding: 0.75rem 1.5rem;
  font-size: 0.9rem;
  font-family: var(--font-sans);
  border-radius: 3px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
  z-index: 999;
  max-width: 90vw;
  text-align: center;
}

/* ── Responsive ───────────────────────────────────────────────────────────── */

@media (max-width: 600px) {
  .masthead-side { display: none; }

  .masthead-title { font-size: 2rem; }

  .issues-grid {
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 0.85rem;
  }

  #flipbook-wrap { padding: 0.5rem 2.5rem; }

  .flip-nav { width: 2rem; height: 4rem; }
}

@media (max-width: 380px) {
  .issues-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ── Print (hide interactive chrome) ─────────────────────────────────────── */

@media print {
  #masthead, #viewer-topbar, .flip-nav { display: none; }
}
