:root {
  --paper-interaction-accent: #ffe600;
  --paper-highlight-fill: rgba(255, 232, 0, 0.66);
  --paper-highlight-edge: rgba(255, 222, 0, 0.96);
  --paper-highlight-solid: #ffe600;
  --paper-highlight-glow: rgba(255, 214, 0, 0.92);
  --paper-interaction-background: #ffffff;
  --paper-interaction-surface: #ffffff;
  --paper-interaction-text: #111111;
  --paper-interaction-muted: #5c564d;
  --paper-interaction-border: #111111;
  --paper-interaction-shadow: 0 18px 50px rgba(17, 17, 17, 0.08);
  --paper-viewer-shell: #ffffff;
}

* {
  box-sizing: border-box;
}

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

body {
  background: var(--paper-interaction-background);
  color: var(--paper-interaction-text);
  font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  overflow-x: hidden;
  overflow-y: auto;
}

.paper-interaction-shell {
  align-items: start;
  background: var(--paper-interaction-background);
  display: grid;
  gap: clamp(20px, 2vw, 36px);
  grid-template-columns: minmax(160px, 1fr) minmax(0, calc(8.5in + 24px)) minmax(160px, 1fr);
  margin: 0 auto;
  max-width: 1760px;
  min-height: 100vh;
  padding: 24px 24px 56px;
  position: relative;
  width: 100%;
}

.paper-viewer-stage {
  background: transparent;
  border: 0;
  box-shadow: none;
  display: flex;
  justify-content: center;
  justify-self: center;
  max-width: calc(8.5in + 24px);
  min-height: calc(100vh - 80px);
  min-width: 0;
  overflow: visible;
  position: relative;
  width: 100%;
}

.paper-pdf-viewer {
  align-items: center;
  background: transparent;
  display: flex;
  flex-direction: column;
  gap: 28px;
  min-height: calc(100vh - 80px);
  overflow: visible;
  padding: 8px 0 56px;
  width: 100%;
}

.page-container {
  margin: 0 auto;
  max-width: 8.5in;
  position: relative;
  transition: transform 140ms ease, box-shadow 180ms ease;
  width: 100%;
}

.page-container.is-deep-linked {
  box-shadow: 0 0 0 8px rgba(255, 242, 0, 0.56), var(--paper-interaction-shadow);
  transform: translateY(-2px);
}

.page-surface {
  background: #ffffff;
  border: 1px solid rgba(17, 17, 17, 0.09);
  box-shadow: 0 16px 28px rgba(17, 17, 17, 0.08);
  height: 100%;
  overflow: hidden;
  position: relative;
  width: 100%;
}

.svg-layer,
.highlight-layer,
.page-text-layer {
  inset: 0;
  position: absolute;
}

.svg-layer {
  z-index: 1;
}

.highlight-layer {
  pointer-events: none;
  z-index: 4;
}

.page-text-layer {
  z-index: 3;
}

.page-svg {
  display: block;
  height: 100%;
  image-rendering: -webkit-optimize-contrast;
  image-rendering: crisp-edges;
  shape-rendering: geometricPrecision;
  text-rendering: geometricPrecision;
  width: 100%;
}

.selection-highlight {
  background: linear-gradient(180deg, rgba(255, 241, 0, 0.82) 0%, var(--paper-highlight-fill) 100%);
  border: 0;
  border-radius: 2px;
  box-shadow:
    inset 0 -1px 0 var(--paper-highlight-edge),
    0 0 0 1px rgba(255, 230, 0, 0.42),
    0 0 10px rgba(255, 230, 0, 0.18);
  cursor: pointer;
  pointer-events: auto;
  position: absolute;
}

.selection-highlight:hover,
.selection-highlight:focus-visible {
  box-shadow:
    inset 0 -1px 0 var(--paper-highlight-edge),
    0 0 0 2px rgba(255, 230, 0, 0.72),
    0 0 14px rgba(255, 230, 0, 0.26);
  outline: none;
}

.page-svg [data-papermache-highlighted="true"] {
  filter: drop-shadow(0 0 1px rgba(247, 205, 0, 0.94)) drop-shadow(0 0 4px var(--paper-highlight-glow));
}

.page-svg [data-papermache-highlighted="true"][data-papermache-asset-type="path"] {
  fill: rgba(255, 238, 0, 0.82) !important;
  stroke: var(--paper-highlight-solid) !important;
  stroke-linejoin: round;
  stroke-width: 2px !important;
}

.textLayer ::selection {
  background: rgba(255, 232, 0, 0.72);
}

.viewer-overlay,
.viewer-empty-state {
  inset: 24px;
  position: absolute;
  z-index: 5;
}

.viewer-overlay {
  align-items: center;
  display: flex;
  justify-content: center;
  pointer-events: none;
}

.viewer-loading-screen {
  background:
    linear-gradient(135deg, rgba(255, 242, 0, 0.12), rgba(255, 255, 255, 0) 38%),
    linear-gradient(180deg, rgba(17, 17, 17, 0.03), rgba(17, 17, 17, 0));
}

.viewer-overlay.is-hidden {
  display: none;
}

.overlay-card,
.empty-card {
  background: var(--paper-interaction-surface);
  border: 2px solid var(--paper-interaction-border);
  box-shadow: var(--paper-interaction-shadow);
  max-width: 480px;
  padding: 24px;
  width: 100%;
}

.overlay-card h1,
.overlay-card h2,
.empty-card h1 {
  font-size: 1.5rem;
  letter-spacing: 0.02em;
  margin: 0 0 10px;
  text-transform: uppercase;
}

.overlay-card p,
.empty-card p {
  color: var(--paper-interaction-muted);
  line-height: 1.6;
  margin: 0;
}

.loading-card {
  display: grid;
  gap: 16px;
  justify-items: center;
  max-width: 560px;
  text-align: center;
}

.loading-meta-row {
  align-items: center;
  display: flex;
  justify-content: space-between;
}

.loading-logo-stack {
  display: grid;
  gap: 14px;
  justify-items: center;
}

.loading-logo-spinner {
  align-items: center;
  animation: loading-logo-spin 1.2s linear infinite;
  background: radial-gradient(circle at 35% 35%, rgba(255, 242, 0, 0.94), rgba(255, 230, 0, 0.34));
  border: 3px solid #111111;
  border-radius: 999px;
  box-shadow: 0 18px 28px rgba(17, 17, 17, 0.14);
  display: flex;
  height: 120px;
  justify-content: center;
  padding: 18px;
  width: 120px;
}

.loading-logo-image {
  display: block;
  height: 72px;
  width: 72px;
}

.loading-kicker {
  background: var(--paper-interaction-accent);
  border: 2px solid #111111;
  display: inline-flex;
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.09em;
  padding: 6px 12px;
  text-transform: uppercase;
}

.loading-progress-track {
  background: rgba(17, 17, 17, 0.08);
  border: 2px solid rgba(17, 17, 17, 0.1);
  height: 16px;
  margin: 18px 0 12px;
  overflow: hidden;
  position: relative;
  width: 100%;
}

.loading-progress-fill {
  background:
    linear-gradient(90deg, #ffe600 0%, #fff200 55%, #fff7a6 100%);
  box-shadow: 0 0 22px rgba(255, 230, 0, 0.44);
  height: 100%;
  transition: width 180ms ease;
  width: 0%;
}

.loading-meta-row {
  color: var(--paper-interaction-muted);
  font-size: 0.82rem;
  font-weight: 700;
  gap: 16px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.viewer-empty-state {
  align-items: center;
  display: flex;
  justify-content: center;
}

.paper-ad-rail {
  display: flex;
  min-height: 0;
}

.paper-ad-rail-inner {
  display: flex;
  justify-content: center;
  min-height: 0;
  overflow: visible;
  width: 100%;
}

.paper-ad-slot {
  max-width: 220px;
  position: sticky;
  top: 24px;
  transition: opacity 180ms ease, transform 180ms ease;
  width: 100%;
}

.paper-ad-slot.is-targeted {
  transform: translateY(-2px);
}

.paper-ad-slot.is-dormant {
  opacity: 0.72;
}

.paper-ad-card {
  background: #fffdf3;
  border: 2px solid #111111;
  box-shadow: 0 14px 28px rgba(17, 17, 17, 0.1);
  padding: 18px;
}

.paper-ad-card-reserve {
  background: #f8f8f8;
  box-shadow: none;
}

.paper-ad-card h2 {
  font-size: 1.15rem;
  line-height: 1.2;
  margin: 0 0 10px;
  text-transform: uppercase;
}

.paper-ad-card p {
  color: var(--paper-interaction-muted);
  line-height: 1.6;
  margin: 0 0 14px;
}

.paper-ad-card a {
  background: var(--paper-interaction-accent);
  border: 2px solid #111111;
  color: #111111;
  display: inline-block;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  padding: 10px 12px;
  text-decoration: none;
  text-transform: uppercase;
}

.paper-ad-kicker {
  color: #6b665a;
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  margin-bottom: 10px;
  text-transform: uppercase;
}

.context-menu {
  background: rgba(17, 17, 17, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  box-shadow: 0 10px 24px rgba(17, 17, 17, 0.28);
  display: none;
  gap: 0;
  left: 0;
  overflow: hidden;
  position: fixed;
  top: 0;
  transform: translateY(-100%);
  z-index: 20;
}

.context-menu.is-open {
  display: inline-flex;
}

.menu-btn {
  background: transparent;
  border: 0;
  border-right: 1px solid rgba(255, 255, 255, 0.14);
  color: #ffffff;
  cursor: pointer;
  font: inherit;
  letter-spacing: 0.02em;
  padding: 12px 18px;
  text-transform: uppercase;
}

.menu-btn:last-child {
  border-right: 0;
}

.menu-btn:hover,
.menu-btn:focus-visible {
  background: rgba(255, 240, 0, 0.16);
  outline: none;
}

.menu-btn.is-hidden {
  display: none;
}

.popover {
  background: var(--paper-interaction-surface);
  border: 2px solid var(--paper-interaction-border);
  box-shadow: var(--paper-interaction-shadow);
  display: none;
  left: 0;
  max-height: calc(100vh - 32px);
  max-width: 420px;
  overflow: hidden;
  position: fixed;
  top: 0;
  width: calc(100vw - 24px);
  z-index: 21;
}

.popover.is-open {
  display: block;
}

.popover-header {
  align-items: center;
  background: #fffdf7;
  border-bottom: 2px solid rgba(17, 17, 17, 0.1);
  display: flex;
  justify-content: space-between;
  padding: 16px 18px;
}

.popover-title {
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.close-btn {
  background: transparent;
  border: 0;
  color: var(--paper-interaction-muted);
  cursor: pointer;
  font-size: 1.25rem;
  line-height: 1;
  padding: 0;
}

.popover-body {
  max-height: calc(100vh - 96px);
  overflow-y: auto;
  padding: 18px;
}

.popover-actions {
  margin-top: 14px;
  text-align: right;
}

.thread-list,
.share-stack {
  display: grid;
  gap: 14px;
}

.thread-item {
  border-bottom: 1px solid rgba(17, 17, 17, 0.08);
  display: grid;
  gap: 10px;
  grid-template-columns: 54px 1fr;
  padding-bottom: 14px;
}

.thread-item:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.vote-widget {
  align-items: center;
  display: grid;
  gap: 6px;
  justify-items: center;
}

.vote-arrow {
  background: transparent;
  border: 0;
  color: var(--paper-interaction-text);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0;
}

.score-val {
  font-size: 1.05rem;
  font-weight: 700;
}

.thread-meta {
  color: var(--paper-interaction-muted);
  display: flex;
  font-size: 0.75rem;
  gap: 12px;
  justify-content: space-between;
}

.thread-content,
.empty-state {
  line-height: 1.6;
}

.empty-state {
  color: var(--paper-interaction-muted);
  padding: 18px 0;
  text-align: center;
}

.input-area,
.share-link-row {
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr auto;
}

.input-area {
  margin-top: 18px;
}

.input-area input,
.share-link-box,
.cite-box {
  background: #ffffff;
  border: 1px solid rgba(17, 17, 17, 0.18);
  color: var(--paper-interaction-text);
  font: inherit;
  padding: 11px 12px;
  width: 100%;
}

.cite-box {
  min-height: 128px;
  resize: vertical;
}

.action-btn {
  background: #ffffff;
  border: 2px solid var(--paper-interaction-border);
  color: var(--paper-interaction-text);
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 11px 14px;
  text-transform: uppercase;
}

.action-btn:hover,
.action-btn:focus-visible {
  background: var(--paper-interaction-accent);
  outline: none;
}

.cite-options,
.share-links {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
}

.cite-options {
  margin-bottom: 16px;
}

.cite-label {
  align-items: center;
  display: inline-flex;
  gap: 6px;
}

.share-row {
  display: grid;
  gap: 8px;
}

.share-label {
  color: var(--paper-interaction-muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.share-links a {
  color: var(--paper-interaction-text);
  text-decoration: none;
}

.share-links a:hover,
.share-links a:focus-visible {
  text-decoration: underline;
}

.interaction-toast {
  background: rgba(17, 17, 17, 0.96);
  border-radius: 999px;
  bottom: 24px;
  color: #ffffff;
  font-size: 0.9rem;
  left: 50%;
  max-width: calc(100vw - 32px);
  opacity: 0;
  padding: 12px 18px;
  pointer-events: none;
  position: fixed;
  transform: translate(-50%, 16px);
  transition: opacity 160ms ease, transform 160ms ease;
  z-index: 30;
}

.interaction-toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

@keyframes loading-pulse {
  0%,
  100% {
    opacity: 0.28;
    transform: scale(0.92);
  }

  50% {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes loading-logo-spin {
  from {
    transform: rotate(0deg);
  }

  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 1300px) {
  .paper-interaction-shell {
    grid-template-columns: minmax(0, 1fr) minmax(180px, 220px);
  }

  .paper-ad-rail-left {
    display: none;
  }
}

@media (max-width: 720px) {
  .paper-pdf-viewer {
    gap: 20px;
    min-height: auto;
    padding: 0 0 28px;
  }

  .viewer-overlay,
  .viewer-empty-state {
    inset: 12px;
  }

  .context-menu {
    border-radius: 24px;
    flex-wrap: wrap;
    max-width: calc(100vw - 24px);
  }

  .menu-btn {
    border-right: 0;
    width: 100%;
  }

  .popover {
    left: 12px !important;
    right: 12px;
    width: auto;
  }

  .input-area,
  .share-link-row {
    grid-template-columns: 1fr;
  }

  .loading-logo-stack,
  .loading-meta-row {
    align-items: flex-start;
    flex-direction: column;
  }
}

@media (max-width: 1140px) {
  .paper-interaction-shell {
    grid-template-columns: 1fr;
    padding: 12px;
  }

  .paper-ad-rail {
    display: none;
  }

  .paper-viewer-stage {
    min-height: auto;
  }
}

@media (min-width: 860px) {
  .overlay-card h1,
  .overlay-card h2,
  .empty-card h1 {
    font-size: 1.85rem;
  }
}

@media (min-width: 1200px) {
  .overlay-card h1,
  .overlay-card h2,
  .empty-card h1 {
    font-size: 2.2rem;
  }
}
