/* A chat's page: the instances' own drawings in a view you pan and zoom, the
   chat beside it, and every chat there is to pick on the left. The tokens are
   the chat widget's, so a drawing that uses them belongs; what a drawing looks
   like is the drawing's business. */
:root {
  color-scheme: light dark;
  --bg: #faf9f7; --panel: #fff; --ink: #1b1a18; --muted: #6b6862; --line: #e4e1db;
  --accent: #5c3a1e; --accent-ink: #fff; --danger: #a8342a; --soft: #f3f1ec;
  --ok: #2f9e5b; --warn: #d99a1e; --bad: #d64545;
  --glass: rgba(250, 249, 247, .66); --glass2: rgba(255, 255, 255, .72); --glass-line: rgba(0, 0, 0, .12);
  --shadow: 0 10px 30px rgba(20, 18, 12, .18), 0 1px 3px rgba(20, 18, 12, .12); --blur: blur(18px) saturate(1.2);
  /* the same, under the names older drawings know them by */
  --dim: var(--muted); --card: var(--panel);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151513; --panel: #1e1e1c; --ink: #eceae5; --muted: #9a968e; --line: #33322e;
    --accent: #b08256; --accent-ink: #241a10; --danger: #e0796d; --soft: #26261f;
    --glass: rgba(24, 24, 22, .62); --glass2: rgba(255, 255, 255, .08); --glass-line: rgba(255, 255, 255, .12);
    --shadow: 0 10px 30px rgba(0, 0, 0, .5), 0 1px 3px rgba(0, 0, 0, .4);
  }
}
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; display: flex; overflow: hidden; background: var(--bg); color: var(--ink);
  font: 14px/1.4 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
#main { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }
/* the band over the top of the view: glass, as the chat is, with the world
   passing under it — the camera counts only what is below it as the view's middle */
#dock { position: absolute; left: 0; right: 0; top: 0; z-index: 5; display: flex; flex-direction: column;
        padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) 0 env(safe-area-inset-left, 0px);
        background: var(--glass); border-bottom: 1px solid var(--glass-line);
        -webkit-backdrop-filter: var(--blur); backdrop-filter: var(--blur); }
#dock:not(:has(> :not([hidden]))) { display: none; }
#stage { flex: 1; min-height: 0; position: relative; overflow: clip; cursor: grab; user-select: none; }
#stage[hidden], #overview[hidden], forji-chat[hidden], #chats[hidden] { display: none !important; }
#world { position: absolute; left: 0; top: 0; transform-origin: 0 0; display: flex; gap: 40px; align-items: flex-start; padding: 8px; }
#world[hidden] { display: none; }
#stage > .fill { position: absolute; inset: 0; cursor: auto; user-select: auto; }
.instance { display: flex; flex-direction: column; gap: 8px; flex: none; }
.instance > .label { font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.instance > .label .is { font-weight: 400; text-transform: none; letter-spacing: 0; margin-left: 6px; }
.instance > .body { position: relative; }
.plain { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; min-width: 200px; max-width: 360px; font-size: 13px; cursor: auto; user-select: text; }
.plain .row { display: flex; gap: 10px; justify-content: space-between; padding: 2px 0; }
.plain .key { color: var(--muted); }
.plain .val { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; overflow-wrap: anywhere; text-align: right; }
.web-error { color: var(--danger); font-size: 13px; white-space: pre-wrap; max-width: 480px; }
.overlay { position: absolute; z-index: 5; cursor: auto; user-select: none; }
/* Fit: all of the world in view again — a glass button at the foot of the view,
   above whatever stands over that foot (the chat, maximized: `--cover-bottom`) */
#stage > .fit { position: absolute; left: calc(12px + env(safe-area-inset-left, 0px)); bottom: calc(12px + max(var(--cover-bottom, 0px), env(safe-area-inset-bottom, 0px))); z-index: 5; display: grid; place-items: center; width: 34px; height: 34px; padding: 0;
                border: 1px solid var(--glass-line); border-radius: 10px; color: var(--ink); cursor: pointer; box-shadow: var(--shadow);
                background: var(--glass); -webkit-backdrop-filter: var(--blur); backdrop-filter: var(--blur); }
#stage > .fit:hover { background: color-mix(in srgb, var(--ink) 8%, var(--panel)); }
#stage > .fit[hidden] { display: none; }
#stage > .fit svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* The chats on the left, the way a messaging app keeps its conversations: one
   group per forest, folded or open, the chat being looked at marked. */
#chats { flex: none; position: relative; width: var(--list-w, 248px); display: flex; flex-direction: column; min-height: 0; background: var(--soft);
         border-right: 1px solid var(--line); font-size: 13px; user-select: none; }
/* its right edge is taken and dragged to make it wider or narrower; a double press gives the width back */
#chats .edge { position: absolute; top: 0; bottom: 0; right: -4px; width: 8px; z-index: 5; cursor: col-resize; touch-action: none; }
#chats .edge::after { content: ""; position: absolute; top: 0; bottom: 0; left: 3px; width: 2px; background: transparent; transition: background .15s ease; }
#chats .edge:hover::after, #chats .edge.held::after { background: var(--accent); }
body.sizing, body.sizing * { cursor: col-resize !important; user-select: none !important; }
#chats .head { flex: none; display: flex; align-items: center; gap: 8px; padding: 12px 12px 8px 16px; }
#chats .head .brand { flex: 1; font-weight: 700; letter-spacing: .01em; }
#chats .list { flex: 1; min-height: 0; overflow-y: auto; padding: 0 8px 16px; scrollbar-width: thin; }
#chats .forest { margin-top: 6px; }
#chats .fhead { display: flex; align-items: center; gap: 4px; padding: 4px 6px; border-radius: 7px; color: var(--muted);
                font-size: 11.5px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; }
#chats .fhead .fold { flex: none; display: flex; width: 20px; height: 20px; align-items: center; justify-content: center; padding: 0;
                      border: 0; border-radius: 5px; background: none; color: inherit; cursor: pointer; }
#chats .fhead .fold svg { width: 14px; height: 14px; transition: transform .15s ease; }
#chats .forest.folded .fhead .fold svg { transform: rotate(-90deg); }
#chats .fhead .fname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: inherit; text-decoration: none; cursor: pointer; }
#chats .fhead .fname:hover { color: var(--ink); }
#chats .fhead.here { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--ink); }
#chats .fhead .n { font-weight: 400; letter-spacing: 0; }
/* how a forest is shared, to its owner: a lock, a link, a globe */
#chats .fhead .share { flex: none; display: flex; width: 22px; height: 22px; align-items: center; justify-content: center; padding: 0;
                       border: 0; border-radius: 6px; background: none; color: var(--muted); cursor: pointer; opacity: .55; }
#chats .fhead .share:hover { opacity: 1; background: color-mix(in srgb, var(--ink) 8%, transparent); }
#chats .fhead .share.on, #chats .fhead .share.anyone { opacity: 1; color: var(--accent); }
/* …and in the corner of a chat's page on the machine, where there is no list */
#share-here { position: absolute; left: 10px; top: 10px; z-index: 6; display: flex; width: 28px; height: 28px; align-items: center; justify-content: center;
              padding: 0; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--muted); box-shadow: var(--shadow); cursor: pointer; }
#share-here:hover { color: var(--ink); }
#share-here.on, #share-here.anyone { color: var(--accent); }
body.with-share #dock { padding-left: calc(46px + env(safe-area-inset-left, 0px)); }
#chats .fhead .share svg, #share-here svg, .share-menu svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.share-menu { position: fixed; z-index: 1100; width: 280px; padding: 6px; border-radius: 10px; font-size: 13px; background: var(--panel);
              color: var(--ink); border: 1px solid var(--line); box-shadow: var(--shadow); }
.share-menu .title { padding: 6px 8px 8px; font-weight: 600; }
.share-menu .way { display: flex; align-items: flex-start; gap: 10px; width: 100%; padding: 7px 8px; text-align: left; font: inherit;
                   border: 0; border-radius: 7px; background: none; color: inherit; cursor: pointer; }
.share-menu .way svg { margin-top: 2px; flex: none; }
.share-menu .way:hover { background: color-mix(in srgb, var(--ink) 6%, transparent); }
.share-menu .way.on { background: color-mix(in srgb, var(--accent) 16%, transparent); }
.share-menu .words { display: flex; flex-direction: column; }
.share-menu .sub { color: var(--muted); font-size: 11.5px; }
.share-menu .link { display: flex; gap: 6px; margin: 6px 4px 2px; }
.share-menu .link input { flex: 1; min-width: 0; font: inherit; font-size: 12px; padding: 4px 6px; border: 1px solid var(--line); border-radius: 6px;
                          background: var(--bg); color: var(--ink); }
.share-menu .copy { font: inherit; font-size: 12px; padding: 4px 10px; border: 0; border-radius: 6px; background: var(--accent); color: var(--accent-ink); cursor: pointer; }
.share-menu .said { padding: 4px 8px 2px; color: var(--muted); font-size: 12px; }
.share-menu .said:empty { display: none; }
.forest-page.nothing { color: var(--muted); padding-top: 80px; text-align: center; }
.forest-page.nothing code { font-size: 12px; padding: 1px 5px; border-radius: 4px; background: var(--soft); }
#chats .account a.btn { flex: 1; text-align: center; padding: 8px 12px; border-radius: 8px; background: var(--accent); color: var(--accent-ink); font-size: 13px; }
#chats .forest.offline .fname { opacity: .6; }
#chats .forest.folded .chats { display: none; }
#chats .dormant .fname { font-style: italic; opacity: .7; }
#chats a.chat { display: flex; align-items: center; gap: 8px; padding: 6px 8px 6px 30px; border-radius: 8px; color: inherit; text-decoration: none; }
#chats a.chat:hover { background: color-mix(in srgb, var(--ink) 6%, transparent); }
#chats a.chat.here { background: color-mix(in srgb, var(--accent) 16%, transparent); font-weight: 600; }
#chats a.chat .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#chats a.chat .when { flex: none; color: var(--muted); font-size: 11px; font-weight: 400; font-variant-numeric: tabular-nums; }
#chats a.chat .going { flex: none; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }
/* notes still open on the chat's runs: feedback nobody has answered yet; and
   its runs that went wrong, red — each a press away from the first of them */
#chats a.chat :is(.notes, .errors) { flex: none; min-width: 18px; height: 18px; padding: 0 5px; box-sizing: border-box; display: grid; place-items: center;
                       border-radius: 9px; font-size: 10px; font-weight: 600; color: #fff; background: var(--warn, #c98a1a); cursor: pointer; }
#chats a.chat .errors { background: var(--danger, #d64545); }
#chats a.chat :is(.notes, .errors):hover { filter: brightness(1.12); box-shadow: 0 0 0 2px color-mix(in srgb, currentColor 30%, transparent); }
#chats .none { padding: 4px 8px 4px 30px; color: var(--muted); font-size: 12px; }
#chats .head a.brand { color: inherit; text-decoration: none; }
/* who is signed in, at the foot of the list, through forji.ai */
#chats .account { flex: none; display: flex; align-items: center; gap: 8px; padding: 10px 12px 12px 14px; border-top: 1px solid var(--line); }
#chats .account .face { flex: none; display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; font-size: 12px; font-weight: 700;
                        background: var(--accent); color: var(--accent-ink); }
#chats .account .who { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#chats .account a { color: var(--muted); font-size: 12px; text-decoration: none; }
#chats .account a:hover { color: var(--ink); }
#chats .error { padding: 8px 16px; color: var(--danger); font-size: 12px; }
.fold-list { flex: none; display: flex; width: 28px; height: 28px; align-items: center; justify-content: center; padding: 0;
             border: 0; border-radius: 7px; background: none; color: var(--muted); cursor: pointer; }
.fold-list:hover { color: var(--ink); background: color-mix(in srgb, var(--ink) 6%, transparent); }
.fold-list svg, #chats .fold svg { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.fold-list svg { width: 18px; height: 18px; }
/* folded away, the list leaves a button in the corner of the view to bring it back */
#unfold { position: absolute; left: 10px; top: 10px; z-index: 6; background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow); }
#unfold[hidden] { display: none; }
body.list-folded #dock { padding-left: calc(46px + env(safe-area-inset-left, 0px)); }
body.list-folded .forest-page { padding-top: 52px; }
/* a phone's window — as narrow as one upright, as short as one on its side: the list opens over the view, not beside it —
   over the chat too, maximized there — with the page dimmed behind it; its edge
   is not dragged, and it keeps clear of the notch and the home bar */
#chats-scrim { position: fixed; inset: 0; z-index: 1049; background: rgba(0, 0, 0, .32); }
#chats-scrim[hidden] { display: none; }
@media (max-width: 760px), (max-height: 500px) and (pointer: coarse) {
  #chats { position: fixed; left: 0; top: 0; bottom: 0; z-index: 1050; box-shadow: var(--shadow); max-width: 86vw;
           padding: env(safe-area-inset-top, 0px) 0 env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px); }
  #chats .edge { display: none; }
}
#unfold, #share-here { margin: env(safe-area-inset-top, 0px) 0 0 env(safe-area-inset-left, 0px); }
/* a finger, not a pointer: what is pressed is big enough to press */
@media (pointer: coarse) {
  #chats a.chat { min-height: 44px; }
  #chats .fhead { min-height: 40px; }
  #chats .fhead .fold, #chats .fhead .share { width: 36px; height: 36px; }
  #chats a.chat :is(.notes, .errors) { position: relative; }
  #chats a.chat :is(.notes, .errors)::before { content: ""; position: absolute; inset: -10px -6px; }
  #chats .account a:not(.btn) { padding: 10px 6px; }
  .fold-list { width: 40px; height: 40px; }
  #share-here { width: 40px; height: 40px; }
  #stage > .fit { width: 44px; height: 44px; }
  .share-menu .copy { padding: 10px 14px; }
}

/* A forest at a glance: its chats and its trees, a page that scrolls rather than a view you pan. */
#overview { flex: 1; min-height: 0; overflow: auto; }
.forest-page { padding: 28px 24px 60px; }
.forest-page > * { max-width: 1100px; margin-left: auto; margin-right: auto; }
.forest-page header { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.forest-page h1 { margin: 0; font-size: 24px; }
.forest-page .sub, .forest-page .quiet { color: var(--muted); font-size: 13px; }
.forest-page h2 { font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); margin: 28px 0 10px; }
.forest-page .grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(320px, 100%), 1fr)); gap: 12px; }
.forest-page .card { display: block; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px;
                     color: inherit; text-decoration: none; box-shadow: 0 1px 2px rgba(0, 0, 0, .06); }
.forest-page a.card:hover { border-color: var(--muted); }
.forest-page .card .title { display: flex; align-items: baseline; gap: 10px; }
.forest-page .card .name { font-weight: 600; }
.forest-page .card .count, .forest-page .card .say { color: var(--muted); font-size: 12px; }
.forest-page .kinds { color: var(--muted); font-size: 12px; margin-top: 3px; white-space: pre-wrap; }
.forest-page .runs-of { margin-top: 10px; }
.forest-page .last { display: flex; align-items: center; gap: 8px; font-size: 12.5px; flex-wrap: wrap; }
.forest-page .last .who { font-weight: 600; }
.forest-page .last .took { font-variant-numeric: tabular-nums; }
.forest-page .last .when { color: var(--muted); }
.forest-page .canned { font-size: 10px; padding: 1px 7px; border-radius: 9px; border: 1px solid var(--muted); color: var(--muted); }
/* notes still open on a run, or on a chat's runs */
.forest-page .notes { font-size: 10px; font-weight: 600; padding: 1px 7px; border-radius: 9px; color: #fff; background: var(--warn, #c98a1a); }
.forest-page .sdot { flex: none; width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.forest-page .sdot.ok { background: var(--ok); } .forest-page .sdot.skipped { background: var(--warn); }
.forest-page .sdot.failed, .forest-page .sdot.stopped { background: var(--bad); } .forest-page .sdot.running { background: var(--accent); }
.forest-page .strip { display: flex; align-items: flex-end; gap: 2px; height: 24px; margin-top: 6px; }
.forest-page .strip .bar { flex: 0 0 8px; border-radius: 2px 2px 0 0; background: var(--muted); opacity: .8; }
.forest-page .strip .bar.ok { background: var(--ok); } .forest-page .strip .bar.skipped { background: var(--warn); }
.forest-page .strip .bar.failed, .forest-page .strip .bar.stopped { background: var(--bad); } .forest-page .strip .bar.running { background: var(--accent); }
.forest-page .error { color: var(--danger); font-size: 12px; margin-top: 4px; overflow-wrap: anywhere; }
.forest-page .trees { display: flex; flex-direction: column; gap: 8px; }
.forest-page .tree .title { cursor: pointer; }
.forest-page .tree .source { display: none; margin: 10px 0 0; padding: 10px 12px; border-radius: 8px; background: var(--soft); overflow: auto;
                             max-height: 70vh; font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre; user-select: text; }
.forest-page .tree.open .source { display: block; }

@media (max-width: 760px) {
  .forest-page { padding: 20px 16px 60px; }
  .forest-page h1 { font-size: 20px; }
}

/* a machine's `/` and `/<forest>`: only where to go (forji.ai) */
body.pointer { display: block; overflow: auto; }
body.pointer main { max-width: 560px; margin: 0 auto; padding: 80px 24px; line-height: 1.55; }
body.pointer h1 { font-size: 22px; margin: 0 0 12px; }
body.pointer a { color: var(--accent); }
body.pointer code { font-size: 12.5px; padding: 1px 5px; border-radius: 4px; background: var(--soft); }
