:root {
  --bg-dark: #0f172a;
  --bg-sidebar: rgba(15, 23, 42, 0.85);
  --bg-card: rgba(30, 41, 59, 0.7);
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --glass-border: rgba(255, 255, 255, 0.1);
  --accent: #8b5cf6;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: "Inter", sans-serif;
}

body {
  background-color: var(--bg-dark);
  background-image:
    radial-gradient(at 0% 0%, rgba(99, 102, 241, 0.15) 0px, transparent 50%),
    radial-gradient(at 100% 100%, rgba(139, 92, 246, 0.15) 0px, transparent 50%);
  background-attachment: fixed;
  color: var(--text-main);
  height: 100vh;
  display: flex;
  overflow: hidden;
}

/* Sidebar Layout */
.app-layout {
  display: flex;
  width: 100%;
  height: 100%;
}

.sidebar {
  width: 300px;
  background: var(--bg-sidebar);
  backdrop-filter: blur(12px);
  border-right: 1px solid var(--glass-border);
  padding: 2rem;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  z-index: 10;
}

.logo-container {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 3rem;
}

.logo {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  object-fit: cover;
  box-shadow: 0 4px 15px rgba(139, 92, 246, 0.4);
}

h1 {
  font-size: 1.8rem;
  font-weight: 800;
  letter-spacing: -0.05em;
  background: linear-gradient(135deg, #818cf8, #c084fc);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.nav-menu {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  flex-grow: 1;
  overflow-y: auto;
  padding-right: 0.5rem;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.2rem;
  border-radius: 12px;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid transparent;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
  text-align: left;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-main);
}

.nav-item.active {
  background: rgba(99, 102, 241, 0.15);
  color: #818cf8;
  border-color: rgba(99, 102, 241, 0.3);
}

.nav-item svg {
  flex-shrink: 0;
  color: var(--primary);
  opacity: 0.8;
  transition: all 0.3s;
}

.nav-item:hover svg, .nav-item.active svg {
  opacity: 1;
}

.sidebar-footer {
  padding-top: 1rem;
  width: 100%;
  flex-shrink: 0;
}

.github-link {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  color: var(--text-muted);
  text-decoration: none;
  padding: 0.8rem 1rem;
  border-radius: 8px;
  transition: all 0.3s ease;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid transparent;
}

.github-link:hover {
  background: rgba(255, 255, 255, 0.1);
  color: white;
  border-color: var(--glass-border);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.github-link svg {
  transition: transform 0.3s ease;
}

.github-link:hover svg {
  transform: scale(1.1);
}

/* Main Content Area */
.main-content {
  flex-grow: 1;
  min-width: 0;
  width: calc(100vw - 300px);
  height: 100%;
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: 1fr;
  overflow: hidden;
}

.content-section {
  grid-area: 1 / 1;
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 0;
  padding: 3rem 4rem;
  display: flex;
  flex-direction: column;
  opacity: 0;
  pointer-events: none;
  transform: translateY(20px);
  transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  overflow-y: auto;
}

.content-section.active {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.section-header {
  margin-bottom: 2rem;
  max-width: 800px;
}

.section-header h2 {
  font-size: 2.5rem;
  font-weight: 800;
  margin-bottom: 0.5rem;
}

.section-header p {
  color: var(--text-muted);
  font-size: 1.1rem;
}

.highlight {
  color: var(--primary);
  background: linear-gradient(135deg, #818cf8, #c084fc);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* Chat Specific */
.chat-container {
  max-width: 900px;
  width: 100%;
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border);
  border-radius: 20px;
  padding: 2rem;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}

.output-area {
  flex-grow: 1;
  overflow-y: auto;
  background: rgba(15, 23, 42, 0.5);
  border-radius: 12px;
  padding: 1.5rem;
  border: 1px inset rgba(255, 255, 255, 0.05);
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-height: 100px;
}

.output-area::-webkit-scrollbar { width: 6px; }
.output-area::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.2); border-radius: 4px; }

/* Interactive Decoding Specific */
.token-candidates {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  margin-bottom: 1rem;
}

.token-candidate-btn {
  position: relative;
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid var(--glass-border);
  border-radius: 8px;
  padding: 1rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  overflow: hidden;
  color: var(--text-main);
  transition: transform 0.2s, border-color 0.2s;
}

.token-candidate-btn:hover {
  transform: translateX(5px);
  border-color: var(--primary);
}

.token-candidate-bg {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  background: rgba(99, 102, 241, 0.2);
  z-index: 0;
}

.token-candidate-text, .token-candidate-prob {
  position: relative;
  z-index: 1;
  font-family: monospace;
  font-size: 1.1rem;
}

.token-candidate-prob {
  color: #818cf8;
  font-weight: bold;
}

.input-area {
  display: flex;
  gap: 1rem;
}

.input-area input {
  flex-grow: 1;
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  padding: 1.2rem;
  color: white;
  font-size: 1rem;
  transition: all 0.3s;
}

.input-area input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.15);
}

.input-area button {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: white;
  border: none;
  border-radius: 12px;
  padding: 0 2rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s;
  box-shadow: 0 10px 15px -3px rgba(99, 102, 241, 0.3);
}

.input-area button:hover:not(:disabled) {
  transform: translateY(-2px);
}

.input-area button:disabled, .input-area input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none;
}

.controls {
  max-width: 900px;
  display: flex;
  gap: 2rem;
  margin-top: 1.5rem;
  padding: 1.5rem;
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  border-radius: 12px;
  border: 1px solid var(--glass-border);
}

.control-group { flex-grow: 1; }
.control-group label {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.control-group label span { color: var(--text-main); }
.control-group input[type="range"] { width: 100%; accent-color: var(--primary); cursor: pointer; }

/* Docs Specific */
.docs-content {
  max-width: 1000px;
}

.math-block {
  background: rgba(15, 23, 42, 0.8);
  padding: 2rem;
  border-radius: 12px;
  border: 1px solid var(--glass-border);
  margin: 2rem 0;
  overflow-x: auto;
  font-size: 1.1rem;
}

.concept-title {
  font-size: 1.4rem;
  color: var(--primary);
  margin-top: 3rem;
  margin-bottom: 1rem;
  font-weight: 600;
}

.section-divider {
  border: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.1), transparent);
  margin: 3rem 0;
}

.feature-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 2rem;
  margin-top: 2rem;
}

.feature-list li {
  background: var(--bg-card);
  border: 1px solid var(--glass-border);
  padding: 2rem;
  border-radius: 12px;
}

.feature-list strong {
  display: block;
  font-size: 1.2rem;
  color: var(--primary);
  margin-bottom: 0.5rem;
}

.feature-list p {
  color: var(--text-muted);
  line-height: 1.7;
}

/* Interactive Widgets */
.interactive-widgets {
  display: flex;
  flex-direction: column;
  gap: 2rem;
  margin-top: 3rem;
  padding-bottom: 3rem;
}

.widget-card {
  background: rgba(15, 23, 42, 0.4);
  border: 1px solid var(--glass-border);
  border-radius: 16px;
  padding: 2.5rem;
}

.widget-card h3 {
  font-size: 1.4rem;
  color: var(--primary);
  margin-bottom: 0.8rem;
  font-weight: 600;
}

.widget-card p {
  color: var(--text-muted);
  margin-bottom: 2rem;
  font-size: 1rem;
  line-height: 1.6;
}

.widget-controls {
  margin-bottom: 1.5rem;
}

.widget-controls label {
  display: flex;
  justify-content: space-between;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.widget-controls input[type="range"] {
  width: 100%;
  accent-color: var(--primary);
  cursor: pointer;
}

.bars-container {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.bar-row {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.bar-label {
  width: 80px;
  font-family: monospace;
  color: var(--text-muted);
  font-size: 1.1rem;
}

.bar-track {
  flex-grow: 1;
  height: 24px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 6px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  width: 0%;
  transition: width 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.bar-value {
  width: 60px;
  text-align: right;
  font-family: monospace;
  color: var(--text-main);
  font-size: 1.1rem;
}

.widget-btn {
  background: rgba(99, 102, 241, 0.15);
  color: #818cf8;
  border: 1px solid rgba(99, 102, 241, 0.3);
  border-radius: 8px;
  padding: 0.8rem 1.5rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s;
  margin-bottom: 1.5rem;
}

.widget-btn:hover {
  background: rgba(99, 102, 241, 0.25);
}

.attention-grid {
  display: flex;
  flex-direction: column;
  gap: 6rem;
  width: 100%;
  padding: 1rem 0;
  max-width: 600px;
  margin: 0 auto;
}

.attn-cell {
  aspect-ratio: 1;
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.4), rgba(139, 92, 246, 0.4));
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: monospace;
  font-size: 1rem;
  color: white;
  transition: all 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

.attn-cell.masked {
  background: rgba(255, 255, 255, 0.02);
  border-color: transparent;
  color: rgba(255,255,255,0.2);
}

/* Attention Lines Widget */
.attention-viz-container {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  height: 200px;
  position: relative;
  margin: 1rem 0;
  background: rgba(15, 23, 42, 0.3);
  border-radius: 12px;
  padding: 1.5rem;
}

.attn-key-row, .attn-query-row {
  display: flex;
  justify-content: space-around;
  position: relative;
  z-index: 2;
}

.attn-word {
  background: rgba(30, 41, 59, 0.8);
  border: 1px solid var(--glass-border);
  padding: 0.6rem 1rem;
  border-radius: 6px;
  font-family: monospace;
  font-size: 1.1rem;
  color: var(--text-muted);
  transition: all 0.3s;
}

.attn-word.q-word {
  cursor: pointer;
}

.attn-word.q-word:hover {
  background: rgba(99, 102, 241, 0.2);
  color: white;
}

.attn-word.q-word.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary-hover);
  box-shadow: 0 0 15px rgba(99, 102, 241, 0.5);
}

.attn-lines {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

/* BPE Widget */
.bpe-display {
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid var(--glass-border);
  border-radius: 8px;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  min-height: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.bpe-tokens {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.bpe-token {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.2), rgba(139, 92, 246, 0.2));
  border: 1px solid rgba(139, 92, 246, 0.4);
  padding: 0.5rem 1rem;
  border-radius: 6px;
  font-family: monospace;
  font-size: 1.2rem;
  color: white;
  transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Mobile Responsiveness */
@media (max-width: 1024px) {
  body {
    height: 100dvh;
    overflow-y: auto;
  }

  .app-layout {
    flex-direction: column;
    height: auto;
  }
  
  .sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--glass-border);
    padding: 1rem 0;
    align-items: center;
    flex-shrink: 0;
    z-index: 20;
    position: relative;
  }
  
  .logo-container {
    margin-bottom: 1rem;
  }

  .nav-menu {
    width: 100%;
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    overflow-x: auto;
    padding: 0 1rem 1rem 1rem;
    gap: 0.5rem;
    -ms-overflow-style: none;
    scrollbar-width: none;
    mask-image: linear-gradient(to right, black 85%, transparent 100%);
    -webkit-mask-image: linear-gradient(to right, black 85%, transparent 100%);
  }

  .nav-menu::-webkit-scrollbar {
    display: none;
  }

  .nav-item {
    padding: 0.8rem 1rem;
    white-space: nowrap;
    font-size: 0.9rem;
    flex-shrink: 0;
    justify-content: center;
  }

  .nav-item svg {
    width: 16px;
    height: 16px;
  }

  .sidebar-footer {
    display: none;
  }
  
  .mobile-footer {
    display: flex !important;
  }

  .main-content {
    display: block;
    overflow-y: visible;
    width: 100%;
    height: auto;
  }

  .content-section {
    position: relative;
    padding: 1.5rem 1rem;
    height: auto;
    overflow-y: visible;
    transform: none;
    display: none;
  }

  .content-section.active {
    display: flex;
    transform: none;
  }

  .section-header h2 {
    font-size: 1.8rem;
  }

  .chat-container {
    padding: 1rem;
  }

  .output-area {
    min-height: 300px;
  }

  .input-area {
    flex-direction: column;
  }
  
  .input-area button {
    padding: 1rem;
  }

  .controls {
    flex-direction: column;
    gap: 1rem;
    padding: 1rem;
  }

  .widget-card {
    padding: 1.5rem;
  }

  .bar-row {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .bar-label {
    width: 100%;
    font-size: 0.9rem;
  }
  
  .attention-grid {
    max-width: 100%;
  }
}

/* Model Metadata */
.model-metadata {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}
.metadata-badge {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.75rem;
  font-family: monospace;
  background: rgba(99, 102, 241, 0.1);
  color: var(--primary);
  padding: 0.4rem 0.8rem;
  border-radius: 9999px;
  border: 1px solid rgba(99, 102, 241, 0.3);
}

/* Empty State & Chips */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1rem 0;
}
.chip-container {
  display: flex;
  flex-wrap: wrap;
  gap: 0.8rem;
  justify-content: center;
}
.example-chip {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 0.5rem 1rem;
  border-radius: 99px;
  font-size: 0.9rem;
  color: var(--text-color);
  cursor: pointer;
  transition: all 0.2s;
}
.example-chip:hover {
  background: rgba(99, 102, 241, 0.15);
  border-color: var(--primary);
}

/* Advanced Settings */
.advanced-settings {
  margin-top: -1rem;
  margin-bottom: 1rem;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--glass-border);
  border-radius: 8px;
  padding: 1rem;
}
.advanced-settings summary {
  color: var(--text-muted);
  font-size: 0.9rem;
  cursor: pointer;
  user-select: none;
  font-weight: 500;
  outline: none;
}
.advanced-settings summary:hover {
  color: var(--text-color);
}
.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1.5rem;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px dashed rgba(255, 255, 255, 0.1);
}
.setting-item label {
  display: block;
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
  color: var(--text-muted);
}

/* Secondary Button */
.btn-secondary {
  background: rgba(255, 255, 255, 0.05) !important;
  border: 1px solid rgba(255, 255, 255, 0.1) !important;
  color: var(--text-color) !important;
  box-shadow: none !important;
}
.btn-secondary:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.1) !important;
  border-color: rgba(255, 255, 255, 0.2) !important;
}
.btn-secondary:disabled {
  opacity: 0.4 !important;
}

/* Flowchart Buttons */
.flow-btn {
  background: rgba(99, 102, 241, 0.1);
  border: 1px solid rgba(99, 102, 241, 0.3);
  color: var(--primary);
  padding: 0.8rem 1.5rem;
  border-radius: 8px;
  cursor: pointer;
  width: 100%;
  max-width: 300px;
  transition: all 0.2s;
}
.flow-btn:hover {
  background: rgba(99, 102, 241, 0.2);
  border-color: var(--primary);
}
.flow-arrow {
  color: var(--text-muted);
  font-size: 1.5rem;
}

/* Math Toggle */
.concept-title {
  color: var(--primary);
  margin-bottom: 0.5rem;
}
.toggle-btn {
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--glass-border);
  color: var(--text-muted);
  padding: 0.3rem 0.8rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.8rem;
}
.toggle-btn:hover {
  color: var(--text-color);
  background: rgba(255,255,255,0.1);
}
.math-block {
  background: rgba(0,0,0,0.3);
  padding: 1rem;
  border-radius: 8px;
  border-left: 3px solid var(--primary);
  overflow-x: auto;
  margin: 1rem 0;
  transition: opacity 0.3s;
}
.math-block.hidden {
  display: none;
}

/* Training Stepper */
.train-step {
  padding: 0.8rem;
  border-radius: 6px;
  color: var(--text-muted);
  border: 1px solid transparent;
  transition: all 0.3s;
}
.train-step.active {
  background: rgba(99, 102, 241, 0.15);
  color: var(--primary);
  border-color: rgba(99, 102, 241, 0.3);
  font-weight: 600;
}
.train-step.done {
  color: var(--text-color);
  opacity: 0.7;
}

/* Bars Container for RMSNorm */
.bars-container {
  display: flex;
  justify-content: center;
  gap: 10px;
  border-bottom: 1px solid var(--glass-border);
  padding-bottom: 2px;
}

/* Training Pipeline Enhancements */
.data-flow-pipeline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(0, 0, 0, 0.2);
  padding: 1.5rem;
  border-radius: 12px;
  overflow-x: auto;
}
.flow-node {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg-card);
  border: 1px solid var(--glass-border);
  padding: 1rem;
  border-radius: 8px;
  min-width: 90px;
  z-index: 2;
  font-size: 0.9rem;
}
.flow-node.highlight {
  border-color: var(--primary);
  box-shadow: 0 0 15px rgba(99, 102, 241, 0.3);
}
.flow-icon {
  font-size: 1.8rem;
  display: flex;
  align-items: center;
  justify-content: center;
}
.flow-icon svg {
  width: 32px;
  height: 32px;
  stroke: var(--primary);
}
.flow-node.highlight .flow-icon svg {
  stroke: #fff;
}
.flow-arrow {
  flex-grow: 1;
  height: 2px;
  background: var(--glass-border);
  position: relative;
  min-width: 30px;
}
.animated-dots {
  position: absolute;
  top: -4px;
  left: 0;
  width: 10px;
  height: 10px;
  background: var(--primary);
  border-radius: 50%;
  box-shadow: 0 0 10px var(--primary);
  animation: moveDot 2s infinite linear;
}
@keyframes moveDot {
  0% { left: 0; opacity: 0; }
  10% { opacity: 1; }
  90% { opacity: 1; }
  100% { left: 100%; opacity: 0; }
}
@keyframes drawLoss {
  to { stroke-dashoffset: 0; }
}
