:root {
  --desk: #0c0c0d;
  --window: #1e1e1e;
  --chrome: #323234;
  --chrome-dim: #262628;
  --sheet: #262628;
  --inset: #161617;
  --hover: rgba(255, 255, 255, 0.045);
  --line: rgba(255, 255, 255, 0.1);
  --line-strong: rgba(255, 255, 255, 0.22);
  --text: #e4e4e6;
  --text-soft: #b4b4b9;
  --muted: #8e8e93;
  --faint: #5c5c61;
  --accent: #32d74b;
  --busy: #ffd60a;
  --danger: #ff453a;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", system-ui, sans-serif;
  --mono: "SF Mono", ui-monospace, Menlo, Monaco, "Cascadia Mono", Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { background: var(--desk); }

body {
  margin: 0;
  height: 100vh;
  height: 100dvh;
  padding: 32px 20px;
  display: flex;
  justify-content: center;
  color: var(--text);
  font: 13px/1.55 var(--mono);
  -webkit-font-smoothing: antialiased;
  background: var(--desk);
}

/* the terminal window */
.window {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 920px;
  min-height: 0;
  overflow: hidden;
  background: var(--window);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.6), 0 24px 60px rgba(0, 0, 0, 0.55);
}

/* title bar */
.titlebar {
  flex: none;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  height: 38px;
  padding: 0 14px;
  background: var(--chrome);
  border-bottom: 1px solid rgba(0, 0, 0, 0.5);
}

.lights { display: flex; gap: 8px; }

.lights i {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #ff5f57;
}

.lights i:nth-child(2) { background: #febc2e; }
.lights i:nth-child(3) { background: #28c840; }

.title {
  font: 600 13px var(--sans);
  color: var(--text-soft);
  white-space: nowrap;
}

/* the scrolling terminal screen */
.screen {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 14px 18px 18px;
  scrollbar-width: thin;
  scrollbar-color: var(--faint) transparent;
}

/* section headings read as the command that produced the output below */
.section {
  margin: 0 0 4px;
  font: inherit;
  font-weight: 400;
  color: var(--text);
}

.section::before {
  content: "$ ";
  color: var(--muted);
}

.note { color: var(--muted); }
.note::before { content: "  # "; white-space: pre; }
.note:empty { display: none; }

.list {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  margin-bottom: 22px;
}

.who {
  grid-area: who;
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 22ch) minmax(0, 1fr);
  column-gap: 2ch;
  align-items: baseline;
}

.project,
.path {
  margin: 0;
  font: inherit;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.project { font-weight: 600; }
.path { color: var(--muted); }

.meta {
  grid-area: meta;
  display: flex;
  align-items: baseline;
  gap: 2ch;
  color: var(--muted);
  text-transform: lowercase;
  white-space: nowrap;
}

/* actions are bracketed words, like [copy] */
.copy {
  flex: none;
  padding: 0;
  font: inherit;
  text-transform: lowercase;
  color: var(--accent);
  background: none;
  border: 0;
  border-radius: 2px;
  cursor: pointer;
}

.copy::before { content: "["; }
.copy::after { content: "]"; }
.copy:hover { color: var(--text); }
.copy:focus-visible { outline: 1px solid var(--accent); outline-offset: 2px; }
.copy.done { color: var(--window); background: var(--accent); }

/* empty and status messages read as shell comments */
.empty {
  margin-bottom: 22px;
  color: var(--muted);
}

.empty::before { content: "# "; }
.empty code { font: inherit; color: var(--text); }

/* idle prompt with a block cursor at the end of the screen */
.prompt-line { margin: 0; color: var(--muted); }
.prompt-line::before { content: "$ "; }

.cursor {
  display: inline-block;
  width: 1ch;
  height: 1.2em;
  vertical-align: text-bottom;
  background: var(--text-soft);
  animation: blink 1.1s steps(1) infinite;
}

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

@media (prefers-reduced-motion: reduce) {
  .cursor { animation: none; }
}

@media (max-width: 560px) {
  body { padding: 0; }
  .window { max-width: none; border: 0; border-radius: 0; box-shadow: none; }
  .screen { padding: 12px 14px 16px; }
}

/* tabs: a Terminal.app tab bar, equal-width tabs under the title bar */
.tabs {
  flex: none;
  display: flex;
  background: var(--chrome-dim);
  border-bottom: 1px solid rgba(0, 0, 0, 0.5);
}

.tabs a {
  flex: 1;
  min-width: 0;
  padding: 6px 12px;
  font: 12px var(--sans);
  text-align: center;
  text-decoration: none;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tabs a + a { border-left: 1px solid rgba(0, 0, 0, 0.5); }
.tabs a:hover { color: var(--text-soft); }
.tabs a[aria-current="page"] { color: var(--text); background: var(--chrome); }

/* sub-navigation reads like `git branch`: the current entry is starred */
.subtabs {
  display: flex;
  gap: 2ch;
  margin-bottom: 14px;
}

.subtabs a {
  text-decoration: none;
  text-transform: lowercase;
  color: var(--muted);
  white-space: pre;
  border-radius: 2px;
}

.subtabs a::before { content: "  "; }
.subtabs a:hover { color: var(--text); }
.subtabs a[aria-current="page"] { color: var(--accent); }
.subtabs a[aria-current="page"]::before { content: "* "; }

.tabs a:focus-visible { outline: 1px solid var(--accent); outline-offset: -3px; }
.subtabs a:focus-visible { outline: 1px solid var(--accent); outline-offset: 2px; }


/* category accent colors (macOS system palette): data-color sets --cat on any element */
[data-color="teal"] { --cat: #63e6e2; }
[data-color="amber"] { --cat: #ff9f0a; }
[data-color="violet"] { --cat: #bf5af2; }
[data-color="rose"] { --cat: #ff6482; }
[data-color="sky"] { --cat: #64d2ff; }
[data-color="lime"] { --cat: #a8e05f; }

/* buttons are bracketed words, like [edit] */
.btn {
  padding: 0;
  font: inherit;
  text-transform: lowercase;
  color: var(--muted);
  background: none;
  border: 0;
  border-radius: 2px;
  cursor: pointer;
}

.btn::before { content: "["; }
.btn::after { content: "]"; }
.btn:hover { color: var(--text); }
.btn:focus-visible { outline: 1px solid var(--accent); outline-offset: 2px; }
.btn:disabled { opacity: 0.5; cursor: default; }

.btn.primary { color: var(--accent); }
.btn.primary:hover { color: var(--text); }

.btn.danger { color: var(--danger); }
.btn.danger:hover { color: var(--text); }

.btn.quiet-danger:hover { color: var(--danger); }

.empty a { color: var(--accent); }
.empty .btn { margin-left: 1ch; }

/* toolbar */
.toolbar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px 3ch;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.toolbar-note {
  margin: 0;
  color: var(--muted);
}

.toolbar-note::before { content: "# "; }

/* tiles (category and prompt rows) */
.tile {
  margin: 0 -8px;
  padding: 5px 8px;
  border-radius: 4px;
}

.tile:hover { background: var(--hover); }

.actions {
  display: flex;
  align-items: baseline;
  gap: 1ch;
}

.swatch-dot {
  grid-area: dot;
  justify-self: start;
  align-self: start;
  margin-top: 6px;
  width: 8px;
  height: 8px;
  background: var(--cat, var(--faint));
}

.tile.category {
  display: grid;
  grid-template-columns: 2ch minmax(0, 1fr) auto;
  grid-template-areas: "dot who actions";
  column-gap: 1ch;
  align-items: baseline;
}

.tile.category .actions { grid-area: actions; }

/* modal: a small sheet over the terminal */
.modal {
  width: min(540px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  padding: 0;
  overflow: auto;
  font: inherit;
  color: var(--text);
  background: var(--sheet);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.6), 0 24px 60px rgba(0, 0, 0, 0.6);
}

.modal::backdrop { background: rgba(0, 0, 0, 0.5); }

.modal-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px 20px;
}

.modal-title {
  margin: 0;
  font: inherit;
  font-weight: 600;
  text-transform: lowercase;
}

.modal-title::before {
  content: "$ ";
  font-weight: 400;
  color: var(--muted);
}

.modal-text {
  margin: 0;
  color: var(--text-soft);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 2ch;
}

/* form fields */
.field { display: grid; gap: 4px; }

.label {
  text-transform: lowercase;
  color: var(--muted);
}

.label::after { content: ":"; }

.input {
  width: 100%;
  padding: 7px 10px;
  font: inherit;
  color: var(--text);
  background: var(--inset);
  border: 1px solid var(--line);
  border-radius: 4px;
}

.input:focus {
  outline: none;
  border-color: var(--accent);
}

.input[aria-invalid="true"] { border-color: var(--danger); }

textarea.input {
  min-height: 180px;
  resize: vertical;
}

.field-error {
  margin: 0;
  color: var(--danger);
}

.form-error {
  margin: 0;
  color: var(--danger);
}

.field-error::before,
.form-error::before { content: "error: "; }

/* color swatches: square blocks, like an ANSI palette */
.swatches { display: flex; flex-wrap: wrap; gap: 10px; padding: 3px; }

.swatch { position: relative; cursor: pointer; }

.swatch input {
  position: absolute;
  inset: 0;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.swatch span {
  display: block;
  width: 20px;
  height: 20px;
  border-radius: 2px;
  background: var(--cat);
}

.swatch input:checked + span { box-shadow: 0 0 0 2px var(--sheet), 0 0 0 3px var(--text); }
.swatch input:focus-visible + span { outline: 1px solid var(--accent); outline-offset: 5px; }

@media (max-width: 560px) {
  .tile.category {
    grid-template-columns: 2ch minmax(0, 1fr);
    grid-template-areas:
      "dot who"
      ".   actions";
  }
  .modal-body { padding: 16px; }
}


/* category filter: plain words, the active one takes its category color */
.filters { display: flex; flex-wrap: wrap; gap: 2px 3ch; }

.filter {
  padding: 0;
  font: inherit;
  text-transform: lowercase;
  color: var(--muted);
  background: none;
  border: 0;
  border-radius: 2px;
  cursor: pointer;
}

.filter:hover { color: var(--text); }
.filter:focus-visible { outline: 1px solid var(--accent); outline-offset: 2px; }

.filter[aria-pressed="true"] {
  color: var(--cat, var(--accent));
  text-decoration: underline;
  text-underline-offset: 4px;
}

/* prompt rows: a colored bar in the margin marks the category */
.tile.prompt {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-left: 0;
  padding-left: calc(3ch - 2px);
  border-left: 2px solid var(--cat, var(--faint));
  border-radius: 0 4px 4px 0;
}

.tile.prompt + .tile.prompt { margin-top: 12px; }

.prompt-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0 3ch;
}

.prompt-head .project { flex: 1 1 200px; min-width: 0; }

.prompt-head .meta {
  flex-wrap: wrap;
  justify-content: flex-end;
  white-space: normal;
}

.chip.cat { color: var(--cat, var(--muted)); }
.chip.model { text-transform: none; }

.prompt-body {
  margin: 0;
  font: inherit;
  color: var(--text-soft);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  overflow: auto;
  max-height: 60vh;
}

.prompt-body.clamped {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  overflow: hidden;
}

.prompt-foot {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0 3ch;
}

.link-btn {
  padding: 0;
  font: inherit;
  text-transform: lowercase;
  color: var(--muted);
  background: none;
  border: 0;
  border-radius: 2px;
  cursor: pointer;
}

.link-btn::before { content: "["; }
.link-btn::after { content: "]"; }
.link-btn:hover { color: var(--text); }
.link-btn:focus-visible { outline: 1px solid var(--accent); outline-offset: 2px; }

@media (max-width: 560px) {
  .prompt-foot .actions { width: 100%; justify-content: flex-end; }
}

/* ---- A.I.D.A. additions (mobile first, PWA) ---- */
/* the app root is layout-transparent so .window is body's flex item, as in the mockup */
#app { display: contents; }
html, body { overscroll-behavior: none; }
body {
  padding-top: max(32px, env(safe-area-inset-top));
  padding-bottom: max(32px, env(safe-area-inset-bottom));
}
@media (max-width: 560px) {
  body { padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom); }
  .lights { display: none; }
  .titlebar { grid-template-columns: 1fr auto; }
}
.user { justify-self: end; display: flex; align-items: baseline; gap: 1.5ch; font-size: 12px; color: var(--muted); white-space: nowrap; }
.user-name { max-width: 14ch; overflow: hidden; text-overflow: ellipsis; }
.search { flex: 1 1 14ch; min-width: 0; }
.login { max-width: 360px; }
.login .modal-actions { justify-content: flex-start; }
/* user data shown exactly as typed inside lowercased chrome (e.g. confirm titles) */
.verbatim { text-transform: none; }
.loading { color: var(--muted); }
.loading::before { content: "# "; }
.tile.category .path { color: var(--muted); }
/* touch: bigger hit areas, 16px inputs so mobile browsers do not zoom on focus */
@media (pointer: coarse) {
  .btn, .copy, .link-btn, .filter { padding-block: 10px; }
  .tabs a { padding-block: 14px; }
  .actions { gap: 2ch; }
  .input { font-size: 16px; }
}
