/* The client's look, following the desktop original: a near-black blue
   ground, green accents, and a console that fills the window. */

:root {
  color-scheme: dark;

  --bg: #0b0f14;
  --panel: #161b22;
  --titlebar: #1a2129;
  --rule: #232b35;

  --fg: #d8d8d8;
  --dim: #7a8290;
  --accent: #3dcf44;
  --gold: #d8a629;
  --error: #ff5f56;
  /* The prompt is the client's `lblue`, which its RGB packing puts at cyan. */
  --prompt: #00ffff;

  --gutter: 4px;
  --prespace: 40px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  display: grid;
  /* Title bar, comm log, console (the prompt is inside it), status bar. */
  grid-template-rows: auto auto 1fr auto;
  /* `minmax(0, 1fr)` rather than the default `auto`: the window is the whole
     of the page, so a row wide enough to overflow it has to be made to fit
     rather than pushing the others off the right edge -- which, with the
     `overflow: hidden` below, is off the screen for good. The title bar is
     the row that would: its account is right-aligned, and on a phone it was
     the part that went. */
  grid-template-columns: minmax(0, 1fr);
  background: var(--bg);
  color: var(--fg);
  font-family: Verdana, "DejaVu Sans", system-ui, sans-serif;
  font-size: 13px;
  overflow: hidden;
}

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

#titlebar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.6rem;
  background: var(--titlebar);
  border-bottom: 1px solid var(--rule);
  font-weight: 700;
}

#status-dot {
  width: 9px;
  height: 9px;
  flex: 0 0 auto;
  border-radius: 1px;
}
#status-dot.offline {
  background: var(--error);
}
#status-dot.connecting {
  background: var(--gold);
}
#status-dot.online {
  background: var(--accent);
}

#brand {
  flex: 0 0 auto;
  padding-right: 0.6rem;
  border-right: 1px solid var(--rule);
  color: var(--accent);
  letter-spacing: 0.04em;
  white-space: nowrap;
}

/* A phone has room for the account and not much else, so the brand goes
   first -- the page's own title says the same thing. */
@media (max-width: 34rem) {
  #brand {
    display: none;
  }
}

/* The connection state is short and stays whole; the name beside it is the
   long one -- twenty characters, at the server's limit -- and is what gives
   way when the bar has not room for both. */
#status-text {
  flex: 0 0 auto;
  white-space: nowrap;
}

/* ---- the account ------------------------------------------------------ */

/* Signed out this is one button; signed in it is a name and a way out. The
   menu hangs from it, so the box is what the menu is measured against. */
#account {
  position: relative;
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  min-width: 0;
  /* Weighted so that a bar too narrow for everything takes it out of the
     name -- which ellipsizes -- before the connection state, which is short
     and is the one thing the bar is for. */
  flex-shrink: 100;
}

#account-label {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  color: var(--dim);
  font-weight: 400;
}
#account-label b {
  color: var(--gold);
}

/* Both wear the status bar's dress: furniture, not something to press by
   accident. */
#logout,
#account-toggle {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 0.4rem;
  white-space: nowrap;
  padding: 0.1rem 0.45rem;
  font-size: 11px;
  background: transparent;
  border-color: transparent;
  color: var(--dim);
}
/* `display` above would otherwise outrank the attribute, leaving whichever
   of the two the bar is not showing laid out beside the one it is. */
#logout[hidden],
#account-toggle[hidden] {
  display: none;
}

#logout:hover,
#account-toggle:hover,
#account-toggle[aria-expanded="true"] {
  color: var(--gold);
  border-color: var(--rule);
}

/* Three bars, drawn rather than typed: U+2630 is missing from half the faces
   this page falls back to. `currentColor` carries the hover with it. */
.hamburger {
  width: 12px;
  height: 9px;
  background:
    linear-gradient(currentColor 0 0) 0 0 / 100% 1.5px no-repeat,
    linear-gradient(currentColor 0 0) 0 50% / 100% 1.5px no-repeat,
    linear-gradient(currentColor 0 0) 0 100% / 100% 1.5px no-repeat;
}

#account-menu {
  position: absolute;
  top: calc(100% + 0.4rem);
  right: 0;
  /* Above the comm log it hangs over. */
  z-index: 10;
  width: 15rem;
  display: grid;
  gap: 0.5rem;
  padding: 0.6rem;
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: 3px;
  box-shadow: 0 8px 20px rgb(0 0 0 / 50%);
}
/* `display` above would otherwise outrank the attribute. */
#account-menu[hidden] {
  display: none;
}

#login {
  display: grid;
  gap: 0.4rem;
  font-weight: 400;
}

#remember-label {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  color: var(--dim);
  cursor: pointer;
  white-space: nowrap;
}

#account-links {
  display: grid;
  gap: 0.3rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--rule);
  font-weight: 400;
}
#account-links a {
  color: var(--dim);
  text-decoration: none;
}
#account-links a:hover {
  color: var(--accent);
  text-decoration: underline;
}

/* The rule below dresses text fields; a checkbox wants none of it. */
#login input[type="checkbox"] {
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  width: auto;
  accent-color: var(--accent);
  cursor: pointer;
}

input:not([type="checkbox"]),
button {
  background: #0e1319;
  color: var(--fg);
  border: 1px solid var(--rule);
  padding: 0.25rem 0.4rem;
  font: inherit;
  font-weight: 400;
  border-radius: 2px;
}

input::placeholder {
  color: var(--dim);
}

button {
  cursor: pointer;
  font-weight: 700;
}
button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ---- communications log ---------------------------------------------- */

#comm {
  height: 7.5rem;
  overflow-y: auto;
  padding: 0.3rem 0.6rem;
  background: var(--panel);
  border-bottom: 1px solid var(--rule);
  font-size: 11px;
  line-height: 1.45;
}

.comm-line {
  display: flex;
  gap: 0.6rem;
}

.comm-time {
  flex: 0 0 4.5rem;
  color: var(--gold);
  font-weight: 700;
  text-align: right;
}

.comm-text {
  color: var(--gold);
  font-weight: 700;
}

/* ---- console --------------------------------------------------------- */

/* The four consoles occupy one cell and are stacked in it, so switching
   shows a different one without anything moving. */
#consoles {
  display: grid;
  min-height: 0;
}

.console {
  grid-area: 1 / 1;
  overflow-y: auto;
  /* The whole area is the terminal: a click in it takes the caret, so the
     cursor says so over the blank space below the last line too. */
  cursor: text;
  padding: 0.4rem 0;
  /* Script output is whitespace-significant. */
  white-space: pre-wrap;
  word-break: break-word;
  min-height: 0;
  /* Hidden rather than `display: none`: an inactive console stays laid out,
     so it keeps its scroll position and its scripts keep measuring against
     the width they will be shown at. */
  visibility: hidden;
}

.console.active {
  visibility: visible;
}

/* Spacing measured off the client: lines sit 19px apart, output is indented
   by `PreSpaceWidth` (600 twips, which is 40px at 96dpi) past a 4px gutter,
   and a `noprespace` line keeps only the gutter. Bold is the console's
   default weight, so anything not carrying its own run styling inherits it. */
.line {
  /* 19px between lines of the default 10pt text. Unitless so a line carrying
     a larger run -- the startup banner is 48pt -- grows to hold it. */
  min-height: 19px;
  line-height: 1.425;
  /* The console's own face, which a line without run styling of its own --
     a blank one, an echo, the prompt -- is drawn in. */
  font-family: Verdana, "DejaVu Sans", system-ui, sans-serif;
  font-size: 10pt;
  font-weight: 700;
  padding: 0 0.6rem 0 calc(var(--gutter) + var(--prespace));
}

/* `noprespace` removes the console's usual left indent. */
.line.no-prespace {
  padding-left: var(--gutter);
}

.align-center {
  text-align: center;
}
.align-right {
  text-align: right;
}

.line.system {
  color: var(--dim);
}
/* An echoed line: what was typed reads as ordinary text, and only the prompt
   in front of it is coloured. */
.line.echo {
  color: #ffffff;
}
.prompt-echo {
  color: var(--prompt);
  font-weight: 700;
  white-space: pre-wrap;
}
.prompt-echo.script {
  color: inherit;
  font-weight: inherit;
}
.line.error {
  color: var(--error);
}
/* Ctrl+B, which the client reports in the same orange it always has. */
.line.stopped {
  color: #ff9a3d;
}

@keyframes blink {
  50% {
    opacity: 0.15;
  }
}
.flash {
  animation: blink 1s step-start infinite;
}
.flash-fast {
  animation: blink 0.35s step-start infinite;
}
.flash-slow {
  animation: blink 2s step-start infinite;
}

@media (prefers-reduced-motion: reduce) {
  .flash,
  .flash-fast,
  .flash-slow {
    animation: none;
  }
}

/* ---- input ----------------------------------------------------------- */

/* The last line of the log, not a bar beneath it. It inherits `.line`
   padding, so the prompt sits in the same column as everything above it. */
.entry {
  display: flex;
  align-items: baseline;
}

/* A script's own prompt is part of its output and is coloured like it; the
   shell's `/home>` keeps the accent. */
.prompt {
  color: var(--prompt);
  font-weight: 700;
  white-space: pre-wrap;
}
.prompt.script {
  color: inherit;
  font-weight: inherit;
}
.prompt:empty {
  display: none;
}

/* Scoped to the entry so it outweighs the rule that dresses the sign-in
   fields: the console's own input is part of the log, not a form control. */
.entry .input {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  color: inherit;
  font: inherit;
  padding: 0;
}
.entry .input:focus {
  outline: none;
}
/* Hidden rather than dimmed while a script is running: a terminal shows no
   caret when it is not listening. */
.entry.idle {
  display: none;
}

/* ---- the sub-windows ------------------------------------------------- */

/* Mail, the editor and the library share a frame: a title bar to drag them
   by, a body, and a status line. */
#mail,
#editor,
#library {
  padding: 0;
  border: 1px solid var(--rule);
  border-radius: 3px;
  background: var(--bg);
  color: var(--fg);
  font-size: 12px;
  max-width: none;
  max-height: none;
}
#mail:not([open]),
#editor:not([open]),
#library:not([open]) {
  display: none;
}
#mail::backdrop,
#editor::backdrop,
#library::backdrop {
  background: rgb(0 0 0 / 60%);
}
#mail[open],
#editor[open],
#library[open] {
  display: grid;
  /* Title bar, body, status line. */
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-height: 0;
}

#mail {
  width: min(56rem, 90vw);
  height: min(38rem, 85vh);
}
#editor {
  width: min(72rem, 94vw);
  height: min(46rem, 90vh);
}
#library {
  width: min(72rem, 94vw);
  height: min(42rem, 88vh);
}

/* The title bar is the handle. Nothing in it should select as it is
   dragged, and the cursor says so before the drag starts. */
.win-drag {
  cursor: move;
  user-select: none;
  touch-action: none;
}
.win-drag.dragging {
  cursor: grabbing;
}

/* ---- mail ------------------------------------------------------------ */

.mail-bar {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.6rem;
  background: var(--titlebar);
  border-bottom: 1px solid var(--rule);
}

.mail-spacer {
  flex: 1;
}

.mail-button {
  font-size: 11px;
  padding: 0.15rem 0.5rem;
}
.mail-button:disabled {
  color: var(--dim);
  cursor: default;
  border-color: transparent;
}

/* The list, and the message under it when one is open. */
.mail-body {
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  min-height: 0;
}
.mail-body:has(.mail-read) {
  grid-template-rows: minmax(6rem, 2fr) minmax(0, 3fr);
}

.mail-list {
  overflow-y: auto;
  min-height: 0;
}

.mail-empty {
  margin: 0;
  padding: 0.6rem;
  color: var(--dim);
}

/* A row, laid out as the original's three columns. */
.mail-row {
  display: grid;
  grid-template-columns: 12rem 1fr 9rem;
  gap: 0.6rem;
  width: 100%;
  padding: 0.2rem 0.6rem;
  border: none;
  border-radius: 0;
  background: transparent;
  color: var(--fg);
  font-weight: 400;
  text-align: left;
}
.mail-row:hover {
  background: var(--panel);
  color: var(--fg);
}
/* Unread is bold, which is the only mark the original gives it. */
.mail-row.unread {
  font-weight: 700;
  color: #ffffff;
}
.mail-row.current {
  background: var(--panel);
  box-shadow: inset 2px 0 0 var(--accent);
}

.mail-from {
  color: var(--gold);
}
.mail-subject,
.mail-date {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.mail-date {
  color: var(--dim);
  text-align: right;
}

.mail-read {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 0;
  border-top: 1px solid var(--rule);
  background: var(--panel);
}

.mail-read-head {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 0.3rem 0.6rem;
  padding: 0.4rem 0.6rem;
  border-bottom: 1px solid var(--rule);
}
.mail-read-subject {
  font-weight: 700;
  color: #ffffff;
}
.mail-read-meta {
  grid-row: 2;
  color: var(--dim);
}
.mail-read-head .mail-button {
  grid-row: 1 / span 2;
  grid-column: 2;
}

.mail-read-body {
  margin: 0;
  padding: 0.6rem;
  overflow: auto;
  min-height: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: "Courier New", "Liberation Mono", monospace;
  font-size: 12px;
}

.mail-compose {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  gap: 0.4rem;
  padding: 0.6rem;
  min-height: 0;
}

.mail-field {
  display: grid;
  grid-template-columns: 5rem 1fr;
  align-items: center;
  gap: 0.6rem;
  color: var(--dim);
}
.mail-field-body {
  align-items: start;
  min-height: 0;
}
.mail-field textarea {
  height: 100%;
  resize: none;
  background: #0e1319;
  color: var(--fg);
  border: 1px solid var(--rule);
  border-radius: 2px;
  padding: 0.3rem 0.4rem;
  font-family: "Courier New", "Liberation Mono", monospace;
  font-size: 12px;
}

.mail-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.35rem;
}

.mail-status {
  padding: 0.25rem 0.6rem;
  border-top: 1px solid var(--rule);
  background: var(--titlebar);
  color: var(--dim);
  font-size: 11px;
  min-height: 1.5rem;
}

/* ---- the editor ------------------------------------------------------ */

.ed-bar {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.6rem;
  background: var(--titlebar);
  border-bottom: 1px solid var(--rule);
}
.ed-title {
  color: var(--gold);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ed-spacer {
  flex: 1;
}

.ed-main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 17rem;
  min-height: 0;
}

/* The gutter and the code, which scroll together. */
.ed-pane {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  min-height: 0;
  background: #0a0e13;
}

/* Everything that has to line up says so once, here: the two layers of the
   editor and the line numbers are drawn in the same metrics, because the
   highlight sits exactly behind the text it colours. */
.ed-numbers,
.ed-highlight,
.ed-input {
  margin: 0;
  border: 0;
  font-family: "Courier New", "Liberation Mono", monospace;
  font-size: 13px;
  line-height: 1.5;
  letter-spacing: 0;
  tab-size: 4;
  white-space: pre;
}

.ed-gutter {
  overflow: hidden;
  border-right: 1px solid var(--rule);
  background: #0d1219;
}
.ed-numbers {
  padding: 0.5rem 0.5rem 0.5rem 0.7rem;
  color: #4a5462;
  text-align: right;
  user-select: none;
}

.ed-code {
  position: relative;
  overflow: hidden;
  min-width: 0;
}
.ed-highlight {
  position: absolute;
  top: 0;
  left: 0;
  min-width: 100%;
  width: max-content;
  padding: 0.5rem 0.7rem;
  color: var(--fg);
  pointer-events: none;
}
.ed-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: 0.5rem 0.7rem;
  resize: none;
  overflow: auto;
  background: transparent;
  /* The text itself is drawn by the layer underneath; only the caret and
     the selection belong to the textarea. */
  color: transparent;
  caret-color: var(--accent);
  border-radius: 0;
}
.ed-input:focus {
  outline: none;
}
.ed-input::selection {
  background: #2b4a6b;
}

/* The colours. Comments recede, strings and the game's own markup stand
   apart, and a name the interpreter knows is lit differently from one it
   does not -- which is how a typo shows itself. */
.tok-comment {
  color: #5f6c7b;
  font-style: italic;
}
.tok-string {
  color: #c8a55b;
}
.tok-markup {
  color: #d8622f;
  font-weight: 700;
}
.tok-number {
  color: #b48ce0;
}
.tok-keyword {
  color: #4aa3ff;
  font-weight: 700;
}
.tok-builtin {
  color: #43c9b0;
}
.tok-constant {
  color: #b48ce0;
}
.tok-api {
  color: var(--accent);
}
.tok-member {
  color: #9fd4ff;
}
.tok-op {
  color: #8e99a8;
}
.tok-continuation {
  color: var(--gold);
  font-weight: 700;
}

/* The API reference, which is the original's command list brought forward. */
.ed-ref {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-height: 0;
  border-left: 1px solid var(--rule);
  background: var(--panel);
}
.ed-search {
  margin: 0.4rem;
  width: calc(100% - 0.8rem);
}
.ed-list {
  overflow-y: auto;
  min-height: 0;
}
.ed-ref-row {
  display: block;
  width: 100%;
  padding: 0.15rem 0.5rem;
  border: none;
  border-radius: 0;
  background: transparent;
  color: var(--fg);
  font-weight: 400;
  text-align: left;
}
.ed-ref-row:hover {
  background: #1f2731;
}
.ed-ref-name {
  color: var(--accent);
}
.ed-ref-args {
  display: block;
  color: var(--dim);
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ed-ref-foot {
  margin: 0;
  padding: 0.3rem 0.5rem;
  border-top: 1px solid var(--rule);
  color: var(--dim);
  font-size: 11px;
}

.ed-status {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.25rem 0.6rem;
  border-top: 1px solid var(--rule);
  background: var(--titlebar);
  color: var(--dim);
  font-size: 11px;
  min-height: 1.6rem;
}
.ed-hint {
  color: var(--accent);
  font-family: "Courier New", "Liberation Mono", monospace;
}
.ed-position,
.ed-state {
  white-space: nowrap;
}

/* ---- the file library ------------------------------------------------- */

.lib-body {
  display: grid;
  grid-template-columns: 12rem minmax(0, 1fr);
  min-height: 0;
}

.lib-categories {
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  min-height: 0;
  border-right: 1px solid var(--rule);
  background: var(--panel);
}
.lib-category {
  border: none;
  border-radius: 0;
  background: transparent;
  color: var(--fg);
  font-weight: 400;
  text-align: left;
  padding: 0.25rem 0.6rem;
}
.lib-category:hover {
  background: #1f2731;
}
.lib-category.current {
  color: var(--gold);
  box-shadow: inset 2px 0 0 var(--accent);
}

.lib-table {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 0;
}
.lib-table:has(.lib-detail) {
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.lib-rows {
  overflow-y: auto;
  min-height: 0;
}

.lib-row {
  display: grid;
  grid-template-columns: minmax(0, 3fr) 5rem 6rem 8rem minmax(0, 2fr) 7rem;
  gap: 0.4rem;
  width: 100%;
  padding: 0.2rem 0.6rem;
  border: none;
  border-radius: 0;
  background: transparent;
  color: var(--fg);
  font-weight: 400;
  text-align: left;
}
.lib-row:hover {
  background: var(--panel);
}
.lib-row.current {
  background: var(--panel);
  box-shadow: inset 2px 0 0 var(--accent);
}
.lib-head {
  border-bottom: 1px solid var(--rule);
  background: var(--titlebar);
  padding: 0;
}
.lib-cell {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.lib-sort {
  border: none;
  border-radius: 0;
  background: transparent;
  color: var(--dim);
  text-align: left;
  padding: 0.2rem 0;
  font-size: 11px;
}
.lib-sort.sorted {
  color: var(--gold);
}
.lib-arrow {
  font-size: 9px;
}

/* Two columns rather than six: an upload is an id and a rendered line. */
.lib-mine {
  grid-template-columns: 5rem minmax(0, 1fr);
}

.lib-detail {
  border-top: 1px solid var(--rule);
  background: var(--panel);
  padding: 0.5rem 0.6rem;
}
.lib-detail-title {
  font-weight: 700;
  color: #ffffff;
}
.lib-detail-meta {
  color: var(--dim);
}
.lib-detail-body {
  margin: 0.4rem 0;
  white-space: pre-wrap;
}

.lib-panel,
.lib-form {
  display: grid;
  align-content: start;
  gap: 0.4rem;
  padding: 0.6rem;
  min-height: 0;
}
.lib-panel {
  grid-template-rows: auto auto minmax(0, 1fr) auto;
}
.lib-heading {
  margin: 0;
  font-size: 13px;
  color: var(--gold);
}
.lib-note {
  margin: 0;
  color: var(--dim);
}

.lib-channel {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--dim);
}
.lib-channel input {
  width: 6rem;
}

.lib-text {
  min-height: 0;
  height: 100%;
  resize: none;
  background: #0e1319;
  color: var(--fg);
  border: 1px solid var(--rule);
  border-radius: 2px;
  padding: 0.4rem;
  font-family: "Courier New", "Liberation Mono", monospace;
  font-size: 12px;
}

.mail-button.current {
  color: var(--gold);
  border-color: var(--accent);
}

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

#statusbar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.25rem 0.6rem;
  background: var(--titlebar);
  border-top: 1px solid var(--rule);
  font-size: 11px;
  color: var(--dim);
}

#hint b {
  color: var(--accent);
}

/* The library has no command in the original either: it is opened from the
   console's own furniture, which here is the status bar. */
#open-library {
  padding: 0.05rem 0.4rem;
  font-size: 11px;
  background: transparent;
  border-color: transparent;
  color: var(--dim);
}
#open-library:hover {
  color: var(--gold);
  border-color: var(--rule);
}

#tabs {
  margin-left: auto;
  display: flex;
  gap: 0.15rem;
}

.tab {
  min-width: 1.4rem;
  padding: 0.05rem 0.3rem;
  font-size: 11px;
  background: transparent;
  border-color: transparent;
  color: var(--dim);
}
.tab.active {
  color: var(--gold);
  border-color: var(--rule);
}
