/* Extends ../../styles.css (loaded first) with layout + widgets for this
   interactive post. Reuses --ink/--muted/--line/--link/--code-bg tokens. */

main.la-page {
  width: min(calc(100% - 2rem), 960px);
}

.site-header,
.site-footer {
  width: min(calc(100% - 2rem), 960px);
}

.la-hero {
  position: relative;
  padding-top: .4rem;
}

.language-link {
  float: right;
  margin: .25rem 0 .5rem 1rem;
  color: var(--muted);
  font-size: .73rem;
}

.la-hero h1 {
  font-size: 1.7rem;
}

.la-sub {
  width: 100%;
  max-width: none;
  color: var(--ink);
}

/* The two conditions that define linearity, set apart from the intro prose. */
.la-axioms {
  margin: 0 0 1rem;
  padding: .75rem 1rem;
  list-style: none;
  background: #f8f8f7;
  border-left: 2px solid #9ca3af;
  border-radius: 0 4px 4px 0;
}

/* name | equation | plain-language gloss, so a long gloss wraps into its own
   column instead of running back under the name. */
.la-axioms li {
  display: grid;
  grid-template-columns: max-content max-content minmax(0, 1fr);
  gap: .2rem 1rem;
  align-items: baseline;
}

.la-axioms li + li { margin-top: .5rem; }

.la-axiom-note { color: var(--muted); }

@media (max-width: 720px) {
  .la-axioms li { grid-template-columns: minmax(0, 1fr); }
  .la-axiom-note { grid-column: 1; }
}

.la-meta {
  margin-bottom: 0;
  color: var(--muted);
  font-size: .82rem;
}

.la-meta time { font-variant-numeric: tabular-nums; }

.la-meta-sep {
  margin: 0 .55rem;
  color: var(--line);
}

.la-layout {
  position: relative;
  margin-top: 2rem;
}

.la-index {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  flex-direction: row;
  gap: .25rem;
  max-height: none;
  margin-bottom: 1rem;
  padding: .55rem;
  background: #f3f4f6;
  border: 1px solid #e5e7eb;
  border-radius: 7px;
  overflow-x: auto;
  overflow-y: hidden;
}

.la-index-title {
  display: none;
  margin: 0 0 .45rem;
  color: #6b7280;
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.la-index a {
  flex: 0 0 auto;
  padding: .28rem .42rem;
  border-left: 0;
  border-radius: 3px;
  color: #6b7280;
  font-size: .75rem;
  line-height: 1.25;
  white-space: nowrap;
}

.la-index a:hover,
.la-index a.active {
  background: #e5e7eb;
  border-left-color: var(--link);
  color: var(--ink);
  text-decoration: none;
}

/* --- topic sections --- */

.topic {
  padding-block: 2.2rem;
  border-bottom: 1px solid var(--line);
  scroll-margin-top: 3.4rem;
}

.topic:last-of-type { border-bottom: none; }

.topic h2 {
  display: flex;
  align-items: baseline;
  gap: .55rem;
  margin-bottom: .55rem;
  font-size: 1.28rem;
}

.topic-lead {
  max-width: 68ch;
  margin: 0 0 1.35rem;
  color: #4b5563;
  font-size: .94rem;
  line-height: 1.75;
}

.topic h2 .en {
  margin-left: .15rem;
  color: var(--muted);
  font-size: .8rem;
  font-weight: 400;
}

.topic h3 {
  margin: 1.6rem 0 .6rem;
  font-size: 1rem;
}

.topic-body {
  display: grid;
  grid-template-columns: minmax(0, 6fr) minmax(0, 4fr);
  gap: 1.8rem;
  align-items: start;
}

.topic-text p { font-size: .92rem; }

.definition {
  margin: 0 0 .9rem;
  padding: .7rem .9rem;
  background: #f8f8f7;
  border-left: 2px solid #9ca3af;
  border-radius: 0 4px 4px 0;
}

.interp { margin: 0 0 .8rem; }
.interp em { font-style: normal; color: var(--muted); }

.formula {
  margin: .9rem 0;
  padding: .55rem .8rem;
  background: var(--code-bg);
  border-radius: 5px;
  color: var(--ink);
  font: 13.5px/1.6 "Iowan Old Style", Georgia, "Times New Roman", serif;
  font-style: italic;
}

/* Keep inline notation visually connected to the prose. Match the size of the
   surrounding text instead of overriding font-family: the text faces lack many
   math glyphs (‖ ℝ ∑ √ ⋯), and forcing them makes those characters fall back to
   whatever the system substitutes. */
.katex { font-size: 1.05em; }
.katex-display > .katex { font-size: 1.1em; }

.hint {
  margin: 0;
  color: var(--muted);
  font-size: .82rem;
}

/* --- interactive demo column --- */

.topic-demo {
  position: sticky;
  top: 3.6rem;
}

.topic-demo canvas {
  display: block;
  width: 100%;
  height: 300px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  touch-action: none;
}

.topic-demo canvas.dragging { cursor: grabbing; }

.topic-demo-dual {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .7rem;
}

.topic-demo-dual canvas { height: 220px; }
.topic-demo-dual .readout { grid-column: 1 / -1; }

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .6rem .9rem;
  margin-top: .7rem;
  font-size: .82rem;
}

.controls label {
  display: flex;
  align-items: center;
  gap: .4rem;
  color: var(--muted);
}

.controls input[type="range"] {
  width: 7.5rem;
  accent-color: var(--link);
}

.preset-row {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
  width: 100%;
  margin-top: .2rem;
}

button {
  font: inherit;
  cursor: pointer;
}

.controls button,
.preset-row button {
  padding: .3rem .65rem;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--ink);
  font-size: .78rem;
}

.controls button:hover,
.preset-row button:hover {
  border-color: var(--link);
  color: var(--link);
}

.controls .toggle.active,
.preset-row button.active {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}

.readout {
  margin: .65rem 0 0;
  padding: .5rem .7rem;
  background: var(--code-bg);
  border-radius: 5px;
  color: var(--ink);
  font: 12.5px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* --- python snippet --- */

.snippet-box {
  margin-top: 1.1rem;
}

.snippet-box summary {
  cursor: pointer;
  color: var(--link);
  font-size: .82rem;
  list-style: none;
}

.snippet-box summary::-webkit-details-marker { display: none; }
.snippet-box summary::before { content: '▸ '; }
.snippet-box[open] summary::before { content: '▾ '; }

.snippet {
  margin: .6rem 0 0;
  padding: .85rem 1rem;
  background: var(--code-bg);
  border-radius: 6px;
  overflow-x: auto;
}

.snippet code {
  font: 12.5px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre;
}

/* --- pytorch section extras --- */

.topic-sub { margin-top: 1.6rem; }

.einsum-view {
  margin-top: .8rem;
  padding: .9rem 1rem;
  background: var(--code-bg);
  border-radius: 6px;
  font: 12.5px/1.7 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre;
  overflow-x: auto;
}

.tensor-box {
  display: flex;
  flex-wrap: wrap;
  gap: 1.6rem;
  margin-top: .9rem;
}

.tensor-grid {
  display: grid;
  gap: 3px;
}

.tensor-cell {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 2.3rem;
  height: 2.3rem;
  background: var(--code-bg);
  border: 1px solid var(--line);
  border-radius: 4px;
  font: 13px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  transition: background .25s;
}

.tensor-cell .buf-idx {
  position: absolute;
  right: 2px;
  bottom: 1px;
  color: var(--muted);
  font-size: 8.5px;
}

.tensor-label {
  margin-bottom: .4rem;
  color: var(--muted);
  font-size: .78rem;
}

.buffer-strip {
  display: flex;
  gap: 3px;
  margin-top: .3rem;
}

.buffer-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.1rem;
  height: 2.1rem;
  background: #fff;
  border: 1px dashed var(--line);
  border-radius: 4px;
  font: 12.5px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.buffer-cell.walked {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}

.la-footnote {
  margin-top: 2rem;
  color: var(--muted);
  font-size: .8rem;
}

/* Sitting directly under the title, the references read as a source note. */
.la-hero .la-footnote {
  margin: .15rem 0 1.15rem;
  padding-bottom: .85rem;
  border-bottom: 1px solid var(--line);
  line-height: 1.6;
}

@media (max-width: 760px) {
  .topic-body { grid-template-columns: 1fr; }
  .topic-demo { position: static; }
  .topic-demo-dual { grid-template-columns: 1fr; }
}

@media (min-width: 1360px) {
  .la-index {
    position: fixed;
    top: 1rem;
    left: calc(50% - 680px);
    z-index: 5;
    width: 10.5rem;
    max-height: calc(100vh - 2rem);
    margin: 0;
    padding: .85rem;
    flex-direction: column;
    gap: .12rem;
    overflow-x: hidden;
    overflow-y: auto;
  }

  .la-index-title { display: block; }

  .la-index a {
    flex: initial;
    border-left: 2px solid transparent;
    white-space: normal;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: .01ms !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
  }
}
