/* ============================================
   PREMIUM TEXTBOOK READER - BASE STYLES
   Based on DESIGN_SPEC.md
   ============================================ */

/* ============================================
   RESET & BASE
   ============================================ */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* Skip link for accessibility */
.skip-link {
  position: absolute;
  top: -100px;
  left: 0;
  background: var(--accent-primary);
  color: var(--text-primary);
  padding: var(--space-md);
  text-decoration: none;
  z-index: 1000;
  font-family: var(--font-ui);
  font-weight: 500;
}

.skip-link:focus {
  top: 0;
  outline: var(--focus-ring-width) solid var(--focus-ring-color);
  outline-offset: var(--focus-ring-offset);
}

html {
  height: 100%;
  overflow: hidden; /* Prevent body scroll */
}

body {
  height: 100vh;
  overflow: hidden;
  font-family: var(--font-body);
  font-size: var(--type-body);
  line-height: var(--line-body);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* ============================================
   BACKGROUND LAYER
   ============================================ */
.background-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: 0;
  overflow: hidden;
}

.background-image {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
  min-width: 100%;
  min-height: 100%;
  max-width: none;
  max-height: none;
  object-fit: cover;
  object-position: center;
  transition: opacity 600ms var(--ease-standard), filter var(--motion-slow) var(--ease-standard);
}

/* Fallback if image doesn't load - solid color background */
.background-container {
  background: #1a1a26; /* Fallback color if image fails to load */
}

.background-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    to bottom,
    var(--overlay-start),
    var(--overlay-end)
  );
  z-index: 1;
  transition: background var(--motion-slow) var(--ease-standard);
}

.background-vignette {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: radial-gradient(
    circle at center,
    transparent 0%,
    transparent 40%,
    var(--overlay-vignette) 100%
  );
  z-index: 2;
  pointer-events: none;
}

/* ============================================
   TOP BAR
   ============================================ */
.top-bar {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: var(--top-bar-height);
  background: rgba(26, 26, 26, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-lg);
  z-index: 100;
  transition: opacity var(--motion-fast) var(--ease-standard);
}

.top-bar-left {
  flex: 0 0 auto;
  font-family: var(--font-ui);
  font-size: var(--type-small-ui);
  font-weight: 500;
  color: rgba(230, 230, 230, 0.9);
  max-width: 20ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.top-bar-center {
  flex: 1 1 auto;
  text-align: center;
  font-family: var(--font-heading);
  font-size: var(--type-h5);
  font-weight: 500;
  font-style: italic;
  color: rgba(230, 230, 230, 0.85);
  max-width: 40ch;
  margin: 0 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.top-bar-right {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: var(--space-lg);
}

.top-bar-icon {
  width: 2.75rem; /* 44px for accessibility tap target */
  height: 2.75rem;
  min-width: 2.75rem;
  min-height: 2.75rem;
  color: rgba(230, 230, 230, 0.7);
  background: transparent;
  border: none;
  padding: 0;
  cursor: pointer;
  transition: color var(--motion-fast) var(--ease-standard),
              transform var(--motion-fast) var(--ease-standard);
  display: flex;
  align-items: center;
  justify-content: center;
}

.top-bar-icon svg {
  width: 1.25rem; /* 20px icon size */
  height: 1.25rem;
  stroke: currentColor;
  fill: none;
  display: block;
  flex-shrink: 0;
}

.top-bar-icon:hover {
  color: rgba(230, 230, 230, 0.95);
  transform: scale(1.05);
}

.top-bar-icon:focus {
  outline: var(--focus-ring-width) solid var(--focus-ring-color);
  outline-offset: var(--focus-ring-offset);
  border-radius: var(--radius-sm);
}

/* ============================================
   GLASS PANEL (CONTENT AREA)
   ============================================ */
.glass-panel {
  position: fixed;
  top: var(--page-top-margin);
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: var(--page-max-width);
  min-width: var(--page-min-width);
  max-height: calc(100vh - var(--page-top-margin) - var(--page-bottom-margin));
  background: transparent;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  border: none;
  border-radius: 0;
  box-shadow: none;
  padding: var(--space-lg);
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 10;
  transition: all var(--motion-slow) var(--ease-standard);
  /* Smooth scrolling */
  scroll-behavior: smooth;
  /* Custom scrollbar */
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
}

.glass-panel::-webkit-scrollbar {
  width: 8px;
}

.glass-panel::-webkit-scrollbar-track {
  background: transparent;
}

.glass-panel::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: var(--radius-full);
}

.glass-panel::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* ============================================
   READING SURFACE
   ============================================ */
.reading-surface {
  max-width: var(--reading-surface-max-width);
  min-width: var(--reading-surface-min-width);
  width: 100%;
  margin: var(--space-2xl) auto;
  padding: var(--reading-surface-padding-desktop);
  
  /* Glass material */
  background: var(--reading-surface-bg);
  backdrop-filter: blur(var(--reading-surface-blur));
  -webkit-backdrop-filter: blur(var(--reading-surface-blur));
  border: 1px solid var(--reading-surface-border);
  border-radius: var(--reading-surface-radius);
  box-shadow: var(--reading-surface-shadow);
}

/* Citation Header (first section inside reading surface) */
.reading-surface > .citation-header,
.reading-surface > aside.citation,
.reading-surface aside.citation {
  background: var(--citation-header-bg);
  border: 1px solid var(--citation-header-border);
  border-radius: var(--radius-md);
  padding: var(--citation-header-padding);
  margin: 0 0 var(--space-2xl) 0;
  text-align: center;
  border-left: none;
}

/* Case/Article opinion blocks */
.reading-surface > aside.opinion {
  background: rgba(0, 0, 0, 0.18);
  border: 1px solid rgba(255, 255, 255, 0.10);
  border-radius: var(--radius-md);
  padding: var(--citation-header-padding);
  margin: 0 0 var(--space-2xl) 0;
  border-left: 3px solid rgba(255, 255, 255, 0.18);
}

.reading-surface > aside.opinion.case {
  border-left-color: rgba(159, 184, 255, 0.45);
}

.reading-surface > aside.opinion.article {
  border-left-color: rgba(143, 227, 255, 0.45);
}

.reading-surface > .citation-header.case,
.reading-surface > aside.citation.case,
.reading-surface aside.citation.case {
  border-left: none;
}

.reading-surface > .citation-header.article,
.reading-surface > aside.citation.article,
.reading-surface aside.citation.article {
  border-left: none;
}

.reading-surface > .citation-header h4,
.reading-surface > aside.citation h4 {
  margin-top: 0;
  color: var(--text-secondary);
}

.reading-surface > .citation-header h5,
.reading-surface > aside.citation h5 {
  color: var(--text-muted);
}

.reading-surface > .citation-header h5:last-child,
.reading-surface > aside.citation h5:last-child {
  margin-bottom: 0;
}

/* Reading Body Typography */
.reading-body h1,
.reading-body h2,
.reading-body h3,
.reading-body h4,
.reading-body h5,
.reading-surface h1:not(.citation-header h1):not(.citation-header h4),
.reading-surface h2:not(.citation-header h2):not(.citation-header h4),
.reading-surface h3:not(.citation-header h3):not(.citation-header h4),
.reading-surface h4:not(.citation-header h4):not(aside.citation h4),
.reading-surface h5:not(.citation-header h5):not(aside.citation h5) {
  margin-top: var(--space-2xl);
  margin-bottom: var(--space-lg);
}

.reading-body h1:first-child,
.reading-body h2:first-child,
.reading-surface > h1:first-of-type,
.reading-surface > h2:first-of-type {
  margin-top: 0;
}

.reading-body p,
.reading-surface p:not(.citation-header p):not(aside.citation p) {
  margin-bottom: var(--space-md);
  line-height: var(--line-body);
}

.reading-body p + h3,
.reading-body p + h4,
.reading-surface p + h3,
.reading-surface p + h4 {
  margin-top: var(--space-2xl);
}

/* Responsive padding for reading surface */
@media (max-width: 1023px) {
  .reading-surface {
    padding: var(--reading-surface-padding-tablet);
    margin-top: var(--space-xl);
    margin-bottom: var(--space-xl);
  }
}

@media (max-width: 767px) {
  .reading-surface {
    padding: var(--reading-surface-padding-mobile);
    margin-top: var(--space-lg);
    margin-bottom: var(--space-lg);
  }
}

/* ============================================
   BOTTOM NAVIGATION
   ============================================ */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  height: var(--bottom-nav-height);
  background: rgba(26, 26, 26, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-md);
  z-index: 100;
  transition: opacity var(--motion-fast) var(--ease-standard);
}

.bottom-nav-button {
  font-family: var(--font-ui);
  font-size: var(--type-button);
  font-weight: 500;
  color: var(--text-primary);
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-md);
  padding: var(--space-sm) var(--space-md);
  cursor: pointer;
  transition: all var(--motion-fast) var(--ease-standard);
  min-height: 44px; /* Accessibility tap target */
  display: flex;
  align-items: center;
  gap: var(--space-xs);
}

.bottom-nav-button:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.2);
}

.bottom-nav-button:focus {
  outline: var(--focus-ring-width) solid var(--focus-ring-color);
  outline-offset: var(--focus-ring-offset);
}

.bottom-nav-button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.bottom-nav-progress {
  flex: 1 1 auto;
  max-width: 60%;
  margin: 0 var(--space-lg);
  height: 2px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-full);
  position: relative;
  overflow: hidden;
}

.bottom-nav-progress-fill {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: 0%;
  background: rgba(159, 184, 255, 0.6);
  border-radius: var(--radius-full);
  transition: width var(--motion-normal) var(--ease-standard);
}

/* ============================================
   TOC DRAWER
   ============================================ */
.toc-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.4);
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--motion-normal) var(--ease-standard);
}

.toc-overlay.active {
  opacity: 1;
  pointer-events: all;
}

.toc-drawer {
  position: fixed;
  top: var(--top-bar-height);
  left: 0;
  width: var(--toc-width);
  max-height: calc(100vh - var(--top-bar-height) - var(--bottom-nav-height));
  background: rgba(26, 26, 26, 0.92);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-right: 1px solid rgba(255, 255, 255, 0.1);
  z-index: 201;
  transform: translateX(-100%);
  transition: transform var(--motion-normal) var(--ease-standard);
  overflow-y: auto;
  padding: var(--space-lg);
}

.toc-drawer.active {
  transform: translateX(0);
}

.toc-list {
  list-style: none;
}

.toc-item {
  margin-bottom: var(--space-sm);
}

.toc-link {
  display: block;
  font-family: var(--font-ui);
  font-size: var(--type-small-ui);
  color: var(--text-secondary);
  text-decoration: none;
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-md);
  transition: all var(--motion-fast) var(--ease-standard);
}

.toc-link:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
}

.toc-link.active {
  background: rgba(159, 184, 255, 0.15);
  color: var(--accent-primary);
  border-left: 3px solid var(--accent-primary);
  padding-left: calc(var(--space-md) - 3px);
}

.toc-link:focus {
  outline: var(--focus-ring-width) solid var(--focus-ring-color);
  outline-offset: var(--focus-ring-offset);
}

/* ============================================
   BACKGROUND SELECTOR PANEL
   ============================================ */
.background-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.4);
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--motion-normal) var(--ease-standard);
}

.background-overlay.active {
  opacity: 1;
  pointer-events: all;
}

.background-panel {
  position: fixed;
  top: var(--top-bar-height);
  right: 0;
  width: 24rem;
  max-height: calc(100vh - var(--top-bar-height) - var(--bottom-nav-height));
  background: rgba(26, 26, 26, 0.92);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-left: 1px solid rgba(255, 255, 255, 0.1);
  z-index: 201;
  transform: translateX(100%);
  transition: transform var(--motion-normal) var(--ease-standard);
  overflow-y: auto;
  padding: var(--space-lg);
}

.background-panel.active {
  transform: translateX(0);
}

.background-panel-title {
  font-family: var(--font-ui);
  font-size: var(--type-h3);
  font-weight: 500;
  color: var(--text-primary);
  margin: 0 0 var(--space-lg) 0;
  padding-bottom: var(--space-md);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.background-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-md);
}

.background-thumbnail {
  position: relative;
  background: transparent;
  border: 2px solid transparent;
  border-radius: var(--radius-md);
  padding: 0;
  cursor: pointer;
  overflow: hidden;
  transition: all var(--motion-fast) var(--ease-standard);
  aspect-ratio: 3 / 2;
  display: flex;
  flex-direction: column;
  min-height: 120px;
}

.background-thumbnail:hover {
  transform: scale(1.05);
  border-color: rgba(255, 255, 255, 0.2);
}

.background-thumbnail:focus {
  outline: var(--focus-ring-width) solid var(--focus-ring-color);
  outline-offset: var(--focus-ring-offset);
  border-radius: var(--radius-md);
}

.background-thumbnail.active {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 1px var(--accent-primary);
}

.background-thumbnail img {
  width: 100%;
  height: 80px;
  object-fit: cover;
  display: block;
  flex-shrink: 0;
}

.background-label {
  font-family: var(--font-ui);
  font-size: var(--type-small-ui);
  color: var(--text-secondary);
  padding: var(--space-xs) var(--space-sm);
  text-align: center;
  background: rgba(0, 0, 0, 0.3);
  margin-top: auto;
}

.background-thumbnail.active .background-label {
  color: var(--text-primary);
  background: rgba(159, 184, 255, 0.15);
}

.background-error {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 80px;
  font-family: var(--font-ui);
  font-size: var(--type-small-ui);
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.05);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* ============================================
   TYPOGRAPHY SYSTEM
   ============================================ */
.reading-surface h1:not(aside.citation h4),
.reading-body h1 {
  font-family: var(--font-heading);
  font-size: var(--type-h1);
  font-weight: 600;
  line-height: var(--line-h1);
  letter-spacing: -0.02em;
  color: var(--text-secondary);
  margin-top: var(--space-2xl);
  margin-bottom: var(--space-lg);
}

.reading-surface h2:not(aside.citation h4),
.reading-body h2 {
  font-family: var(--font-heading);
  font-size: var(--type-h2);
  font-weight: 500;
  line-height: var(--line-h2);
  letter-spacing: -0.01em;
  color: var(--text-secondary);
  margin-top: var(--space-xl);
  margin-bottom: var(--space-lg);
}

.reading-surface h3:not(aside.citation h4),
.reading-body h3 {
  font-family: var(--font-heading);
  font-size: var(--type-h3);
  font-weight: 500;
  line-height: var(--line-h3);
  color: var(--text-secondary);
  margin-top: var(--space-lg);
  margin-bottom: var(--space-lg);
}

.reading-surface h4:not(aside.citation h4),
.reading-body h4 {
  font-family: var(--font-heading);
  font-size: var(--type-h4);
  font-weight: 500;
  line-height: var(--line-h4);
  color: var(--text-secondary);
  margin-top: var(--space-lg);
  margin-bottom: var(--space-md);
}

.reading-surface h5:not(aside.citation h5),
.reading-body h5 {
  font-family: var(--font-heading);
  font-size: var(--type-h5);
  font-weight: 500;
  line-height: var(--line-h5);
  letter-spacing: 0.01em;
  color: var(--text-muted);
  margin-top: var(--space-md);
  margin-bottom: var(--space-sm);
}


.reading-surface a,
.reading-body a {
  color: var(--text-link);
  text-decoration: none;
  transition: color var(--motion-fast) var(--ease-standard);
}

.reading-surface a:hover,
.reading-body a:hover {
  color: var(--text-link-hover);
}

.reading-surface a:visited,
.reading-body a:visited {
  color: var(--text-link-visited);
}

.reading-surface blockquote,
.reading-body blockquote {
  font-family: var(--font-body);
  font-size: var(--type-blockquote);
  font-style: italic;
  line-height: var(--line-blockquote);
  color: var(--text-secondary);
  margin: var(--space-lg) 0;
  padding-left: var(--space-lg);
  border-left: 3px solid var(--accent-primary);
}

.reading-surface code,
.reading-body code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.95em;
  background: rgba(255, 255, 255, 0.05);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
}

.reading-surface pre,
.reading-body pre {
  background: rgba(255, 255, 255, 0.05);
  padding: var(--space-lg);
  border-radius: var(--radius-lg);
  overflow-x: auto;
  margin: var(--space-lg) 0;
}

.reading-surface sup.footnote-ref,
.reading-body sup.footnote-ref {
  font-size: var(--type-footnote);
  line-height: var(--line-footnote);
  color: var(--text-muted);
}

/* ============================================
   PAGE NUMBERS
   ============================================ */
.reading-surface span[id^="page"],
.reading-body span[id^="page"] {
  position: absolute;
  right: -4rem;
  color: rgba(255, 255, 255, 0.65);
  font-size: 0.875rem;
  font-weight: 600;
  pointer-events: none;
  white-space: nowrap;
}

/* Ensure parent elements have relative positioning for absolute page numbers */
.reading-surface p,
.reading-surface aside,
.reading-body p,
.reading-body aside {
  position: relative;
}

/* ============================================
   CITATION BLOCKS (from existing CSS)
   ============================================ */
/* Citation blocks inside reading surface are handled above */

/* ============================================
   TEXT SELECTION
   ============================================ */
::selection {
  background: var(--text-selection);
  color: var(--text-primary);
}

::-moz-selection {
  background: var(--text-selection);
  color: var(--text-primary);
}

/* ============================================
   PAGE LOAD ANIMATION
   ============================================ */
@keyframes pageLoad {
  from {
    opacity: 0;
    transform: translateX(-50%) scale(0.98);
    filter: blur(4px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) scale(1);
    filter: blur(0);
  }
}

.glass-panel {
  animation: pageLoad var(--motion-settle) var(--ease-standard);
}

/* ============================================
   REDUCED MOTION
   ============================================ */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  
  .glass-panel {
    animation: none;
  }
}

/* ============================================
   MOBILE RESPONSIVE
   ============================================ */
@media (max-width: 1023px) {
  :root {
    --page-max-width: calc(100vw - 2rem);
    --page-min-width: 20rem;
    --page-padding-x: 1.5rem;
    --page-padding-y: 3rem;
    --page-top-margin: 4.5rem;
    --page-bottom-margin: 5rem;
    --toc-width: 85vw;
  }
  
  .toc-drawer {
    max-height: 100vh;
    top: 0;
  }
  
  .background-panel {
    width: 90vw;
    max-height: 100vh;
    top: 0;
    bottom: 0;
    transform: translateY(100%);
  }
  
  .background-panel.active {
    transform: translateY(0);
  }
  
  .background-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .top-bar-center {
    font-size: 0.875rem;
    max-width: 30ch;
  }
  
  .reading-surface {
    max-width: 100%;
  }
  
  .top-bar {
    padding: 0 var(--space-md);
  }
  
  .top-bar-right {
    gap: var(--space-md);
  }
  
  .bottom-nav {
    padding: 0 var(--space-sm);
  }
  
  .bottom-nav-button {
    padding: var(--space-xs) var(--space-sm);
    font-size: 0.875rem;
  }
  
  .bottom-nav-button span {
    display: none; /* Hide text on mobile, show only icons */
  }
  
  .bottom-nav-progress {
    max-width: 50%;
  }
}

/* ============================================
   FOCUS MODE ADJUSTMENTS
   ============================================ */
body.focus-mode .reading-surface p:not(aside.citation p),
body.focus-mode .reading-body p {
  margin-bottom: var(--focus-paragraph-spacing);
}

