/**
 * Langsplain - Styles
 * Dark mode, responsive design, animations
 */

/* ============================================
   CSS Variables / Design Tokens
   ============================================ */

:root {
    /* Colors */
    --bg-primary: #0a0a0a;
    --bg-secondary: #141414;
    --bg-elevated: #1a1a1a;
    --bg-hover: #242424;
    --text-primary: #f0f0f0;
    --text-secondary: #a0a0a0;
    --text-muted: #606060;
    --accent-cyan: #00d4ff;
    --accent-purple: #a855f7;
    --accent-green: #22c55e;
    --accent-orange: #f97316;
    --accent-pink: #ec4899;
    --accent-yellow: #eab308;

    /* Borders */
    --border-color: #2a2a2a;
    --border-subtle: #1f1f1f;

    /* Diagram colors */
    --box-stroke: #404040;
    --box-fill: #1a1a1a;
    --arrow-color: #606060;

    /* Effects */
    --glow-cyan: 0 0 20px rgba(0, 212, 255, 0.4);
    --glow-purple: 0 0 20px rgba(168, 85, 247, 0.4);

    /* Typography */
    --font-main: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', Consolas, monospace;

    /* Spacing */
    --panel-width: 400px;
    --header-height: 60px;
    --diagram-padding: 40px;

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
    --transition-slow: 400ms ease;
}

/* ============================================
   Reset & Base Styles
   ============================================ */

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

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-main);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
}

a {
    color: var(--accent-cyan);
    text-decoration: none;
    transition: color var(--transition-fast);
}

a:hover {
    color: var(--text-primary);
}

button {
    font-family: inherit;
    cursor: pointer;
    border: none;
    background: none;
    color: inherit;
}

/* ============================================
   Navigation Header
   ============================================ */

.nav-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background: rgba(10, 10, 10, 0.9);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    z-index: 1000;
}

.nav-logo {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

.nav-logo svg {
    width: 32px;
    height: 32px;
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 32px;
}

.nav-link {
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
    transition: color var(--transition-fast);
}

.nav-link:hover,
.nav-link.active {
    color: var(--text-primary);
}

.tour-start-btn {
    background: linear-gradient(135deg, var(--accent-cyan), var(--accent-purple));
    color: var(--bg-primary);
    padding: 10px 20px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.9rem;
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
    animation: pulse-glow 2s ease-in-out infinite;
}

.tour-start-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--glow-cyan);
}

@keyframes pulse-glow {

    0%,
    100% {
        box-shadow: 0 0 10px rgba(0, 212, 255, 0.3);
    }

    50% {
        box-shadow: 0 0 20px rgba(0, 212, 255, 0.5);
    }
}

/* ============================================
   Main Layout
   ============================================ */

.main-container {
    display: flex;
    min-height: 100vh;
    padding-top: var(--header-height);
}

.diagram-section {
    flex: 1;
    padding: var(--diagram-padding);
    display: flex;
    flex-direction: column;
    align-items: center;
    transition: margin-right var(--transition-normal);
}

.diagram-section.panel-open {
    margin-right: var(--panel-width);
}

.diagram-container {
    width: 100%;
    max-width: 600px;
    position: relative;
}

.diagram-svg {
    width: 100%;
    height: auto;
}

/* Demo buttons below diagram */
.demo-buttons {
    display: flex;
    gap: 16px;
    margin-top: 24px;
    flex-wrap: wrap;
    justify-content: center;
}

.demo-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 24px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-weight: 500;
    transition: all var(--transition-fast);
}

.demo-btn:hover {
    background: var(--bg-hover);
    border-color: var(--accent-cyan);
    box-shadow: var(--glow-cyan);
}

.demo-btn svg {
    width: 20px;
    height: 20px;
}

/* ============================================
   Info Panel (Right Sidebar)
   ============================================ */

.info-panel {
    position: fixed;
    top: var(--header-height);
    right: 0;
    width: var(--panel-width);
    height: calc(100vh - var(--header-height));
    background: var(--bg-secondary);
    border-left: 1px solid var(--border-color);
    transform: translateX(100%);
    transition: transform var(--transition-normal);
    overflow-y: auto;
    z-index: 500;
}

.info-panel.open {
    transform: translateX(0);
}

.panel-header {
    position: sticky;
    top: 0;
    background: var(--bg-secondary);
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.panel-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

.panel-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    color: var(--text-secondary);
    font-size: 1.5rem;
    transition: all var(--transition-fast);
}

.panel-close:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.panel-content {
    padding: 24px;
}

.simple-explanation {
    color: var(--text-primary);
    font-size: 1rem;
    line-height: 1.7;
    margin-bottom: 20px;
}

.simple-explanation p {
    margin-bottom: 12px;
}

.technical-details {
    margin-top: 20px;
    border-top: 1px solid var(--border-color);
    padding-top: 16px;
}

.technical-details summary {
    cursor: pointer;
    color: var(--accent-cyan);
    font-weight: 500;
    font-size: 0.9rem;
    padding: 8px 0;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 8px;
}

.technical-details summary::before {
    content: '▶';
    font-size: 0.7rem;
    transition: transform var(--transition-fast);
}

.technical-details[open] summary::before {
    transform: rotate(90deg);
}

.technical-content {
    padding: 16px 0;
    color: var(--text-secondary);
    font-size: 0.95rem;
}

.technical-content code {
    background: var(--bg-primary);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 0.85em;
    color: var(--accent-cyan);
}

.technical-content pre {
    background: var(--bg-primary);
    padding: 16px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 12px 0;
}

.technical-content pre code {
    padding: 0;
    background: none;
}

.formula {
    background: var(--bg-primary);
    padding: 16px;
    border-radius: 8px;
    font-family: var(--font-mono);
    font-size: 0.9rem;
    color: var(--accent-purple);
    text-align: center;
    margin: 12px 0;
    overflow-x: auto;
}

.panel-visual {
    margin-top: 24px;
    padding: 20px;
    background: var(--bg-primary);
    border-radius: 12px;
    border: 1px solid var(--border-color);
}

/* ============================================
   Demo Modals
   ============================================ */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-normal);
}

.modal-overlay.open {
    opacity: 1;
    visibility: visible;
}

.modal {
    width: 90vw;
    max-width: 1200px;
    max-height: 90vh;
    background: var(--bg-secondary);
    border-radius: 16px;
    border: 1px solid var(--border-color);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transform: scale(0.95);
    transition: transform var(--transition-normal);
}

.modal-overlay.open .modal {
    transform: scale(1);
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-header h2 {
    font-size: 1.5rem;
    font-weight: 600;
}

.modal-close {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    color: var(--text-secondary);
    font-size: 1.5rem;
    transition: all var(--transition-fast);
}

.modal-close:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

/* ============================================
   Demo Components
   ============================================ */

.demo-content {
    max-width: 1000px;
    margin: 0 auto;
}

.demo-header {
    text-align: center;
    margin-bottom: 32px;
}

.demo-header h2 {
    font-size: 1.75rem;
    margin-bottom: 8px;
}

.demo-description {
    color: var(--text-secondary);
    font-size: 1rem;
}

.demo-input-section {
    margin-bottom: 24px;
}

.demo-input-section label {
    display: block;
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 8px;
}

.input-row {
    display: flex;
    gap: 12px;
}

.input-row input {
    flex: 1;
    padding: 12px 16px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 1rem;
    transition: border-color var(--transition-fast);
}

.input-row input:focus {
    outline: none;
    border-color: var(--accent-cyan);
}

.primary-btn {
    padding: 12px 24px;
    background: var(--accent-cyan);
    color: var(--bg-primary);
    font-weight: 600;
    border-radius: 8px;
    transition: all var(--transition-fast);
}

.primary-btn:hover {
    background: #00b8e6;
    transform: translateY(-1px);
}

.primary-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.secondary-btn {
    padding: 10px 20px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    font-weight: 500;
    border-radius: 8px;
    transition: all var(--transition-fast);
}

.secondary-btn:hover {
    background: var(--bg-hover);
    border-color: var(--accent-cyan);
}

.secondary-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Demo controls */
.demo-controls {
    display: flex;
    gap: 24px;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 24px;
    padding: 16px;
    background: var(--bg-elevated);
    border-radius: 12px;
}

.control-group {
    display: flex;
    align-items: center;
    gap: 12px;
}

.control-group label {
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
}

.layer-buttons,
.head-buttons {
    display: flex;
    gap: 6px;
}

.selector-btn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 500;
    transition: all var(--transition-fast);
}

.selector-btn:hover {
    border-color: var(--accent-cyan);
    color: var(--text-primary);
}

.selector-btn.active {
    background: var(--accent-cyan);
    border-color: var(--accent-cyan);
    color: var(--bg-primary);
}

/* Visualization area */
.visualization-area {
    display: grid;
    grid-template-columns: 1fr;
    gap: 24px;
    margin-bottom: 24px;
}

.tokens-display {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    padding: 16px;
    background: var(--bg-elevated);
    border-radius: 12px;
}

.token-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 8px 12px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    min-width: 50px;
}

.token-text {
    font-family: var(--font-mono);
    font-size: 0.9rem;
    color: var(--text-primary);
}

.token-pos {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 2px;
}

/* Attention visualization */
.attention-viz {
    background: var(--bg-elevated);
    border-radius: 12px;
    padding: 20px;
    min-height: 200px;
}

#attention-svg {
    width: 100%;
    display: block;
}

.attention-arc {
    transition: stroke-width var(--transition-fast), stroke-opacity var(--transition-fast);
}

/* Heatmap */
.heatmap-container {
    background: var(--bg-elevated);
    border-radius: 12px;
    padding: 20px;
}

.heatmap-container h4 {
    margin-bottom: 16px;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.heatmap-grid {
    display: grid;
    gap: 2px;
    font-size: 0.75rem;
}

.heatmap-header {
    text-align: center;
    color: var(--text-secondary);
    padding: 4px;
    font-weight: 500;
    transform: rotate(-45deg);
    white-space: nowrap;
}

.heatmap-label {
    text-align: right;
    color: var(--text-secondary);
    padding: 4px 8px;
    font-weight: 500;
}

.heatmap-cell {
    width: 100%;
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 2px;
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 0.65rem;
    min-width: 30px;
    min-height: 30px;
}

.heatmap-cell.masked {
    background: var(--bg-primary);
    color: var(--text-muted);
}

/* Demo explanation */
.demo-explanation {
    padding: 16px;
    background: var(--bg-elevated);
    border-radius: 12px;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.demo-explanation strong {
    color: var(--text-primary);
}

.demo-explanation .hint {
    color: var(--text-muted);
    font-style: italic;
    margin-top: 8px;
}

/* ============================================
   MOE Demo Specific Styles
   ============================================ */

.moe-visualization {
    display: grid;
    grid-template-columns: 150px 1fr 180px;
    gap: 20px;
    margin-bottom: 24px;
    min-height: 300px;
}

.moe-tokens,
.moe-experts {
    background: var(--bg-elevated);
    border-radius: 12px;
    padding: 16px;
}

.moe-tokens h4,
.moe-experts h4 {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-bottom: 12px;
}

.token-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.moe-token {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.moe-token:hover {
    border-color: var(--accent-purple);
}

.moe-token.selected {
    border-color: var(--accent-cyan);
    box-shadow: var(--glow-cyan);
}

.token-experts {
    display: flex;
    gap: 4px;
}

.expert-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.expert-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.expert-box {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    background: var(--bg-primary);
    border: 1px solid;
    border-radius: 6px;
}

.expert-icon {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--bg-primary);
}

.expert-info {
    display: flex;
    flex-direction: column;
}

.expert-name {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-primary);
}

.expert-load {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.moe-flow {
    background: var(--bg-elevated);
    border-radius: 12px;
    padding: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#moe-svg {
    width: 100%;
    height: 100%;
    min-height: 200px;
}

.routing-path {
    transition: opacity var(--transition-fast), stroke-width var(--transition-fast);
}

/* MOE Stats */
.moe-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 24px;
}

.stat-panel {
    background: var(--bg-elevated);
    border-radius: 12px;
    padding: 16px;
}

.stat-panel h4 {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-bottom: 12px;
}

.stat-panel .hint {
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* Routing detail */
.selected-experts {
    margin-bottom: 16px;
}

.all-probs {
    margin-top: 12px;
}

.prob-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
    font-size: 0.8rem;
}

.prob-expert {
    width: 80px;
    font-weight: 500;
}

.prob-bar-track {
    flex: 1;
    height: 8px;
    background: var(--bg-primary);
    border-radius: 4px;
    overflow: hidden;
}

.prob-bar-fill {
    height: 100%;
    border-radius: 4px;
    transition: width var(--transition-normal);
}

.prob-value {
    width: 45px;
    text-align: right;
    color: var(--text-secondary);
}

/* Load balance chart */
.load-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}

.bar-label {
    width: 24px;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.bar-track {
    flex: 1;
    height: 12px;
    background: var(--bg-primary);
    border-radius: 6px;
    position: relative;
    overflow: hidden;
}

.bar-fill {
    height: 100%;
    border-radius: 6px;
    transition: width var(--transition-normal);
}

.bar-ideal {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--text-primary);
    opacity: 0.5;
}

.bar-count {
    width: 20px;
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-align: right;
}

.load-legend {
    margin-top: 12px;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.legend-line {
    width: 16px;
    height: 2px;
    background: var(--text-primary);
    opacity: 0.5;
}

/* ============================================
   Tour Styles
   ============================================ */

.tour-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    z-index: 3000;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-normal);
}

.tour-overlay.active {
    opacity: 1;
    visibility: visible;
}

.tour-spotlight {
    position: absolute;
    border-radius: 8px;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.75);
    transition: all var(--transition-normal);
    pointer-events: none;
}

.tour-tooltip {
    position: fixed;
    width: 320px;
    background: var(--bg-secondary);
    border: 1px solid var(--accent-cyan);
    border-radius: 12px;
    padding: 20px;
    z-index: 3001;
    box-shadow: var(--glow-cyan);
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-normal);
}

.tour-tooltip.active {
    opacity: 1;
    visibility: visible;
}

.tour-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    color: var(--text-secondary);
    font-size: 1.25rem;
    transition: all var(--transition-fast);
}

.tour-close:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.tour-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 12px;
    padding-right: 24px;
}

.tour-content {
    color: var(--text-secondary);
    font-size: 0.95rem;
    line-height: 1.6;
    margin-bottom: 20px;
}

.tour-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.tour-progress {
    color: var(--text-muted);
    font-size: 0.8rem;
}

.tour-buttons {
    display: flex;
    gap: 8px;
}

.tour-btn {
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all var(--transition-fast);
}

.tour-prev {
    background: var(--bg-elevated);
    color: var(--text-secondary);
}

.tour-prev:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.tour-next {
    background: var(--accent-cyan);
    color: var(--bg-primary);
}

.tour-next:hover {
    background: #00b8e6;
}

/* ============================================
   Glossary Styles
   ============================================ */

.glossary-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 40px 24px;
}

.glossary-header {
    text-align: center;
    margin-bottom: 40px;
}

.glossary-header h1 {
    font-size: 2rem;
    margin-bottom: 8px;
}

.glossary-header p {
    color: var(--text-secondary);
}

.glossary-search {
    margin-bottom: 32px;
}

.glossary-search input {
    width: 100%;
    padding: 14px 20px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    color: var(--text-primary);
    font-size: 1rem;
    transition: border-color var(--transition-fast);
}

.glossary-search input:focus {
    outline: none;
    border-color: var(--accent-cyan);
}

.glossary-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.glossary-item {
    background: var(--bg-elevated);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 20px;
    transition: border-color var(--transition-fast);
}

.glossary-item:hover {
    border-color: var(--accent-cyan);
}

.glossary-term {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--accent-cyan);
    margin-bottom: 8px;
}

.glossary-definition {
    color: var(--text-secondary);
    line-height: 1.6;
}

/* ============================================
   About Page Styles
   ============================================ */

.about-container {
    max-width: 700px;
    margin: 0 auto;
    padding: 40px 24px;
}

.about-header {
    text-align: center;
    margin-bottom: 40px;
}

.about-header h1 {
    font-size: 2rem;
    margin-bottom: 16px;
}

.about-content {
    color: var(--text-secondary);
    line-height: 1.8;
}

.about-content h2 {
    color: var(--text-primary);
    font-size: 1.25rem;
    margin: 32px 0 16px;
}

.about-content p {
    margin-bottom: 16px;
}

.about-content ul {
    margin: 16px 0;
    padding-left: 24px;
}

.about-content li {
    margin-bottom: 8px;
}

.about-content a {
    color: var(--accent-cyan);
}

/* ============================================
   View Management
   ============================================ */

.view {
    display: none;
}

.view.active {
    display: block;
}

/* ============================================
   Component Diagram Styles
   ============================================ */

.component-box {
    transition: opacity var(--transition-normal);
}

.component-box.hidden {
    opacity: 0;
    pointer-events: none;
}

.component-box:hover {
    cursor: pointer;
}

.box-bg {
    transition: filter var(--transition-fast), stroke-width var(--transition-fast);
}

.box-label {
    pointer-events: none;
}

.box-sublabel {
    pointer-events: none;
}

.container-label {
    pointer-events: none;
}

/* Token flow animation */
.flowing-token rect {
    filter: drop-shadow(0 0 8px rgba(168, 85, 247, 0.5));
}

/* ============================================
   Responsive Design
   ============================================ */

/* Tablet */
@media (max-width: 1024px) {
    :root {
        --panel-width: 350px;
    }

    .nav-links {
        gap: 20px;
    }

    .moe-visualization {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto auto;
    }

    .moe-tokens,
    .moe-experts {
        flex-direction: row;
        flex-wrap: wrap;
    }

    .token-list,
    .expert-list {
        flex-direction: row;
        flex-wrap: wrap;
    }

    .moe-stats {
        grid-template-columns: 1fr;
    }
}

/* Mobile */
@media (max-width: 768px) {
    :root {
        --header-height: 56px;
        --diagram-padding: 20px;
    }

    .nav-header {
        padding: 0 16px;
    }

    .nav-logo span {
        display: none;
    }

    .nav-links {
        gap: 12px;
    }

    .nav-link {
        font-size: 0.85rem;
    }

    .tour-start-btn {
        padding: 8px 16px;
        font-size: 0.85rem;
    }

    .diagram-section {
        padding: 16px;
    }

    .diagram-container {
        display: flex;
        flex-direction: column;
        align-items: center;
    }

    .diagram-section.panel-open {
        margin-right: 0;
    }

    .main-container {
        flex-direction: column;
    }

    .view {
        width: 100%;
    }

    .info-panel {
        width: 100%;
        height: 60vh;
        top: auto;
        bottom: 0;
        transform: translateY(100%);
        border-left: none;
        border-top: 1px solid var(--border-color);
        border-radius: 20px 20px 0 0;
    }

    .info-panel.open {
        transform: translateY(0);
    }

    .demo-buttons {
        flex-direction: column;
        align-items: center;
        width: 100%;
    }

    .demo-btn {
        width: 100%;
        max-width: 280px;
        justify-content: center;
    }

    .modal {
        width: 100%;
        max-width: none;
        height: 100%;
        max-height: none;
        border-radius: 0;
    }

    .demo-controls {
        flex-direction: column;
        align-items: flex-start;
    }

    .visualization-area {
        gap: 16px;
    }

    .heatmap-cell {
        min-width: 24px;
        min-height: 24px;
        font-size: 0.55rem;
    }

    .tour-tooltip {
        width: calc(100vw - 32px);
        left: 16px !important;
        bottom: 100px;
        top: auto !important;
    }
}

/* Small mobile */
@media (max-width: 480px) {
    .nav-links a:not(.tour-start-btn) {
        display: none;
    }

    .input-row {
        flex-direction: column;
    }

    .primary-btn {
        width: 100%;
    }

    .glossary-container,
    .about-container {
        padding: 24px 16px;
    }
}

/* ============================================
   Animations
   ============================================ */

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideRight {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.animate-fade-in {
    animation: fadeIn var(--transition-normal) ease forwards;
}

.animate-slide-up {
    animation: slideUp var(--transition-normal) ease forwards;
}

.animate-slide-right {
    animation: slideRight var(--transition-normal) ease forwards;
}

/* ============================================
   Scrollbar Styling
   ============================================ */

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* Firefox */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) var(--bg-primary);
}

/* ============================================
   Sampling Demo Styles
   ============================================ */

.sampling-demo .sampling-controls {
    display: flex;
    gap: 24px;
    flex-wrap: wrap;
    margin-bottom: 24px;
    padding: 20px;
    background: var(--bg-elevated);
    border-radius: 12px;
}

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

.slider-group label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.slider-label {
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
}

.slider-value {
    color: var(--accent-cyan);
    font-family: var(--font-mono);
    font-size: 0.9rem;
    font-weight: 600;
}

.slider-group input[type="range"] {
    width: 100%;
    height: 6px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--bg-primary);
    border-radius: 3px;
    outline: none;
}

.slider-group input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--accent-cyan);
    cursor: pointer;
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.slider-group input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.1);
    box-shadow: var(--glow-cyan);
}

.slider-group input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border: none;
    border-radius: 50%;
    background: var(--accent-cyan);
    cursor: pointer;
}

.slider-hints {
    display: flex;
    justify-content: space-between;
    margin-top: 4px;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.sampling-actions {
    display: flex;
    gap: 12px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}

.sampling-actions .primary-btn {
    display: flex;
    align-items: center;
    gap: 8px;
}

.probability-chart-container {
    background: var(--bg-elevated);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 24px;
}

.probability-chart-container h4 {
    margin-bottom: 12px;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.chart-legend {
    display: flex;
    gap: 24px;
    margin-bottom: 16px;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.chart-legend strong {
    color: var(--accent-cyan);
}

.probability-chart {
    min-height: 250px;
}

.probability-chart.small {
    min-height: 150px;
}

.probability-chart svg {
    display: block;
}

.probability-chart .bar {
    transition: filter var(--transition-fast);
}

.comparison-container {
    background: var(--bg-elevated);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 24px;
}

.comparison-container.hidden {
    display: none;
}

.comparison-container h4 {
    margin-bottom: 16px;
    color: var(--text-secondary);
}

.comparison-charts {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.comparison-panel {
    background: var(--bg-primary);
    border-radius: 8px;
    padding: 16px;
}

.comparison-panel h5 {
    margin-bottom: 8px;
    color: var(--text-primary);
    font-size: 0.9rem;
}

.comparison-params {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--accent-purple);
    margin-bottom: 12px;
}

.sampled-history {
    background: var(--bg-elevated);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 24px;
}

.sampled-history h4 {
    margin-bottom: 12px;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.history-tokens {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    min-height: 40px;
}

.history-tokens .hint {
    color: var(--text-muted);
    font-style: italic;
}

.sampled-token {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: var(--bg-primary);
    border: 1px solid var(--accent-cyan);
    border-radius: 20px;
    font-family: var(--font-mono);
    font-size: 0.85rem;
    color: var(--text-primary);
}

.sampled-token .token-prob {
    font-size: 0.7rem;
    color: var(--text-muted);
}

/* ============================================
   KV Cache Demo Styles
   ============================================ */

.kv-cache-demo .kv-controls {
    display: flex;
    gap: 24px;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 24px;
    padding: 16px;
    background: var(--bg-elevated);
    border-radius: 12px;
}

.toggle-buttons {
    display: flex;
    gap: 4px;
}

.toggle-btn {
    padding: 8px 16px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-secondary);
    font-size: 0.85rem;
    transition: all var(--transition-fast);
}

.toggle-btn:hover {
    border-color: var(--accent-cyan);
    color: var(--text-primary);
}

.toggle-btn.active {
    background: var(--accent-cyan);
    border-color: var(--accent-cyan);
    color: var(--bg-primary);
}

.kv-comparison {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 24px;
}

.kv-panel {
    background: var(--bg-elevated);
    border-radius: 12px;
    padding: 20px;
    border: 2px solid transparent;
}

.kv-panel.with-cache {
    border-color: var(--accent-green);
}

.kv-panel.without-cache {
    border-color: var(--accent-orange);
}

.panel-header-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.panel-header-bar h4 {
    color: var(--text-primary);
    font-size: 1rem;
}

.efficiency-badge {
    padding: 4px 10px;
    background: rgba(34, 197, 94, 0.2);
    border-radius: 12px;
    font-size: 0.75rem;
    color: var(--accent-green);
    font-weight: 500;
}

.inefficiency-badge {
    padding: 4px 10px;
    background: rgba(249, 115, 22, 0.2);
    border-radius: 12px;
    font-size: 0.75rem;
    color: var(--accent-orange);
    font-weight: 500;
}

.token-sequence {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    min-height: 36px;
    margin-bottom: 16px;
    padding: 10px;
    background: var(--bg-primary);
    border-radius: 8px;
}

.token-sequence .placeholder {
    color: var(--text-muted);
    font-style: italic;
    font-size: 0.85rem;
}

.kv-token {
    padding: 4px 10px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 0.85rem;
    color: var(--text-primary);
    transition: all var(--transition-fast);
}

.kv-token.new {
    background: var(--accent-cyan);
    border-color: var(--accent-cyan);
    color: var(--bg-primary);
    animation: pulse-new 0.5s ease;
}

@keyframes pulse-new {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.1);
    }
}

.cache-grid-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 16px;
}

.cache-section h5 {
    color: var(--text-secondary);
    font-size: 0.8rem;
    margin-bottom: 8px;
}

.cache-grid {
    background: var(--bg-primary);
    border-radius: 8px;
    padding: 12px;
    min-height: 120px;
}

.cache-grid.recompute .cache-row.recomputing {
    animation: recompute-flash 0.5s ease;
}

@keyframes recompute-flash {

    0%,
    100% {
        background: transparent;
    }

    50% {
        background: rgba(249, 115, 22, 0.3);
    }
}

.cache-empty {
    color: var(--text-muted);
    font-style: italic;
    font-size: 0.8rem;
    text-align: center;
    padding: 20px;
}

.cache-header {
    display: flex;
    gap: 4px;
    margin-bottom: 8px;
}

.cache-header .col-label {
    flex: 1;
    text-align: center;
    font-size: 0.65rem;
    color: var(--text-muted);
}

.cache-row {
    display: flex;
    gap: 4px;
    margin-bottom: 4px;
    padding: 2px;
    border-radius: 4px;
    transition: background var(--transition-fast);
}

.cache-row.highlighted {
    background: rgba(0, 212, 255, 0.1);
}

.cache-row .row-label {
    width: 24px;
    font-size: 0.65rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
}

.cache-cell {
    flex: 1;
    height: 16px;
    border-radius: 2px;
    transition: background var(--transition-fast);
}

.computation-counter {
    display: flex;
    gap: 20px;
    padding: 12px;
    background: var(--bg-primary);
    border-radius: 8px;
}

.counter-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.counter-label {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.counter-value {
    font-family: var(--font-mono);
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--accent-cyan);
}

.counter-value.warning {
    color: var(--accent-orange);
}

.savings-display {
    background: var(--bg-elevated);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 24px;
}

.savings-display h4 {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 12px;
}

.savings-bar-container {
    height: 32px;
    background: var(--bg-primary);
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 12px;
}

.savings-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-green), var(--accent-cyan));
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 80px;
    transition: width 0.5s ease;
}

.savings-text {
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--bg-primary);
}

.savings-detail {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.savings-detail strong {
    color: var(--accent-cyan);
}

/* ============================================
   BPE Visualization Styles
   ============================================ */

.bpe-demo-section {
    margin-top: 20px;
    padding: 16px;
    background: var(--bg-primary);
    border-radius: 12px;
    border: 1px solid var(--border-color);
}

.bpe-demo-section h4 {
    color: var(--text-primary);
    font-size: 0.95rem;
    margin-bottom: 12px;
}

.bpe-note {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 12px;
    font-style: italic;
}

.bpe-suggestions {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.bpe-suggestions>span {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.bpe-suggest-btn {
    padding: 4px 10px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--accent-cyan);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.bpe-suggest-btn:hover {
    background: var(--accent-cyan);
    color: var(--bg-primary);
}

.bpe-input-row {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.bpe-input-row input {
    flex: 1;
    padding: 10px 14px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 0.9rem;
}

.bpe-input-row input:focus {
    outline: none;
    border-color: var(--accent-cyan);
}

.bpe-visualization {
    background: var(--bg-secondary);
    border-radius: 8px;
    padding: 16px;
}

.bpe-steps {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.bpe-step {
    padding: 12px;
    background: var(--bg-elevated);
    border-radius: 8px;
    border-left: 3px solid var(--border-color);
}

.bpe-step.final {
    border-left-color: var(--accent-cyan);
    background: rgba(0, 212, 255, 0.05);
}

.step-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.step-number {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.step-freq {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

.step-tokens {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    align-items: center;
}

.bpe-token {
    padding: 4px 8px;
    background: var(--bg-primary);
    border: 2px solid var(--border-color);
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 0.85rem;
    color: var(--text-primary);
    transition: all var(--transition-fast);
}

.bpe-token.merged {
    background: rgba(0, 212, 255, 0.1);
    border-color: var(--accent-cyan);
    animation: merge-pulse 0.3s ease;
}

@keyframes merge-pulse {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.05);
    }
}

.token-separator {
    color: var(--text-muted);
    font-size: 0.8rem;
}

.step-description {
    margin-top: 6px;
    font-size: 0.75rem;
    color: var(--accent-purple);
}

.step-arrow {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.9rem;
    padding: 4px 0;
}

.bpe-summary {
    margin-top: 16px;
    padding: 12px;
    background: var(--bg-elevated);
    border-radius: 8px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-align: center;
}

.bpe-summary strong {
    color: var(--accent-cyan);
}

/* ============================================
   Responsive Adjustments for New Components
   ============================================ */

@media (max-width: 1024px) {
    .kv-comparison {
        grid-template-columns: 1fr;
    }

    .comparison-charts {
        grid-template-columns: 1fr;
    }

    .sampling-demo .sampling-controls {
        flex-direction: column;
    }

    .slider-group {
        min-width: 100%;
    }
}

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

    .computation-counter {
        flex-direction: column;
        gap: 12px;
    }

    .kv-cache-demo .kv-controls {
        flex-direction: column;
        align-items: stretch;
    }

    .toggle-buttons {
        justify-content: center;
    }

    .sampling-actions {
        flex-direction: column;
    }

    .sampling-actions button {
        width: 100%;
        justify-content: center;
    }
}