/* =====================================================================
   MT History — design system
   Academic, editorial look layered on sphinx-book-theme.
   Namespace: .mt-*  (custom components)  +  theme refinements.
   ===================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Fraunces:opsz,wght@9..144,400;9..144,500;9..144,600&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  --mt-font-ui: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --mt-font-display: 'Fraunces', Georgia, serif;
  --mt-font-mono: 'JetBrains Mono', 'SFMono-Regular', Consolas, monospace;

  --mt-accent: #1e3a5f;
  --mt-accent-mid: #2d5fa0;
  --mt-accent-light: #dbeafe;

  --mt-bg: #ffffff;
  --mt-bg-soft: #f8f9fa;
  --mt-card: #ffffff;
  --mt-border: #dee2e8;
  --mt-text: #111827;
  --mt-text-soft: #4b5563;
  --mt-text-muted: #9ca3af;
  --mt-shadow: 0 1px 3px rgba(0,0,0,.06), 0 4px 12px -4px rgba(0,0,0,.08);
}

html[data-theme="dark"] {
  --mt-accent: #93c5fd;
  --mt-accent-mid: #60a5fa;
  --mt-accent-light: #1e3a5f;
  --mt-bg: #111827;
  --mt-bg-soft: #1f2937;
  --mt-card: #1f2937;
  --mt-border: #374151;
  --mt-text: #f3f4f6;
  --mt-text-soft: #9ca3af;
  --mt-text-muted: #6b7280;
  --mt-shadow: 0 1px 3px rgba(0,0,0,.3), 0 4px 12px -4px rgba(0,0,0,.4);
}

/* ----------------------------------------------------------------------
   Theme-wide typography & polish
   ---------------------------------------------------------------------- */

body {
  font-family: var(--mt-font-ui);
  -webkit-font-smoothing: antialiased;
}

.bd-article h1 {
  font-family: var(--mt-font-display);
  font-weight: 500;
  letter-spacing: -0.015em;
  line-height: 1.2;
}

.bd-article h2 {
  font-weight: 600;
  letter-spacing: -0.01em;
  margin-top: 2.2rem;
  padding-bottom: .35rem;
  border-bottom: 1px solid var(--mt-border);
}

.bd-article h3 { font-weight: 600; }

code, pre, .highlight {
  font-family: var(--mt-font-mono) !important;
  font-size: 0.875em;
}

div.cell div.cell_input,
div.highlight {
  border-radius: 8px !important;
  border: 1px solid var(--mt-border) !important;
  overflow: hidden;
}

div.cell div.cell_input { border-left: 3px solid var(--mt-accent) !important; }

div.cell div.cell_output {
  border-left: 3px solid var(--mt-border);
  margin-top: .4rem;
  padding-left: .9rem;
}

div.cell div.cell_output pre {
  background: var(--mt-bg-soft) !important;
  border-radius: 8px;
  border: 1px solid var(--mt-border);
  padding: .9rem 1.1rem;
}

.bd-article table {
  border-collapse: collapse;
  border: 1px solid var(--mt-border);
  border-radius: 6px;
  overflow: hidden;
}
.bd-article table thead th {
  background: var(--mt-bg-soft);
  font-weight: 600;
  font-size: .82rem;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.bd-article table tbody tr:hover { background: var(--mt-bg-soft); }

.bd-article blockquote {
  border-left: 3px solid var(--mt-accent);
  background: var(--mt-bg-soft);
  border-radius: 0 6px 6px 0;
  padding: .9rem 1.2rem;
  font-style: normal;
  color: var(--mt-text-soft);
}

.bd-sidebar-primary { font-size: .9rem; }
.bd-sidebar-primary .sidebar-primary-items__start .caption-text {
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--mt-text-muted);
}
.bd-sidebar-primary li.toctree-l1 > a:hover { color: var(--mt-accent); }
.bd-sidebar-primary li.toctree-l1.current > a {
  color: var(--mt-accent);
  font-weight: 600;
}

/* Scroll-reveal — subtle fade only, no translate */
.mt-reveal {
  opacity: 0;
  transition: opacity .5s ease;
}
.mt-reveal.mt-in { opacity: 1; }

/* ----------------------------------------------------------------------
   HERO (landing page)
   ---------------------------------------------------------------------- */

.mt-hero {
  position: relative;
  margin: -1rem -1rem 3rem;
  padding: 4rem 2.5rem 3.5rem;
  border-bottom: 1px solid var(--mt-border);
  background: var(--mt-bg);
}

.mt-hero-badge {
  display: inline-flex; align-items: center; gap: .5rem;
  font-size: .75rem; font-weight: 600; letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--mt-accent);
  background: var(--mt-accent-light);
  border: 1px solid rgba(30,58,95,.15);
  padding: .3rem .8rem;
  border-radius: 4px;
  margin-bottom: 1.4rem;
}
.mt-hero-badge .mt-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--mt-accent);
}

.mt-hero h1.mt-hero-title {
  font-family: var(--mt-font-display);
  font-size: clamp(2.1rem, 5vw, 3.6rem);
  font-weight: 500;
  line-height: 1.1;
  letter-spacing: -0.02em;
  margin: 0 0 1.1rem;
  border: none;
  color: var(--mt-text);
}
.mt-hero-title .mt-grad-text {
  color: var(--mt-accent);
}

.mt-hero-sub {
  font-size: 1.05rem;
  line-height: 1.7;
  color: var(--mt-text-soft);
  max-width: 580px;
  margin-bottom: 2rem;
}

.mt-cta-row { display: flex; flex-wrap: wrap; gap: .7rem; margin-bottom: 2.5rem; }

.mt-btn {
  display: inline-flex; align-items: center; gap: .5rem;
  font-weight: 600; font-size: .9rem;
  padding: .65rem 1.3rem;
  border-radius: 6px;
  text-decoration: none !important;
  transition: background .15s ease, border-color .15s ease;
}
.mt-btn-primary {
  color: #fff !important;
  background: var(--mt-accent);
  border: 1px solid var(--mt-accent);
}
.mt-btn-primary:hover { background: var(--mt-accent-mid); border-color: var(--mt-accent-mid); }
.mt-btn-ghost {
  color: var(--mt-text) !important;
  background: var(--mt-card);
  border: 1px solid var(--mt-border);
}
.mt-btn-ghost:hover { border-color: var(--mt-accent); color: var(--mt-accent) !important; }

.mt-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: .8rem;
  max-width: 680px;
}
.mt-stat {
  background: var(--mt-bg-soft);
  border: 1px solid var(--mt-border);
  border-radius: 6px;
  padding: .9rem 1rem;
}
.mt-stat b {
  display: block;
  font-size: 1.5rem; font-weight: 700;
  color: var(--mt-accent);
}
.mt-stat span { font-size: .78rem; color: var(--mt-text-soft); font-weight: 500; }

/* ----------------------------------------------------------------------
   TIMELINE (landing page)
   ---------------------------------------------------------------------- */

.mt-tl-wrap { margin: 1.2rem 0 2.8rem; }
.mt-tl-scroller {
  overflow-x: auto;
  padding: 2.2rem .4rem 1.2rem;
  scrollbar-width: thin;
}
.mt-tl {
  position: relative;
  display: flex;
  gap: 0;
  min-width: 1400px;
  padding: 0 1rem;
}
.mt-tl::before {
  content: "";
  position: absolute;
  left: 1rem; right: 1rem; top: 14px;
  height: 2px;
  background: var(--mt-border);
}
.mt-tl-node {
  position: relative;
  flex: 1;
  min-width: 96px;
  text-decoration: none !important;
  padding-top: 34px;
  cursor: pointer;
}
.mt-tl-node::before {
  content: "";
  position: absolute;
  top: 8px; left: 0;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--mt-bg);
  border: 2px solid var(--mt-accent);
  transition: background .2s ease;
}
.mt-tl-node:hover::before {
  background: var(--mt-accent);
}
.mt-tl-year {
  font-family: var(--mt-font-mono);
  font-size: .76rem; font-weight: 500;
  color: var(--mt-accent);
  display: block;
}
.mt-tl-label {
  font-size: .82rem; font-weight: 600;
  color: var(--mt-text);
  display: block;
  line-height: 1.3;
  padding-right: .8rem;
}
.mt-tl-node small {
  font-size: .7rem; color: var(--mt-text-soft);
  display: block; margin-top: .15rem;
  padding-right: .8rem;
  opacity: 0;
  transition: opacity .2s ease;
}
.mt-tl-node:hover small { opacity: 1; }

/* ----------------------------------------------------------------------
   FEATURE + PART CARDS
   ---------------------------------------------------------------------- */

.mt-grid {
  display: grid;
  gap: 1rem;
  margin: 1.2rem 0 2.4rem;
}
.mt-grid-3 { grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
.mt-grid-2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }

.mt-card {
  background: var(--mt-card);
  border: 1px solid var(--mt-border);
  border-radius: 8px;
  padding: 1.25rem 1.3rem;
  box-shadow: var(--mt-shadow);
  transition: border-color .15s ease;
}
.mt-card:hover { border-color: var(--mt-accent); }

.mt-card-icon {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  font-size: 1.1rem;
  border-radius: 8px;
  background: var(--mt-bg-soft);
  border: 1px solid var(--mt-border);
  margin-bottom: .8rem;
}

.mt-card h3, .mt-card h4 {
  margin: 0 0 .35rem !important;
  font-size: 1rem !important;
  font-weight: 600 !important;
}
.mt-card p { font-size: .87rem; color: var(--mt-text-soft); margin: 0 0 .6rem; line-height: 1.6; }

.mt-era-chip {
  display: inline-block;
  font-family: var(--mt-font-mono);
  font-size: .68rem; font-weight: 500;
  letter-spacing: .03em;
  color: var(--mt-accent);
  background: var(--mt-accent-light);
  border: 1px solid rgba(30,58,95,.12);
  padding: .15rem .55rem;
  border-radius: 4px;
  margin-bottom: .55rem;
}

.mt-chapter-links { display: flex; flex-direction: column; gap: .1rem; margin-top: .5rem; }
.mt-chapter-links a {
  font-size: .84rem;
  font-weight: 500;
  text-decoration: none !important;
  color: var(--mt-text-soft) !important;
  padding: .25rem .5rem;
  border-radius: 4px;
  transition: background .12s ease, color .12s ease;
}
.mt-chapter-links a:hover {
  background: var(--mt-accent-light);
  color: var(--mt-accent) !important;
}
.mt-chapter-links a::before { content: "→ "; opacity: .45; }

/* ----------------------------------------------------------------------
   TIME MACHINE page
   ---------------------------------------------------------------------- */

.mt-tm-panel {
  background: var(--mt-card);
  border: 1px solid var(--mt-border);
  border-radius: 8px;
  box-shadow: var(--mt-shadow);
  padding: 1.5rem 1.6rem;
  margin: 1.4rem 0 2rem;
}

.mt-tm-tabs { display: flex; gap: .4rem; margin-bottom: 1.4rem; }
.mt-tm-tab {
  font-size: .85rem; font-weight: 600;
  padding: .45rem 1rem;
  border-radius: 6px;
  border: 1px solid var(--mt-border);
  background: var(--mt-bg-soft);
  color: var(--mt-text-soft);
  cursor: pointer;
  transition: all .15s ease;
}
.mt-tm-tab.mt-active {
  background: var(--mt-accent);
  color: #fff;
  border-color: var(--mt-accent);
}

.mt-tm-head {
  display: flex; flex-wrap: wrap; align-items: baseline;
  gap: .8rem; margin-bottom: .4rem;
}
.mt-tm-era-name {
  font-family: var(--mt-font-display);
  font-size: 1.55rem; font-weight: 500;
  color: var(--mt-text);
}
.mt-tm-era-year {
  font-family: var(--mt-font-mono);
  font-size: .9rem; font-weight: 500;
  color: var(--mt-accent);
}
.mt-tm-era-desc { font-size: .88rem; color: var(--mt-text-soft); margin-bottom: 1.1rem; max-width: 640px; }

input[type="range"].mt-tm-slider {
  width: 100%;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  border-radius: 4px;
  background: var(--mt-border);
  outline: none;
  margin: .6rem 0 .3rem;
  accent-color: var(--mt-accent);
}
input[type="range"].mt-tm-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--mt-accent);
  border: 3px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,.2);
  cursor: grab;
}
input[type="range"].mt-tm-slider::-moz-range-thumb {
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--mt-accent); border: 3px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,.2); cursor: grab;
}

.mt-tm-ticks {
  display: flex; justify-content: space-between;
  font-family: var(--mt-font-mono);
  font-size: .67rem; color: var(--mt-text-muted);
  margin-bottom: 1.2rem;
}
.mt-tm-ticks span { cursor: pointer; transition: color .15s; }
.mt-tm-ticks span:hover, .mt-tm-ticks span.mt-active { color: var(--mt-accent); font-weight: 600; }

.mt-tm-meter-row { display: flex; align-items: center; gap: .9rem; margin-bottom: 1.3rem; }
.mt-tm-meter-label { font-size: .76rem; font-weight: 600; color: var(--mt-text-soft); white-space: nowrap; }
.mt-tm-meter {
  flex: 1; height: 8px;
  background: var(--mt-bg-soft);
  border: 1px solid var(--mt-border);
  border-radius: 999px;
  overflow: hidden;
}
.mt-tm-meter-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--mt-accent);
  transition: width .6s ease;
}
.mt-tm-meter-val {
  font-family: var(--mt-font-mono);
  font-size: .82rem; font-weight: 600;
  color: var(--mt-accent);
  min-width: 3rem; text-align: right;
}

.mt-tm-pairs { display: flex; flex-direction: column; gap: .45rem; }
.mt-tm-pair {
  background: var(--mt-bg-soft);
  border: 1px solid var(--mt-border);
  border-radius: 6px;
  padding: .65rem .9rem;
  animation: mt-fadein .3s ease both;
}
.mt-tm-pair .mt-en {
  font-size: .78rem; color: var(--mt-text-soft);
  margin-bottom: .2rem;
}
.mt-tm-pair .mt-de {
  font-size: .92rem; font-weight: 500; color: var(--mt-text);
}
.mt-tm-pair .mt-en::before, .mt-tm-pair .mt-de::before {
  font-family: var(--mt-font-mono);
  font-size: .65rem; font-weight: 600;
  padding: .08rem .38rem;
  border-radius: 3px;
  margin-right: .5rem;
  vertical-align: 1px;
}
.mt-tm-pair .mt-en::before { content: "EN"; background: var(--mt-bg-soft); border: 1px solid var(--mt-border); color: var(--mt-text-muted); }
.mt-tm-pair .mt-de::before { content: "DE"; background: var(--mt-accent-light); border: 1px solid rgba(30,58,95,.15); color: var(--mt-accent); }

@keyframes mt-fadein {
  from { opacity: 0; }
  to { opacity: 1; }
}

.mt-tm-select {
  width: 100%;
  font-family: var(--mt-font-ui);
  font-size: .9rem;
  padding: .6rem .85rem;
  border-radius: 6px;
  border: 1px solid var(--mt-border);
  background: var(--mt-bg-soft);
  color: var(--mt-text);
  margin-bottom: 1.4rem;
  cursor: pointer;
}
.mt-tm-trace { position: relative; padding-left: 1.6rem; }
.mt-tm-trace::before {
  content: "";
  position: absolute; left: 6px; top: 10px; bottom: 10px;
  width: 2px; border-radius: 2px;
  background: var(--mt-border);
}
.mt-tm-trace-item {
  position: relative;
  margin-bottom: .8rem;
  animation: mt-fadein .3s ease both;
}
.mt-tm-trace-item::before {
  content: "";
  position: absolute; left: -1.6rem; top: 8px;
  width: 11px; height: 11px; border-radius: 50%;
  background: var(--mt-bg);
  border: 2px solid var(--mt-accent);
}
.mt-tm-trace-meta {
  display: flex; gap: .6rem; align-items: baseline;
  font-size: .74rem; margin-bottom: .12rem;
}
.mt-tm-trace-meta b { color: var(--mt-accent); font-family: var(--mt-font-mono); }
.mt-tm-trace-meta span { color: var(--mt-text-soft); font-weight: 600; }
.mt-tm-trace-text {
  background: var(--mt-bg-soft);
  border: 1px solid var(--mt-border);
  border-radius: 6px;
  padding: .5rem .8rem;
  font-size: .9rem;
}

/* ----------------------------------------------------------------------
   In-notebook interactive widgets
   ---------------------------------------------------------------------- */

.mt-widget {
  background: var(--mt-card);
  border: 1px solid var(--mt-border);
  border-radius: 8px;
  box-shadow: var(--mt-shadow);
  padding: 1.3rem 1.4rem;
  margin: 1.5rem 0;
}
.mt-widget-head {
  display: flex; align-items: center; gap: .6rem;
  margin-bottom: .3rem;
}
.mt-widget-head .mt-widget-chip {
  font-size: .62rem; font-weight: 700;
  letter-spacing: .06em; text-transform: uppercase;
  color: var(--mt-accent);
  background: var(--mt-accent-light);
  border: 1px solid rgba(30,58,95,.12);
  padding: .18rem .55rem;
  border-radius: 3px;
}
.mt-widget-head h4 { margin: 0 !important; font-size: 1.02rem !important; font-weight: 600 !important; }
.mt-widget-sub { font-size: .83rem; color: var(--mt-text-soft); margin-bottom: 1rem; }

/* Attention heatmap */
.mt-attn-grid { display: inline-grid; gap: 3px; }
.mt-attn-cell {
  width: 40px; height: 40px;
  border-radius: 4px;
  display: grid; place-items: center;
  font-family: var(--mt-font-mono);
  font-size: .62rem; font-weight: 500;
  color: var(--mt-text);
  transition: outline .1s ease;
  cursor: crosshair;
}
.mt-attn-cell:hover { outline: 2px solid var(--mt-accent); outline-offset: 1px; z-index: 2; }
.mt-attn-hdr {
  font-family: var(--mt-font-mono);
  font-size: .68rem; font-weight: 500;
  color: var(--mt-text-soft);
  display: grid; place-items: center;
  padding: 2px;
}
.mt-attn-hdr.mt-hl { color: var(--mt-accent); font-weight: 700; }
.mt-attn-readout {
  margin-top: .9rem;
  font-size: .84rem;
  color: var(--mt-text-soft);
  min-height: 1.5em;
}
.mt-attn-readout b { color: var(--mt-accent); }

/* BPE stepper */
.mt-bpe-controls { display: flex; gap: .6rem; align-items: center; margin-bottom: 1rem; flex-wrap: wrap; }
.mt-bpe-step-label {
  font-family: var(--mt-font-mono);
  font-size: .8rem; font-weight: 600;
  color: var(--mt-accent);
  margin-left: .4rem;
}
.mt-bpe-words { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: 1rem; }
.mt-bpe-word {
  display: inline-flex; gap: 3px;
  background: var(--mt-bg-soft);
  border: 1px solid var(--mt-border);
  border-radius: 6px;
  padding: .35rem .45rem;
}
.mt-bpe-tok {
  font-family: var(--mt-font-mono);
  font-size: .78rem; font-weight: 500;
  padding: .16rem .4rem;
  border-radius: 4px;
  background: var(--mt-bg-soft);
  border: 1px solid var(--mt-border);
  color: var(--mt-text);
  transition: background .25s ease, color .25s ease;
}
.mt-bpe-tok.mt-merged {
  background: var(--mt-accent);
  color: #fff;
  border-color: var(--mt-accent);
}
.mt-bpe-merge-log {
  font-family: var(--mt-font-mono);
  font-size: .77rem;
  color: var(--mt-text-soft);
  background: var(--mt-bg-soft);
  border: 1px solid var(--mt-border);
  border-radius: 6px;
  padding: .65rem .85rem;
  max-height: 130px;
  overflow-y: auto;
}
.mt-bpe-merge-log .mt-latest { color: var(--mt-accent); font-weight: 600; }

/* Positional encoding explorer */
.mt-pe-controls {
  display: flex; flex-wrap: wrap; gap: 1.2rem;
  align-items: center; margin-bottom: 1rem;
  font-size: .84rem; color: var(--mt-text-soft);
}
.mt-pe-controls label { font-weight: 600; }
.mt-pe-controls input[type="range"] { accent-color: var(--mt-accent); width: 180px; }
.mt-pe-val { font-family: var(--mt-font-mono); font-weight: 600; color: var(--mt-accent); }
canvas.mt-pe-canvas {
  width: 100%;
  border: 1px solid var(--mt-border);
  border-radius: 6px;
  background: var(--mt-bg-soft);
}

/* Generic small button used by widgets */
.mt-mini-btn {
  font-family: var(--mt-font-ui);
  font-size: .82rem; font-weight: 600;
  color: #fff;
  background: var(--mt-accent);
  border: 1px solid var(--mt-accent);
  padding: .45rem .95rem;
  border-radius: 6px;
  cursor: pointer;
  transition: background .15s ease;
}
.mt-mini-btn:hover { background: var(--mt-accent-mid); border-color: var(--mt-accent-mid); }
.mt-mini-btn:disabled { opacity: .4; cursor: not-allowed; }
.mt-mini-btn.mt-secondary {
  background: var(--mt-bg-soft);
  color: var(--mt-text);
  border: 1px solid var(--mt-border);
}
.mt-mini-btn.mt-secondary:hover { border-color: var(--mt-accent); color: var(--mt-accent); }

/* Section headers on landing page */
.mt-section-title {
  font-family: var(--mt-font-display);
  font-size: 1.6rem;
  font-weight: 500;
  letter-spacing: -0.015em;
  margin: 2.6rem 0 .4rem;
}
.mt-section-sub { color: var(--mt-text-soft); font-size: .93rem; margin-bottom: 1.1rem; }

@media (max-width: 700px) {
  .mt-hero { padding: 2.8rem 1.3rem 2.5rem; }
  .mt-attn-cell { width: 30px; height: 30px; font-size: .5rem; }
}
