/* The Ursa Web Shell: a header bar and a terminal, in light and dark.
   Ink on white by day, starlight on a night sky by night. Colour is kept
   for the prompt and a few syntax notes, from the star-temperature ramp. */

:root {
  --bg: #ffffff;
  --bar-bg: #ffffff;
  --fg: #12120f;
  --muted: #6b6963;
  --faint: #b3afa5;
  --border: #e8e6e1;
  --table-border: #b3afa5;
  --menu-bg: #ffffff;
  --menu-hover: #f4f3f0;
  --accent: #c4491b;       /* the hottest star on the ramp: focus rings only */
  --logo-ink: #12120f;
  --prompt: #c4491b;
  --keyword: #12120f;
  --string: #b07728;
  --number: #12120f;
  --comment: #6b6963;
  --dot: #1f3e8c;
  --error: #c0262d;
  --ok: #1f3e8c;
  --selection: #1f3e8c24;
  --scrollbar: #c9c6be;
  --scrollbar-hover: #a19e95;
  /* The graph view's colours (graph.js hands them to ursa-viz): its ground,
     edge ink and plain nodes, and the categories COLOR BY colours, eight hues
     in a fixed order told apart with colour-vision deficiencies too, then
     "other". By night the same hues, stepped for the sky. */
  --graph-bg: #ffffff;
  --graph-edge: #595966;
  --graph-node: #2a2a2a;
  --graph-c0: #2a78d6;
  --graph-c1: #eb6834;
  --graph-c2: #1baf7a;
  --graph-c3: #eda100;
  --graph-c4: #e87ba4;
  --graph-c5: #008300;
  --graph-c6: #6250d6;
  --graph-c7: #e34948;
  --graph-other: #a3a097;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0b0a;
    --bar-bg: #0b0b0a;
    --fg: #f4f1ea;
    --muted: #8a877f;
    --faint: #5a5852;
    --border: #2a2a26;
    --table-border: #4a4842;
    --menu-bg: #141412;
    --menu-hover: #1e1e1b;
    --accent: #ff9f51;
    --logo-ink: #f4f1ea;
    --prompt: #ff9f51;
    --keyword: #f4f1ea;
    --string: #ffd2a1;
    --number: #f4f1ea;
    --comment: #8a877f;
    --dot: #aabfff;
    --error: #ff6b6b;
    --ok: #aabfff;
    --selection: #aabfff33;
    --scrollbar: #3a3935;
    --scrollbar-hover: #5a5852;
    --graph-bg: #0b0b0a;
    --graph-edge: #b4b8c8;
    --graph-node: #e8e4dc;
    --graph-c0: #3987e5;
    --graph-c1: #d95926;
    --graph-c2: #199e70;
    --graph-c3: #c98500;
    --graph-c4: #d55181;
    --graph-c5: #0ca30c;
    --graph-c6: #9085e9;
    --graph-c7: #e66767;
    --graph-other: #6b6963;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0b0b0a;
  --bar-bg: #0b0b0a;
  --fg: #f4f1ea;
  --muted: #8a877f;
  --faint: #5a5852;
  --border: #2a2a26;
  --table-border: #4a4842;
  --menu-bg: #141412;
  --menu-hover: #1e1e1b;
  --accent: #ff9f51;
  --logo-ink: #f4f1ea;
  --prompt: #ff9f51;
  --keyword: #f4f1ea;
  --string: #ffd2a1;
  --number: #f4f1ea;
  --comment: #8a877f;
  --dot: #aabfff;
  --error: #ff6b6b;
  --ok: #aabfff;
  --selection: #aabfff33;
  --scrollbar: #3a3935;
  --scrollbar-hover: #5a5852;
  --graph-bg: #0b0b0a;
  --graph-edge: #b4b8c8;
  --graph-node: #e8e4dc;
  --graph-c0: #3987e5;
  --graph-c1: #d95926;
  --graph-c2: #199e70;
  --graph-c3: #c98500;
  --graph-c4: #d55181;
  --graph-c5: #0ca30c;
  --graph-c6: #9085e9;
  --graph-c7: #e66767;
  --graph-other: #6b6963;
  color-scheme: dark;
}

/* The terminal's font, IBM Plex Mono (SIL OFL 1.1), served with the page:
   see scripts/build.ts. */
/* Box drawing (U+2500-257F), which the Plex Mono web fonts lack: our own
   strokes on Plex Mono's metrics that run past each row, so a table's lines
   join whatever the line height (scripts/box-font.py makes the font). */
@font-face {
  font-family: "Ursa Box";
  font-style: normal;
  font-weight: 400;
  font-display: block;
  src: url("/fonts/ursa-box.woff2") format("woff2");
  unicode-range: U+2500-257F;
}
@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/fonts/ibm-plex-mono-latin-ext-400-normal.woff2") format("woff2");
  unicode-range: U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF;
}
@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/fonts/ibm-plex-mono-latin-400-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD;
}
@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("/fonts/ibm-plex-mono-latin-ext-500-normal.woff2") format("woff2");
  unicode-range: U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF;
}
@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("/fonts/ibm-plex-mono-latin-500-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD;
}
@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("/fonts/ibm-plex-mono-latin-ext-600-normal.woff2") format("woff2");
  unicode-range: U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF;
}
@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("/fonts/ibm-plex-mono-latin-600-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD;
}
@font-face {
  font-family: "IBM Plex Mono";
  font-style: italic;
  font-weight: 400;
  font-display: swap;
  src: url("/fonts/ibm-plex-mono-latin-ext-400-italic.woff2") format("woff2");
  unicode-range: U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF;
}
@font-face {
  font-family: "IBM Plex Mono";
  font-style: italic;
  font-weight: 400;
  font-display: swap;
  src: url("/fonts/ibm-plex-mono-latin-400-italic.woff2") format("woff2");
  unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD;
}

* { box-sizing: border-box; }

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

body {
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  display: flex;
  flex-direction: column;
}

::selection { background: var(--selection); }

/* Scrollbars in the theme's colours: thin, on no track. The terminal draws
   its own (xterm.js), coloured from app.js (THEMES) and shaped below. */
html, .dropdown-menu, .xterm-viewport { scrollbar-color: var(--scrollbar) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; background: transparent; }
::-webkit-scrollbar-thumb { background: var(--scrollbar); border: 2px solid transparent; border-radius: 5px; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background-color: var(--scrollbar-hover); }
::-webkit-scrollbar-corner { background: transparent; }

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

.bar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: minmax(max-content, 1fr) auto minmax(max-content, 1fr);
  align-items: center;
  column-gap: 16px;
  height: 52px;
  padding: 0 16px;
  background: var(--bar-bg);
  border-bottom: 1px solid var(--border);
}

.menu { display: flex; align-items: center; gap: 4px; }

.menu button,
.theme {
  font: inherit;
  color: var(--fg);
  background: none;
  border: 0;
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
  white-space: nowrap;
}
.menu button:hover, .menu button[aria-expanded="true"] { color: var(--prompt); }
.menu button:focus-visible, .theme:focus-visible, .dropdown-menu button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.chevron { width: 12px; height: 12px; vertical-align: -1px; margin-left: 2px; }
/* New, Share and Import show these instead of their labels on a phone. */
.menu .icon { display: none; width: 18px; height: 18px; }

.dropdown { position: relative; }
.dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 260px;
  padding: 8px 0;
  background: var(--menu-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 24px #0000001f;
}
.dropdown-menu button {
  display: block;
  width: 100%;
  text-align: left;
  font: inherit;
  font-size: 14px;
  color: var(--fg);
  background: none;
  border: 0;
  padding: 8px 18px;
  cursor: pointer;
}
.dropdown-menu button:hover { background: var(--menu-hover); }

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--fg);
  text-decoration: none;
  font-size: 15px;
}
.brand b { font-weight: 650; }
.logo { width: 45px; height: 19px; flex: none; }
.logo-line { fill: none; stroke: var(--logo-ink); stroke-width: 0.7; stroke-linejoin: round; opacity: 0.5; }
.logo-star { fill: var(--logo-ink); }

.right { display: flex; justify-content: flex-end; }
.theme {
  width: 34px;
  height: 34px;
  padding: 7px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--fg);
}
.theme svg { width: 18px; height: 18px; display: block; }
.theme .sun { display: none; }
:root[data-theme="dark"] .theme .sun { display: block; }
:root[data-theme="dark"] .theme .moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme .sun { display: block; }
  :root:not([data-theme="light"]) .theme .moon { display: none; }
}

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

/* The terminal, and the graph view beside it when open (.graph). */
.workspace {
  flex: 1;
  min-height: 0;
  display: flex;
}
/* Half each, whatever their padding. */
.workspace > .terminal { flex: 1 1 50%; min-width: 0; }

/* xterm.js draws the terminal; this is the room it fills. Its colours are set
   from app.js (THEMES), to match these tokens. */
.terminal {
  flex: 1;
  min-height: 0;
  padding: 16px 18px 8px;
  background: var(--bg);
}
.terminal .xterm { height: 100%; }
.terminal .xterm-viewport { background: var(--bg) !important; }
/* The hidden textarea xterm.js types into: at under 16px, iOS zooms the page
   in when it takes the focus. Nothing shows it, so its size changes nothing. */
.terminal .xterm .xterm-helper-textarea { font-size: 16px; }
/* The terminal's scrollbar: a rounded thumb inset from the edge. */
.terminal .xterm .xterm-scrollable-element > .scrollbar > .slider {
  border: 3px solid transparent;
  border-radius: 7px;
  background-clip: padding-box !important;
  box-sizing: border-box;
}

/* ---------------------------------------------------------------- graph view */

/* Beside the terminal, half the width; under it on a phone. ursa-viz draws
   in the --graph-* colours, ink on white by day and starlight on the sky by
   night: switching the theme recolours an open view (graph.js). */
.graph-pane {
  flex: 1 1 50%;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--border);
  background: var(--bg);
}
.graph-pane[hidden] { display: none; }
.graph-head {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 40px;
  padding: 0 6px 0 14px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  color: var(--muted);
}
.graph-status {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
}
/* The legend: what sizes the nodes, and each colour named, in text. */
.graph-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 14px;
  padding: 6px 14px 7px;
  border-bottom: 1px solid var(--border);
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 12px;
  color: var(--muted);
}
.graph-legend[hidden] { display: none; }
.graph-legend .key { color: var(--fg); }
.graph-legend ul {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.graph-legend li { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.graph-legend .swatch {
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--graph-other);
}
.graph-legend .count { color: var(--muted); }
.graph-legend .size-key { display: inline-flex; align-items: center; gap: 4px; }
.graph-legend .dot { display: inline-block; border-radius: 50%; background: var(--graph-node); }
.graph-legend .dot.small { width: 4px; height: 4px; }
.graph-legend .dot.large { width: 11px; height: 11px; }
.swatch.c0 { background: var(--graph-c0); }
.swatch.c1 { background: var(--graph-c1); }
.swatch.c2 { background: var(--graph-c2); }
.swatch.c3 { background: var(--graph-c3); }
.swatch.c4 { background: var(--graph-c4); }
.swatch.c5 { background: var(--graph-c5); }
.swatch.c6 { background: var(--graph-c6); }
.swatch.c7 { background: var(--graph-c7); }
.graph-close {
  flex: none;
  width: 30px;
  height: 30px;
  padding: 6px;
  color: var(--fg);
  background: none;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
}
.graph-close svg { width: 18px; height: 18px; display: block; }
.graph-close:hover { color: var(--prompt); }
.graph-close:focus-visible, .graph-stage canvas:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
.graph-stage { flex: 1; min-height: 0; position: relative; }
.graph-stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
}
.graph-stage canvas:active { cursor: grabbing; }

/* A phone: one row, the logo first (its name left to screen readers). Under
   420px, New, Share and Import are icons, their labels still naming them. */
@media (max-width: 640px) {
  .bar { display: flex; gap: 6px; padding: 0 10px; }
  .brand { order: -1; flex: none; padding: 4px; }
  .menu { flex: 1; min-width: 0; gap: 0; }
  .menu button { padding: 6px 8px; }
  /* The menu drops from the bar, across it, so it stays on screen. */
  .dropdown { position: static; }
  .dropdown-menu { top: calc(100% + 4px); left: 8px; right: 8px; min-width: 0; }
  .terminal { padding: 12px 8px 4px; }
  /* The graph view under the terminal. */
  .workspace { flex-direction: column; }
  .workspace > .terminal { min-height: 0; }
  .graph-pane { border-left: 0; border-top: 1px solid var(--border); }
  .brand .label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
}
@media (max-width: 420px) {
  .menu .icon { display: block; }
  .menu button:has(.icon) { padding: 8px; }
  .menu .label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
}
