/* ---------- tokens ---------- */
:root {
  --bg: #f3f4f1;          /* page */
  --panel: #ffffff;       /* panes, sheet cells */
  --canvas: #f6f7f4;      /* area behind the sheet */
  --head: #eef0eb;        /* sheet header + gutter */
  --sunk: #f0f2ee;        /* inset controls */
  --fg: #1a1c19;
  --muted: #595e56;
  --faint: #868b82;
  --line: #e1e4dd;
  --line-strong: #c9cdc3;
  --accent: #1b6a50;
  --accent-hover: #155a43;
  --accent-fg: #ffffff;
  --accent-soft: #e7f2ec;
  --accent-line: #c3dccf;
  --danger: #a3392c;
  --danger-soft: #f8e8e4;
  --lift: #f2f8f5;
  --shadow: rgba(24, 34, 28, 0.12);
  --shadow-strong: rgba(24, 34, 28, 0.24);
  --sel: #cfe5d9;
  --radius: 10px;
  --radius-sm: 6px;
  --gutter: 56px;
  --mono: ui-monospace, "Cascadia Mono", "SF Mono", Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101210;
    --panel: #181b18;
    --canvas: #141614;
    --head: #1e221e;
    --sunk: #1c1f1c;
    --fg: #e5e8e2;
    --muted: #a1a79c;
    --faint: #767c72;
    --line: #2a2e29;
    --line-strong: #3b4039;
    --accent: #6ac7a1;
    --accent-hover: #82d4b2;
    --accent-fg: #0a1b13;
    --accent-soft: #15241c;
    --accent-line: #284536;
    --danger: #ef8a7a;
    --danger-soft: #2c1916;
    --lift: #1d2a23;
    --shadow: rgba(0, 0, 0, 0.35);
    --shadow-strong: rgba(0, 0, 0, 0.6);
    --sel: #24493a;
    color-scheme: dark;
  }
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
html { scrollbar-color: var(--line-strong) transparent; }
body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  caret-color: var(--accent);
  -webkit-font-smoothing: antialiased;
}
::selection { background: var(--sel); color: var(--fg); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; flex: none; }
svg.fill { fill: currentColor; stroke: none; }
code { font: 0.9em var(--mono); background: var(--sunk); border: 1px solid var(--line); padding: 0 4px; border-radius: 4px; }
h1, h2, p { margin: 0; }

/* ---------- controls ---------- */
button, select, input {
  font: inherit;
  font-size: 13px;
  color: var(--fg);
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  height: 30px;
  padding: 0 10px;
  box-shadow: 0 1px 0 var(--shadow);
}
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  font-weight: 500;
  white-space: nowrap;
  transition: background-color .12s, border-color .12s, color .12s;
}
button:hover:not(:disabled) { background: var(--sunk); border-color: var(--faint); }
button:active:not(:disabled) { transform: translateY(0.5px); }
button:disabled { opacity: 0.4; cursor: default; box-shadow: none; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); font-weight: 600; }
button.primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
button.danger { color: var(--danger); }
button.danger:hover:not(:disabled) { background: var(--danger-soft); border-color: var(--danger); }
button.icon { width: 30px; padding: 0; }
select { padding-right: 6px; cursor: pointer; }
input[type=number] { width: 52px; padding: 0 6px; text-align: center; font-variant-numeric: tabular-nums; box-shadow: inset 0 1px 0 var(--shadow); }
select:hover, input:hover { border-color: var(--faint); }

/* ---------- app bar ---------- */
.appbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 24px;
  padding: 14px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; }
.mark { width: 26px; height: 26px; padding: 4px; color: var(--accent-fg); background: var(--accent); border-radius: 7px; stroke-width: 2.2; }
.brand-text { display: grid; gap: 1px; }
h1 { font-size: 17px; font-weight: 650; letter-spacing: -0.01em; line-height: 1.2; }
.tag { font-size: 12px; color: var(--muted); max-width: 270px; line-height: 1.35; }

.proofs {
  list-style: none;
  margin: 0 0 0 auto;
  padding: 0;
  display: flex;
  align-items: stretch;
  background: var(--accent-soft);
  border: 1px solid var(--accent-line);
  border-radius: var(--radius);
}
.proof { display: flex; align-items: center; gap: 9px; padding: 7px 14px; line-height: 1.25; }
.proof + .proof { border-left: 1px solid var(--accent-line); }
.proof svg { color: var(--accent); width: 18px; height: 18px; }
.proof strong { display: block; font-size: 12.5px; font-weight: 600; }
.proof .sub { display: block; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.proof.bad { background: var(--danger-soft); }
.proof.bad svg, .proof.bad strong { color: var(--danger); }
.trust-actions { display: flex; gap: 8px; }

.verify {
  flex: 1 1 100%;
  margin-top: 2px;
  padding: 14px 18px;
  font-size: 13px;
  background: var(--canvas);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.verify h2 { font-size: 16px; font-weight: 650; margin-bottom: 4px; }
.verify-lead { color: var(--muted); margin-bottom: 12px; max-width: 80ch; }
.verify-lead strong { color: var(--fg); }
.safety-grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  column-gap: 32px;
}
.safety-grid li { display: flex; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.safety-grid svg { color: var(--accent); width: 18px; height: 18px; margin-top: 1px; }
.safety-grid h3 { font-size: 13.5px; font-weight: 600; margin: 0 0 3px; }
.safety-grid p { color: var(--muted); line-height: 1.5; }
.safety-grid strong { color: var(--fg); font-weight: 600; }
.verify code, .verify kbd { font-family: var(--mono); font-size: 12px; padding: 1px 4px; background: var(--sunk); border: 1px solid var(--line); border-radius: 4px; }
@media (max-width: 760px) { .safety-grid { grid-template-columns: 1fr; } }

/* ---------- workspace ---------- */
.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr);
  gap: 16px;
  padding: 16px 24px 8px;
}
.pane {
  height: clamp(440px, calc(100vh - 170px), 1100px);
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 1px 2px var(--shadow);
  overflow: hidden;
}
.pane-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  min-height: 50px;
  padding: 9px 10px 9px 16px;
  border-bottom: 1px solid var(--line);
}
.pane-head h2 { font-size: 13px; font-weight: 650; margin-right: 4px; }
.md-pane .pane-head h2 { flex: 1; }
.pane-foot {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 36px;
  padding: 7px 16px;
  border-top: 1px solid var(--line);
  background: var(--panel);
}
.hint { font-size: 12px; color: var(--muted); }

.tools-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.group { display: flex; align-items: center; gap: 6px; }
.group-label { font-size: 12px; font-weight: 500; color: var(--muted); }
.times { color: var(--faint); font-size: 12px; }
.divider { width: 1px; height: 20px; background: var(--line); margin: 0 2px; }

.seg { display: inline-flex; height: 30px; padding: 3px; gap: 2px; background: var(--sunk); border: 1px solid var(--line); border-radius: var(--radius-sm); }
.seg button { height: 22px; padding: 0 10px; border: 0; background: transparent; box-shadow: none; color: var(--muted); border-radius: 4px; font-size: 12.5px; }
.seg button:hover:not(:disabled) { background: transparent; color: var(--fg); }
.seg button[aria-checked="true"] { background: var(--panel); color: var(--fg); box-shadow: 0 1px 2px var(--shadow-strong); }

/* ---------- markdown editor ---------- */
textarea {
  flex: 1;
  width: 100%;
  min-height: 0;
  resize: none;
  margin: 0;
  padding: 14px 16px;
  border: 0;
  color: var(--fg);
  background: var(--panel);
  font: 12.5px/1.65 var(--mono);
  font-variant-numeric: tabular-nums;
  white-space: pre;
  overflow: auto;
  tab-size: 4;
}
textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
textarea[readonly] { color: var(--muted); }
.large-note {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 10px;
  padding: 8px 10px 8px 16px;
  font-size: 12.5px;
  background: var(--accent-soft);
  border-bottom: 1px solid var(--accent-line);
}
.large-note[hidden] { display: none; }
.large-note svg { color: var(--accent); }
.large-note span { flex: 1; min-width: 200px; }
.large-note button { height: 26px; }

/* ---------- sheet ---------- */
.grid-scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  background: var(--canvas);
}
.sheet { display: inline-grid; grid-template-columns: auto auto; align-items: start; }
.grid {
  table-layout: fixed;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13.5px;
  font-variant-numeric: tabular-nums;
}
.grid th, .grid td {
  position: relative;
  padding: 0;
  background: var(--panel);
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
  text-align: left;
  font-weight: 400;
}

/* sticky header rows */
.grid thead th { position: sticky; z-index: 3; }
.colbar th { top: 0; height: 28px; background: var(--canvas); border-right-color: transparent; border-bottom: 0; }
.head th { top: 28px; background: var(--head); font-weight: 600; border-top: 1px solid var(--line-strong); border-bottom: 1px solid var(--line-strong); }
.head th:nth-child(2) { border-left: 1px solid var(--line-strong); }
.grid .corner { left: 0; z-index: 4; background: var(--canvas); border-color: transparent; }
.head .corner { background: var(--canvas); border-top-color: transparent; border-right: 1px solid var(--line-strong); }

/* column letters + tools */
.grid .colctl { text-align: center; }
.colctl .letter { font-size: 11px; font-weight: 600; color: var(--faint); letter-spacing: 0.06em; }
.colctl.is-active .letter { color: var(--accent); }
.tools {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .12s;
}
.colctl:hover .letter, .colctl:focus-within .letter,
tr:hover > .gutter .num, .gutter:focus-within .num { opacity: 0; }
.colctl:hover .tools, .colctl:focus-within .tools,
tr:hover > .gutter .tools, .gutter:focus-within .tools { opacity: 1; pointer-events: auto; }
.tools button.icon { width: 22px; height: 22px; border: 0; background: transparent; box-shadow: none; color: var(--muted); border-radius: 4px; }
.tools button.icon:hover:not(:disabled) { background: var(--line); color: var(--fg); }
.tools button.del:hover:not(:disabled) { background: var(--danger-soft); color: var(--danger); }
.tools svg { width: 14px; height: 14px; }
button.grip { cursor: grab; touch-action: none; }
.dragging, .dragging * { cursor: grabbing !important; user-select: none; }

/* row gutter (sticky left) */
.grid .gutter {
  position: sticky;
  left: 0;
  z-index: 2;
  width: var(--gutter);
  text-align: center;
  background: var(--head) !important;
  border-right: 1px solid var(--line-strong) !important;
}
.gutter .num { font-size: 12px; font-weight: 500; color: var(--faint); }
.gutter.is-active { box-shadow: inset -2px 0 0 var(--accent); }
.gutter.is-active .num { color: var(--accent); font-weight: 650; }

/* cells */
.cell {
  min-height: 1.45em;
  padding: 8px 12px;
  line-height: 1.45;
  white-space: pre;
  overflow: hidden;
  text-overflow: ellipsis;
  outline: none;
}
.cell:focus {
  text-overflow: clip;
  overflow-x: auto;
  scrollbar-width: none;
  background: var(--lift);
  box-shadow: inset 0 0 0 2px var(--accent);
}
.a-center .cell { text-align: center; }
.a-right .cell { text-align: right; }
.grid tbody tr:hover > td { background: color-mix(in srgb, var(--panel) 95%, var(--accent)); }
.grid tr.spacer td { height: 0; padding: 0; border: 0; background: transparent; }

/* drag lift */
.lifted {
  z-index: 5 !important;
  background: var(--lift) !important;
  box-shadow: 0 10px 22px -12px var(--shadow-strong), 0 2px 6px -2px var(--shadow);
}
.dragging tr, .dragging td, .dragging th { will-change: transform; }

/* add row / column */
.add { color: var(--muted); background: transparent; border-color: transparent; box-shadow: none; font-size: 12.5px; }
.add:hover:not(:disabled) { color: var(--accent); background: var(--accent-soft); border-color: var(--accent-line); }
.add svg { width: 14px; height: 14px; }
.add-col { grid-row: 1; grid-column: 2; width: 30px; height: 30px; padding: 0; margin: 33px 0 0 6px; border: 1px dashed var(--line-strong); }
.add-row { grid-row: 2; grid-column: 1; justify-content: flex-start; height: 34px; margin: 6px 0 24px var(--gutter); padding: 0 12px; border: 1px dashed var(--line-strong); }

/* empty / oversize */
.empty { max-width: 380px; margin: 72px auto; padding: 0 16px; text-align: center; display: grid; justify-items: center; gap: 8px; }
.empty-title { font-size: 15px; font-weight: 650; }
.empty-body { color: var(--muted); font-size: 13px; margin-bottom: 8px; }

/* progress (in the pane footer) */
.progress { flex: 1; display: flex; align-items: center; gap: 10px; min-width: 0; }
.progress[hidden] { display: none; }
.pane-foot:has(.progress:not([hidden])) .hint { display: none; }
.progress-label { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.progress-track { flex: 1; max-width: 260px; height: 4px; border-radius: 2px; background: var(--line); overflow: hidden; }
.progress-bar { display: block; height: 100%; background: var(--accent); transform-origin: left; transform: scaleX(0.02); transition: transform .12s linear; }

/* ---------- status bar ---------- */
.statusbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 4px 24px 14px;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* ---------- responsive ---------- */
@media (max-width: 1360px) {
  .proofs { order: 3; margin-left: 0; flex: 1 1 100%; }
  .proof { flex: 1; }
  .trust-actions { margin-left: auto; }
}
@media (max-width: 1100px) {
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .pane { height: clamp(420px, 70vh, 900px); }
}
@media (max-width: 720px) {
  .appbar { padding: 12px 16px; }
  .workspace { padding: 12px 16px 8px; }
  .statusbar { padding: 4px 16px 12px; }
  .proofs { display: grid; grid-template-columns: 1fr 1fr; }
  .proof { padding: 8px 10px; }
  .proof + .proof { border-left: 0; }
  .proof:nth-child(even) { border-left: 1px solid var(--accent-line); }
  .proof:nth-child(n+3) { border-top: 1px solid var(--accent-line); }
  .proof .sub { white-space: normal; }
  .trust-actions { order: 4; margin-left: 0; width: 100%; }
  .trust-actions button { flex: 1; }
  .tag { max-width: none; }
  .divider { display: none; }
}
@media (hover: none) {
  .colctl .tools, .gutter .tools { opacity: 1; pointer-events: auto; }
  .colctl .letter, .gutter .num { opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ---------- delight: reassurance, certainty, closure ---------- */
/* Paste reassurance: the network proof answers at the moment of worry. */
.proof { transition: background-color .4s ease-out; }
.proof.pulse { background: color-mix(in srgb, var(--accent-soft) 55%, var(--accent-line)); }
.proof.pulse svg { animation: proof-beat 0.9s cubic-bezier(0.16, 1, 0.3, 1); }
.proof.pulse .sub { color: var(--accent); font-weight: 600; }
.proofs { overflow: hidden; }
@keyframes proof-beat {
  0% { transform: scale(1); }
  30% { transform: scale(1.18); }
  100% { transform: scale(1); }
}

/* Wipe: armed state reads as a deliberate second step. */
button.danger.armed {
  background: var(--danger);
  border-color: var(--danger);
  color: var(--panel);
  font-weight: 600;
  animation: arm-in 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}
button.danger.armed:hover:not(:disabled) { background: var(--danger); filter: brightness(1.06); }
@keyframes arm-in { from { transform: scale(0.97); } to { transform: scale(1); } }
textarea.dissolving { transition: opacity .25s cubic-bezier(0.4, 0, 1, 1), filter .25s; opacity: 0; filter: blur(3px); }

/* Wiped state: calm closure, not celebration. */
.empty.wiped .seal {
  width: 40px;
  height: 40px;
  padding: 8px;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid var(--accent-line);
  border-radius: 12px;
  stroke-width: 1.75;
  animation: seal-in 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}
.empty.wiped .seal path:last-child { stroke-dasharray: 12; stroke-dashoffset: 12; animation: draw 0.4s 0.2s cubic-bezier(0.16, 1, 0.3, 1) forwards; }
.empty.wiped .empty-title, .empty.wiped .empty-body, .empty.wiped button { animation: rise 0.45s cubic-bezier(0.16, 1, 0.3, 1) both; }
.empty.wiped .empty-body { animation-delay: 0.05s; }
.empty.wiped button { animation-delay: 0.1s; }
@keyframes seal-in { from { opacity: 0; transform: scale(0.9); } to { opacity: 1; transform: scale(1); } }
@keyframes draw { to { stroke-dashoffset: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

/* Copy receipt */
button.primary.copied { background: var(--accent-hover); }
button.copied .check path { stroke-dasharray: 22; stroke-dashoffset: 22; animation: draw 0.35s cubic-bezier(0.16, 1, 0.3, 1) forwards; }
button.copied .check { stroke-width: 2.2; }

@media (prefers-reduced-motion: reduce) {
  .proof.pulse svg, button.danger.armed, .empty.wiped *, button.copied .check path { animation: none !important; }
  .empty.wiped .seal path:last-child, button.copied .check path { stroke-dashoffset: 0; }
  textarea.dissolving { transition: none; }
}
