:root {
  --ink: #14251d;
  --paper: #f2f0e4;
  --paper-deep: #e6e1cf;
  --leaf: #c9f45a;
  --leaf-deep: #799d20;
  --berry: #ff6b78;
  --lilac: #9d91ff;
  --line: rgba(20, 37, 29, .22);
  --shadow: 8px 8px 0 #14251d;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(rgba(20,37,29,.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(20,37,29,.045) 1px, transparent 1px),
    var(--paper);
  background-size: 28px 28px;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Monaco, Consolas, monospace;
  min-width: 320px;
}
button, a { font: inherit; }
button { color: inherit; }
button:focus-visible, a:focus-visible { outline: 3px solid var(--lilac); outline-offset: 3px; }

.topbar {
  min-height: 74px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 24px;
  padding: 12px clamp(18px, 4vw, 64px);
  border-bottom: 1px solid var(--ink);
  background: rgba(242, 240, 228, .94);
  backdrop-filter: blur(12px);
  position: relative;
  z-index: 5;
}
.topbar p { margin: 0; font-family: system-ui, sans-serif; font-size: 13px; text-align: center; }
.brand { display: inline-flex; align-items: center; gap: 12px; color: inherit; font-weight: 900; letter-spacing: .12em; text-decoration: none; width: fit-content; }
.brand-mark { position: relative; width: 28px; height: 30px; display: block; }
.brand-mark i { width: 15px; height: 20px; border: 2px solid var(--ink); border-radius: 100% 0 100% 0; background: var(--leaf); position: absolute; transform-origin: bottom right; }
.brand-mark i:nth-child(1) { left: 0; top: 7px; transform: rotate(-32deg); }
.brand-mark i:nth-child(2) { right: 0; top: 7px; transform: rotate(58deg); }
.brand-mark i:nth-child(3) { left: 7px; top: 0; transform: rotate(13deg); background: var(--berry); }
.bookmark-jump { justify-self: end; border: 1px solid var(--ink); padding: 9px 12px; background: transparent; cursor: pointer; }
.bookmark-jump b { display: inline-grid; place-items: center; background: var(--ink); color: white; min-width: 22px; height: 22px; margin-left: 6px; border-radius: 50%; }

main { max-width: 1540px; margin: 0 auto; padding: 0 clamp(16px, 4vw, 60px) 72px; }
.hero { display: grid; grid-template-columns: 1.5fr .7fr; gap: 70px; align-items: end; padding: clamp(54px, 8vw, 110px) 0 48px; }
.eyebrow { font-size: 11px; font-weight: 800; letter-spacing: .16em; text-transform: uppercase; }
.hero h1 { margin: 18px 0 0; font-family: Georgia, "Times New Roman", serif; font-weight: 500; font-size: clamp(56px, 8vw, 128px); line-height: .82; letter-spacing: -.065em; }
.hero h1 em { color: var(--berry); font-weight: inherit; }
.hero-intro { margin: 0 0 4px; padding: 22px 0 0 22px; border-left: 1px solid var(--ink); font: 17px/1.7 system-ui, sans-serif; max-width: 440px; }

.relation-switcher { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--ink); margin-bottom: 22px; box-shadow: 5px 5px 0 rgba(20,37,29,.18); }
.relation-tab { position: relative; display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: 18px; text-align: left; padding: 18px 22px; background: var(--paper); border: 0; border-right: 1px solid var(--ink); cursor: pointer; overflow: hidden; }
.relation-tab:last-child { border-right: 0; }
.relation-tab::after { content: ""; position: absolute; inset: auto 0 0; height: 0; background: var(--leaf); z-index: 0; transition: height .25s ease; }
.relation-tab > * { position: relative; z-index: 1; }
.relation-tab > span { grid-row: 1 / 3; font-size: 12px; opacity: .55; }
.relation-tab strong { font: 700 22px Georgia, serif; }
.relation-tab small { margin-top: 5px; font-family: system-ui, sans-serif; }
.relation-tab:hover::after { height: 6px; }
.relation-tab.is-active::after { height: 100%; }

.lab-grid { display: grid; grid-template-columns: 250px minmax(430px, 1fr) 310px; min-height: 620px; border: 1px solid var(--ink); background: var(--paper); }
.map-panel, .canvas-panel, .explain-panel { min-width: 0; padding: 18px; }
.map-panel, .canvas-panel { border-right: 1px solid var(--ink); }
.section-label { min-height: 28px; display: flex; justify-content: space-between; gap: 10px; border-bottom: 1px solid var(--line); font-size: 10px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
.section-label span:last-child { opacity: .5; text-align: right; }

.relation-map { height: 455px; position: relative; max-width: 320px; margin: 20px auto 0; }
.map-lines { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 0; overflow: visible; }
.line { fill: none; stroke: var(--ink); stroke-width: 1.3; stroke-dasharray: 5 4; opacity: .4; vector-effect: non-scaling-stroke; transition: d .5s ease; }
.map-node { position: absolute; z-index: 2; border: 1px solid var(--ink); background: var(--paper-deep); width: 80px; height: 80px; border-radius: 50%; display: grid; place-content: center; text-align: center; cursor: pointer; transition: transform .25s, background .25s, left .45s, top .45s; }
.map-node:hover { transform: scale(1.06); }
.map-node span { font: 34px/1 Georgia, serif; }
.map-node small { margin-top: 4px; font-size: 9px; }
.map-node.event-a { left: 4px; top: 18px; }
.map-node.event-b { right: 4px; top: 18px; }
.map-node.joint { width: 66px; height: 66px; left: calc(50% - 33px); top: 150px; background: var(--ink); color: white; }
.map-node.joint span { font-size: 27px; }
.map-edge { position: absolute; z-index: 3; border: 1px solid var(--ink); background: var(--paper); padding: 6px 8px; cursor: pointer; font-size: 10px; }
.map-edge::after { content: " →"; }
.map-edge.edge-ab { top: 16px; left: calc(50% - 26px); }
.map-edge.edge-ba { top: 98px; left: calc(50% - 26px); }
.map-node.is-selected, .map-edge.is-selected { background: var(--leaf); color: var(--ink); box-shadow: 3px 3px 0 var(--ink); }
.map-hint { display: flex; gap: 10px; margin: 0; padding-top: 14px; border-top: 1px solid var(--line); font: 12px/1.5 system-ui, sans-serif; }
.map-hint span { background: var(--berry); color: white; padding: 1px 5px; font: 10px/1.6 ui-monospace, monospace; }

.canvas-panel { display: flex; flex-direction: column; }
.canvas-wrap { min-height: 0; flex: 1; display: grid; align-content: center; }
.probability-canvas { width: 100%; height: auto; overflow: visible; }
.sample-space { fill: #e9e6d9; stroke: var(--ink); stroke-width: 1.5; }
.sample-dots { color: var(--ink); pointer-events: none; }
.event-shape { stroke: var(--ink); stroke-width: 2; cursor: pointer; transition: cx .55s cubic-bezier(.2,.8,.2,1), cy .55s, r .55s, fill .25s, opacity .25s; }
.shape-a { fill: rgba(201, 244, 90, .72); }
.shape-b { fill: rgba(157, 145, 255, .62); }
.intersection-shape { fill: var(--berry); opacity: 0; cursor: pointer; transition: opacity .25s; }
.event-label { text-anchor: middle; font: 700 28px Georgia, serif; pointer-events: none; transition: x .55s, y .55s; }
.outside-label { font: italic 19px Georgia, serif; }
.probability-canvas.selection-a .shape-b { opacity: .24; }
.probability-canvas.selection-b .shape-a { opacity: .24; }
.probability-canvas.selection-intersection .shape-a, .probability-canvas.selection-intersection .shape-b { opacity: .25; }
.probability-canvas.selection-intersection .intersection-shape { opacity: 1; }
.probability-canvas.selection-aGivenB .shape-a { opacity: .22; }
.probability-canvas.selection-aGivenB .shape-b { fill: var(--berry); opacity: .9; }
.probability-canvas.selection-aGivenB .intersection-shape { opacity: 1; fill: var(--leaf); }
.probability-canvas.selection-bGivenA .shape-b { opacity: .22; }
.probability-canvas.selection-bGivenA .shape-a { fill: var(--berry); opacity: .9; }
.probability-canvas.selection-bGivenA .intersection-shape { opacity: 1; fill: var(--lilac); }
.probability-canvas.mode-exclusive .intersection-shape { opacity: 0 !important; }
.canvas-legend { display: flex; flex-wrap: wrap; justify-content: center; gap: 16px; font-size: 10px; }
.canvas-legend span { display: inline-flex; align-items: center; gap: 5px; }
.swatch { width: 9px; height: 9px; border: 1px solid var(--ink); display: inline-block; }
.swatch-a { background: var(--leaf); }.swatch-b { background: var(--lilac); }.swatch-focus { background: var(--berry); }
.canvas-caption { max-width: 570px; margin: 14px auto 0; padding: 12px 15px; border-top: 1px solid var(--line); font: 13px/1.55 system-ui, sans-serif; text-align: center; }

.explain-panel { display: flex; flex-direction: column; }
.concept-index { margin-top: 30px; font: italic 64px/1 Georgia, serif; color: var(--berry); }
.explain-panel h2 { margin: 11px 0 12px; font: 700 27px/1.1 Georgia, serif; }
.definition { margin: 0; min-height: 76px; font: 14px/1.65 system-ui, sans-serif; }
.formula-card { padding: 16px; border: 1px solid var(--ink); background: var(--ink); color: var(--paper); margin: 18px 0 14px; box-shadow: 4px 4px 0 var(--berry); overflow-wrap: anywhere; }
.formula-card > span, .plain-note > span { display: block; font-size: 9px; letter-spacing: .1em; opacity: .64; text-transform: uppercase; margin-bottom: 12px; }
.formula { font-size: 12px; line-height: 1.5; }
.formula-card strong { display: block; margin-top: 7px; color: var(--leaf); font: 32px/1 Georgia, serif; }
.plain-note { padding: 10px 0; }
.plain-note p { margin: 0; font: 13px/1.6 system-ui, sans-serif; }
.save-button { width: 100%; margin-top: auto; padding: 13px 10px; border: 1px solid var(--ink); background: var(--leaf); cursor: pointer; font-weight: 800; transition: transform .15s, box-shadow .15s; }
.save-button:hover { transform: translate(-2px,-2px); box-shadow: 4px 4px 0 var(--ink); }
.save-button.is-saved { background: var(--paper-deep); }

.readout-strip { display: grid; grid-template-columns: repeat(4, minmax(100px, 1fr)) 2fr; border: 1px solid var(--ink); border-top: 0; background: var(--ink); color: white; }
.readout-strip > div { padding: 15px 16px; border-right: 1px solid rgba(255,255,255,.22); }
.readout-strip span { display: block; font-size: 10px; opacity: .6; margin-bottom: 5px; }
.readout-strip strong { font: 25px Georgia, serif; color: var(--leaf); }
.readout-strip p { align-self: center; margin: 0; padding: 16px 20px; font: 13px/1.5 system-ui, sans-serif; }

.bookmarks { padding: 86px 0 20px; scroll-margin-top: 20px; }
.bookmark-heading { display: grid; grid-template-columns: 1fr 1fr; align-items: end; border-bottom: 1px solid var(--ink); padding-bottom: 20px; }
.bookmark-heading h2 { font: 500 clamp(44px,6vw,78px)/1 Georgia, serif; margin: 10px 0 0; }
.bookmark-heading p { margin: 0; justify-self: end; max-width: 400px; font: 14px/1.6 system-ui, sans-serif; }
.bookmark-list { display: grid; grid-template-columns: repeat(3,1fr); gap: 16px; padding-top: 22px; }
.bookmark-card { position: relative; min-height: 180px; padding: 18px 48px 18px 18px; border: 1px solid var(--ink); background: var(--paper-deep); }
.bookmark-card:nth-child(3n+2) { background: #e6e1ff; }.bookmark-card:nth-child(3n+3) { background: #f5d8d8; }
.bookmark-card button.remove { position: absolute; right: 10px; top: 10px; border: 1px solid var(--ink); background: transparent; width: 28px; height: 28px; cursor: pointer; }
.bookmark-card button.reopen { padding: 0; border: 0; background: transparent; cursor: pointer; text-align: left; }
.bookmark-card small { font-size: 9px; letter-spacing: .1em; text-transform: uppercase; }
.bookmark-card h3 { font: 700 21px Georgia, serif; margin: 18px 0 8px; }
.bookmark-card p { font: 12px/1.55 system-ui, sans-serif; margin: 0; }
.bookmark-empty { grid-column: 1 / -1; padding: 42px; border: 1px dashed var(--ink); text-align: center; font: 14px/1.6 system-ui, sans-serif; }

footer { min-height: 90px; padding: 22px clamp(18px,4vw,64px); border-top: 1px solid var(--ink); display: flex; justify-content: space-between; align-items: center; gap: 20px; font-size: 11px; }
footer > span:first-child { font-weight: 900; letter-spacing: .14em; }
footer p { font-family: system-ui, sans-serif; }

@media (max-width: 1120px) {
  .lab-grid { grid-template-columns: 210px 1fr; }
  .explain-panel { grid-column: 1 / -1; border-top: 1px solid var(--ink); display: grid; grid-template-columns: 80px 1fr 1.25fr; gap: 14px 22px; align-items: start; }
  .explain-panel .section-label { grid-column: 1 / -1; }
  .concept-index { margin-top: 10px; grid-row: 2 / 5; }
  .explain-panel h2 { margin-top: 10px; }
  .definition { grid-column: 2; }
  .formula-card { grid-column: 3; grid-row: 2 / 4; margin: 10px 0 0; }
  .plain-note { grid-column: 2; }
  .save-button { grid-column: 3; }
  .readout-strip { grid-template-columns: repeat(4,1fr); }
  .readout-strip p { grid-column: 1 / -1; border-top: 1px solid rgba(255,255,255,.2); }
}

@media (max-width: 720px) {
  .topbar { grid-template-columns: 1fr auto; }
  .topbar p { display: none; }
  main { padding-left: 12px; padding-right: 12px; }
  .hero { grid-template-columns: 1fr; gap: 28px; padding-top: 54px; }
  .hero h1 { font-size: clamp(49px, 17vw, 78px); }
  .hero-intro { max-width: none; }
  .relation-switcher { grid-template-columns: 1fr; }
  .relation-tab { border-right: 0; border-bottom: 1px solid var(--ink); }
  .relation-tab:last-child { border-bottom: 0; }
  .lab-grid { grid-template-columns: 1fr; }
  .map-panel, .canvas-panel { border-right: 0; border-bottom: 1px solid var(--ink); }
  .relation-map { height: 270px; }
  .map-node.joint { top: 145px; }
  .map-lines { height: 280px; }
  .canvas-panel { min-height: 450px; }
  .explain-panel { grid-column: auto; display: flex; }
  .concept-index { margin-top: 24px; }
  .formula-card, .definition, .plain-note, .save-button { width: 100%; }
  .readout-strip { grid-template-columns: 1fr 1fr; }
  .readout-strip > div:nth-child(2) { border-right: 0; }
  .readout-strip > div { border-bottom: 1px solid rgba(255,255,255,.2); }
  .bookmark-heading { grid-template-columns: 1fr; gap: 16px; }
  .bookmark-heading p { justify-self: start; }
  .bookmark-list { grid-template-columns: 1fr; }
  footer p { display: none; }
}

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