/* crate.naaxa.com: every tool on one screen, in a terminal */

@font-face {
  font-family: "Iosevka";
  src: url("fonts/iosevka-400.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Iosevka";
  src: url("fonts/iosevka-700.woff2") format("woff2");
  font-weight: 700;
  font-display: swap;
}

/* gruvbox dark, hard */
:root {
  --bg: #1d2021;
  --bg1: #282828;
  --bg2: #3c3836;
  --bg3: #504945;
  --bg4: #665c54;
  --fg: #ebdbb2;
  --fg2: #d5c4a1;
  --fg3: #bdae93;
  --fg4: #a89984;
  --gray: #928374;
  --red: #fb4934;
  --green: #b8bb26;
  --yellow: #fabd2f;
  --blue: #83a598;
  --purple: #d3869b;
  --aqua: #8ec07c;
  --orange: #fe8019;

  --font: "Iosevka", "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
/* no pinch or double-tap zoom on phones; scrolling still works */
html { touch-action: pan-x pan-y; }

body {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
  background: var(--bg);
  color: var(--fg);
  font: 400 14px/1.25 var(--font);
  font-variant-ligatures: none;
  -webkit-font-smoothing: antialiased;
}
b, strong { font-weight: 700; }
pre, kbd { font: inherit; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; text-align: inherit; }
::selection { background: var(--bg4); color: var(--fg); }
:focus-visible { outline: 1px solid var(--yellow); outline-offset: 0; }
.dim { color: var(--gray); }
/* parked off to the left, where it can't widen the page on a phone */
.probe { position: absolute; top: 0; left: -10000px; visibility: hidden; white-space: pre; pointer-events: none; }

/* ---------- header ---------- */

.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 2ch 2px;
}
.brand { display: flex; align-items: center; gap: 1ch; color: var(--fg3); }
.brand img { display: block; height: 18px; width: auto; }
.top-r { color: var(--fg4); }
.top-r:hover, .brand:hover span:last-child { color: var(--fg); }

/* ---------- coming in ---------- */

.intro { position: fixed; inset: 0; z-index: 100; width: 100%; height: 100%; cursor: progress; }
/* behind everything, under the panes: see torch.js */
.torch { position: fixed; inset: 0; z-index: -1; width: 100%; height: 100%; pointer-events: none; }
@media (hover: none) { .torch { display: none; } }
.top, .pane, .bottom { transition: opacity 0.5s ease var(--d, 0s), transform 0.7s cubic-bezier(0.2, 0.7, 0.2, 1) var(--d, 0s); }
.booting .top, .booting .pane, .booting .bottom { opacity: 0; transform: translateY(12px); animation: failsafe 0s 8s forwards; }
/* if the script never runs, show the page anyway */
@keyframes failsafe { to { opacity: 1; transform: none; } }
.brand img { transition: opacity 0.25s ease; }
.logo-hidden .brand img { opacity: 0; }
.booting .sight { visibility: hidden; }

/* ---------- panes ---------- */

.term {
  display: grid;
  grid-template-columns: minmax(0, 28fr) minmax(0, 39fr) minmax(0, 33fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas:
    "lib scope eye"
    "lib scope input"
    "lib info live";
  gap: 14px 8px;
  min-height: 0;
  padding: 14px 8px 8px;
}
.p-lib { grid-area: lib; }
.p-scope { grid-area: scope; }
.p-info { grid-area: info; }
.p-eye { grid-area: eye; }
.p-input { grid-area: input; }
.p-live { grid-area: live; }

.pane {
  position: relative;
  min-width: 0;
  min-height: 0;
  padding: 12px 1ch 8px;
  border: 1px solid var(--bg3);
  border-radius: 5px;
}
.pane.is-focus { border-color: var(--fg4); }
.pane-t,
.pane-m {
  position: absolute;
  z-index: 1;
  top: -0.65em;
  padding: 0 0.5ch;
  background: var(--bg);
  font: inherit;
  font-style: normal;
  white-space: nowrap;
}
.pane-t { left: 1ch; color: var(--fg); }
.pane-t b { margin-right: 0.5ch; color: var(--orange); font-weight: 400; }
.pane.is-focus .pane-t { color: var(--yellow); }
.pane-m { right: 1ch; color: var(--gray); }

/* ---------- library (pane 1) ---------- */

.p-lib { display: flex; flex-direction: column; }
.banner { margin: 6px 1ch 12px; color: var(--yellow); white-space: pre; overflow: hidden; }
.banner span { color: var(--gray); }
.lib-head,
.row {
  display: grid;
  grid-template-columns: 4ch minmax(0, 1fr) minmax(0, 18ch) 2ch;
  column-gap: 1ch;
  padding: 0 1ch;
}
.lib-head { margin-bottom: 4px; padding-bottom: 2px; border-bottom: 1px solid var(--bg2); color: var(--gray); }
.lib { position: relative; flex: 1; min-height: 0; overflow: hidden auto; scrollbar-width: none; }
.lib > * { position: relative; z-index: 1; }
.lib > .lib-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 0;
  background: var(--bg3);
  box-shadow: inset 2px 0 0 var(--c, var(--yellow));
  pointer-events: none;
  transition: transform 0.18s cubic-bezier(0.2, 0.8, 0.2, 1), height 0.18s;
}
.lib-bar.is-new { animation: bar-in 0.5s ease-out; }
@keyframes bar-in { from { background: var(--bg4); } }
/* on the way in, the list types itself out */
.lib.is-typing .row,
.lib.is-typing .sec { animation: type-in 0.3s steps(12, end) both; animation-delay: calc(var(--k) * 26ms + 0.15s); }
@keyframes type-in { from { clip-path: inset(0 100% 0 0); } }
.lib::-webkit-scrollbar { display: none; }
.sec {
  display: flex;
  gap: 1ch;
  margin-top: 8px;
  padding: 0 1ch;
  white-space: nowrap;
  overflow: hidden;
  color: var(--gray);
  cursor: pointer;
}
.sec:first-child { margin-top: 0; }
.sec b { color: var(--c); }
.sec::after { content: "────────────────────────────────────────────────────────────────────────────────────────────────────"; color: var(--bg3); }
.sec:hover b + span { color: var(--fg); }
.row { color: var(--fg2); cursor: pointer; }
.row > span { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.row .c-no { color: var(--gray); }
.row .c-host { color: var(--gray); }
.row .c-key { color: var(--orange); text-align: right; }
.row:hover { background: var(--bg1); }
.row.is-cur, .row.is-cur:hover { background: none; color: var(--fg); }
.row.is-cur .c-no { color: var(--yellow); }
.row.is-cur .c-host { color: var(--fg3); }
.row.is-open .c-title { color: var(--orange); font-weight: 700; }
.row.is-down .c-host { color: var(--red); }
/* phone-only parts of the library: hidden on a desktop */
.msearch, .row .c-desc, .row .c-act { display: none; }
mark { background: var(--yellow); color: var(--bg); }
.lib-empty { padding: 0 1ch; color: var(--gray); }

/* ---------- scope (pane 2) ---------- */

.p-scope { padding: 0; }
.scope { position: absolute; inset: 0; display: block; width: 100%; height: 100%; border-radius: 5px; touch-action: manipulation; }

/* ---------- track (pane 3) ---------- */

.big { margin: 6px 0 12px; color: var(--fg); white-space: pre; overflow: hidden; }
.info { display: grid; grid-template-columns: 8ch minmax(0, 1fr); column-gap: 1ch; }
.info .k { color: var(--yellow); }
.info .v { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--fg2); }
.info .v.err { color: var(--red); }
.acts { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 0 2ch; margin-top: 10px; }
.tbtn { color: var(--fg); white-space: nowrap; }
.tbtn kbd { color: var(--orange); }
.tbtn:hover { background: var(--fg); color: var(--bg); }
.tbtn:hover kbd { color: var(--bg); }
.swatch { grid-column: 1 / -1; display: flex; margin-top: 10px; }
.swatch i { width: 3ch; height: 1.25em; }

/* ---------- eye, input, listeners (panes 4–6) ---------- */

.ascii { white-space: pre; overflow: hidden; user-select: none; -webkit-user-select: none; }
#eye { margin-top: 4px; color: var(--fg3); }
#eye .sc { color: var(--fg3); }
#eye .sh { color: var(--bg4); }
#eye .ir { color: var(--gray); }
#eye .ig { color: var(--fg); }
#eye .lb { color: var(--c, var(--orange)); }
#eye .gl { color: #fff; }
#eye .ln { color: var(--fg); }
#eye .tb { color: var(--orange); }
.eye-read { margin-top: 4px; color: var(--gray); white-space: pre; overflow: hidden; }
.eye-read b { color: var(--fg3); font-weight: 400; }

.p-input { display: flex; flex-direction: column; }
.desk { display: block; flex: 1; width: 100%; min-height: 150px; cursor: default; }
.echo { min-height: 1.25em; color: var(--gray); white-space: pre; overflow: hidden; text-overflow: ellipsis; }
.echo b { color: var(--fg); font-weight: 400; }
.echo i { font-style: normal; background: var(--fg); }

.live p { white-space: pre; overflow: hidden; text-overflow: ellipsis; }
.live b { color: var(--fg); font-weight: 400; }
#online { color: var(--orange); font-weight: 700; }
.spark { margin: 2px 0 4px; color: var(--aqua); }
.spark i { font-style: normal; color: var(--orange); }

/* ---------- vim statusline, command line, tmux ---------- */

.bottom { min-width: 0; }
.statusline {
  display: flex;
  margin: 0 8px;
  background: var(--bg2);
  color: var(--fg3);
  white-space: nowrap;
  overflow: hidden;
}
.statusline > span { padding: 0 1ch; }
.statusline .mode { background: var(--yellow); color: var(--bg); font-weight: 700; }
.statusline .mode.m-search { background: var(--blue); }
.statusline .mode.m-command { background: var(--aqua); }
.statusline .mode.m-open { background: var(--orange); }
.statusline .path { min-width: 0; overflow: hidden; text-overflow: ellipsis; color: var(--fg); }
.statusline .grow { flex: 1; padding: 0; }
.statusline .hi { background: var(--bg4); color: var(--fg); }
.statusline .pos { background: var(--fg4); color: var(--bg); }

.cmdline { display: flex; margin: 0 8px; height: 1.25em; white-space: pre; cursor: text; }
.cmdline input {
  width: 1ch;
  min-width: 1ch;
  max-width: 60ch;
  background: none;
  border: 0;
  outline: 0;
  font: inherit;
  color: var(--fg);
  caret-color: var(--fg);
}
.cmdline:not(.on) input { position: absolute; opacity: 0; pointer-events: none; }
#cmd-msg { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; color: var(--fg3); }
#cmd-msg.err { color: var(--red); }
.cmd-right { color: var(--gray); }

.tmux {
  display: flex;
  margin-top: 2px;
  background: var(--bg1);
  color: var(--fg4);
  white-space: nowrap;
  overflow: hidden;
}
.tmux .ses { padding: 0 1ch; margin-right: 1ch; background: var(--fg4); color: var(--bg); }
.tmux button { padding: 0 1ch 0 0; }
.tmux button:hover { color: var(--fg); }
.tmux button.on { color: var(--yellow); }
.tmux .right { margin-left: auto; padding: 0 1ch; color: var(--fg3); }

/* ---------- line of sight ---------- */

.sight { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 40; pointer-events: none; opacity: 0; transition: opacity 0.6s ease; }
.sight.on { opacity: 1; transition-duration: 0.15s; }
#sight-line { stroke: var(--fg4); stroke-width: 1; stroke-dasharray: 2 6; opacity: 0.5; }
#sight-text { font: 13px var(--font); fill: var(--fg3); }

/* ---------- smaller screens ---------- */

@media (max-width: 1180px) {
  .term {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr);
    grid-template-rows: minmax(0, 1fr) auto auto;
    grid-template-areas:
      "lib scope"
      "lib info"
      "live live";
  }
  .p-eye, .p-input, .sight { display: none; }
}

/* fingers instead of a keyboard: bigger targets, buttons instead of key hints */
@media (hover: none) {
  body { -webkit-tap-highlight-color: transparent; }
  .k-hint { display: none; }
  .acts { gap: 10px; margin-top: 14px; }
  .tbtn { padding: 8px 2ch; border: 1px solid var(--bg4); }
  .tbtn:active { background: var(--fg); color: var(--bg); }
  .row { padding-top: 5px; padding-bottom: 5px; }
  .row:active { background: var(--bg2); }
}

@media (max-width: 760px) {
  body { display: block; overflow: auto; height: auto; }
  .top { padding: 14px 16px 4px; }
  .term { display: flex; flex-direction: column; gap: 22px; padding: 18px 8px 12px; }
  .p-scope { height: min(88vw, 64vh); order: -1; }

  /* the library becomes the main list: a search field, and two-line rows big enough to tap */
  .banner, .lib-head { display: none; }
  .msearch {
    display: flex;
    align-items: center;
    gap: 1ch;
    margin: 8px 0 12px;
    padding: 0 1ch;
    border: 1px solid var(--bg3);
  }
  .msearch:focus-within { border-color: var(--yellow); }
  .msearch span { color: var(--yellow); }
  .msearch input {
    flex: 1;
    min-width: 0;
    padding: 10px 0;
    background: none;
    border: 0;
    outline: 0;
    color: var(--fg);
    font: 16px/1.2 var(--font);   /* 16px or iOS zooms in on focus */
  }
  .msearch input::placeholder { color: var(--gray); }
  .sec { margin-top: 14px; padding-top: 4px; padding-bottom: 4px; }
  .row {
    grid-template-columns: 3ch minmax(0, 1fr) auto;
    grid-template-areas: "no title act" ". desc act";
    row-gap: 2px;
    padding: 9px 1ch;
  }
  .row .c-no { grid-area: no; }
  .row .c-title { grid-area: title; }
  .row .c-desc { grid-area: desc; display: block; color: var(--gray); font-size: 12px; }
  .row .c-host, .row .c-key { display: none; }
  .row.is-cur .c-act { grid-area: act; display: block; align-self: center; margin-left: 1ch; }
  .c-act a { display: block; padding: 12px 1.5ch; border: 1px solid var(--orange); color: var(--orange); }
  .c-act a:active { background: var(--orange); color: var(--bg); }

  /* the vim lines need a keyboard; the sections stay, as a bar you can swipe along */
  .statusline, .cmdline { display: none; }
  .bottom { position: sticky; bottom: 0; z-index: 5; background: var(--bg); padding-bottom: env(safe-area-inset-bottom); }
  .tmux { margin-top: 0; overflow-x: auto; scrollbar-width: none; border-top: 1px solid var(--bg3); }
  .tmux::-webkit-scrollbar { display: none; }
  .tmux .ses, .tmux .right { display: none; }
  .tmux button { flex: none; padding: 12px 1.5ch; }
}

@media (prefers-reduced-motion: reduce) {
  .top, .pane, .bottom, .lib > .lib-bar { transition: none; }
  .lib.is-typing .row, .lib.is-typing .sec, .lib-bar.is-new { animation: none; }
}
