:root {
  --primary-dark: #0d0d14;
  --primary-blue: #865DFF;
  --primary-light-blue: #c4b1ff;
  --surface: rgba(25, 24, 37, 0.8);
  --border: rgba(134, 93, 255, 0.2);
  --text: #fff;
  --text-muted: #aaa;
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
  background: transparent;
}

::-webkit-scrollbar-track {
  background: rgba(13, 13, 20, 0.5);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb {
  background: var(--primary-blue);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--primary-light-blue);
}

* {
  scrollbar-width: thin;
  scrollbar-color: var(--primary-blue) rgba(13, 13, 20, 0.5);
}

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

body {
  font-family: 'Montserrat', sans-serif;
  background-color: var(--primary-dark);
  background-image:
    linear-gradient(rgba(134, 93, 255, 0.15) 1px, transparent 1px),
    linear-gradient(90deg, rgba(134, 93, 255, 0.15) 1px, transparent 1px),
    radial-gradient(ellipse at 20% 50%, rgba(134, 93, 255, 0.12) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 30%, rgba(64, 224, 208, 0.08) 0%, transparent 50%);
  background-size: 40px 40px, 40px 40px, 100% 100%, 100% 100%;
  background-attachment: fixed;
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  /* Removed opacity:0 fade-in — it was blocking FCP until CSS animation fired */
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background: radial-gradient(ellipse at 50% 50%, transparent 40%, var(--primary-dark) 100%);
  pointer-events: none;
  z-index: 0;
}

header {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 32px;
  background: var(--surface);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  min-height: 52px;
}

header a {
  color: var(--primary-light-blue);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.5px;
  transition: color 0.2s, transform 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

header a:hover {
  color: #fff;
  transform: translateX(-2px);
}

header a:last-child:hover {
  transform: translateX(2px);
}

.back-link img {
  width: 18px;
  height: 18px;
  opacity: 0.85;
}

.logo {
  font-family: 'Major Mono Display', monospace;
  font-size: 14px;
  color: var(--text);
  letter-spacing: 1px;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  pointer-events: none;
}

.kbd-hint {
  font-size: 11px;
  color: var(--text-muted);
  opacity: 0.6;
  margin-left: 6px;
}

.kbd {
  display: inline-block;
  padding: 1px 5px;
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 3px;
  font-size: 10px;
  font-family: monospace;
  vertical-align: middle;
}

main {
  position: relative;
  z-index: 1;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.pdf-wrapper {
  width: 100%;
  max-width: 860px;
  height: calc(100vh - 140px);
  border-radius: 12px;
  overflow: hidden;
  position: relative;
  background: var(--surface);
  padding: 2px;
  isolation: isolate;
}

.pdf-wrapper::before {
  content: '';
  position: absolute;
  inset: -50%;
  border-radius: 0;
  background: conic-gradient(
    from 0deg,
    rgba(134, 93, 255, 0.7),
    rgba(64, 224, 208, 0.5),
    rgba(134, 93, 255, 0.2),
    rgba(227, 132, 255, 0.5),
    rgba(134, 93, 255, 0.7)
  );
  z-index: -1;
  opacity: 1;
  transition: opacity 0.6s ease;
}

.pdf-wrapper.loaded::before {
  opacity: 0.4;
}


.pdf-inner {
  width: 100%;
  height: 100%;
  border-radius: 10px;
  overflow: hidden;
  background: var(--primary-dark);
  position: relative;
  padding: 12px 0;
}

.pdf-inner::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 10px;
  box-shadow: inset 0 0 12px 4px var(--primary-dark);
  pointer-events: none;
  z-index: 1;
  opacity: 0.2;
}

.pdf-inner iframe {
  width: 100%;
  height: 100%;
  border: none;
  opacity: 0;
  transition: opacity 0.5s ease;
}

.pdf-inner iframe.loaded {
  opacity: 1;
}

/* Loading state */
.loader {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  transition: opacity 0.4s ease;
}

.loader.hidden {
  opacity: 0;
  pointer-events: none;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid rgba(134, 93, 255, 0.2);
  border-top-color: var(--primary-blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.loader p {
  font-size: 13px;
  color: var(--text-muted);
  letter-spacing: 0.3px;
}

.loader .slow-hint {
  font-size: 12px;
  color: var(--text-muted);
  opacity: 0;
  transition: opacity 0.4s ease;
  margin-top: -8px;
}

.loader .slow-hint.visible {
  opacity: 0.7;
}

/* Fallback state */
.fallback {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 32px;
  text-align: center;
}

.fallback.active {
  display: flex;
}

.fallback-icon {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: rgba(134, 93, 255, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
}

.fallback h2 {
  font-size: 18px;
  font-weight: 500;
  color: var(--text);
}

.fallback p {
  font-size: 14px;
  color: var(--text-muted);
  max-width: 400px;
  line-height: 1.6;
}

.fallback-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 28px;
  background: var(--primary-blue);
  color: #fff;
  text-decoration: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  border: none;
  cursor: pointer;
  transition: background 0.2s, transform 0.15s, box-shadow 0.2s;
  box-shadow: 0 2px 12px rgba(134, 93, 255, 0.3);
}

.fallback-btn:hover {
  background: #9b7aff;
  transform: translateY(-1px);
  box-shadow: 0 4px 20px rgba(134, 93, 255, 0.4);
}

.fallback-btn-secondary {
  background: transparent;
  border: 1px solid var(--border);
  box-shadow: none;
  color: var(--primary-light-blue);
}

.fallback-btn-secondary:hover {
  background: rgba(134, 93, 255, 0.1);
  box-shadow: none;
  transform: translateY(-1px);
}

.fallback-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

/* Offline-specific message */
.offline-msg {
  display: none;
}

.fallback.offline .offline-msg {
  display: block;
}

.fallback.offline .online-msg {
  display: none;
}

/* View count - centered above PDF */
.view-count {
  font-family: 'Major Mono Display', monospace;
  font-size: 11px;
  font-weight: 400;
  color: rgba(255, 255, 255, 0.5);
  letter-spacing: 0.5px;
  visibility: hidden;
  opacity: 0;
  transition: opacity 0.4s ease;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 14px;
  min-height: 28px;
  min-width: 100px;
  background: rgba(13, 13, 20, 0.5);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(134, 93, 255, 0.15);
  border-radius: 20px;
  margin-bottom: 10px;
}

.view-count.visible {
  visibility: visible;
  opacity: 1;
}

/* Mobile */
@media (max-width: 768px) {
  header {
    padding: 12px 16px;
  }
  .logo {
    display: none;
  }
  .kbd-hint {
    display: none;
  }
  main {
    padding: 12px;
    flex: 1;
    min-height: 0;
  }
  .pdf-wrapper {
    height: calc(100vh - 130px);
    border-radius: 8px;
  }
  .pdf-inner {
    border-radius: 6px;
    padding: 8px 0;
  }
}
