/* Brain Anatomy Explorer — Styles */
/* Design tokens inlined for standalone page (no shared tokens.css dependency) */

/* ===== Layer order ===== */
@layer reset, tokens, base, components, utilities;

/* ===== Design Tokens ===== */
@layer tokens {
  :root {
    --font-heading: 'Instrument Serif', Georgia, 'Times New Roman', serif;
    --font-body: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;

    --text-xs: 0.75rem;
    --text-sm: 0.875rem;
    --text-base: 1rem;
    --text-lg: 1.125rem;
    --text-xl: 1.25rem;
    --text-2xl: 1.5rem;

    --leading-tight: 1.2;
    --leading-normal: 1.6;

    /* Palette */
    --color-bg: #0a0c10;
    --color-surface: #12151c;
    --color-surface-2: #1a1e28;
    --color-border: #252a36;
    --color-border-bright: #3d4556;
    --color-foreground: #e8eaf0;
    --color-dim: #8891a5;
    --color-muted: #515a6b;

    /* Accent colors */
    --color-purple: #c084fc;
    --color-purple-dim: rgba(192, 132, 252, 0.15);
    --color-purple-glow: 0 0 16px rgba(192, 132, 252, 0.35), 0 0 40px rgba(192, 132, 252, 0.12);

    --color-gold: #ffd166;
    --color-gold-dim: rgba(255, 209, 102, 0.15);
    --color-gold-glow: 0 0 16px rgba(255, 209, 102, 0.4), 0 0 40px rgba(255, 209, 102, 0.12);

    --color-coral: #ff6b6b;
    --color-coral-dim: rgba(255, 107, 107, 0.15);
    --color-coral-glow: 0 0 16px rgba(255, 107, 107, 0.35), 0 0 40px rgba(255, 107, 107, 0.12);

    --color-teal: #4ecdc4;
    --color-teal-dim: rgba(78, 205, 196, 0.15);
    --color-teal-glow: 0 0 16px rgba(78, 205, 196, 0.35), 0 0 40px rgba(78, 205, 196, 0.12);

    --color-blue: #6c9bff;
    --color-blue-dim: rgba(108, 155, 255, 0.15);
    --color-blue-glow: 0 0 16px rgba(108, 155, 255, 0.35), 0 0 40px rgba(108, 155, 255, 0.12);

    /* Spacing */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.5rem;
    --space-6: 2rem;

    /* Radius */
    --radius-sm: 0.25rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;
    --radius-full: 9999px;

    /* Transitions */
    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-normal: 250ms cubic-bezier(0.4, 0, 0.2, 1);

    /* Layout */
    --panel-width: 320px;
    --header-height: 4rem;
  }
}

/* ===== Reset ===== */
@layer reset {
  *, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
  }

  html {
    -webkit-text-size-adjust: 100%;
    tab-size: 4;
  }

  body {
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
  }

  img, canvas, svg {
    display: block;
    max-width: 100%;
  }

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

  ul[role="list"] {
    list-style: none;
  }
}

/* ===== Base ===== */
@layer base {
  html, body {
    height: 100%;
  }

  body {
    background: var(--color-bg);
    color: var(--color-foreground);
    font-family: var(--font-body);
    font-size: var(--text-base);
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
  }
}

/* ===== Components ===== */
@layer components {

  /* Grain texture */
  .grain {
    position: fixed;
    inset: 0;
    z-index: 9999;
    pointer-events: none;
    opacity: 0.028;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  }

  /* ===== Tool Header ===== */

  .tool-header {
    position: sticky;
    top: 0;
    z-index: 50;
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-inline: var(--space-5);
    background: rgba(10, 12, 16, 0.92);
    backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
  }

  .tool-header-left {
    display: flex;
    align-items: center;
    gap: var(--space-4);
  }

  .back-link {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    font-weight: 400;
    color: var(--color-dim);
    text-decoration: none;
    letter-spacing: 0.04em;
    transition: color var(--transition-fast);
    white-space: nowrap;
  }

  .back-link:hover {
    color: var(--color-teal);
  }

  .header-divider {
    width: 1px;
    height: 1.5rem;
    background: var(--color-border);
    flex-shrink: 0;
  }

  .tool-title-group {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
  }

  .tool-title {
    font-family: var(--font-heading);
    font-size: var(--text-xl);
    font-weight: 400;
    line-height: var(--leading-tight);
    color: var(--color-foreground);
    letter-spacing: -0.01em;
  }

  .tool-subtitle {
    font-family: var(--font-mono);
    font-size: 0.65rem;
    font-weight: 300;
    color: var(--color-muted);
    letter-spacing: 0.08em;
    text-transform: uppercase;
  }

  .tool-badge {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    font-weight: 400;
    color: var(--color-teal);
    letter-spacing: 0.06em;
    border: 1px solid var(--color-teal-dim);
    border-radius: var(--radius-full);
    padding: var(--space-1) var(--space-3);
    background: rgba(78, 205, 196, 0.05);
  }

  .tool-badge-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--color-teal);
    box-shadow: 0 0 6px rgba(78, 205, 196, 0.8);
    animation: pulse-dot 2s ease-in-out infinite;
  }

  @keyframes pulse-dot {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
  }

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

  .tool-main {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr auto var(--panel-width);
    grid-template-rows: 1fr;
    min-height: 0;
    overflow: hidden;
  }

  /* ===== Canvas Section ===== */

  .canvas-section {
    position: relative;
    overflow: hidden;
    background: var(--color-bg);
    display: flex;
    flex-direction: column;
  }

  .canvas-wrapper {
    position: relative;
    flex: 1;
    overflow: hidden;
  }

  /* Three.js canvas container — fills the wrapper */
  #brain-canvas-container {
    width: 100%;
    height: 100%;
    display: block;
    cursor: grab;
  }

  #brain-canvas-container:active {
    cursor: grabbing;
  }

  /* The canvas Three.js injects */
  #brain-canvas-container canvas {
    width: 100% !important;
    height: 100% !important;
    display: block;
  }

  /* Canvas Tooltip */
  .canvas-tooltip {
    position: absolute;
    z-index: 20;
    background: var(--color-surface);
    border: 1px solid var(--color-border-bright);
    border-radius: var(--radius-md);
    padding: var(--space-2) var(--space-3);
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    color: var(--color-foreground);
    pointer-events: none;
    max-width: 200px;
    line-height: var(--leading-normal);
    backdrop-filter: blur(8px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
    transform: translate(12px, -50%);
  }

  .canvas-tooltip[hidden] {
    display: none;
  }

  .canvas-tooltip-name {
    display: block;
    font-weight: 500;
    color: var(--color-foreground);
    margin-bottom: 2px;
  }

  .canvas-tooltip-system {
    display: block;
    font-size: 0.65rem;
    color: var(--color-muted);
    letter-spacing: 0.04em;
  }

  /* View controls overlay (reset button) */
  .view-controls-overlay {
    position: absolute;
    bottom: var(--space-4);
    right: var(--space-4);
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    z-index: 10;
  }

  .view-ctrl-btn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(18, 21, 28, 0.85);
    border: 1px solid var(--color-border-bright);
    border-radius: var(--radius-md);
    color: var(--color-dim);
    backdrop-filter: blur(8px);
    transition: color var(--transition-fast), border-color var(--transition-fast);
  }

  .view-ctrl-btn:hover {
    color: var(--color-teal);
    border-color: var(--color-teal);
  }

  /* No-JS fallback */
  .noscript-fallback {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: var(--space-6);
    text-align: center;
    color: var(--color-muted);
    font-family: var(--font-body);
    font-size: var(--text-sm);
    gap: var(--space-2);
    line-height: var(--leading-normal);
  }

  /* ===== Resize Handle ===== */

  .resize-handle {
    width: 6px;
    cursor: col-resize;
    position: relative;
    z-index: 10;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    transition: background var(--transition-fast);
    margin-left: -3px;
    margin-right: -3px;
  }

  .resize-handle:hover,
  .resize-handle.active {
    background: var(--color-border-bright);
  }

  .resize-handle-line {
    width: 2px;
    height: 32px;
    border-radius: var(--radius-full);
    background: var(--color-muted);
    opacity: 0;
    transition: opacity var(--transition-fast);
  }

  .resize-handle:hover .resize-handle-line,
  .resize-handle.active .resize-handle-line {
    opacity: 1;
  }

  /* ===== Side Panel ===== */

  .panel {
    background: var(--color-surface);
    border-left: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .panel::-webkit-scrollbar {
    width: 4px;
  }

  .panel::-webkit-scrollbar-thumb {
    background: var(--color-border);
    border-radius: var(--radius-full);
  }

  .panel-section {
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--color-border);
  }

  .panel-heading {
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    font-weight: 500;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--color-muted);
    margin-bottom: var(--space-3);
  }

  .panel-hint {
    margin-top: var(--space-3);
    font-family: var(--font-mono);
    font-size: 0.65rem;
    color: var(--color-muted);
    letter-spacing: 0.04em;
    line-height: var(--leading-normal);
  }

  /* ===== Tab Navigation ===== */

  .tab-nav {
    display: flex;
    border-bottom: 1px solid var(--color-border);
    padding: 0;
    flex-shrink: 0;
  }

  .tab-btn {
    flex: 1;
    padding: var(--space-3) var(--space-2);
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    font-weight: 400;
    color: var(--color-dim);
    letter-spacing: 0.06em;
    text-transform: uppercase;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    transition:
      color var(--transition-fast),
      border-color var(--transition-fast);
  }

  .tab-btn:hover {
    color: var(--color-foreground);
  }

  .tab-btn.active {
    color: var(--color-teal);
    border-bottom-color: var(--color-teal);
  }

  /* ===== Tab Panels ===== */

  .tab-panel {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
    scrollbar-width: thin;
    scrollbar-color: var(--color-border) transparent;
  }

  .tab-panel[hidden] {
    display: none;
  }

  /* ===== Toggle group ===== */

  .toggle-group {
    display: flex;
    gap: var(--space-2);
  }

  .toggle-btn {
    flex: 1;
    padding: var(--space-2) var(--space-3);
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    font-weight: 500;
    letter-spacing: 0.06em;
    color: var(--color-dim);
    background: var(--color-surface-2);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    transition:
      color var(--transition-fast),
      background var(--transition-fast),
      border-color var(--transition-fast),
      box-shadow var(--transition-fast);
    text-align: center;
    white-space: nowrap;
  }

  .toggle-btn:hover {
    color: var(--color-foreground);
    border-color: var(--color-border-bright);
  }

  .toggle-btn[aria-pressed="true"] {
    color: var(--color-teal);
    background: var(--color-teal-dim);
    border-color: rgba(78, 205, 196, 0.4);
    box-shadow: inset 0 0 0 1px rgba(78, 205, 196, 0.1);
  }

  /* ===== Opacity Slider ===== */

  .slider-row {
    display: flex;
    align-items: center;
    gap: var(--space-3);
  }

  .opacity-slider {
    flex: 1;
    -webkit-appearance: none;
    appearance: none;
    height: 4px;
    background: var(--color-border);
    border-radius: var(--radius-full);
    outline: none;
  }

  .opacity-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--color-teal);
    cursor: pointer;
    box-shadow: 0 0 6px rgba(78, 205, 196, 0.5);
  }

  .opacity-slider::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border: none;
    border-radius: 50%;
    background: var(--color-teal);
    cursor: pointer;
    box-shadow: 0 0 6px rgba(78, 205, 196, 0.5);
  }

  .slider-value {
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    color: var(--color-dim);
    min-width: 2.5em;
    text-align: right;
  }

  /* ===== Info Card ===== */

  .info-card {
    background: var(--color-surface-2);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: var(--space-4);
  }

  .info-card-empty {
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    color: var(--color-muted);
    text-align: center;
    letter-spacing: 0.04em;
    padding: var(--space-3) 0;
  }

  /* ===== Overview Tab ===== */

  .overview-intro {
    font-size: var(--text-sm);
    color: var(--color-dim);
    line-height: var(--leading-normal);
  }

  /* Stats grid — 2×2 */
  .stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-2);
  }

  .stat-cell {
    background: var(--color-surface-2);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: var(--space-3) var(--space-4);
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
  }

  .stat-value {
    font-family: var(--font-mono);
    font-size: var(--text-xl);
    font-weight: 400;
    color: var(--color-teal);
    letter-spacing: -0.02em;
  }

  .stat-label {
    font-family: var(--font-mono);
    font-size: 0.65rem;
    font-weight: 400;
    color: var(--color-muted);
    letter-spacing: 0.06em;
    text-transform: uppercase;
  }

  /* Interaction hints */
  .hint-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
  }

  .hint-item {
    display: flex;
    align-items: flex-start;
    gap: var(--space-2);
    font-size: var(--text-sm);
    color: var(--color-dim);
    line-height: var(--leading-normal);
  }

  .hint-icon {
    font-size: 0.5rem;
    color: var(--color-teal);
    margin-top: 5px;
    flex-shrink: 0;
  }

  /* Color legend */
  .legend-grid {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
  }

  .legend-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    font-size: var(--text-xs);
    color: var(--color-dim);
    font-family: var(--font-mono);
    letter-spacing: 0.04em;
  }

  .legend-swatch {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
  }

  /* ===== Region Detail Tab ===== */

  .region-empty-state {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 120px;
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    color: var(--color-muted);
    text-align: center;
    letter-spacing: 0.04em;
  }

  .region-header-section {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
  }

  .region-title-row {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    flex-wrap: wrap;
  }

  .region-name {
    font-family: var(--font-heading);
    font-size: var(--text-2xl);
    font-weight: 400;
    color: var(--color-foreground);
    line-height: var(--leading-tight);
    letter-spacing: -0.01em;
  }

  .region-system-badge {
    margin-top: 4px;
    display: inline-flex;
    align-items: center;
    padding: var(--space-1) var(--space-2);
    font-family: var(--font-mono);
    font-size: 0.65rem;
    font-weight: 400;
    border-radius: var(--radius-full);
    letter-spacing: 0.06em;
    white-space: nowrap;
    /* color and background set via JS inline styles */
  }

  .region-summary {
    font-size: var(--text-sm);
    color: var(--color-dim);
    line-height: var(--leading-normal);
  }

  /* Detail lists (functions, structures, neurotransmitters) */
  .detail-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
  }

  .detail-item {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    font-size: var(--text-sm);
    line-height: var(--leading-normal);
  }

  .detail-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    margin-top: 7px;
    flex-shrink: 0;
  }

  .detail-item-body {
    flex: 1;
  }

  .detail-item-name {
    font-weight: 500;
    color: var(--color-foreground);
    display: block;
  }

  .detail-item-desc {
    font-size: var(--text-xs);
    color: var(--color-dim);
    display: block;
    margin-top: 1px;
  }

  /* Clinical notes callout */
  .clinical-callout {
    background: rgba(255, 107, 107, 0.06);
    border: 1px solid rgba(255, 107, 107, 0.2);
    border-left: 3px solid var(--color-coral);
    border-radius: var(--radius-md);
    padding: var(--space-3) var(--space-4);
    font-size: var(--text-sm);
    color: var(--color-dim);
    line-height: var(--leading-normal);
  }

  /* Fun fact callout */
  .funfact-callout {
    background: rgba(255, 209, 102, 0.06);
    border: 1px solid rgba(255, 209, 102, 0.2);
    border-left: 3px solid var(--color-gold);
    border-radius: var(--radius-md);
    padding: var(--space-3) var(--space-4);
    font-size: var(--text-sm);
    color: var(--color-dim);
    line-height: var(--leading-normal);
    font-style: italic;
  }

  /* ===== Systems Tab ===== */

  .system-toggles {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
  }

  .system-btn {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    background: var(--color-surface-2);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    font-weight: 500;
    letter-spacing: 0.06em;
    color: var(--color-dim);
    text-align: left;
    transition:
      color var(--transition-fast),
      background var(--transition-fast),
      border-color var(--transition-fast);
    width: 100%;
  }

  .system-btn:hover {
    color: var(--color-foreground);
    border-color: var(--color-border-bright);
  }

  .system-btn[aria-pressed="true"] {
    color: var(--color-foreground);
  }

  .system-btn-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
  }

  .system-btn-name {
    flex: 1;
  }

  .system-btn-count {
    font-family: var(--font-mono);
    font-size: 0.65rem;
    color: var(--color-muted);
  }

  .system-region-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
  }

  .system-region-item {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    font-size: var(--text-sm);
    color: var(--color-dim);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background var(--transition-fast), color var(--transition-fast);
  }

  .system-region-item:hover {
    background: var(--color-surface-2);
    color: var(--color-foreground);
  }

  .system-region-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    flex-shrink: 0;
  }

  /* ===== Cross-Section Tab ===== */

  .preset-btn-row {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
  }

  .preset-btn {
    padding: var(--space-2) var(--space-3);
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    font-weight: 500;
    letter-spacing: 0.06em;
    color: var(--color-dim);
    background: var(--color-surface-2);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    transition:
      color var(--transition-fast),
      background var(--transition-fast),
      border-color var(--transition-fast);
    white-space: nowrap;
  }

  .preset-btn:hover {
    color: var(--color-foreground);
    border-color: var(--color-border-bright);
  }

  .preset-btn[aria-pressed="true"] {
    color: var(--color-teal);
    background: var(--color-teal-dim);
    border-color: rgba(78, 205, 196, 0.4);
  }

  /* View description list */
  .view-desc-list {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: var(--space-2) var(--space-3);
    font-size: var(--text-xs);
  }

  .view-desc-list dt {
    font-family: var(--font-mono);
    font-weight: 500;
    color: var(--color-teal);
    letter-spacing: 0.04em;
    align-self: baseline;
  }

  .view-desc-list dd {
    color: var(--color-dim);
    line-height: var(--leading-normal);
  }

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

  @media (max-width: 768px) {
    .tool-main {
      grid-template-columns: 1fr;
      grid-template-rows: 1fr auto;
      overflow: visible;
    }

    .canvas-section {
      min-height: 55vh;
    }

    .panel {
      border-left: none;
      border-top: 1px solid var(--color-border);
      max-height: 45vh;
      overflow-y: auto;
    }

    .back-link {
      display: none;
    }

    .header-divider {
      display: none;
    }

    .resize-handle {
      display: none;
    }
  }

  @media (max-width: 480px) {
    .tool-title {
      font-size: var(--text-lg);
    }

    .tool-subtitle {
      display: none;
    }

    .tool-badge span:last-child {
      display: none;
    }
  }

} /* end @layer components */
