/*
 * Plain CSS on purpose: no CSS-in-JS, no animation library. Anything that renders would land in the recordings and
 * the fixture would stop measuring the app instead of its own styling.
 */
:root {
  --bg: #131317;
  --card: #1c1c22;
  --line: #2e2e38;
  --text: #e8e8ea;
  --muted: #8c8c96;
  --accent: #0a84ff;
  --warm: #ffd60a;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

button,
input {
  font: inherit;
  color: inherit;
}

.app {
  max-width: 1040px;
  margin: 0 auto;
  padding: 18px 20px 40px;
}

/* Header */
.head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 10px;
}

.workspace {
  font-size: 17px;
}

.badge {
  padding: 1px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 12px;
  color: var(--warm);
}

.badge.muted {
  color: var(--muted);
}

.sync {
  width: 90px;
  height: 5px;
  border-radius: 3px;
  background: #2a2a33;
  overflow: hidden;
}

.sync-fill {
  display: block;
  height: 5px;
  background: #33c27f;
}

.connection {
  color: var(--muted);
  font-size: 12px;
}

/* Layout */
.chat {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  margin-top: 12px;
}

.chat.wide {
  grid-template-columns: minmax(0, 1fr) 260px;
}

.panel,
.side,
.composer {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.panel {
  padding: 6px 6px 10px;
}

/* Tabs */
.tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
}

.tabs button {
  padding: 4px 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.tabs button[aria-selected='true'] {
  background: #2a2a33;
  color: var(--text);
}

/* Messages */
.messages,
.people {
  list-style: none;
  margin: 0;
  padding: 4px;
  min-height: 210px;
}

.message,
.people li {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
}

.message:hover {
  background: #23232b;
}

.message.dense {
  padding: 4px 10px;
}

.avatar {
  flex: none;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #34344a;
  color: #cfd0ff;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.body {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}

.who {
  display: flex;
  gap: 8px;
  align-items: baseline;
  font-weight: 600;
  font-size: 13px;
}

.who small {
  font-weight: 400;
  color: var(--muted);
}

.text {
  color: #d5d5dd;
}

.status {
  flex: none;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.delete {
  flex: none;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #4a4a57;
  cursor: pointer;
}

.message:hover .delete {
  color: var(--muted);
}

.delete:hover {
  background: #3a2a2e;
  color: #ff8a80;
}

.people li {
  color: #d5d5dd;
}

/* Composer */
.composer {
  margin-top: 12px;
  padding: 10px 12px 12px;
}

.composer .row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.composer .row.meta {
  margin-top: 8px;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.field.grow {
  flex: 1;
}

.field.small {
  flex-direction: row;
  align-items: center;
  gap: 6px;
}

.field input {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #16161b;
}

.field.small input {
  width: 64px;
  padding: 3px 6px;
}

.field input:focus {
  outline: 1px solid var(--accent);
}

.hint {
  height: 14px;
  color: var(--muted);
  font-size: 11px;
}

.error {
  color: #ff8a80;
  font-size: 11px;
  font-style: normal;
}

.hints {
  display: flex;
  gap: 12px;
  margin-left: auto;
}

.stat b {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.composer button[type='submit'],
.side-form button {
  padding: 8px 16px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}

.composer button[type='submit']:disabled,
.side-form button:disabled {
  background: #2a2a33;
  color: var(--muted);
  cursor: default;
}

/* Side */
.side {
  padding: 12px 14px;
  align-self: start;
}

.side h3 {
  margin: 10px 0 6px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.side h3:first-child {
  margin-top: 0;
}

.side-line {
  margin: 4px 0;
  color: #d5d5dd;
}

.side-form {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.side-form input {
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #16161b;
}

/* Basics: one textbook mistake per page, the broken and the fixed version side by side. */
.basics {
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px 20px 48px;
}

.basics h1 {
  margin: 0 0 6px;
  font-size: 20px;
}

.basics .what {
  margin: 0 0 14px;
  max-width: 90ch;
  color: #b9b9c2;
}

.basics code {
  color: var(--warm);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 14px;
}

.bar button {
  padding: 7px 14px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}

.bar button + button {
  background: #2a2a33;
  color: var(--text);
}

/* A row of choices marks the picked one with aria-pressed, not by being first. */
.bar button[aria-pressed] {
  background: #2a2a33;
  color: var(--text);
}

.bar button[aria-pressed='true'] {
  background: var(--accent);
  color: #fff;
}

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

.two,
.three {
  display: grid;
  gap: 12px;
}

.two {
  grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr));
}

.three {
  grid-template-columns: repeat(auto-fit, minmax(min(270px, 100%), 1fr));
}

.case {
  padding: 12px 14px 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
}

.case h2 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 8px;
  font-size: 14px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.case .mark {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
}

.case.broken {
  border-color: #4a2a30;
}

.case.broken .mark {
  background: #3a2028;
  color: #ff8a80;
}

.case.fixed {
  border-color: #23472f;
}

.case.fixed .mark {
  background: #163124;
  color: #5ddc9a;
}

.case .says {
  margin: 10px 0 0;
  padding-top: 8px;
  border-top: 1px solid var(--line);
  color: #9fb7ff;
  font-size: 12px;
}

.rows {
  list-style: none;
  margin: 0;
  padding: 0;
}

.rows li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 4px;
  border-bottom: 1px solid #23232b;
}

.rows li:last-child {
  border-bottom: 0;
}

.rows .grow {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rows button {
  padding: 2px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}

.count {
  flex: none;
  min-width: 82px;
  text-align: right;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.count[data-count='1'] {
  color: #5ddc9a;
}

.count.mounts {
  min-width: 78px;
  color: #6b6b78;
}

.count.mounts.again {
  color: #ff8a80;
}

.clock {
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.basics h3.pair {
  margin: 18px 0 6px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.rows input {
  width: 110px;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #16161b;
  color: var(--text);
}

/* A checkbox keeps its own size: at the field width above it pushed the task title down to one letter. */
.rows input[type='checkbox'] {
  width: auto;
  flex: none;
}

.rows .label {
  width: 42px;
  flex: none;
  color: var(--muted);
}

.rows .link {
  color: var(--accent);
}

/* The code behind a case: open where the versions stand side by side, folded on a phone. */
.code {
  margin-top: 10px;
  border: 1px solid #25252e;
  border-radius: 10px;
  background: #121216;
  overflow: hidden;
}

.code summary {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 12px;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
  list-style: none;
  user-select: none;
  transition: color 0.15s, background-color 0.15s;
}

.code summary::-webkit-details-marker {
  display: none;
}

/* A chevron drawn with two borders: it turns down as the code opens. */
.code summary::before {
  content: '';
  flex: none;
  width: 6px;
  height: 6px;
  margin: 0 1px 0 2px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(-45deg);
  transition: transform 0.15s;
}

.code[open] summary::before {
  transform: translateY(-2px) rotate(45deg);
}

.code summary:hover {
  color: var(--text);
  background: #18181e;
}

.code summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  border-radius: 10px;
}

.code[open] summary {
  border-bottom: 1px solid #25252e;
}

.code summary .meta {
  margin-left: auto;
  color: #5f5f6c;
  font: 11px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.code pre {
  margin: 0;
  padding: 10px 0;
  font: 12px/1.65 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: #d6deeb;
  tab-size: 2;
}

.code[open] pre {
  animation: code-in 0.18s ease-out;
}

@keyframes code-in {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .code[open] pre {
    animation: none;
  }
}

/* A long line wraps under its own indent instead of hiding the note at its end behind a scroll. */
.code .line {
  display: block;
  padding: 0 12px 0 calc(10px + var(--indent, 2ch));
  text-indent: calc(-1 * var(--indent, 2ch));
  border-left: 2px solid transparent;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.code .bad {
  border-left-color: #ff8a80;
  background: rgba(255, 138, 128, 0.09);
}

.case.fixed .code .bad {
  border-left-color: #5ddc9a;
  background: rgba(93, 220, 154, 0.08);
}

.tk-k {
  color: #c792ea;
}

.tk-s {
  color: #c3e88d;
}

.tk-n {
  color: #f78c6c;
}

.tk-f {
  color: #82aaff;
}

.tk-t {
  color: #ffcb6b;
}

.tk-tag {
  color: #f07178;
}

.tk-a {
  color: #addb67;
  font-style: italic;
}

.tk-p {
  color: #89ddff;
}

.tk-c {
  color: #6c7086;
  font-style: italic;
}

/* Kept whole: a note that does not fit goes under its line rather than leaving `// ←` at the edge. */
.tk-note {
  display: inline-block;
  text-indent: 0;
  color: #ffb4ab;
  font-style: italic;
}

.case.fixed .tk-note {
  color: #8ee6b5;
}

/*
 * Side by side, the parts of the versions line up: each case lends its heading, demo, note and code to the rows of
 * the pair, so the two snippets start on one line and end on another.
 */
@media (min-width: 900px) {
  .basics {
    max-width: 1320px;
  }

  .two > .case,
  .three > .case {
    display: grid;
    grid-row: span 4;
    grid-template-rows: subgrid;
    grid-template-columns: minmax(0, 1fr);
    row-gap: 0;
  }

  .two > .case > .code[open],
  .three > .case > .code[open] {
    display: flex;
    flex-direction: column;
  }

  .two > .case > .code[open]::details-content,
  .three > .case > .code[open]::details-content {
    display: flex;
    flex: 1;
  }

  .two > .case > .code[open] pre,
  .three > .case > .code[open] pre {
    flex: 1;
  }
}

/* A surface to move the pointer over: what happens to its position is the whole point of the ref case. */
.pad {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  height: 110px;
  padding: 10px;
  border: 1px dashed var(--line);
  border-radius: 10px;
  color: var(--muted);
  font-size: 12px;
  user-select: none;
}

.pad .grow {
  flex: 1;
}

.pad button {
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}

/* A row that can be picked: the whole title is the button, and the picked one says so. */
.rows li.row button.grow {
  background: none;
  border: 0;
  padding: 0;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.rows li.row.on {
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  border-radius: 6px;
}

/* A page of its own inside a case: a button, the dialog it opens, and a feed under them. */
.stack {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
}

.stack > .rows {
  align-self: stretch;
}

.dialog {
  display: flex;
  align-items: center;
  gap: 8px;
  align-self: stretch;
  padding: 10px 12px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}

.stack > button,
.dialog button {
  padding: 6px 12px;
  border: 0;
  border-radius: 8px;
  background: #2a2a33;
  color: var(--text);
  cursor: pointer;
}

.stack > button:disabled {
  opacity: 0.5;
  cursor: default;
}

/* Harder cases: a row of tags that fits its box, a long list, the lag under a field. */
.measured {
  overflow: hidden;
}

.tags {
  display: flex;
  gap: 6px;
  flex-wrap: nowrap;
}

.tag {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  width: 90px;
  flex: none;
  padding: 3px 6px;
  border-radius: 6px;
  background: #2a2a33;
  font-size: 12px;
  overflow: hidden;
}

.tag .n {
  font-size: 10px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.rows .label.wide {
  width: 64px;
}

.tag.more {
  width: auto;
  color: var(--muted);
}

.rows.tall {
  max-height: 260px;
  overflow: auto;
}

.lag {
  font-variant-numeric: tabular-nums;
}

/* A long list in a case: its rows scroll inside the panel, not the page. */
.rows.scroll {
  max-height: 260px;
  overflow: auto;
}

.rows li.selected {
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  border-radius: 6px;
}

/* A row of fields: they share what the label and the counter leave, and a long value scrolls inside its field. */
.rows.fields input {
  flex: 1 1 0;
  width: auto;
  min-width: 0;
}

/* A phone: the side panel goes under the thread instead of squeezing it to a word a line. */
@media (max-width: 640px) {
  .app {
    padding: 12px 12px 40px;
  }

  .head {
    flex-wrap: wrap;
  }

  .chat.wide {
    grid-template-columns: minmax(0, 1fr);
  }
}
