:root {
  color-scheme: light;
  --canvas: #f3f1eb;
  --surface: #ffffff;
  --surface-muted: #f6f5f2;
  --surface-active: #eceae4;
  --line: #e9e7e1;
  --line-strong: #d9d6cf;
  --text: #1c1e1b;
  --text-muted: #76736f;
  --brand: #20241e;
  --olive: #52692f;
  --olive-soft: #f6f7f2;
  --olive-line: #e0e2d0;
  --olive-deep: #43591f;
  --danger: #9b4d57;
  --warn: #9b6a27;
  --ok: #5a8f3e;
  --toast-bg: rgba(28, 30, 27, 0.94);
  --toast-text: #f7f7f3;
  --terminal: #151814;
  --terminal-deep: #10130f;
  --terminal-muted: #aeb6a6;
  --terminal-line: rgba(237, 240, 231, 0.09);
  --app-bar-bg: rgba(248, 247, 243, 0.97);
  --shadow-sm: 0 1px 2px rgba(32, 36, 30, 0.05);
  --shadow: 0 8px 24px rgba(32, 36, 30, 0.06);
  --shadow-lift: 0 16px 40px rgba(32, 36, 30, 0.1);
  --ease-spring: cubic-bezier(0.32, 0.72, 0, 1);
  --ease-out: cubic-bezier(0.22, 0.61, 0.36, 1);
  --radius-card: 14px;
  --radius-control: 12px;
  --font-sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", "SFMono-Regular", ui-monospace, Menlo, monospace;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--canvas);
  color: var(--text);
  font-family: var(--font-sans);
}

body {
  min-height: 100vh;
  min-height: 100dvh;
}

body.sheet-open {
  overflow: hidden;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  border: 0;
  background: none;
  color: inherit;
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
}

a,
summary {
  touch-action: manipulation;
}

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

.icon {
  width: 18px;
  height: 18px;
  display: block;
  flex: 0 0 auto;
}

.shell {
  min-height: 100vh;
  min-height: 100dvh;
  padding-bottom: max(20px, env(safe-area-inset-bottom));
}

.frame {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow);
}

/* ------------------------------------------------------------------ app bar */

.app-bar {
  position: sticky;
  top: 0;
  z-index: 10;
  min-height: calc(58px + env(safe-area-inset-top));
  padding: max(8px, env(safe-area-inset-top)) 12px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px solid var(--line);
  background: var(--app-bar-bg);
  user-select: none;
}

.app-bar-main,
.app-bar-actions {
  display: flex;
  align-items: center;
  min-width: 0;
}

.app-bar-main {
  gap: 9px;
}

.app-bar-copy {
  min-width: 0;
}

.app-context {
  margin-bottom: 1px;
  color: var(--text-muted);
  font-size: 10px;
  line-height: 1.15;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-title {
  margin: 0;
  max-width: 190px;
  font-size: 18px;
  line-height: 1.15;
  font-weight: 750;
  letter-spacing: -0.025em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-mark,
.back-button,
.icon-button {
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 11px;
}

.app-mark {
  border: 1px solid var(--line-strong);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.back-button {
  color: var(--text);
  text-decoration: none;
  transition: background 0.15s var(--ease-out);
}

.back-button:active {
  background: var(--surface-active);
}

.app-bar-actions {
  gap: 4px;
  flex: 0 0 auto;
}

.host-state {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 30px;
  padding: 0 9px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.host-state.is-live {
  color: var(--olive-deep);
  border-color: var(--olive-line);
}

.host-state.is-connecting {
  color: var(--warn);
}

.host-state.is-offline {
  color: var(--danger);
}

.app-bar .icon-button {
  min-height: 40px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  transition:
    color 0.15s var(--ease-out),
    background 0.15s var(--ease-out),
    transform 0.1s var(--ease-out);
}

.app-bar .icon-button:hover {
  color: var(--text);
}

.icon-button:active {
  transform: scale(0.9);
}

/* -------------------------------------------------------------- typography */

.eyebrow,
.meta,
.chip,
.toast,
.empty-note,
.status-copy {
  font-size: 12px;
  line-height: 1.4;
}

.eyebrow,
.meta,
.empty-note,
.status-copy {
  color: var(--text-muted);
}

.eyebrow {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.section-title {
  margin: 0;
  font-size: 15px;
  line-height: 1.2;
  font-weight: 730;
}

/* --------------------------------------------------------------- controls */

.pill,
.ghost-pill,
.sheet-item {
  border-radius: 999px;
}

.pill,
.ghost-pill,
.sheet-item {
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
}

.pill {
  background: var(--brand);
  color: #f5f4f1;
  border-color: var(--brand);
  box-shadow: var(--shadow-sm);
  font-weight: 650;
  transition:
    transform 0.1s var(--ease-out),
    filter 0.15s var(--ease-out);
}

.pill:hover {
  filter: brightness(1.06);
}

.pill:active {
  transform: scale(0.96);
}

.ghost-pill {
  color: var(--text);
  transition:
    transform 0.1s var(--ease-out),
    background 0.15s var(--ease-out);
}

.ghost-pill:active {
  transform: scale(0.96);
  background: var(--surface-active);
}

.ghost-pill.is-active,
.sheet-item.is-active,
.project-row.is-active,
.terminal-card.is-active {
  border-color: var(--olive-line);
  background: var(--olive-soft);
}

.chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 24px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface-muted);
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.4;
}

.chip.olive {
  background: var(--olive-soft);
  border-color: var(--olive-line);
  color: var(--olive-deep);
}

.chip.warn {
  color: var(--warn);
}

.chip.danger {
  color: var(--danger);
}

.chip.ok {
  color: var(--ok);
}

.host-banner {
  display: none;
  gap: 8px;
  align-items: center;
  margin: 10px 12px 0;
  padding: 9px 11px;
  border: 1px solid rgba(155, 77, 87, 0.22);
  color: var(--danger);
  background: rgba(155, 77, 87, 0.08);
  border-radius: 10px;
  font-size: 12px;
}

.host-banner.is-visible {
  display: flex;
}

/* ------------------------------------------------------------------ layout */

.layout {
  display: grid;
  /* minmax(0, …) keeps wide terminal content from blowing out the track. */
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
  min-height: 0;
}

.page-content {
  padding: 12px;
}

.project-board {
  align-content: start;
}

.board-section {
  min-width: 0;
}

.board-heading {
  min-height: 32px;
  margin-bottom: 7px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.board-count {
  min-width: 24px;
  height: 24px;
  padding: 0 7px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: var(--surface-active);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.project-facts {
  min-height: 36px;
  padding: 8px 10px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 5px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.6);
  color: var(--text-muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.project-facts strong {
  color: var(--text);
  font-weight: 750;
}

.fact-primary {
  color: var(--olive-deep);
}

.fact-separator {
  color: var(--line-strong);
}

.project-list,
.terminal-list {
  display: grid;
  gap: 8px;
}

.project-row,
.terminal-card {
  width: 100%;
  text-align: left;
  padding: 12px;
  border-radius: 13px;
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition:
    transform 0.12s var(--ease-out),
    box-shadow 0.15s var(--ease-out),
    border-color 0.15s var(--ease-out);
}

.project-row:hover,
.terminal-card:hover {
  border-color: var(--line-strong);
  box-shadow: var(--shadow);
}

.project-row {
  display: grid;
  gap: 8px;
}

.project-row:active,
.terminal-card:active {
  transform: scale(0.99);
}

.project-name,
.terminal-name {
  font-size: 15px;
  line-height: 1.2;
  font-weight: 720;
}

.project-row-head,
.terminal-row-head {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: space-between;
}

.terminal-row-meta {
  display: flex;
  align-items: center;
  gap: 10px;
}

.project-name-wrap,
.terminal-name-line,
.project-live-line,
.terminal-location {
  display: flex;
  align-items: center;
  min-width: 0;
}

.project-name-wrap {
  gap: 7px;
}

.project-status,
.current-label {
  flex: 0 0 auto;
  padding: 2px 6px;
  border-radius: 999px;
  background: var(--olive-soft);
  color: var(--olive-deep);
  font-size: 9px;
  line-height: 1.35;
  font-weight: 750;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.project-status.paused,
.project-status.archived {
  background: var(--surface-muted);
  color: var(--text-muted);
}

.row-chevron {
  display: inline-flex;
  color: var(--text-muted);
}

.row-chevron .icon {
  width: 16px;
  height: 16px;
}

.project-live-line {
  gap: 6px;
  color: var(--text-muted);
  font-size: 12px;
}

.project-live-line strong {
  min-width: 0;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.project-live-line.is-quiet {
  color: var(--text-muted);
}

.project-output-line {
  padding: 7px 9px;
  display: flex;
  align-items: baseline;
  gap: 7px;
  border-radius: 8px;
  background: var(--terminal);
  color: #dfe4d8;
  font-family: var(--font-mono);
  font-size: 10px;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.project-row-meta,
.terminal-row-meta {
  flex-wrap: wrap;
  color: var(--text-muted);
  font-size: 11px;
}

.project-row-meta {
  display: flex;
  align-items: center;
  gap: 6px 12px;
  font-variant-numeric: tabular-nums;
}

.project-row-meta strong {
  color: var(--text);
}

.terminal-card {
  display: grid;
  gap: 9px;
  overflow: hidden;
}

.terminal-card.is-current {
  border-color: #cfd6bb;
  box-shadow: inset 3px 0 0 var(--olive);
}

.terminal-identity {
  min-width: 0;
}

.terminal-name-line {
  gap: 7px;
}

.terminal-location {
  margin-top: 4px;
  gap: 5px;
  color: var(--text-muted);
  font-size: 10px;
  white-space: nowrap;
  overflow: hidden;
}

.terminal-location span:last-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.scope-label {
  color: var(--olive-deep);
  font-weight: 700;
}

.state-badge {
  min-height: 25px;
  padding: 0 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex: 0 0 auto;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface-muted);
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 740;
}

.state-badge.ok {
  border-color: #cedcbe;
  background: #f3f8ec;
  color: var(--olive-deep);
}

.state-badge.warn {
  border-color: #ead8bc;
  background: #fff8ec;
  color: var(--warn);
}

.state-badge.danger {
  border-color: #e8cbd0;
  background: #fff4f5;
  color: var(--danger);
}

.terminal-preview {
  padding: 8px 10px 9px;
  border-radius: 10px;
  background: var(--terminal);
  color: #e9ede3;
  overflow: hidden;
}

.preview-head {
  margin-bottom: 5px;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--terminal-muted);
  font-size: 9px;
  line-height: 1.2;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-variant-numeric: tabular-nums;
}

.terminal-preview pre {
  margin: 0;
  max-height: 70px;
  overflow: hidden;
  font-family: var(--font-mono);
  font-size: 10.5px;
  line-height: 1.42;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.terminal-row-meta {
  justify-content: space-between;
  gap: 8px;
}

.origin-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.open-label {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  color: var(--olive-deep);
  font-weight: 750;
}

.open-label .icon {
  width: 14px;
  height: 14px;
}

.compact-empty {
  padding: 15px 12px;
  border: 1px dashed var(--line-strong);
  border-radius: 12px;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.5);
  font-size: 12px;
  text-align: center;
}

.context-panel,
.completed-group {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.66);
  overflow: hidden;
}

.context-panel summary,
.completed-group summary {
  min-height: 44px;
  padding: 0 11px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  cursor: pointer;
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  list-style: none;
}

.context-panel summary::-webkit-details-marker,
.completed-group summary::-webkit-details-marker {
  display: none;
}

.context-panel summary::after,
.completed-group summary::after {
  content: "+";
  margin-left: auto;
  color: var(--text-muted);
  font-size: 18px;
  font-weight: 400;
}

.context-panel[open] summary::after,
.completed-group[open] summary::after {
  content: "−";
}

.summary-hint {
  margin-left: auto;
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 500;
}

.context-body {
  padding: 0 11px 11px;
}

.context-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
}

.context-stat {
  padding: 8px;
  display: grid;
  gap: 2px;
  border-radius: 9px;
  background: var(--surface-muted);
  font-variant-numeric: tabular-nums;
}

.context-stat strong {
  font-size: 16px;
  line-height: 1.1;
}

.context-stat span,
.context-attributes,
.project-description {
  color: var(--text-muted);
  font-size: 10px;
  line-height: 1.4;
}

.project-description {
  margin: 10px 0 0;
}

.context-attributes {
  margin-top: 9px;
}

.completed-group .terminal-list {
  padding: 0 8px 8px;
}

.terminal-list.compact .terminal-preview pre {
  max-height: 31px;
}

.terminal-list.compact .terminal-card {
  background: rgba(255, 255, 255, 0.72);
}

/* -------------------------------------------------------------------- dots */

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex: 0 0 auto;
}

.dot.ready {
  background: var(--olive);
}

.dot.working {
  background: #be8a33;
  animation: dot-pulse 1.8s var(--ease-out) infinite;
}

.dot.offline,
.dot.failed,
.dot.interrupted {
  background: var(--danger);
}

.dot.done {
  background: var(--ok);
}

.dot.paused,
.dot.tracking {
  background: var(--text-muted);
}

@keyframes dot-pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(190, 138, 51, 0.4);
  }
  70% {
    box-shadow: 0 0 0 6px rgba(190, 138, 51, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(190, 138, 51, 0);
  }
}

/* --------------------------------------------------------- terminal page */

.terminal-page {
  padding-top: 10px;
}

.terminal-panel {
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  /* Fill the viewport below the sticky app bar so the input dock stays put;
     --kb lifts it above the virtual keyboard. */
  height: calc(100vh - 58px - env(safe-area-inset-top, 0px) - 34px - var(--kb, 0px));
  height: calc(100dvh - 58px - env(safe-area-inset-top, 0px) - 34px - var(--kb, 0px));
}

.terminal-context {
  min-width: 0;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 10px;
}

.context-item {
  color: var(--text-muted);
  font-size: 10px;
  line-height: 1.35;
}

.context-time {
  margin-left: auto;
  font-variant-numeric: tabular-nums;
}

.mode-row {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: space-between;
}

.mode-toggle.segmented {
  position: relative;
  display: flex;
  padding: 3px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface-active);
}

.seg-thumb {
  position: absolute;
  top: 3px;
  left: 0;
  height: calc(100% - 6px);
  border-radius: 9px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  transition:
    transform 0.22s var(--ease-spring),
    width 0.22s var(--ease-spring);
  pointer-events: none;
}

.mode-toggle.segmented .mode-button {
  position: relative;
  z-index: 1;
  min-height: 34px;
  padding: 0 15px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 680;
  transition: color 0.18s var(--ease-out);
}

.mode-toggle.segmented .mode-button.is-active {
  color: var(--text);
}

.mode-side {
  display: flex;
  align-items: center;
  gap: 6px;
}

.mode-side .icon-button {
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text-muted);
  transition:
    color 0.15s var(--ease-out),
    border-color 0.15s var(--ease-out),
    transform 0.1s var(--ease-out);
}

.mode-side .icon-button:hover {
  color: var(--text);
}

.mode-side .icon-button.is-active {
  border-color: var(--olive-line);
  background: var(--olive-soft);
  color: var(--olive-deep);
}

.mode-side .icon-button .icon {
  width: 16px;
  height: 16px;
}

.viewport {
  position: relative;
  flex: 1 1 auto;
  min-height: 200px;
  display: flex;
  flex-direction: column;
  border-radius: 16px;
  border: 1px solid #262a24;
  background: var(--terminal-deep);
  box-shadow:
    inset 0 1px 0 rgba(237, 240, 231, 0.04),
    var(--shadow);
  overflow: hidden;
}

.viewport-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 12px;
  border-bottom: 1px solid var(--terminal-line);
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--terminal-muted);
  user-select: none;
}

.viewport-path {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.viewport-time {
  flex: 0 0 auto;
  font-variant-numeric: tabular-nums;
}

.viewport-body {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
}

.tail-pane,
.raw-pane,
.flow-pane {
  height: 100%;
}

.tail-pane {
  overflow: auto;
  overscroll-behavior: contain;
  padding: 14px 16px 16px;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.55;
  color: #edf0e7;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.tail-pre {
  margin: 0;
}

.raw-pane {
  padding: 10px 8px 8px;
  overflow: hidden;
}

.raw-pane.is-unavailable {
  display: grid;
  place-items: center;
  color: var(--terminal-muted);
  font-size: 12px;
}

.xterm,
.xterm-viewport,
.xterm-screen {
  border-radius: 12px;
}

.xterm-viewport {
  overscroll-behavior: contain;
}

.jump-live {
  position: absolute;
  right: 12px;
  bottom: 12px;
  z-index: 2;
  padding: 10px 12px;
  border-radius: 999px;
  background: rgba(246, 247, 242, 0.96);
  color: var(--olive-deep);
  border: 1px solid var(--olive-line);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.25);
  font-size: 12px;
  font-weight: 650;
  display: none;
}

.jump-live.is-visible {
  display: inline-flex;
}

/* --------------------------------------------------------------- flow pane */

.flow-pane {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 6px 10px 14px;
}

.flow-hero {
  position: sticky;
  top: -6px;
  z-index: 1;
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 4px 8px;
  padding: 10px 4px 12px;
  background: linear-gradient(180deg, var(--terminal-deep) 78%, transparent);
  font-size: 14px;
}

.flow-hero .dot {
  align-self: center;
}

.flow-hero-status {
  color: #f2f4ec;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.flow-hero-elapsed {
  color: var(--terminal-muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.flow-hero-reason {
  flex-basis: 100%;
  color: var(--terminal-muted);
  font-size: 11px;
  line-height: 1.4;
}

.flow-list {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.flow-block {
  min-width: 0;
  max-width: 100%;
}

.flow-block summary {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 7px 8px;
  border-radius: 10px;
  cursor: pointer;
  list-style: none;
  min-width: 0;
  transition: background 0.15s var(--ease-out);
}

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

.flow-block summary::before {
  content: "›";
  flex: 0 0 10px;
  color: var(--terminal-muted);
  font-size: 12px;
  transition: transform 0.18s var(--ease-spring);
}

.flow-block[open] > summary::before {
  transform: rotate(90deg);
}

.flow-block summary:hover {
  background: rgba(237, 240, 231, 0.05);
}

.flow-block-title {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: #cfd5c5;
}

.flow-block.is-latest > summary .flow-block-title {
  color: #f2f4ec;
  font-weight: 650;
}

.flow-block-meta {
  flex: 0 0 auto;
  color: var(--terminal-muted);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}

.flow-block.is-latest > summary .flow-block-meta {
  color: #9ec26e;
  font-weight: 700;
}

.flow-block.is-flat {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 7px 8px 7px 26px;
  min-width: 0;
}

.flow-block.is-flat.is-latest .flow-block-title {
  color: #f2f4ec;
  font-weight: 650;
}

.flow-block.is-flat.is-latest .flow-block-meta {
  color: #9ec26e;
  font-weight: 700;
}

.flow-block-body {
  margin: 0 8px 8px 20px;
  padding: 8px 10px;
  border-left: 2px solid var(--terminal-line);
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.5;
  color: #c2c8b6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  overflow-x: hidden;
}

.flow-empty {
  padding: 14px 8px;
  color: var(--terminal-muted);
  font-size: 12px;
}

/* --------------------------------------------------------------- skeletons */

.skeleton-card {
  height: 96px;
  border-radius: 13px;
  border: 1px solid var(--line);
  background: linear-gradient(
    100deg,
    var(--surface) 40%,
    var(--surface-muted) 50%,
    var(--surface) 60%
  );
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.4s linear infinite;
}

.terminal-skeleton {
  height: 100%;
  min-height: 200px;
  padding: 16px;
  display: grid;
  gap: 10px;
  align-content: start;
}

.skeleton-line {
  height: 12px;
  border-radius: 6px;
  background: rgba(237, 240, 231, 0.12);
  animation: skeleton-pulse 1.6s ease-in-out infinite;
}

.skeleton-line.short {
  width: 42%;
}

@keyframes skeleton-shimmer {
  to {
    background-position: -200% 0;
  }
}

@keyframes skeleton-pulse {
  50% {
    opacity: 0.45;
  }
}

/* -------------------------------------------------------------- empty pane */

.empty-pane {
  display: grid;
  place-items: center;
  padding: 28px 18px;
  text-align: center;
  min-height: 280px;
  border: 1px dashed var(--line-strong);
  border-radius: 16px;
  background: rgba(246, 245, 242, 0.8);
}

.empty-pane.is-inline {
  height: 100%;
  min-height: 200px;
  border-color: rgba(237, 240, 231, 0.18);
  background: transparent;
  color: #edf0e7;
}

.empty-pane.is-inline .empty-note {
  color: var(--terminal-muted);
}

.empty-title {
  margin: 0 0 8px;
  font-size: 17px;
}

/* ------------------------------------------------------------- input panel */

.input-panel {
  flex: 0 0 auto;
  display: grid;
  gap: 8px;
}

.keybar {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 2px;
  scrollbar-width: none;
  overscroll-behavior-x: contain;
}

.keybar::-webkit-scrollbar {
  display: none;
}

.key-button {
  flex: 0 0 auto;
  min-width: 44px;
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1;
  transition:
    transform 0.1s var(--ease-out),
    background 0.15s var(--ease-out),
    border-color 0.15s var(--ease-out);
}

.key-button:active {
  transform: scale(0.94);
  background: var(--surface-active);
}

.key-button.is-latched {
  border-color: var(--olive-line);
  background: var(--olive-soft);
  color: var(--olive-deep);
  box-shadow: inset 0 0 0 1px var(--olive-line);
}

.composer-row {
  position: relative;
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.composer-row::before {
  content: "❯";
  position: absolute;
  left: 12px;
  top: 11px;
  color: var(--olive);
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 700;
  pointer-events: none;
}

.composer-row .input-field {
  flex: 1 1 auto;
  min-width: 0;
  padding-left: 30px;
}

.composer-actions {
  display: flex;
  gap: 6px;
  flex: 0 0 auto;
}

.input-field {
  width: 100%;
  padding: 10px 12px;
  resize: none;
  border-radius: 12px;
  border: 1px solid var(--line-strong);
  background: var(--surface-muted);
  color: var(--text);
  font-size: 16px; /* >= 16px keeps iOS from zooming on focus */
  line-height: 1.4;
  transition:
    border-color 0.15s var(--ease-out),
    background 0.15s var(--ease-out);
}

.input-field:focus {
  outline: none;
  border-color: var(--olive);
  background: var(--surface);
}

/* ------------------------------------------------------------------- sheet */

.sheet {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 12;
  visibility: hidden;
  transition: visibility 0s 0.3s;
}

.sheet.is-open {
  visibility: visible;
  transition-delay: 0s;
}

.sheet-backdrop {
  position: absolute;
  inset: -100vh 0 0 0;
  background: rgba(28, 30, 27, 0.45);
  opacity: 0;
  transition: opacity 0.24s var(--ease-out);
}

.sheet.is-open .sheet-backdrop {
  opacity: 1;
}

.sheet-panel {
  position: relative;
  margin-top: 20vh;
  max-height: 80vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  border-radius: 22px 22px 0 0;
  border: 1px solid var(--line);
  background: var(--canvas);
  padding:
    6px 16px
    max(22px, env(safe-area-inset-bottom))
    16px;
  box-shadow: 0 -12px 30px rgba(32, 36, 30, 0.16);
  opacity: 0;
  transform: translateY(32px);
  transition:
    transform 0.28s var(--ease-spring),
    opacity 0.24s var(--ease-out);
}

.sheet-panel.is-dragging {
  transition: none;
}

.sheet.is-open .sheet-panel {
  opacity: 1;
  transform: none;
}

.sheet-grab {
  margin: 0 -16px 8px;
  padding: 8px 0 6px;
  display: grid;
  place-items: center;
  cursor: grab;
  touch-action: none;
}

.sheet-handle {
  width: 36px;
  height: 4px;
  border-radius: 999px;
  background: var(--line-strong);
}

.sheet-header {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: space-between;
  margin-bottom: 12px;
}

.sheet-list {
  display: grid;
  gap: 10px;
}

.sheet-item {
  width: 100%;
  min-height: 60px;
  padding: 12px 14px;
  display: grid;
  gap: 8px;
  text-align: left;
  border-radius: 18px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  transition:
    transform 0.12s var(--ease-out),
    border-color 0.15s var(--ease-out);
}

.sheet-item:active {
  transform: scale(0.99);
}

.sheet-item-title {
  font-size: 15px;
  font-weight: 650;
}

/* ------------------------------------------------------------------ toasts */

.toasts {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 18;
  display: grid;
  gap: 10px;
  pointer-events: none;
}

.toast {
  padding: 12px 14px;
  border-radius: 14px;
  color: var(--toast-text);
  background: var(--toast-bg);
  box-shadow: 0 10px 24px rgba(32, 36, 30, 0.2);
  font-size: 12px;
  line-height: 1.4;
  opacity: 0;
  transform: translateY(6px) scale(0.98);
  transition:
    opacity 0.18s var(--ease-out),
    transform 0.22s var(--ease-spring);
}

.toast.is-visible {
  opacity: 1;
  transform: none;
}

/* -------------------------------------------------------------- link dead */

.link-dead {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.link-dead-card {
  max-width: 340px;
  display: grid;
  gap: 10px;
  justify-items: center;
  text-align: center;
}

.link-dead-mark {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  font-size: 14px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.link-dead-title {
  margin: 6px 0 0;
  font-size: 19px;
  line-height: 1.25;
  letter-spacing: -0.02em;
}

.link-dead-note {
  margin: 0;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.5;
}

/* ---------------------------------------------------------------- utilities */

.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;
}

@media (min-width: 880px) {
  .shell {
    padding-left: max(24px, env(safe-area-inset-left));
    padding-right: max(24px, env(safe-area-inset-right));
  }

  .layout {
    grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
    align-items: start;
  }

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

/* ------------------------------------------------------------ dark scheme */

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --canvas: #14160f;
    --surface: #1d2017;
    --surface-muted: #23261c;
    --surface-active: #2b2f22;
    --line: #2e3226;
    --line-strong: #3d4230;
    --text: #e9ebe1;
    --text-muted: #9aa091;
    --brand: #e9ebe1;
    --olive: #7a9b4a;
    --olive-soft: rgba(122, 155, 74, 0.14);
    --olive-line: #41502c;
    --olive-deep: #aec77f;
    --danger: #c47d88;
    --warn: #cf9a4e;
    --ok: #7fb35e;
    --toast-bg: rgba(233, 235, 225, 0.96);
    --toast-text: #1c1e1b;
    --terminal: #12150f;
    --terminal-deep: #0d100b;
    --terminal-muted: #828a7b;
    --terminal-line: rgba(233, 235, 225, 0.1);
    --app-bar-bg: rgba(20, 22, 15, 0.96);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow: 0 8px 24px rgba(0, 0, 0, 0.32);
    --shadow-lift: 0 16px 40px rgba(0, 0, 0, 0.4);
  }

  .pill {
    color: #20241e;
  }

  .project-facts,
  .context-panel,
  .completed-group,
  .compact-empty,
  .empty-pane,
  .terminal-list.compact .terminal-card {
    background: rgba(255, 255, 255, 0.04);
  }

  .state-badge.ok {
    border-color: #41502c;
    background: rgba(122, 155, 74, 0.16);
    color: var(--olive-deep);
  }

  .state-badge.warn {
    border-color: #4d3f22;
    background: rgba(207, 154, 78, 0.14);
    color: var(--warn);
  }

  .state-badge.danger {
    border-color: #57313a;
    background: rgba(196, 125, 136, 0.14);
    color: var(--danger);
  }

  .terminal-card.is-current {
    border-color: #41502c;
  }

  .jump-live {
    background: rgba(35, 38, 28, 0.96);
    color: var(--olive-deep);
  }

  .empty-pane.is-inline {
    border-color: var(--terminal-line);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
