/* JetBrains Mono for the Ghostty theme, self-hosted (SIL OFL, see fonts/OFL.txt).
   The browser only downloads it when a theme uses it. */
@font-face {
  font-family: "JetBrains Mono";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url(fonts/jetbrains-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: "JetBrains Mono";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url(fonts/jetbrains-mono-latin-700-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;
}

/* ---- themes: each sets colours, fonts and the window frame ---------------- */

/* classic (default): flat, full height, tmux-style tabs */
:root {
  --desk: #16181d;
  --chrome: #1e2128;
  --chrome-hi: #16181d;
  --chrome-fg: #d4d7dd;
  --chrome-dim: #959ca8;
  --chrome-line: #4a505b;
  --bg: #16181d;
  --bg-alt: #1e2128;
  --sel: #2b303a;
  --fg: #d4d7dd;
  --dim: #959ca8;
  --faint: #4a505b;   /* decoration only: markers and borders */
  --green: #8fd18a;
  --blue: #7fb4e8;
  --yellow: #e2c47a;
  --red: #e88a7f;
  --mark: #5a4a1e;
  --mono: ui-monospace, "Cascadia Mono", "SF Mono", Menlo, Consolas, "DejaVu Sans Mono", monospace;
  --ui: var(--mono);
  --frame-gap: 0px;
  --frame-radius: 0;
  --frame-border: 0;
  --frame-shadow: none;
  --fs: 16px;
  --lh: 1.6;
  color-scheme: dark;
}

/* Ghostty: GTK window, Ghostty's default colours and font */
:root[data-theme="ghostty"] {
  --desk: #18191c;
  --chrome: #303030;
  --chrome-hi: #3a3a3a;
  --chrome-fg: #eaeaea;
  --chrome-dim: #acb2bc;
  --chrome-line: #1c1c1c;
  --bg: #282c34;
  --bg-alt: #2f343e;
  --sel: #353a45;
  --fg: #eaeaea;
  --dim: #acb2bc;
  --faint: #5c6370;
  --green: #b5bd68;
  --blue: #81a2be;
  --yellow: #f0c674;
  --red: #e78a8a;
  --mark: #5c4f2a;
  --mono: "JetBrains Mono", ui-monospace, "DejaVu Sans Mono", monospace;
  --ui: system-ui, -apple-system, "Segoe UI", Cantarell, Ubuntu, sans-serif;
  --frame-gap: 24px;
  --frame-radius: 10px;
  --frame-border: 1px solid #000;
  --frame-shadow: 0 20px 40px rgb(0 0 0 / .35);
}

/* Ubuntu: old GNOME Terminal, aubergine with the Tango palette, Ambiance title bar */
:root[data-theme="ubuntu"] {
  --desk: #1c1a17;
  --chrome: #3c3b37;
  --chrome-hi: #2b2a27;
  --chrome-fg: #dfdbd2;
  --chrome-dim: #aba79d;
  --chrome-line: #1e1d1b;
  --bg: #300a24;
  --bg-alt: #3b1230;
  --sel: #4a1f3d;
  --fg: #ffffff;
  --dim: #c9b8c4;
  --faint: #7a5a70;
  --green: #8ae234;
  --blue: #729fcf;
  --yellow: #fce94f;
  --red: #ef6b6b;
  --mark: #6b4a10;
  --mono: "Ubuntu Mono", "DejaVu Sans Mono", ui-monospace, monospace;
  --ui: Ubuntu, Cantarell, system-ui, sans-serif;
  --frame-gap: 24px;
  --frame-radius: 6px 6px 0 0;
  --frame-border: 1px solid #000;
  --frame-shadow: 0 10px 24px rgb(0 0 0 / .4);
}

/* VT100: green phosphor, one colour, inverse video for highlights */
:root[data-theme="vt100"] {
  --desk: #0b0f0b;
  --chrome: #0f1a11;
  --chrome-hi: #4dff7a;
  --chrome-fg: #4dff7a;
  --chrome-dim: #2fbf55;
  --chrome-line: #1f5a2c;
  --bg: #0b0f0b;
  --bg-alt: #0f1a11;
  --sel: #163a20;
  --fg: #4dff7a;
  --dim: #2fbf55;
  --faint: #1f6a33;
  --green: #4dff7a;
  --blue: #4dff7a;
  --yellow: #4dff7a;
  --red: #4dff7a;
  --mark: #1f5a2c;
  --mono: "DejaVu Sans Mono", ui-monospace, Menlo, Consolas, monospace;
}

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

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--desk);
  color: var(--fg);
  font: var(--fs)/var(--lh) var(--mono);
}

.term {
  display: flex;
  flex-direction: column;
  height: calc(100dvh - 2 * var(--frame-gap));
  max-width: 1000px;
  margin: var(--frame-gap) auto;
  background: var(--bg);
  border: var(--frame-border);
  border-radius: var(--frame-radius);
  box-shadow: var(--frame-shadow);
  overflow: hidden;
}

/* top bar. classic and vt100: tabs left, buttons right. window themes: title row, then tabs */
.chrome {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: "tabs btns";
  background: var(--chrome);
  color: var(--chrome-fg);
  border-bottom: 1px solid var(--chrome-line);
  font-family: var(--ui);
}
.title { grid-area: title; display: none; }
.tabs { grid-area: tabs; display: flex; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.btns { grid-area: btns; display: flex; align-items: center; }

.tabs a {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 44px;
  padding: 0 14px;
  color: var(--chrome-dim);
  text-decoration: none;
  white-space: nowrap;
}
.tabs a:hover { color: var(--chrome-fg); }
.tabs a[aria-current="page"] { background: var(--chrome-hi); color: var(--green); }
.tabs a span { color: var(--chrome-dim); }

.icon-btn {
  font: 13px var(--ui);
  color: var(--chrome-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 44px;
  min-height: 44px;
  padding: 0 12px;
  border: 0;
  background: none;
  cursor: pointer;
}
.icon-btn:hover { color: var(--chrome-fg); }
.icon-btn svg { flex: none; }
.icon-btn .cap { display: none; }

/* window themes (Ghostty, Ubuntu): centred title, equal-width tabs under it */
:is([data-theme="ghostty"], [data-theme="ubuntu"]) .chrome {
  grid-template-columns: 1fr auto 1fr;
  grid-template-areas: ". title btns" "tabs tabs tabs";
  padding: 0 6px;
}
:is([data-theme="ghostty"], [data-theme="ubuntu"]) .title {
  display: block;
  align-self: center;
  max-width: 60vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
  font-weight: 700;
}
:is([data-theme="ghostty"], [data-theme="ubuntu"]) .btns { justify-self: end; min-height: 46px; }
:is([data-theme="ghostty"], [data-theme="ubuntu"]) .icon-btn { min-width: 34px; min-height: 34px; padding: 0 8px; border-radius: 6px; color: var(--chrome-fg); }
:is([data-theme="ghostty"], [data-theme="ubuntu"]) .icon-btn:hover { background: rgb(255 255 255 / .08); }
:is([data-theme="ghostty"], [data-theme="ubuntu"]) .tabs { gap: 4px; padding-bottom: 6px; font-size: 14px; }
:is([data-theme="ghostty"], [data-theme="ubuntu"]) .tabs a {
  flex: 1 1 0;
  min-width: 0;
  min-height: 34px;
  justify-content: center;
  padding: 0 10px;
  border-radius: 6px;
}
:is([data-theme="ghostty"], [data-theme="ubuntu"]) .tabs a[aria-current="page"] { color: var(--chrome-fg); }
:is([data-theme="ghostty"], [data-theme="ubuntu"]) .tabs a span { font: 12px var(--mono); }
[data-theme="ghostty"] .tabs a:hover { background: rgb(255 255 255 / .05); }

/* Ubuntu: square notebook tabs joined to the terminal */
[data-theme="ubuntu"] .tabs { gap: 2px; padding-bottom: 0; }
[data-theme="ubuntu"] .tabs a { border-radius: 4px 4px 0 0; }
[data-theme="ubuntu"] .tabs a[aria-current="page"] { background: var(--bg); color: var(--chrome-fg); }

/* VT100: inverse video for the current tab and the mode */
[data-theme="vt100"] .tabs a[aria-current="page"] { color: var(--bg); }
[data-theme="vt100"] .tabs a[aria-current="page"] span { color: var(--bg); }
[data-theme="vt100"] .portrait span { color: var(--fg) !important; }   /* one-colour screen */
[data-theme="vt100"] a { text-decoration-color: var(--dim); }

/* one shared hover/focus label, placed by app.js so it stays on screen */
#tip {
  position: fixed;
  padding: 2px 8px;
  background: var(--fg);
  color: var(--bg);
  font: 13px var(--ui);
  white-space: nowrap;
  pointer-events: none;
  z-index: 10;
}
#tip[hidden] { display: none; }

/* theme menu */
#themes {
  inset: auto;   /* app.js places it under the button */
  margin: 0;
  padding: 4px;
  min-width: 160px;
  background: var(--chrome);
  color: var(--chrome-fg);
  border: 1px solid var(--chrome-line);
  font: 14px var(--ui);
}
#themes button {
  display: flex;
  width: 100%;
  min-height: 36px;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  font: inherit;
  color: var(--chrome-dim);
  background: none;
  border: 0;
  cursor: pointer;
  text-align: left;
}
#themes button:hover { background: var(--sel); color: var(--chrome-fg); }
#themes button[aria-pressed="true"] { color: var(--green); }
#themes button[aria-pressed="true"]::before { content: "*"; }
#themes button[aria-pressed="false"]::before { content: " "; white-space: pre; }
#themes kbd { margin-left: auto; color: var(--chrome-dim); }

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

/* ---- buffer --------------------------------------------------------------- */

.buf {
  flex: 1;
  overflow-y: auto;
  padding: 12px 20px 0;
  scroll-padding: 48px 0;
}
.buf:focus { outline: none; }

.prompt { color: var(--dim); margin: 0 0 12px; }
.prompt b { color: var(--green); font-weight: normal; }
.prompt i { color: var(--blue); font-style: normal; }

/* block cursor on the last prompt; hollow when the window is not focused */
.cursor {
  display: inline-block;
  width: 1ch;
  height: 1.25em;
  vertical-align: text-bottom;
  background: var(--fg);
  animation: blink 1.2s step-end infinite;
}
.term:not(:focus-within) .cursor { background: none; box-shadow: inset 0 0 0 1px var(--fg); animation: none; }
@keyframes blink { 50% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .cursor { animation: none; } }

h1, h2, h3 { font-size: 1em; margin: 0; font-weight: bold; }
h1 { color: var(--yellow); }
h1::before { content: "# "; color: var(--faint); }
h2 { color: var(--blue); margin-top: 1.6em; }
h2::before { content: "## "; color: var(--faint); }
h3::before { content: "### "; color: var(--faint); }
p, ul { margin: 0 0 1em; max-width: 72ch; }
ul { padding-left: 0; list-style: none; }
li { padding-left: 2ch; text-indent: -2ch; }
ul li::before { content: "- "; color: var(--faint); }
ol { margin: 0 0 1em; padding-left: 3ch; max-width: 72ch; }
ol li { padding-left: 0; text-indent: 0; }
ol li::marker { color: var(--faint); }
a { color: var(--blue); text-underline-offset: 3px; }
code { color: var(--green); }
blockquote { margin: 0 0 1em; padding-left: 2ch; color: var(--dim); border-left: 1px solid var(--faint); max-width: 70ch; }
pre.block { background: var(--bg-alt); padding: 8px 12px; overflow-x: auto; margin: 0 0 1em; font: inherit; }
mark { background: var(--mark); color: inherit; }
mark.cur { outline: 1px solid var(--yellow); }

.job { display: grid; grid-template-columns: 1fr auto; column-gap: 2ch; margin-top: 1em; }
.job .when { color: var(--dim); text-align: right; }
.job .where { color: var(--dim); grid-column: 1 / -1; }
.meta { color: var(--dim); margin-bottom: 1em; }
.tag { color: var(--green); }
.tag::before { content: "["; color: var(--faint); }
.tag::after { content: "]"; color: var(--faint); }

/* hello: neofetch-style portrait and facts */
.fetch { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 8px 4ch; margin-bottom: 1.2em; }
.fetch pre { margin: 0; font: inherit; }
.fetch .portrait { font-size: 9px; line-height: 1; letter-spacing: 0; color: var(--dim); }
.info { white-space: pre-wrap; min-width: 0; flex: 1 1 40ch; }
.info b { color: var(--blue); font-weight: normal; }
.info b.who { color: var(--green); font-weight: bold; }

/* list view: one row per entry, vim-like cursor line */
.list { margin: 0; padding: 0; }
.row {
  display: grid;
  grid-template-columns: 3ch 1fr auto;
  column-gap: 1.5ch;
  padding: 4px 8px;
  margin: 0 -8px;
  cursor: pointer;
  color: inherit;
  text-decoration: none;
}
.row::before { content: none; }
.row .n { color: var(--dim); text-align: right; }
.row .t { color: var(--fg); }
.row .d { color: var(--dim); text-align: right; }
.row .s { grid-column: 2 / -1; color: var(--dim); }
.row:hover { background: var(--bg-alt); }
.row.sel { background: var(--sel); }
.row.sel .n { color: var(--yellow); }
.row.sel .t { color: var(--green); }

.group { color: var(--blue); margin: 1.2em 0 4px; }
.group span { color: var(--dim); }
.group:first-child { margin-top: 0; }

/* ---- status line and command line ----------------------------------------- */

.status {
  display: flex;
  gap: 2ch;
  background: var(--sel);
  color: var(--dim);
  white-space: nowrap;
  overflow: hidden;
}
.status .mode { background: var(--green); color: var(--bg); padding: 0 1ch; font-weight: bold; }
.status .mode.cmd { background: var(--yellow); }
.status .file { color: var(--fg); overflow: hidden; text-overflow: ellipsis; flex: 1; }
.status .pos { padding-right: 1ch; }

.cmdline { display: flex; padding: 2px 8px; min-height: calc(var(--fs) * var(--lh) + 4px); }
.cmdline input {
  flex: 1;
  font: inherit;
  color: var(--fg);
  background: none;
  border: 0;
  padding: 0;
  outline: none;
  display: none;
}
.cmdline.active input { display: block; }
.cmdline.active output { display: none; }
#msg { color: var(--dim); }
#msg.err { color: var(--red); }
#cmdprefix { color: var(--yellow); }

/* help */
dialog {
  background: var(--chrome);
  color: var(--fg);
  border: 1px solid var(--chrome-line);
  border-radius: var(--frame-radius);
  box-shadow: var(--frame-shadow);
  padding: 12px 20px;
  font: inherit;
  max-width: calc(100vw - 24px);
  max-height: calc(100dvh - 24px);
  overflow: auto;
}
dialog::backdrop { background: rgb(0 0 0 / .5); }
dialog pre { margin: 0 0 12px; font: inherit; overflow-x: auto; }
dialog b { color: var(--blue); }
dialog .close { position: absolute; top: 0; right: 0; }
kbd { color: var(--dim); font: inherit; }

/* touch screens: no hover and usually no keyboard */
@media (hover: none) {
  .icon-btn .cap { display: inline; }
  .icon-btn, .tabs a, :is([data-theme="ghostty"], [data-theme="ubuntu"]) :is(.icon-btn, .tabs a) { min-height: 44px; }
  .tabs a span, .status .hint, .kbd-hint, #themes kbd { display: none; }
  #themes button { min-height: 44px; }
}

/* phones: the window fills the screen */
@media (max-width: 600px) {
  .term { height: 100dvh; margin: 0; border: 0; border-radius: 0; box-shadow: none; }
  .tabs a { padding: 0 9px; }
  .icon-btn { padding: 0 8px; }
  :is([data-theme="ghostty"], [data-theme="ubuntu"]) .chrome { grid-template-columns: 1fr auto; grid-template-areas: "title btns" "tabs tabs"; }
  :is([data-theme="ghostty"], [data-theme="ubuntu"]) .title { max-width: none; padding-left: 8px; }
  .buf { padding: 10px 12px 0; }
  .row { grid-template-columns: 2ch 1fr; }
  .row .d { grid-column: 2; text-align: left; order: 3; }
  .job { grid-template-columns: 1fr; }
  .job .when { text-align: left; }
  .status .hint { display: none; }
}
@media (max-width: 360px) {
  #help-btn .cap { display: none; }
  .tabs a { padding: 0 7px; }
}
