:root {
  --bg: #f5efe3;
  --bg-accent: #efe4d2;
  --surface: rgba(255, 251, 245, 0.92);
  --surface-strong: rgba(255, 255, 252, 0.98);
  --surface-soft: rgba(246, 239, 230, 0.84);
  --text: #1d2528;
  --muted: #6b7479;
  --line: rgba(88, 71, 47, 0.14);
  --accent: #cc5b31;
  --accent-strong: #a94320;
  --viewer-bg: linear-gradient(180deg, #f4ecdf 0%, #ece0cf 100%);
  --canvas-bg: #ffffff;
  --shadow: 0 8px 22px rgba(40, 30, 19, 0.08);
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 10px;
}

body[data-theme="dark"] {
  --bg: #101417;
  --bg-accent: #172026;
  --surface: rgba(24, 30, 35, 0.92);
  --surface-strong: rgba(30, 37, 43, 0.98);
  --surface-soft: rgba(21, 27, 32, 0.92);
  --text: #eef2f4;
  --muted: #a4b0b7;
  --line: rgba(205, 218, 225, 0.1);
  --accent: #f39a62;
  --accent-strong: #ffb27f;
  --viewer-bg: linear-gradient(180deg, #0f1418 0%, #182128 100%);
  --canvas-bg: #ffffff;
  --shadow: 0 10px 24px rgba(0, 0, 0, 0.22);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background:
    radial-gradient(
      circle at top left,
      rgba(204, 91, 49, 0.1),
      transparent 28%
    ),
    radial-gradient(
      circle at 88% 12%,
      rgba(43, 104, 110, 0.08),
      transparent 24%
    ),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-accent) 100%);
  color: var(--text);
  font-family: "Manrope", sans-serif;
}

body.calendar-open {
  overflow: hidden;
}

button,
select,
iframe {
  font: inherit;
}

button {
  cursor: pointer;
}

a {
  color: inherit;
}

h1,
h2,
p {
  margin: 0;
}

h1,
h2,
.calendar-header strong {
  font-family: "Fraunces", serif;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 8px;
  padding: 8px;
}

.reader-header,
.viewer-panel,
.site-footer {
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, 0.34);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.reader-header,
.site-footer,
.viewer-panel {
  border-radius: var(--radius-lg);
}

.reader-header {
  position: relative;
  z-index: 20;
  display: grid;
  gap: 10px;
  padding: 10px 12px;
}

.reader-top-row {
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  gap: 8px;
}

.reader-top-info {
  flex: 1;
  min-width: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.reader-main-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.reader-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.reader-logo {
  width: 46px;
  height: 46px;
  border-radius: 10px;
  object-fit: cover;
  border: 1px solid var(--line);
}

.reader-brand h1 {
  font-size: clamp(1.25rem, 2.2vw, 1.85rem);
  line-height: 1.02;
}

.reader-description {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.88rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.info-chip,
.calendar-trigger,
.icon-button,
.ad-banner,
.calendar-nav {
  border: 1px solid var(--line);
}

.info-chip,
.calendar-trigger,
.icon-button {
  background: var(--surface-strong);
}

.info-chip {
  min-width: 142px;
  display: grid;
  gap: 2px;
  padding: 7px 10px;
  border-radius: var(--radius-md);
}

.chip-label,
.calendar-trigger-label,
.viewer-kicker,
.calendar-header small,
.footer-meta p {
  color: var(--muted);
}

.chip-label,
.calendar-trigger-label,
.viewer-kicker {
  font-size: 0.64rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.info-chip strong {
  font-size: 0.9rem;
  font-weight: 700;
}

.issue-summary small {
  color: var(--accent-strong);
  font-size: 0.78rem;
  font-weight: 700;
}

.calendar-trigger,
.icon-button,
.calendar-nav {
  transition:
    transform 0.18s ease,
    background-color 0.18s ease,
    border-color 0.18s ease,
    box-shadow 0.18s ease,
    color 0.18s ease;
}

.calendar-wrap {
  position: relative;
}

.calendar-trigger {
  min-width: 210px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 10px;
  border-radius: var(--radius-md);
  text-align: left;
}

.calendar-trigger:hover,
.icon-button:hover,
.calendar-nav:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 14px rgba(40, 30, 19, 0.08);
}

.calendar-trigger-copy {
  display: grid;
  gap: 2px;
}

.calendar-trigger strong {
  font-size: 0.92rem;
}

.calendar-trigger-icon {
  color: var(--accent);
  font-size: 0.92rem;
}

.icon-button {
  width: 40px;
  height: 40px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  border-radius: 999px;
  color: var(--text);
}

.icon-button span {
  font-size: 1rem;
  line-height: 1;
}

.calendar-layer {
  position: fixed;
  inset: 0;
  z-index: 20000;
  display: grid;
  place-items: center;
  padding: 12px;
}

.calendar-layer.hidden {
  display: none;
}

.calendar-backdrop {
  position: absolute;
  inset: 0;
  border: 0;
  background: rgba(14, 16, 18, 0.34);
}

.calendar-popover {
  position: relative;
  z-index: 1;
  width: min(360px, calc(100vw - 24px));
  padding: 12px;
  border-radius: 16px;
  background: var(--surface-strong);
  border: 1px solid var(--line);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.2);
  animation: calendar-in 0.18s ease;
}

.calendar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.calendar-header strong {
  display: block;
  font-size: 0.96rem;
}

.calendar-nav {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--surface-soft);
  color: var(--text);
}

.calendar-weekdays,
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
}

.calendar-weekdays {
  margin-bottom: 6px;
}

.calendar-weekdays span {
  text-align: center;
  color: var(--muted);
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.calendar-day {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  border: 0;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.88);
  color: #1d2528;
  font-size: 0.82rem;
  font-weight: 700;
  transition:
    transform 0.18s ease,
    box-shadow 0.18s ease,
    background-color 0.18s ease;
}

body[data-theme="dark"] .calendar-day {
  background: rgba(233, 238, 242, 0.9);
}

.calendar-day:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 14px rgba(40, 30, 19, 0.08);
}

.calendar-day.is-muted {
  opacity: 0.34;
}

.calendar-day.is-today::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 6px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  transform: translateX(-50%);
}

.calendar-day.is-selected {
  background: linear-gradient(135deg, var(--accent) 0%, #e07a49 100%);
  color: #fffdf8;
  box-shadow: 0 8px 16px rgba(204, 91, 49, 0.18);
}

.viewer-shell {
  min-height: 0;
}

.viewer-panel {
  min-height: 100%;
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
}

.viewer-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 250, 244, 0.42);
}

body[data-theme="dark"] .viewer-topbar {
  background: rgba(19, 24, 30, 0.52);
}

.viewer-topbar h2 {
  font-size: clamp(1rem, 1.8vw, 1.3rem);
}

.viewer-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.viewer-date-trigger {
  min-width: 210px;
}

.viewer-stage {
  position: relative;
  min-height: clamp(560px, calc(100vh - 190px), 980px);
  background: var(--viewer-bg);
}

.viewer-stage-content {
  width: 100%;
  height: 100%;
  padding: 8px;
}

.viewer-empty-state {
  width: 100%;
  height: 100%;
  min-height: inherit;
  display: grid;
  place-items: center;
  padding: 12px;
}

.viewer-empty-card {
  width: min(520px, 100%);
  padding: 28px 24px;
  border-radius: 20px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 20px 42px rgba(18, 21, 24, 0.1);
  text-align: center;
}

body[data-theme="dark"] .viewer-empty-card {
  background: rgba(24, 30, 35, 0.9);
  box-shadow: 0 20px 42px rgba(0, 0, 0, 0.28);
}

.viewer-empty-kicker {
  color: var(--accent-strong);
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.viewer-empty-card h3 {
  margin: 10px 0 8px;
  font-family: "Fraunces", serif;
  font-size: clamp(1.4rem, 2.5vw, 2rem);
}

.viewer-empty-card p:last-child {
  color: var(--muted);
  font-size: 0.98rem;
  line-height: 1.6;
}

.pdf-scroll-shell,
.pdf-frame {
  width: 100%;
  height: 100%;
  min-height: clamp(540px, calc(100vh - 206px), 960px);
  border-radius: 12px;
}

.pdf-scroll-shell {
  overflow: auto;
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.25),
    rgba(255, 255, 255, 0.08)
  );
  padding: 10px 12px 22px;
}

body[data-theme="dark"] .pdf-scroll-shell {
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.05),
    rgba(255, 255, 255, 0.02)
  );
}

.pdf-scroll-shell .pdfViewer {
  padding-bottom: 24px;
}

.pdf-scroll-shell .pdfViewer .page {
  margin: 0 auto 18px;
  border: 0;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 18px 34px rgba(18, 21, 24, 0.12);
}

body[data-theme="dark"] .pdf-scroll-shell .pdfViewer .page {
  box-shadow: 0 18px 34px rgba(0, 0, 0, 0.28);
}

.pdf-frame {
  border: 0;
  background: var(--canvas-bg);
}

.hidden {
  display: none !important;
}

.viewer-status {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.88);
  color: #1f282b;
  font-size: 0.78rem;
  font-weight: 700;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.08);
}

.viewer-status[data-state="fallback"] {
  background: rgba(249, 226, 206, 0.94);
}

.viewer-status[data-state="error"] {
  background: rgba(255, 219, 219, 0.95);
}

.site-footer {
  display: grid;
  gap: 8px;
  padding: 10px 12px;
}

.ad-banner {
  min-height: 64px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-md);
  background: linear-gradient(
    135deg,
    rgba(204, 91, 49, 0.12),
    rgba(43, 104, 110, 0.08)
  );
  color: var(--muted);
  font-weight: 700;
}

.footer-meta {
  display: grid;
  gap: 4px;
}

.footer-meta a {
  color: var(--accent-strong);
}

@keyframes calendar-in {
  from {
    opacity: 0;
    transform: translateY(6px) scale(0.98);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (min-width: 1100px) {
  .viewer-stage {
    min-height: clamp(700px, calc(100vh - 170px), 1180px);
  }

  .pdf-scroll-shell,
  .pdf-frame {
    min-height: clamp(680px, calc(100vh - 188px), 1160px);
  }
}

@media (max-width: 960px) {
  .reader-top-info {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .info-chip {
    min-width: 0;
  }

  .viewer-date-trigger {
    min-width: 0;
    width: 100%;
  }

  .viewer-topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .viewer-actions {
    justify-content: space-between;
  }
}

@media (max-width: 640px) {
  .app-shell {
    gap: 6px;
    padding: 6px;
  }

  .reader-header,
  .site-footer {
    padding: 9px 10px;
  }

  .reader-top-row {
    gap: 6px;
  }

  .reader-top-info {
    gap: 6px;
  }

  .reader-logo {
    width: 40px;
    height: 40px;
  }

  .reader-description {
    white-space: normal;
  }

  .viewer-stage {
    min-height: calc(100vh - 230px);
  }

  .pdf-scroll-shell,
  .pdf-frame {
    min-height: calc(100vh - 246px);
  }
}
