/* Marginalia — interactive demo. Red paper, charcoal panes, thin rules,
   one type scale carried over from the site. No radius, no shadow, no gradient.

   Standalone: landing + stage. Embed (?embed=1): the demo's own top bar and
   the stage only, sized to the iframe. */

:root {
  --red: #9c1220;
  --red-deep: #8a101c;
  --red-soft: #a92330;
  --ink: #ffffff;
  --muted: #f4c6c9;
  --accent: #ffd9dc;
  --char: #141111;
  --char-2: #1d1918;
  --char-ink: #f1f3f7;
  --char-muted: #a9a0a0;
  --rule: rgba(255, 217, 220, 0.22);
  --rule-soft: rgba(255, 217, 220, 0.13);

  --sans: "Switzer", "Space Grotesk", -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  --display: "Panchang", "Switzer", "Space Grotesk", -apple-system, BlinkMacSystemFont, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  --step-small: clamp(0.8125rem, 0.79rem + 0.1vw, 0.875rem);
  --step-body: clamp(1rem, 0.97rem + 0.16vw, 1.0625rem);
  --step-lead: clamp(1.125rem, 1.03rem + 0.45vw, 1.5rem);

  --pad: clamp(16px, 4vw, 56px);
  --bar: 54px;
  --focusbar: 0px;
}

html[data-embed] {
  --bar: 42px;
  --focusbar: 26px;
}

html[data-embed][data-touch] { --focusbar: 0px; }

* { box-sizing: border-box; }

[hidden] { display: none !important; }

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

body {
  margin: 0;
  background: var(--red);
  color: var(--ink);
  font-family: var(--sans);
  font-size: var(--step-body);
  line-height: 1.5;
  overflow-x: clip;
  -webkit-font-smoothing: antialiased;
}

h1 {
  font-family: var(--display);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: -0.03em;
  line-height: 0.94;
  margin: 0;
}

p { margin: 0; }

a { color: inherit; }

::selection { background: var(--accent); color: var(--red); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

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

/* ---------- top bar + step rail ---------- */

.top {
  display: flex;
  align-items: center;
  gap: 14px;
  height: var(--bar);
  padding: 0 var(--pad);
  border-bottom: 1px solid var(--rule);
}

.mark {
  flex: none;
  font-family: var(--display);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: -0.02em;
  font-size: 1.05rem;
  text-decoration: none;
  white-space: nowrap;
}

.tag {
  flex: none;
  margin-left: 0;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
}

.tag .sep { color: var(--accent); padding: 0 2px; }

.steps {
  display: flex;
  align-items: center;
  gap: 2px;
  margin: 0 auto;
  min-width: 0;
}

.step {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 8px;
  border: 1px solid transparent;
  font-family: var(--mono);
  font-size: 10px;
  line-height: 1.2;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  opacity: 0.5;
  white-space: nowrap;
}

.step-mark { font-weight: 500; }

.step-key {
  display: none;
  padding: 1px 4px;
  font-family: var(--mono);
  font-size: 9.5px;
  line-height: 1.3;
  letter-spacing: 0.02em;
  background: rgba(255, 217, 220, 0.12);
  color: inherit;
}

.step.on {
  opacity: 1;
  color: var(--ink);
  border-color: rgba(255, 217, 220, 0.5);
  background: rgba(255, 217, 220, 0.12);
}

.step.on .step-key { background: var(--accent); color: var(--red); }

.step.done { opacity: 0.78; color: var(--accent); }

.step.done .step-key { display: none; }

@media (min-width: 821px) {
  .step-key { display: inline-block; }
}

/* ---------- focus strip (embed only) ---------- */

.focusbar {
  display: flex;
  align-items: center;
  gap: 8px;
  height: var(--focusbar);
  padding: 0 var(--pad);
  border-bottom: 1px solid var(--rule);
  background: var(--red-deep);
  font-family: var(--mono);
  font-size: 10px;
  line-height: 1.2;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}

.focusbar.live { color: var(--muted); }

.focus-dot {
  flex: none;
  width: 6px;
  height: 6px;
  background: currentColor;
}

.focusbar.live .focus-dot { background: var(--accent); }

/* ---------- landing ---------- */

.intro {
  max-width: 1240px;
  margin: 0 auto;
  padding: clamp(26px, 6vh, 84px) var(--pad) clamp(28px, 5vh, 56px);
  min-height: calc(100dvh - var(--bar));
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr);
  gap: clamp(26px, 5vw, 76px);
  align-items: center;
}

.kicker {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 16px;
}

.intro h1 {
  font-size: clamp(2.75rem, 1.1rem + 5vw, 5.1rem);
  max-width: 11ch;
}

.lead {
  margin-top: 18px;
  max-width: 40ch;
  font-size: var(--step-lead);
  line-height: 1.35;
  color: var(--ink);
  opacity: 0.94;
}

.start {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 16px;
  margin-top: clamp(24px, 4vh, 40px);
  padding: 19px 28px 19px 30px;
  border: 0;
  border-radius: 0;
  background: var(--accent);
  color: var(--red);
  font-family: var(--display);
  font-weight: 700;
  font-size: clamp(1rem, 0.95rem + 0.3vw, 1.2rem);
  line-height: 1;
  letter-spacing: 0.01em;
  text-transform: uppercase;
  cursor: pointer;
  text-align: left;
}

.start:hover { background: #ffffff; }
.start:active { transform: translateY(1px); }

.start-label { display: inline-flex; align-items: center; }

.start-key {
  margin-left: 10px;
  padding-left: 10px;
  border-left: 1px solid rgba(156, 18, 32, 0.35);
  font-family: var(--mono);
  font-size: 0.85em;
  font-weight: 400;
  letter-spacing: 0.04em;
}

.start-arrow { font-size: 1.1em; line-height: 0.8; }

.note {
  margin-top: 22px;
  max-width: 48ch;
  padding-left: 12px;
  border-left: 1px solid var(--accent);
  font-size: var(--step-small);
  line-height: 1.55;
  color: var(--accent);
}

.noscript { margin: 0 auto; max-width: 1240px; padding: 0 var(--pad) 40px; }

.intro-art {
  container-type: inline-size;
  align-self: center;
  border-left: 1px solid var(--rule);
  padding-left: clamp(18px, 3vw, 40px);
  min-width: 0;
}

.ascii {
  margin: 0;
  font-family: var(--mono);
  font-size: clamp(9px, 3.6cqw, 15px);
  line-height: 1;
  color: var(--accent);
  white-space: pre;
  overflow: hidden;
}

.art-note {
  margin-top: 14px;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  opacity: 0.8;
}

/* ---------- embed: no page header, no landing, one start card ---------- */

html[data-embed] .mark,
html[data-embed] .tag { display: none; }

html[data-embed] .top {
  justify-content: center;
  padding: 0 12px;
}

html[data-embed] .steps { margin: 0; }

html[data-embed] .intro { display: none; }

.embed-start {
  display: none;
  min-height: calc(100dvh - var(--bar) - var(--focusbar));
  padding: clamp(16px, 4vh, 40px) var(--pad);
  place-items: center;
}

html[data-embed] .embed-start { display: grid; }

html[data-embed] .embed-start.is-hidden { display: none; }

.es-card {
  width: min(680px, 100%);
  padding: clamp(22px, 4vw, 42px);
  background: var(--char);
  border: 1px solid var(--rule-soft);
}

.es-kicker {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent);
}

.es-line {
  margin-top: 16px;
  max-width: 54ch;
  font-size: clamp(1.05rem, 1rem + 0.4vw, 1.3rem);
  line-height: 1.35;
  color: var(--ink);
}

.es-card .start {
  margin-top: 26px;
  width: 100%;
  justify-content: space-between;
}

.es-fine {
  margin-top: 16px;
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.5;
  color: var(--char-muted);
}

/* ---------- stage ---------- */

.stage {
  position: relative;
  max-width: 1240px;
  margin: 0 auto;
  padding: 12px var(--pad) 16px;
  height: calc(100dvh - var(--bar) - var(--focusbar));
  min-height: 460px;
  display: grid;
  grid-template-columns: minmax(0, clamp(320px, 36vw, 460px)) minmax(0, 1fr);
  gap: 2px;
}

.pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--char);
  border: 1px solid var(--rule-soft);
  transition: opacity 0.35s ease;
}

.pane-bar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 13px;
  border-bottom: 1px solid var(--rule-soft);
  font-family: var(--mono);
  font-size: 10.5px;
  line-height: 1.2;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--char-muted);
}

.pane-title { color: var(--accent); }

.pane-meta {
  color: var(--char-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pane-meta::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-right: 7px;
  background: currentColor;
  vertical-align: 1px;
}

/* ---------- coach strip + pinned task ---------- */

.coach {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--rule-soft);
  background: rgba(255, 217, 220, 0.05);
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.45;
  color: var(--muted);
}

.coach-dot {
  flex: none;
  width: 6px;
  height: 6px;
  background: var(--accent);
  animation: blink 1.2s steps(1) infinite;
}

.pin {
  flex: none;
  display: flex;
  align-items: baseline;
  gap: 9px;
  padding: 9px 14px;
  border-bottom: 1px solid var(--rule-soft);
  background: var(--char-2);
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.45;
  color: var(--ink);
}

.pin span {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pin b {
  flex: none;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
}

/* ---------- transcript ---------- */

.log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 15px 16px 20px;
  scrollbar-width: thin;
  scrollbar-color: var(--red-soft) transparent;
}

.log::-webkit-scrollbar { width: 8px; }
.log::-webkit-scrollbar-thumb { background: var(--red-soft); }

.line { margin: 0 0 16px; }
.line:last-child { margin-bottom: 0; }

.who {
  display: block;
  margin-bottom: 5px;
  font-family: var(--mono);
  font-size: 9.5px;
  line-height: 1.2;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--char-muted);
}

.line.ask .body {
  font-size: 0.9375rem;
  line-height: 1.5;
  color: var(--char-ink);
  opacity: 0.86;
}

.line.answer {
  padding-left: 12px;
  border-left: 1px solid rgba(255, 217, 220, 0.32);
}

.line.answer .who { color: var(--accent); }

.line.answer .body {
  font-size: 0.9375rem;
  line-height: 1.55;
  color: var(--ink);
}

.sys {
  margin: 0 0 16px;
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.5;
  letter-spacing: 0.02em;
  color: var(--char-muted);
}

.sys b {
  font-weight: 500;
  color: var(--accent);
}

.cursor {
  display: inline-block;
  width: 0.55em;
  height: 1em;
  margin-left: 1px;
  background: var(--accent);
  vertical-align: -0.13em;
  animation: blink 1s steps(1) infinite;
}

@keyframes blink { 50% { opacity: 0; } }

/* the mock screenshot attached to the conversation */
.shot-frame {
  border: 1px solid rgba(255, 217, 220, 0.3);
  background: var(--char);
}

.shot-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 9px;
  border-bottom: 1px solid var(--rule-soft);
  font-family: var(--mono);
  font-size: 9px;
  line-height: 1.3;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--char-muted);
}

.shot-bar b {
  font-weight: 500;
  color: var(--accent);
}

.shot-body {
  margin: 0;
  padding: 11px 12px;
  font: 400 11.5px/1.5 var(--mono);
  color: var(--char-ink);
  white-space: pre-wrap;
}

/* ---------- step hint: key chip + line + button + arrow ---------- */

.pane-foot { flex: none; }

.hint {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 9px 12px;
  padding: 12px 46px 12px 14px;
  border-top: 1px solid var(--rule-soft);
}

.hint-chip {
  display: inline-flex;
  align-items: center;
  padding: 6px 8px;
  border: 1px solid var(--accent);
  background: rgba(255, 217, 220, 0.1);
  animation: chip-pulse 1.5s ease-in-out infinite;
}

@keyframes chip-pulse {
  0%, 100% { background: rgba(255, 217, 220, 0.08); transform: scale(1); }
  50% { background: rgba(255, 217, 220, 0.28); transform: scale(1.05); }
}

.hint-label {
  flex: 1 1 180px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.45;
  color: var(--ink);
}

kbd {
  font-family: var(--mono);
  font-size: 0.95em;
  font-weight: 500;
  color: var(--red);
  background: var(--accent);
  padding: 1px 6px;
  white-space: nowrap;
}

.hint-chip kbd {
  font-size: 14px;
  padding: 2px 6px;
}

.ghost-link {
  appearance: none;
  padding: 0 0 2px;
  border: 0;
  border-bottom: 1px solid var(--accent);
  background: none;
  color: var(--accent);
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.3;
  cursor: pointer;
  white-space: nowrap;
}

.ghost-link:hover { color: var(--ink); border-bottom-color: var(--ink); }

.hint-arrow {
  position: absolute;
  right: 14px;
  bottom: 12px;
  font-family: var(--mono);
  font-size: 20px;
  line-height: 1;
  color: var(--accent);
  animation: nudge-x 1.1s ease-in-out infinite;
}

@keyframes nudge-x {
  0%, 100% { transform: translateX(0); }
  50% { transform: translateX(7px); }
}

/* ---------- editor ---------- */

.pane-code { background: var(--char-2); }

.code {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  background: var(--char-2);
}

.gutter {
  margin: 0;
  padding: 15px 9px 24px 11px;
  min-width: 42px;
  border-right: 1px solid var(--rule-soft);
  background: var(--char);
  font: 400 13px/1.65 var(--mono);
  text-align: right;
  color: #6d6461;
  white-space: pre;
  overflow: hidden;
  user-select: none;
}

.editor {
  margin: 0;
  padding: 15px 18px 24px 16px;
  min-height: 0;
  font: 400 13px/1.65 var(--mono);
  color: var(--char-ink);
  white-space: pre;
  overflow: auto;
  outline: none;
  caret-color: var(--accent);
  tab-size: 2;
  scrollbar-width: thin;
  scrollbar-color: var(--red-soft) transparent;
}

.editor::-webkit-scrollbar { width: 8px; height: 8px; }
.editor::-webkit-scrollbar-thumb { background: var(--red-soft); }

.editor::selection { background: var(--accent); color: var(--red); }

.code-foot {
  display: flex;
  gap: 18px;
  padding: 7px 13px;
  border-top: 1px solid var(--rule-soft);
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--char-muted);
}

.caret-info { margin-left: auto; color: var(--accent); }

.pane-code.nudge { animation: edge-pulse 1.25s ease-out 1; }

@keyframes edge-pulse {
  0%, 100% { border-color: var(--rule-soft); }
  12% { border-color: var(--accent); }
  42% { border-color: var(--rule-soft); }
  60% { border-color: var(--accent); }
}

/* ---------- closing (after ⌃⌥X) ---------- */

.stage.is-blanked .pane { opacity: 0.05; }

.closing {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: var(--pad);
  background: rgba(156, 18, 32, 0.96);
}

.closing-inner { max-width: min(1000px, 100%); }

.closing-line {
  max-width: none;
  font-family: var(--display);
  font-weight: 700;
  font-size: clamp(1.7rem, 1rem + 2.2vw, 2.8rem);
  line-height: 1.02;
  letter-spacing: -0.02em;
  text-transform: uppercase;
}

.replay {
  appearance: none;
  margin-top: 24px;
  border: 0;
  border-radius: 0;
  padding: 12px 18px;
  background: var(--accent);
  color: var(--red);
  font-family: var(--display);
  font-weight: 700;
  font-size: 12px;
  line-height: 1;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
}

.replay:hover { background: #ffffff; }

/* ---------- touch: buttons only, no keyboard wording ---------- */

html[data-touch] .start-key { display: none; }

html[data-touch] .focusbar { display: none; }

html[data-touch] .hint {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 12px;
}

html[data-touch] .hint-chip { display: none; }

html[data-touch] .hint-label {
  grid-column: 1 / -1;
  font-size: 11.5px;
}

html[data-touch] .ghost-link {
  grid-column: 1;
  display: block;
  width: 100%;
  padding: 14px 16px;
  border: 0;
  background: var(--accent);
  color: var(--red);
  font-family: var(--display);
  font-weight: 700;
  font-size: 13.5px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  text-align: center;
}

html[data-touch] .ghost-link:hover { color: var(--red); }

html[data-touch] .hint-arrow {
  position: static;
  grid-column: 2;
  transform: rotate(90deg);
  animation: nudge-y 1.1s ease-in-out infinite;
}

@keyframes nudge-y {
  0%, 100% { transform: rotate(90deg) translateX(0); }
  50% { transform: rotate(90deg) translateX(7px); }
}

/* ---------- narrow ---------- */

@media (max-width: 900px) {
  .intro {
    grid-template-columns: minmax(0, 1fr);
    align-items: start;
    min-height: 0;
  }

  .intro-art {
    border-left: 0;
    border-top: 1px solid var(--rule);
    padding: 22px 0 0;
  }
}

@media (max-width: 820px) {
  .tag { display: none; }

  .stage {
    grid-template-columns: minmax(0, 1fr);
    height: auto;
    gap: 2px;
    padding-bottom: 16px;
  }

  .pane-log { height: min(43vh, 380px); min-height: 300px; }
  .pane-code { height: min(46vh, 400px); min-height: 300px; }

  .gutter { display: none; }

  .editor {
    white-space: pre-wrap;
    overflow-wrap: break-word;
    font-size: 12.5px;
    padding: 13px 14px 20px;
  }

  .intro h1 { max-width: 9ch; }

  /* embed: fill the iframe exactly, split it between the two panes */
  html[data-embed] .stage {
    height: calc(100dvh - var(--bar) - var(--focusbar));
    grid-template-rows: minmax(0, 47fr) minmax(0, 53fr);
    padding-top: 8px;
    padding-bottom: 8px;
  }

  html[data-embed] .pane-log,
  html[data-embed] .pane-code {
    height: auto;
    min-height: 0;
  }
}

/* standalone phone: the rail gets its own row instead of squeezing the mark */
@media (max-width: 700px) {
  html:not([data-embed]) .top {
    height: auto;
    flex-wrap: wrap;
    row-gap: 4px;
    padding: 10px var(--pad);
  }

  html:not([data-embed]) .steps {
    order: 3;
    width: 100%;
    margin: 0;
    justify-content: space-between;
  }
}

@media (max-width: 600px) {
  .step {
    padding: 4px 5px;
    gap: 4px;
    font-size: 9px;
    letter-spacing: 0.02em;
  }

  .step-key { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .hint-chip {
    animation: none;
    border-color: var(--accent);
    background: rgba(255, 217, 220, 0.18);
  }
  .hint-arrow { animation: none; }
  .coach-dot { animation: none; }
  .cursor { animation: none; }
  .pane-code.nudge { animation: none; border-color: var(--accent); }
  .pane { transition: none; }
  .start:active { transform: none; }
}
