/* Synaptic Transmission Tool — 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);

    /* Panel width */
    --panel-width: 300px;
    --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;
  }

  input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
  }

  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;
  }

  #synapse-canvas {
    width: 100%;
    height: 100%;
    display: block;
    cursor: crosshair;
  }

  /* 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);
  }

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

  /* Step overlay */
  .step-overlay {
    position: absolute;
    top: var(--space-4);
    left: 50%;
    transform: translateX(-50%);
    pointer-events: none;
    z-index: 10;
  }

  .step-label {
    display: block;
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    font-weight: 500;
    color: var(--color-purple);
    letter-spacing: 0.1em;
    text-transform: uppercase;
    background: rgba(10, 12, 16, 0.85);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(192, 132, 252, 0.2);
    border-radius: var(--radius-full);
    padding: var(--space-1) var(--space-4);
    min-width: 180px;
    text-align: center;
    transition: opacity var(--transition-normal);
  }

  .step-label:empty {
    opacity: 0;
  }

  /* Canvas legend */
  .canvas-legend {
    position: absolute;
    bottom: var(--space-4);
    left: var(--space-4);
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-3);
    background: rgba(10, 12, 16, 0.8);
    backdrop-filter: blur(8px);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: var(--space-2) var(--space-3);
    pointer-events: none;
  }

  .legend-item {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-family: var(--font-mono);
    font-size: 0.65rem;
    color: var(--color-dim);
    letter-spacing: 0.04em;
    white-space: nowrap;
  }

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

  /* No-JS fallback */
  .noscript-fallback {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-4);
    height: 100%;
    padding: var(--space-6);
  }

  .noscript-fallback svg {
    width: 100%;
    max-width: 600px;
    height: auto;
    border-radius: var(--radius-lg);
    border: 1px solid var(--color-border);
  }

  .noscript-message {
    font-family: var(--font-mono);
    font-size: var(--text-sm);
    color: var(--color-dim);
    text-align: center;
  }

  /* ===== 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-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: var(--color-border) transparent;
  }

  .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-2);
    font-family: var(--font-mono);
    font-size: 0.65rem;
    color: var(--color-muted);
    letter-spacing: 0.04em;
    line-height: var(--leading-normal);
  }

  /* ===== 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.active,
  .toggle-btn[aria-pressed="true"] {
    color: var(--color-purple);
    background: var(--color-purple-dim);
    border-color: rgba(192, 132, 252, 0.4);
    box-shadow: inset 0 0 0 1px rgba(192, 132, 252, 0.1);
  }

  /* ===== Playback controls ===== */

  .playback-controls {
    display: flex;
    gap: var(--space-2);
    margin-bottom: var(--space-4);
  }

  .ctrl-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    height: 2.5rem;
    border-radius: var(--radius-md);
    background: var(--color-surface-2);
    border: 1px solid var(--color-border);
    color: var(--color-dim);
    transition:
      color var(--transition-fast),
      background var(--transition-fast),
      border-color var(--transition-fast),
      box-shadow var(--transition-fast);
    flex-shrink: 0;
  }

  .ctrl-btn:hover {
    color: var(--color-foreground);
    border-color: var(--color-border-bright);
    background: rgba(255, 255, 255, 0.04);
  }

  .ctrl-btn:focus-visible {
    outline: 2px solid var(--color-teal);
    outline-offset: 2px;
  }

  .ctrl-play {
    color: var(--color-dim);
    border-color: var(--color-border);
    background: var(--color-surface-2);
  }

  .ctrl-play.active {
    color: var(--color-teal);
    border-color: rgba(78, 205, 196, 0.6);
    background: rgba(78, 205, 196, 0.12);
    box-shadow: 0 0 12px rgba(78, 205, 196, 0.25);
  }

  .ctrl-play:hover {
    color: var(--color-teal);
    border-color: rgba(78, 205, 196, 0.6);
    box-shadow: 0 0 12px rgba(78, 205, 196, 0.2);
    background: rgba(78, 205, 196, 0.1);
  }

  .ctrl-pause {
    color: var(--color-dim);
    border-color: var(--color-border);
    background: var(--color-surface-2);
  }

  .ctrl-pause.active {
    color: var(--color-gold);
    border-color: rgba(255, 209, 102, 0.6);
    background: rgba(255, 209, 102, 0.12);
    box-shadow: 0 0 12px rgba(255, 209, 102, 0.2);
  }

  .ctrl-pause:hover {
    color: var(--color-gold);
    border-color: rgba(255, 209, 102, 0.6);
    box-shadow: 0 0 12px rgba(255, 209, 102, 0.15);
    background: rgba(255, 209, 102, 0.08);
  }

  .ctrl-step {
    color: var(--color-blue);
    border-color: rgba(108, 155, 255, 0.3);
    background: rgba(108, 155, 255, 0.06);
  }

  .ctrl-step:hover {
    border-color: rgba(108, 155, 255, 0.6);
    box-shadow: 0 0 12px rgba(108, 155, 255, 0.15);
    background: rgba(108, 155, 255, 0.08);
  }

  /* ===== Speed control ===== */

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

  .speed-label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    color: var(--color-dim);
    letter-spacing: 0.06em;
  }

  .speed-value {
    color: var(--color-foreground);
    font-weight: 500;
    min-width: 2.5rem;
    text-align: right;
  }

  .speed-slider {
    width: 100%;
    height: 4px;
    border-radius: var(--radius-full);
    background: var(--color-surface-2);
    outline: none;
    cursor: pointer;
  }

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

  .speed-slider::-webkit-slider-thumb:hover {
    box-shadow: 0 0 14px rgba(78, 205, 196, 0.7);
  }

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

  .speed-slider:focus-visible {
    outline: 2px solid var(--color-teal);
    outline-offset: 2px;
    border-radius: var(--radius-full);
  }

  .speed-ticks {
    display: flex;
    justify-content: space-between;
    font-family: var(--font-mono);
    font-size: 0.6rem;
    color: var(--color-muted);
    letter-spacing: 0.04em;
  }

  /* ===== Progress ===== */

  .step-progress {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    margin-bottom: var(--space-2);
  }

  .step-progress-bar {
    height: 3px;
    background: var(--color-surface-2);
    border-radius: var(--radius-full);
    overflow: hidden;
  }

  .step-progress-fill {
    height: 100%;
    background: linear-gradient(to right, var(--color-purple), var(--color-teal));
    border-radius: var(--radius-full);
    width: 0%;
    transition: width var(--transition-normal);
  }

  .step-dots {
    display: flex;
    gap: var(--space-1);
    flex-wrap: wrap;
  }

  .step-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--color-surface-2);
    border: 1px solid var(--color-border);
    transition:
      background var(--transition-fast),
      border-color var(--transition-fast),
      box-shadow var(--transition-fast);
    flex-shrink: 0;
  }

  .step-dot.completed {
    background: var(--color-purple);
    border-color: rgba(192, 132, 252, 0.4);
  }

  .step-dot.active {
    background: var(--color-teal);
    border-color: rgba(78, 205, 196, 0.6);
    box-shadow: 0 0 8px rgba(78, 205, 196, 0.5);
  }

  .step-counter {
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    color: var(--color-muted);
    letter-spacing: 0.06em;
  }

  /* ===== Info card ===== */

  .panel-info {
    flex: none;
  }

  .info-card {
    background: var(--color-surface-2);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: var(--space-4);
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    transition: border-color var(--transition-normal);
  }

  .info-card:has(.info-step-number:not(:empty)) {
    border-color: rgba(192, 132, 252, 0.25);
  }

  .info-step-number {
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    font-weight: 500;
    color: var(--color-purple);
    letter-spacing: 0.12em;
    text-transform: uppercase;
    min-height: 1.2em;
  }

  .info-step-title {
    font-family: var(--font-heading);
    font-size: var(--text-lg);
    font-weight: 400;
    color: var(--color-foreground);
    line-height: var(--leading-tight);
  }

  .info-step-desc {
    font-family: var(--font-body);
    font-size: var(--text-sm);
    color: var(--color-dim);
    line-height: var(--leading-normal);
  }

  .info-biology {
    margin-top: var(--space-2);
    padding-top: var(--space-2);
    border-top: 1px solid var(--color-border);
  }

  .info-biology[hidden] {
    display: none;
  }

  .info-biology-heading {
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    font-weight: 500;
    color: var(--color-gold);
    letter-spacing: 0.1em;
    text-transform: uppercase;
    margin-bottom: var(--space-1);
  }

  .info-biology-text {
    font-family: var(--font-body);
    font-size: var(--text-xs);
    color: var(--color-dim);
    line-height: var(--leading-normal);
    font-style: italic;
  }

  /* ===== Insight callouts (accessible content) ===== */

  .insight-callout {
    background: rgba(78, 205, 196, 0.06);
    border-left: 2px solid var(--color-teal, #4ecdc4);
    padding: 8px 10px;
    border-radius: 0 4px 4px 0;
    margin: 8px 0;
  }

  .insight-label {
    font-family: var(--font-mono, 'JetBrains Mono', monospace);
    font-size: 9px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--color-muted, #5a6175);
    margin-bottom: 4px;
  }

  .insight-text {
    font-size: 13px;
    line-height: 1.6;
    color: var(--color-foreground, #e8eaf0);
  }

  /* ===== Molecule list ===== */

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

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

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

}

/* ===== Utilities ===== */
@layer utilities {

  /* Focus visible */
  :focus-visible {
    outline: 2px solid var(--color-teal);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
  }

  /* Visually hidden */
  .sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
  }

  /* Hidden */
  [hidden] {
    display: none !important;
  }
}

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

/* Mobile: stack vertically */
@media (max-width: 768px) {
  :root {
    --panel-width: 100%;
    --header-height: 3.5rem;
  }

  .resize-handle {
    display: none;
  }

  .tool-main {
    grid-template-columns: 1fr !important;
    grid-template-rows: 60dvh auto;
    overflow: auto;
  }

  .canvas-section {
    min-height: 60dvh;
    max-height: 60dvh;
  }

  .panel {
    border-left: none;
    border-top: 1px solid var(--color-border);
    overflow-y: visible;
  }

  .tool-title {
    font-size: var(--text-lg);
  }

  .tool-subtitle {
    display: none;
  }

  .back-link span {
    display: none;
  }

  .canvas-legend {
    display: none;
  }
}

@media (max-width: 480px) {
  .tool-header {
    padding-inline: var(--space-3);
  }

  .panel-section {
    padding: var(--space-3) var(--space-4);
  }

  .tool-badge {
    display: none;
  }
}

/* ===== Reduced motion ===== */
@media (prefers-reduced-motion: reduce) {
  .tool-badge-dot {
    animation: none;
  }

  .step-progress-fill,
  .step-dot,
  .ctrl-btn,
  .toggle-btn,
  .info-card {
    transition: none;
  }
}
