:root {
  /* Scholarly Mystic Palette */
  --color-creamy-linen: #F7F5EC;
  --color-rich-soil: #3B2A1F;
  --color-burnt-gold: #B8860B;
  --color-mystic-glass: rgba(247, 245, 236, 0.15);
  --color-glass-border: rgba(255, 255, 255, 0.2);
  --color-glass-highlight: rgba(255, 255, 255, 0.4);
  --color-shadow: rgba(59, 42, 31, 0.1);

  /* Typography */
  --font-display: 'Playfair Display', serif;
  --font-body: 'Outfit', sans-serif;

  /* Spacing */
  --spacing-xs: 0.5rem;
  --spacing-sm: 1rem;
  --spacing-md: 2rem;
  --spacing-lg: 4rem;
  --spacing-xl: 8rem;

  /* Animation */
  --transition-smooth: all 0.6s cubic-bezier(0.22, 1, 0.36, 1);
}

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

body {
  font-family: var(--font-body);
  color: var(--color-rich-soil);
  background-color: var(--color-creamy-linen);
  overflow-x: hidden;
  min-height: 100vh;
  line-height: 1.6;
}

/* 3D Background Container */
#canvas-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: -1;
  pointer-events: none;
  /* Allow clicks to pass through */
}

/* Typography Overrides */
h1,
h2,
h3,
h4,
h5,
h6 {
  font-family: var(--font-display);
  font-weight: 600;
  line-height: 1.2;
  color: var(--color-rich-soil);
}

p {
  font-weight: 300;
  opacity: 0.9;
}

/* Navigation */
.glass-nav {
  position: fixed;
  top: 2rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  width: 90%;
  max-width: 1200px;
}

.nav-content {
  background: rgba(247, 245, 236, 0.6);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--color-glass-border);
  border-radius: 100px;
  /* Pill shape */
  padding: 1rem 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 10px 30px var(--color-shadow);
}

.logo {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.nav-links {
  display: flex;
  gap: 0.5rem;
}

.nav-link {
  background: transparent;
  border: none;
  color: var(--color-rich-soil);
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 500;
  padding: 0.5rem 1.25rem;
  border-radius: 20px;
  cursor: pointer;
  transition: var(--transition-smooth);
  opacity: 0.7;
}

.nav-link:hover {
  opacity: 1;
  background: rgba(59, 42, 31, 0.05);
}

.nav-link.active {
  opacity: 1;
  background: var(--color-rich-soil);
  color: var(--color-creamy-linen);
}

/* Main Layout */
.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 8rem 2rem 4rem;
  /* Top padding for fixed nav */
  position: relative;
  z-index: 1;
}

.page {
  display: none;
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.8s ease, transform 0.8s ease;
}

.page.active {
  display: block;
  opacity: 1;
  transform: translateY(0);
}

/* Hero Section */
.hero-section {
  text-align: center;
  margin-bottom: 6rem;
  padding-top: 4rem;
}

.hero-title {
  font-size: clamp(3.5rem, 8vw, 6rem);
  font-weight: 400;
  font-style: italic;
  margin-bottom: 1.5rem;
  letter-spacing: -0.03em;
}

.hero-subtitle {
  font-size: 1.25rem;
  font-family: var(--font-body);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  opacity: 0.7;
}

.page-header {
  text-align: center;
  margin-bottom: 4rem;
}

.page-title {
  font-size: 4rem;
  font-style: italic;
  margin-bottom: 1rem;
}

/* Bento Grid */
.bento-grid {
  display: grid;
  gap: 2rem;
  grid-template-columns: repeat(12, 1fr);
  grid-auto-rows: minmax(200px, auto);
}

/* Glass Cards */
.glass-card {
  background: rgba(255, 255, 255, 0.4);
  /* More transparent for dither to show */
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid var(--color-glass-border);
  border-top: 1px solid var(--color-glass-highlight);
  border-radius: 32px;
  padding: 2.5rem;
  box-shadow:
    0 20px 40px -10px rgba(59, 42, 31, 0.1),
    inset 0 0 0 1px rgba(255, 255, 255, 0.2);
  transition: var(--transition-smooth);
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

.glass-card:hover {
  transform: translateY(-5px) scale(1.01);
  box-shadow:
    0 30px 60px -12px rgba(59, 42, 31, 0.15),
    inset 0 0 0 1px rgba(255, 255, 255, 0.4);
  border-color: var(--color-burnt-gold);
}

/* Grid Spans */
.home-grid .bento-card.large {
  grid-column: span 6;
  grid-row: span 2;
}

.home-grid .bento-card.small {
  grid-column: span 6;
  grid-row: span 1;
}

/* Card Content */
.card-icon {
  font-size: 2.5rem;
  margin-bottom: 1.5rem;
  opacity: 0.8;
}

.bento-card h2 {
  font-size: 2rem;
  margin-bottom: 1rem;
}

.bento-card h3 {
  font-size: 1.5rem;
  margin-bottom: 0.75rem;
}

/* Buttons */
.primary-btn {
  background: var(--color-rich-soil);
  color: var(--color-creamy-linen);
  border: none;
  font-family: var(--font-body);
  font-size: 1rem;
  font-weight: 500;
  padding: 1rem 2rem;
  border-radius: 100px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  transition: var(--transition-smooth);
  margin-top: auto;
}

.primary-btn:hover:not(:disabled) {
  background: var(--color-burnt-gold);
  transform: translateX(5px);
}

.primary-btn:disabled {
  background: rgba(59, 42, 31, 0.3);
  cursor: not-allowed;
}

/* Chat Interface */
.chat-interface {
  display: flex;
  flex-direction: column;
  height: 450px;
  /* Fixed height to prevent growing */
  max-height: 60vh;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-bottom: 1rem;
  background: rgba(255, 255, 255, 0.3);
  border-radius: 20px;
  border: 1px solid var(--color-glass-border);
  /* Custom Scrollbar for Chat */
  scrollbar-width: thin;
  scrollbar-color: var(--color-burnt-gold) transparent;
}

.chat-messages::-webkit-scrollbar {
  width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
  background-color: var(--color-burnt-gold);
  border-radius: 20px;
}

.message {
  max-width: 85%;
  padding: 1rem 1.5rem;
  border-radius: 20px;
  font-size: 1rem;
  line-height: 1.5;
}

.bot-message {
  background: rgba(255, 255, 255, 0.5);
  border-bottom-left-radius: 4px;
  align-self: flex-start;
}

.user-message {
  background: var(--color-rich-soil);
  color: var(--color-creamy-linen);
  border-bottom-right-radius: 4px;
  align-self: flex-end;
}

.chat-input-area {
  display: flex;
  gap: 1rem;
  background: rgba(255, 255, 255, 0.5);
  padding: 0.5rem;
  border-radius: 100px;
  border: 1px solid var(--color-glass-border);
}

#chat-input {
  flex: 1;
  background: transparent;
  border: none;
  padding: 0.75rem 1.5rem;
  font-family: var(--font-body);
  font-size: 1rem;
  color: var(--color-rich-soil);
  outline: none;
}

.send-btn {
  background: var(--color-rich-soil);
  color: var(--color-creamy-linen);
  border: none;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition-smooth);
}

.send-btn:hover {
  background: var(--color-burnt-gold);
  transform: rotate(-10deg);
}

/* Words Grid */
.words-grid {
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  display: grid;
  /* Override bento grid specific columns */
}

.word-term {
  font-family: var(--font-display);
  font-size: 2.5rem;
  color: var(--color-burnt-gold);
  margin-bottom: 0.5rem;
}

.word-pronunciation {
  font-family: var(--font-body);
  font-style: italic;
  opacity: 0.6;
  margin-bottom: 1.5rem;
}

/* Essay Grid */
.essay-grid {
  grid-template-columns: 1fr 300px;
  display: grid;
  gap: 2rem;
}

.essay-card {
  grid-column: 1;
}

.essay-sidebar {
  grid-column: 2;
  height: fit-content;
}

.essay-title {
  font-size: 3rem;
  margin-bottom: 2rem;
}

.essay-content p {
  font-size: 1.15rem;
  margin-bottom: 1.5rem;
  line-height: 1.8;
}

.tag {
  display: inline-block;
  padding: 0.5rem 1rem;
  background: rgba(59, 42, 31, 0.05);
  border-radius: 100px;
  font-size: 0.85rem;
  margin: 0.25rem;
  transition: var(--transition-smooth);
}

.tag:hover {
  background: var(--color-burnt-gold);
  color: var(--color-creamy-linen);
  border-color: var(--color-burnt-gold);
  color: var(--color-creamy-linen);
}

/* Reading Grid */
.reading-grid {
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  display: grid;
}

.book-cover {
  font-size: 3rem;
  margin-bottom: 1rem;
}

/* Responsive */
@media (max-width: 1024px) {
  .bento-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .home-grid .bento-card.large,
  .home-grid .bento-card.small {
    grid-column: span 1;
    grid-row: auto;
  }

  .essay-grid {
    grid-template-columns: 1fr;
  }

  .essay-sidebar {
    grid-column: 1;
  }
}

@media (max-width: 768px) {
  .bento-grid {
    grid-template-columns: 1fr;
  }

  .home-grid .bento-card.large,
  .home-grid .bento-card.small {
    grid-column: span 1;
  }

  .hero-title {
    font-size: 3.5rem;
  }

  .nav-content {
    padding: 0.75rem 1.5rem;
  }

  .nav-link span {
    display: none;
  }
}

/* Rolodex Styles */
.rolodex-container {
  width: 100%;
  min-height: 800px;
  /* Ensure enough vertical space */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  perspective: 2000px;
  overflow: visible;
  position: relative;
  padding-top: 220px;
  /* Push down well below nav bar */
  padding-bottom: 100px;
  /* Space for the table below */
}

.rolodex-stage {
  width: 100%;
  height: 400px;
  position: relative;
  transform-style: preserve-3d;
  display: flex;
  justify-content: center;
  align-items: center;
}

.rolodex-wheel {
  position: relative;
  width: 600px;
  height: 400px;
  transform-style: preserve-3d;
  transition: transform 0.8s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.rolodex-card {
  position: absolute;
  width: 600px;
  height: 400px;
  left: 0;
  top: 0;
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 24px;
  padding: 3rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  box-shadow:
    0 20px 50px rgba(0, 0, 0, 0.1),
    0 0 0 1px rgba(255, 255, 255, 0.5) inset;
  backface-visibility: hidden;
  /* Or visible if we want double sided */
  /* Glass effect on top of white for texture */
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

/* Dark mode adjustment if needed, but keeping it light/clean for now as per inspo */
@media (prefers-color-scheme: dark) {
  .rolodex-card {
    background: rgba(30, 30, 35, 0.95);
    border-color: rgba(255, 255, 255, 0.1);
    color: white;
  }
}

.rolodex-card.active {
  z-index: 10;
  box-shadow:
    0 30px 60px rgba(0, 0, 0, 0.15),
    0 0 0 2px rgba(255, 255, 255, 0.8) inset,
    0 0 20px rgba(255, 255, 255, 0.2);
}

.card-content {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  width: 100%;
}

.card-term {
  font-family: 'Outfit', sans-serif;
  font-size: 4rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: #1a1a1a;
  line-height: 1;
  text-transform: uppercase;
}

@media (prefers-color-scheme: dark) {
  .card-term {
    color: #ffffff;
  }
}

.card-meta {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  font-family: 'Outfit', sans-serif;
  color: #666;
  font-size: 1.1rem;
  font-weight: 500;
}

.card-pronunciation {
  font-family: 'Playfair Display', serif;
  font-style: italic;
  color: #888;
}

.card-divider {
  width: 60px;
  height: 4px;
  background: #1a1a1a;
  margin: 1rem auto;
  border-radius: 2px;
}

@media (prefers-color-scheme: dark) {
  .card-divider {
    background: #ffffff;
  }
}

.card-definition {
  font-family: 'Playfair Display', serif;
  font-size: 1.5rem;
  line-height: 1.4;
  color: #333;
  max-width: 90%;
  margin: 0 auto;
}

@media (prefers-color-scheme: dark) {
  .card-definition {
    color: #e0e0e0;
  }
}

/* Controls */
.rolodex-controls {
  margin-top: 3rem;
  display: flex;
  align-items: center;
  gap: 2rem;
  z-index: 20;
}

.rolodex-btn {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 2px solid rgba(0, 0, 0, 0.1);
  background: rgba(255, 255, 255, 0.8);
  color: #1a1a1a;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s ease;
  backdrop-filter: blur(10px);
}

@media (prefers-color-scheme: dark) {
  .rolodex-btn {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
    color: white;
  }
}

.rolodex-btn:hover {
  transform: scale(1.1);
  background: #1a1a1a;
  color: white;
  border-color: #1a1a1a;
}

@media (prefers-color-scheme: dark) {
  .rolodex-btn:hover {
    background: white;
    color: #1a1a1a;
    border-color: white;
  }
}

.rolodex-progress {
  font-family: 'Outfit', sans-serif;
  font-weight: 600;
  font-size: 1.2rem;
  display: flex;
  gap: 0.5rem;
  color: #666;
}

@media (prefers-color-scheme: dark) {
  .rolodex-progress {
    color: #aaa;
  }
}

/* Responsive */
@media (max-width: 768px) {
  .rolodex-wheel {
    width: 90vw;
    height: 60vh;
  }

  .rolodex-card {
    width: 100%;
    height: 100%;
    padding: 1.5rem;
  }

  .card-term {
    font-size: 2.5rem;
  }

  .card-definition {
    font-size: 1.2rem;
  }
}

.rolodex-center-controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.spin-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.5);
  border: 1px solid rgba(0, 0, 0, 0.1);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
}

.spin-btn:hover {
  background: #1a1a1a;
  color: white;
  transform: rotate(180deg);
}

@media (prefers-color-scheme: dark) {
  .spin-btn {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
    color: white;
  }

  .spin-btn:hover {
    background: white;
    color: #1a1a1a;
  }
}

.card-definition.loading {
  opacity: 0.5;
  font-style: italic;
}

.card-definition.error {
  opacity: 0.5;
  font-size: 1rem;
}

/* Table Styles */
.words-table-section {
  width: 100%;
  max-width: 800px;
  margin: 4rem auto 2rem;
  padding: 0 1rem;
  animation: fadeIn 0.5s ease-out;
}

.words-table-section h3 {
  font-family: 'Playfair Display', serif;
  font-size: 2rem;
  margin-bottom: 1.5rem;
  text-align: center;
  color: #1a1a1a;
}

@media (prefers-color-scheme: dark) {
  .words-table-section h3 {
    color: white;
  }
}

.table-search-container {
  margin-bottom: 1rem;
  display: flex;
  justify-content: center;
}

.table-search-input {
  width: 100%;
  max-width: 400px;
  padding: 0.8rem 1.2rem;
  border-radius: 24px;
  border: 1px solid rgba(0, 0, 0, 0.1);
  background: rgba(255, 255, 255, 0.5);
  backdrop-filter: blur(10px);
  font-family: 'Outfit', sans-serif;
  font-size: 1rem;
  transition: all 0.3s ease;
}

.table-search-input:focus {
  outline: none;
  background: white;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

@media (prefers-color-scheme: dark) {
  .table-search-input {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
    color: white;
  }

  .table-search-input:focus {
    background: rgba(255, 255, 255, 0.2);
  }
}

.table-container {
  max-height: 500px;
  overflow-y: auto;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.3);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.05);
}

@media (prefers-color-scheme: dark) {
  .table-container {
    background: rgba(0, 0, 0, 0.2);
    border-color: rgba(255, 255, 255, 0.1);
  }
}

#words-table {
  width: 100%;
  border-collapse: collapse;
}

#words-table th {
  position: sticky;
  top: 0;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(10px);
  padding: 1rem;
  text-align: left;
  font-family: 'Outfit', sans-serif;
  font-weight: 600;
  color: #666;
  z-index: 10;
}

@media (prefers-color-scheme: dark) {
  #words-table th {
    background: rgba(30, 30, 35, 0.95);
    color: #aaa;
  }
}

#words-table td {
  padding: 1rem;
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
  font-family: 'Outfit', sans-serif;
  color: #333;
  cursor: pointer;
  transition: background 0.2s ease;
}

@media (prefers-color-scheme: dark) {
  #words-table td {
    border-color: rgba(255, 255, 255, 0.05);
    color: #e0e0e0;
  }
}

#words-table tr:hover td {
  background: rgba(0, 0, 0, 0.05);
}

@media (prefers-color-scheme: dark) {
  #words-table tr:hover td {
    background: rgba(255, 255, 255, 0.05);
  }
}

#words-table td:first-child {
  font-weight: 600;
  width: 30%;
}

/* Scrollbar Styling */
.table-container::-webkit-scrollbar {
  width: 8px;
}

.table-container::-webkit-scrollbar-track {
  background: transparent;
}

.table-container::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 4px;
}

@media (prefers-color-scheme: dark) {
  .table-container::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
  }
}

/* Drag Cursor */
.rolodex-wheel {
  cursor: grab;
}

.rolodex-wheel:active {
  cursor: grabbing;
}