/*
 * Scholarly Editorial Theme
 * A refined academic aesthetic with subtle texture and deliberate typography
 */

/* Fonts: Cormorant for editorial elegance, DM Sans for modern clarity */
@import url('https://fonts.googleapis.com/css2?family=Cormorant:ital,wght@0,400;0,500;0,600;1,400&family=DM+Sans:ital,wght@0,400;0,500;1,400&display=swap');

:root {
  /* Warm parchment palette with ink accents */
  --bg-main: #f9f7f4;
  --bg-sidebar: #f4f1ec;
  --bg-paper: #fffef9;
  --text-primary: #1a1a1a;
  --text-secondary: #4a4a4a;
  --text-muted: #7a7a7a;
  --accent: #8b4513;
  --accent-deep: #6b3410;
  --accent-light: rgba(139, 69, 19, 0.08);
  --border: #e5e0d8;
  --border-subtle: #ede9e3;

  /* Spacing scale */
  --space-xs: 0.5rem;
  --space-sm: 1rem;
  --space-md: 1.5rem;
  --space-lg: 2.5rem;
  --space-xl: 4rem;

  /* Animation */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --duration: 0.4s;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 17px;
  font-weight: 400;
  background-color: var(--bg-main);
  color: var(--text-primary);
  line-height: 1.75;
  margin: 0;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;

  /* Subtle paper texture */
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 400 400' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)'/%3E%3C/svg%3E");
  background-blend-mode: soft-light;
  background-size: 200px;
}

/* Typography */
h1, h2, h3 {
  font-family: 'Cormorant', Georgia, serif;
  font-weight: 500;
  letter-spacing: -0.01em;
}

h1 {
  font-size: 2.75rem;
  line-height: 1.15;
  color: var(--text-primary);
  margin: 0 0 var(--space-md) 0;
}

h2 {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: var(--space-lg) 0 var(--space-sm) 0;
}

p {
  margin: 0 0 var(--space-md) 0;
  font-size: 1.05rem;
}

a {
  color: var(--accent);
  text-decoration: none;
  transition: color var(--duration) var(--ease-out);
}

a:hover {
  color: var(--accent-deep);
}

/* Sidebar Navigation */
.sidenav {
  position: fixed;
  top: 0;
  left: 0;
  width: 220px;
  height: 100vh;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  padding: var(--space-xl) 0 var(--space-lg);
  display: flex;
  flex-direction: column;
  z-index: 100;

  /* Subtle inner shadow for depth */
  box-shadow: inset -8px 0 24px -12px rgba(0, 0, 0, 0.04);
}

.sidenav::before {
  content: '';
  position: absolute;
  top: var(--space-lg);
  left: var(--space-md);
  right: var(--space-md);
  height: 2px;
  background: linear-gradient(90deg, var(--accent) 0%, transparent 100%);
  opacity: 0.4;
}

.sidenav a {
  position: relative;
  padding: 0.875rem var(--space-md) 0.875rem calc(var(--space-md) + 12px);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.95rem;
  font-weight: 400;
  color: var(--text-secondary);
  text-decoration: none;
  letter-spacing: 0.02em;
  transition: all var(--duration) var(--ease-out);
}

.sidenav a::before {
  content: '';
  position: absolute;
  left: var(--space-md);
  top: 50%;
  transform: translateY(-50%) scaleX(0);
  width: 6px;
  height: 1px;
  background: var(--accent);
  transition: transform var(--duration) var(--ease-out);
  transform-origin: left center;
}

.sidenav a:hover {
  color: var(--text-primary);
  background: var(--accent-light);
}

.sidenav a:hover::before {
  transform: translateY(-50%) scaleX(1);
}

.sidenav a.active {
  color: var(--accent);
  font-weight: 500;
}

.sidenav a.active::before {
  transform: translateY(-50%) scaleX(1);
  width: 8px;
  height: 2px;
}

.sidenav a.hidden-link {
  display: none;
}

/* Main Content */
.main {
  margin-left: 260px;
  max-width: 680px;
  padding: var(--space-xl) var(--space-lg) calc(var(--space-xl) * 2);
  min-height: 100vh;

  /* Fade in animation */
  animation: fadeInUp 0.6s var(--ease-out) both;
}

.main.wide {
  max-width: 1020px;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}


/* Research page styles */
.section-title {
  font-family: 'Cormorant', Georgia, serif;
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--text-muted);
  margin: var(--space-xl) 0 var(--space-lg) 0;
  padding-bottom: var(--space-xs);
  border-bottom: 1px solid var(--border);

  /* Stagger animation */
  animation: fadeInUp 0.6s var(--ease-out) both;
  animation-delay: 0.1s;
}

.section-title:first-of-type {
  margin-top: var(--space-lg);
}

.paper {
  margin-bottom: var(--space-lg);
  padding-bottom: var(--space-lg);
  border-bottom: 1px solid var(--border-subtle);

  /* Stagger animation */
  animation: fadeInUp 0.6s var(--ease-out) both;
}

.paper:nth-child(2) { animation-delay: 0.15s; }
.paper:nth-child(3) { animation-delay: 0.2s; }
.paper:nth-child(4) { animation-delay: 0.25s; }
.paper:nth-child(5) { animation-delay: 0.3s; }
.paper:nth-child(6) { animation-delay: 0.35s; }

.paper:last-child {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}

.paper-title {
  font-family: 'Cormorant', Georgia, serif;
  font-size: 1.35rem;
  font-weight: 500;
  color: var(--text-primary);
  margin: 0 0 0.375rem 0;
  line-height: 1.35;
  transition: color var(--duration) var(--ease-out);
}

.paper:hover .paper-title {
  color: var(--accent);
}

.paper-meta {
  font-size: 0.9rem;
  color: var(--text-muted);
  font-style: italic;
  margin: 0 0 var(--space-sm) 0;
}

.abstract-toggle {
  background: none;
  border: none;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--accent);
  cursor: pointer;
  padding: 0;
  letter-spacing: 0.03em;
  transition: all var(--duration) var(--ease-out);
  display: inline-flex;
  align-items: center;
  gap: 0.5em;
}

.abstract-toggle::before {
  content: '';
  display: inline-block;
  width: 8px;
  height: 8px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(-45deg);
  transition: transform var(--duration) var(--ease-out);
  margin-top: -2px;
}

.abstract-toggle.open::before {
  transform: rotate(45deg);
  margin-top: 2px;
}

.abstract-toggle:hover {
  color: var(--accent-deep);
}

.abstract {
  display: grid;
  grid-template-rows: 0fr;
  opacity: 0;
  transition:
    grid-template-rows 0.5s var(--ease-out),
    opacity 0.4s var(--ease-out),
    margin 0.4s var(--ease-out);
  margin-top: 0;
}

.abstract-inner {
  overflow: hidden;
}

.abstract.show {
  grid-template-rows: 1fr;
  opacity: 1;
  margin-top: var(--space-md);
}

.abstract-content {
  position: relative;
  padding: var(--space-md) var(--space-md) var(--space-md) calc(var(--space-md) + 12px);
  background: linear-gradient(135deg, var(--bg-paper) 0%, #fdfcf8 100%);
  border-radius: 4px;
  font-size: 0.95rem;
  line-height: 1.75;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.8),
    0 1px 3px rgba(0, 0, 0, 0.04),
    0 4px 12px rgba(0, 0, 0, 0.03);
}

.abstract-content::before {
  content: '';
  position: absolute;
  left: 0;
  top: 8px;
  bottom: 8px;
  width: 3px;
  background: linear-gradient(180deg, var(--accent) 0%, var(--accent-deep) 100%);
  border-radius: 2px;
}


.abstract p {
  margin: 0;
}

/* Contact page */
.contact-item {
  display: flex;
  flex-direction: column;
  margin-bottom: var(--space-md);
}

.contact-label {
  font-family: 'Cormorant', Georgia, serif;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

/* Image Grid (for visualizations) */
.row {
  display: flex;
  flex-wrap: wrap;
  margin: var(--space-lg) 0;
  gap: var(--space-sm);
}

.column {
  flex: 1;
  min-width: 200px;
}

.column img {
  width: 100%;
  border-radius: 4px;
  box-shadow:
    0 2px 8px rgba(0, 0, 0, 0.06),
    0 8px 24px rgba(0, 0, 0, 0.04);
  transition: transform var(--duration) var(--ease-out), box-shadow var(--duration) var(--ease-out);
}

.column img:hover {
  transform: translateY(-2px);
  box-shadow:
    0 4px 12px rgba(0, 0, 0, 0.08),
    0 12px 32px rgba(0, 0, 0, 0.06);
}

/* Responsive */
@media screen and (max-width: 900px) {
  .main {
    margin-left: 220px;
    padding: var(--space-lg) var(--space-md);
  }
}

@media screen and (max-width: 768px) {
  body {
    background-image: none;
  }

  .sidenav {
    position: relative;
    width: 100%;
    height: auto;
    padding: var(--space-sm) 0;
    flex-direction: row;
    justify-content: center;
    gap: var(--space-xs);
    border-right: none;
    border-bottom: 1px solid var(--border);
    box-shadow: none;
  }

  .sidenav::before {
    display: none;
  }

  .sidenav a {
    padding: var(--space-xs) var(--space-sm);
  }

  .sidenav a::before {
    display: none;
  }

  .main {
    margin-left: 0;
    padding: var(--space-lg) var(--space-md);
    max-width: 100%;
  }

  .main > p:first-of-type::first-letter {
    font-size: 2.75rem;
  }

  h1 {
    font-size: 2rem;
  }

  .paper-title {
    font-size: 1.2rem;
  }

  .row {
    flex-direction: column;
  }
}

/* Print styles */
@media print {
  .sidenav {
    display: none;
  }

  .main {
    margin: 0;
    padding: 0;
    max-width: 100%;
  }
}

/* ============================================================================
   Distribution Plotter Styles
   ============================================================================ */

.dist-plotter {
  margin-top: var(--space-lg);
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: var(--space-md);
  align-items: start;
}

.dist-plot-area {
  background: var(--bg-paper);
  border-radius: 6px;
  padding: var(--space-sm);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.8),
    0 2px 8px rgba(0, 0, 0, 0.04),
    0 8px 24px rgba(0, 0, 0, 0.03);
  position: sticky;
  top: var(--space-md);
}

.dist-plot-area svg {
  width: 100%;
  height: auto;
  display: block;
}

.dist-controls {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  max-height: calc(100vh - 2 * var(--space-md));
  overflow-y: auto;
}

.dist-add-section {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

.dist-select {
  flex: 1;
  min-width: 150px;
  padding: 0.6rem 0.8rem;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.9rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg-paper);
  color: var(--text-primary);
  cursor: pointer;
  transition: border-color var(--duration) var(--ease-out);
}

.dist-select:hover,
.dist-select:focus {
  border-color: var(--accent);
  outline: none;
}

.dist-add-btn {
  padding: 0.6rem 1.2rem;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--bg-paper);
  background: var(--accent);
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: all var(--duration) var(--ease-out);
  white-space: nowrap;
}

.dist-add-btn:hover {
  background: var(--accent-deep);
  transform: translateY(-1px);
}

.dist-add-btn:active {
  transform: translateY(0);
}

.dist-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.dist-card {
  background: var(--bg-paper);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: var(--space-sm) var(--space-md);
  transition: border-color var(--duration) var(--ease-out);
}

.dist-card:hover {
  border-color: var(--border-subtle);
}

.dist-card-header {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  margin-bottom: 0.4rem;
}

.dist-card-formula {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: var(--space-sm);
  padding-left: calc(18px + var(--space-sm));
}

.dist-visibility-btn {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid;
  cursor: pointer;
  transition: all var(--duration) var(--ease-out);
  flex-shrink: 0;
}

.dist-visibility-btn:hover {
  transform: scale(1.1);
}

.dist-card-title {
  font-family: 'Cormorant', Georgia, serif;
  font-size: 1.1rem;
  font-weight: 500;
  color: var(--text-primary);
  flex: 1;
}

.dist-remove-btn {
  width: 24px;
  height: 24px;
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 1.2rem;
  cursor: pointer;
  border-radius: 4px;
  transition: all var(--duration) var(--ease-out);
  display: flex;
  align-items: center;
  justify-content: center;
}

.dist-remove-btn:hover {
  background: var(--accent-light);
  color: var(--accent);
}

.dist-card-params {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.dist-param {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.dist-param-label {
  font-family: 'DM Sans', sans-serif;
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.dist-param-control {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.dist-slider {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

.dist-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
  transition: transform var(--duration) var(--ease-out);
}

.dist-slider::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}

.dist-slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  background: var(--accent);
  border: none;
  border-radius: 50%;
  cursor: pointer;
}

.dist-number {
  width: 70px;
  padding: 0.4rem 0.5rem;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.85rem;
  text-align: center;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg-main);
  color: var(--text-primary);
  transition: border-color var(--duration) var(--ease-out);
}

.dist-number:hover,
.dist-number:focus {
  border-color: var(--accent);
  outline: none;
}

/* Hide number input spinners */
.dist-number::-webkit-outer-spin-button,
.dist-number::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.dist-number[type=number] {
  -moz-appearance: textfield;
}

.dist-card-description {
  margin-top: var(--space-sm);
  font-size: 0.85rem;
  color: var(--text-muted);
  font-style: italic;
  padding-top: var(--space-xs);
  border-top: 1px solid var(--border-subtle);
}

/* Responsive styles for distribution plotter */
@media screen and (max-width: 900px) {
  .dist-plotter {
    grid-template-columns: 1fr;
  }

  .dist-plot-area {
    position: static;
  }

  .dist-controls {
    max-height: none;
    overflow-y: visible;
  }
}

@media screen and (max-width: 768px) {
  .dist-param-control {
    flex-wrap: wrap;
  }

  .dist-slider {
    width: 100%;
    flex: none;
  }

  .dist-number {
    width: 100%;
  }
}
