:root {
  --bg: #ffffff;
  --ink: #111111;
  --soft: rgba(17, 17, 17, 0.38);
  --cell-pad-y: 10px;
  --cell-pad-x: 12px;
  /* the editor layout: the focused column is 80 characters wide and stays in the middle */
  --focus-w: 80ch;
  /* the smallest a row can be: six text lines */
  --row-min-h: calc(6 * 1.5em);
  --side-w: 40ch;
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 ui-sans-serif, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.boot {
  padding: 24px 14px;
  color: var(--soft);
}

/* ── the list of grids: name, then the columns inside it ──────────────────── */

.list {
  max-width: 760px;
  margin: 0 auto;
  padding: 48px 20px 80px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.list__head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 22px;
}

.list__title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.list__head .btn {
  margin-left: auto;
}

.btn {
  padding: 6px 14px;
  border: 0;
  border-radius: 999px;
  background: var(--ink);
  color: var(--bg);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.file {
  display: flex;
  align-items: baseline;
  gap: 14px;
  padding: 12px 14px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.file:hover {
  background: rgba(17, 17, 17, 0.04);
}

.file__name {
  font-size: 15px;
  min-width: 12ch;
}

.file__title {
  font-size: 12px;
  color: var(--soft);
}

.file__meta {
  font-size: 12px;
  color: var(--soft);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file__meta--error {
  color: #8a2b1f;
}

/* ── editor: file name, selector, then the grid ───────────────────────────── */

/* the bar stays put; only the grid below it scrolls — sideways too */
.editor {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

.bar {
  flex: 0 0 auto;
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  align-items: center;
  padding: 10px 14px;
  background: var(--bg);
}

.back {
  border: 0;
  background: none;
  padding: 0 4px;
  color: var(--soft);
  font: inherit;
  font-size: 16px;
  cursor: pointer;
}

.back:hover {
  color: var(--ink);
}

.file-name {
  padding: 4px 8px;
  border: 0;
  border-radius: 6px;
  outline: none;
  background: none;
  color: var(--ink);
  font: inherit;
  font-size: 1.4em;
}

.file-name:hover {
  background: rgba(17, 17, 17, 0.04);
}

.file-name:focus {
  background: rgba(17, 17, 17, 0.06);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 5px 6px 5px 12px;
  border: 0;
  border-radius: 999px;
  background: var(--ink);
  color: var(--bg);
  font: inherit;
  font-size: 13px;
  cursor: grab;
  user-select: none;
  touch-action: none;
}

/* hidden column: no fill — the background alone says whether it is shown */
.chip--off {
  background: transparent;
  color: var(--ink);
}

.chip--src {
  opacity: 0.25;
}

.chip--ghost {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 100;
  margin: 0;
  background: var(--ink);
  color: var(--bg);
  opacity: 0.96;
  pointer-events: none;
  cursor: grabbing;
  will-change: transform;
}

.chip__title {
  max-width: 26ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chip__input {
  width: 12ch;
  padding: 0;
  border: 0;
  outline: none;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 13px;
}

.chip__menu {
  padding: 0 4px;
  border: 0;
  border-radius: 999px;
  background: none;
  color: inherit;
  font: inherit;
  line-height: 1;
  cursor: pointer;
  opacity: 0.5;
}

.chip__menu:hover,
.chip:hover .chip__menu {
  opacity: 1;
}

.chip--off .chip__menu {
  color: var(--soft);
}

.menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  min-width: 12em;
  padding: 4px;
  border-radius: 10px;
  background: var(--bg);
  box-shadow: 0 8px 28px rgba(17, 17, 17, 0.16);
  cursor: default;
}

.menu__item {
  padding: 7px 10px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
}

.menu__item:hover {
  background: rgba(17, 17, 17, 0.06);
}

.menu__item--danger:hover {
  color: #8a2b1f;
}

.chip--add,
.chip--new {
  padding: 5px 11px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}

.chip--new {
  cursor: text;
}

/* ── the grid: quiet column titles, rows of textareas, no frames ──────────── */

.grid {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 4px 14px 72px;
}

.grid__head {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  gap: 10px;
  background: var(--bg);
}

.head {
  flex: 1 1 0;
  min-width: 0;
  padding: 6px var(--cell-pad-x) 10px;
  border: 0;
  background: none;
  font: inherit;
  color: var(--soft);
  text-align: center;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── the editor layout: the focused column moves to the middle, neighbours narrow beside it ──
   Only widths change (flex-basis and flex-grow), so the switch animates instead of jumping. */

.row,
.grid__head {
  justify-content: center;
}

.spacer {
  /* never shrinks: its whole point is to give the centred column room on a narrower side */
  flex: 0 0 0;
  transition: flex-basis 260ms cubic-bezier(0.3, 0.7, 0.2, 1);
}

.cell,
.head {
  transition: flex-basis 260ms cubic-bezier(0.3, 0.7, 0.2, 1), flex-grow 260ms cubic-bezier(0.3, 0.7, 0.2, 1);
}

/* no column ever gets narrower than its set width — the page scrolls sideways instead */
.grid--editor .cell:not(.cell--focus),
.grid--editor .head:not(.head--focus) {
  min-width: var(--side-w);
}

.grid--editor .cell--focus,
.grid--editor .head--focus {
  min-width: var(--focus-w);
}

/* when the block is wider than the screen it runs off to the left too — the page scrolls, and
   `safe` keeps the left edge reachable instead of clipping it */
.row,
.grid__head {
  justify-content: center;
  justify-content: safe center;
}

/* the faint line on the left marks where the text of the centred block begins — cells only */
.grid--editor .cell--focus {
  border-left-color: rgba(17, 17, 17, 0.12);
}

.rows {
  display: flex;
  flex-direction: column;
}

.row {
  display: flex;
  align-items: stretch;
  gap: 10px;
  border-radius: 8px;
}

/* only while the focus is switching do the heights animate with the widths — typing stays instant */
.grid--animating .row {
  transition: height 260ms cubic-bezier(0.3, 0.7, 0.2, 1);
}

.row + .row {
  margin-top: 1ch;
}

.cell {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  border-left: 1px solid transparent;
}

.cell__area {
  flex: 1 1 auto;
  width: 100%;
  min-height: var(--row-min-h);
  padding: var(--cell-pad-y) var(--cell-pad-x);
  border: 0;
  outline: none;
  border-radius: 8px;
  background: none;
  color: inherit;
  font: inherit;
  resize: none;
  overflow-y: hidden;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
