/* A night sky, a blue coat, a straw hat and a pair of amber lights. */
:root {
  color-scheme: dark;
  --void: #06070e; /* the page: where text is typed */
  --panel: #10142a;
  --panel-top: #161b36;
  --line: #242b4e;
  --line-soft: #1a2040;
  --coat: #8fa8f5;
  --glow: #ffc857;
  --straw: #d2b27c;
  --moss: #8fcf9b;
  --ember: #ee7b6a;
  --text: #ece6d7;
  --muted: #9094b2;
  --faint: #5f6489;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, P052, "URW Palladio L", "Book Antiqua", "Noto Serif", Georgia, serif;
  --sans: system-ui, "Segoe UI", "Noto Sans", sans-serif;
  --mono: "JetBrains Mono", "Cascadia Code", "Fira Code", ui-monospace, Menlo, Consolas, "Noto Sans Mono", monospace;
}

* {
  box-sizing: border-box;
  scrollbar-width: thin;
  scrollbar-color: #2c3462 transparent;
}

/* `hidden` must win over the display values set below. */
[hidden] {
  display: none !important;
}

::selection {
  background: rgb(255 200 87 / 28%);
}

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

body {
  display: flex;
  flex-direction: column;
  color: var(--text);
  font: 14px/1.45 var(--sans);
  background: var(--void);
}

:focus-visible {
  outline: 2px solid rgb(255 200 87 / 70%);
  outline-offset: 2px;
}

/* --------------------------------------------------------- the handle */

/* A tab hanging from the top edge. The terminal leaves this strip clear. */
#top {
  position: fixed;
  inset: 0 0 auto;
  z-index: 5;
  display: flex;
  justify-content: center;
  pointer-events: none;
}

#menu-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 25px;
  padding: 0 12px 1px 11px;
  font: 500 12.5px/1 var(--sans);
  color: var(--muted);
  background: linear-gradient(180deg, var(--panel-top), var(--panel));
  border: 1px solid var(--line);
  border-top: 0;
  border-radius: 0 0 11px 11px;
  box-shadow: 0 6px 18px rgb(0 0 0 / 45%);
  pointer-events: auto;
}

#menu-button:hover,
#menu-button:has(+ #menu:popover-open) {
  color: var(--text);
  border-color: #3a4885;
  box-shadow: 0 6px 18px rgb(0 0 0 / 45%);
}

#menu-button:active {
  translate: none;
}

.spark {
  width: 15px;
  height: 15px;
  fill: var(--glow);
  filter: drop-shadow(0 0 6px rgb(255 200 87 / 75%));
}

/* The handle's spark is the machine's light: lit while it runs. */
#menu-button .spark {
  width: 11px;
  height: 11px;
}

#menu-button[data-phase="starting"] .spark {
  animation: wake 1.1s ease-in-out infinite;
}

#menu-button[data-phase="stopped"] .spark {
  fill: var(--faint);
  filter: none;
}

#menu-button[data-phase="failed"] .spark {
  fill: var(--ember);
  filter: none;
}

.caret {
  width: 6px;
  height: 6px;
  margin: -3px 0 0 1px;
  border: solid var(--faint);
  border-width: 0 1.5px 1.5px 0;
  rotate: 45deg;
}

/* ----------------------------------------------------------- the menu */

#menu {
  position: fixed;
  inset: 31px auto auto 50%;
  translate: -50% 0;
  width: min(390px, calc(100vw - 20px));
  max-height: calc(100vh - 44px);
  margin: 0;
  padding: 16px 12px 10px;
  overflow: auto;
  color: var(--text);
  background: linear-gradient(180deg, #1b2245, #121730);
  border: 1px solid #303b6e;
  border-radius: 16px;
  box-shadow:
    inset 0 1px 0 rgb(255 255 255 / 6%),
    0 30px 90px rgb(0 0 0 / 70%);
}

#menu:popover-open {
  animation: drop 0.16s ease-out;
}

@keyframes drop {
  from {
    opacity: 0;
    translate: -50% -8px;
  }
}

.brand {
  display: flex;
  align-items: baseline;
  margin: 0 6px 12px;
  font: 600 19px/1 var(--serif);
  letter-spacing: 0.01em;
}

.brand .spark {
  align-self: center;
  margin-right: 9px;
}

.brand-harness {
  margin-left: 6px;
  font-size: 14px;
  font-style: italic;
  font-weight: 400;
  color: var(--straw);
}

/* The machine switcher: one row per machine, the same in every browser tab. */
#machines {
  display: grid;
  gap: 2px;
}

/* ------------------------------------------------------------ buttons */

button {
  padding: 7px 15px;
  font: 600 13px/1.3 var(--sans);
  color: #201703;
  background: linear-gradient(180deg, #ffd780, #f5b942);
  border: 1px solid transparent;
  border-radius: 8px;
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 40%);
  cursor: pointer;
  transition:
    box-shadow 0.15s,
    background 0.15s,
    border-color 0.15s,
    color 0.15s;
}

button:hover:not(:disabled) {
  box-shadow:
    inset 0 1px 0 rgb(255 255 255 / 40%),
    0 0 18px rgb(255 200 87 / 38%);
}

button:active:not(:disabled) {
  translate: 0 1px;
}

button:disabled {
  opacity: 0.4;
  cursor: default;
}

button.ghost,
.toast button {
  padding: 6px 13px;
  font-weight: 500;
  color: var(--text);
  background: rgb(255 255 255 / 3%);
  border-color: var(--line);
  box-shadow: none;
}

button.ghost:hover:not(:disabled),
.toast button:hover {
  background: rgb(255 255 255 / 8%);
  border-color: #3a4885;
  box-shadow: none;
}

button.ghost.danger {
  color: var(--ember);
}

button.ghost.danger:hover:not(:disabled) {
  background: rgb(238 123 106 / 10%);
  border-color: rgb(238 123 106 / 45%);
}

button.add,
.chip {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  height: 36px;
  padding: 0 12px;
  font-weight: 500;
  font-size: 13.5px;
  text-align: left;
  color: var(--muted);
  background: none;
  border-radius: 9px;
  box-shadow: none;
}

button.add:hover:not(:disabled),
.chip:hover:not(:disabled) {
  color: var(--text);
  background: rgb(255 255 255 / 5%);
  box-shadow: none;
}

button.add:active:not(:disabled),
.chip:active:not(:disabled) {
  translate: none;
}

button.add {
  margin-top: 2px;
}

button.add::before {
  content: "+";
  width: 8px;
  font-weight: 600;
  text-align: center;
  color: var(--glow);
}

.chip[aria-selected="true"] {
  color: var(--text);
  background: linear-gradient(180deg, #2a366b, #1f2853);
  border-color: #3a4885;
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 7%);
}

.chip small {
  margin-left: auto;
  font-size: 11px;
  letter-spacing: 0.04em;
  color: var(--faint);
}

.chip[aria-selected="true"] small {
  color: #9da6d3;
}

/* A light that is on while the machine is awake. */
.dot {
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  box-shadow: inset 0 0 0 1.5px var(--faint);
}

.dot.running {
  background: var(--glow);
  box-shadow:
    0 0 0 3px rgb(255 200 87 / 14%),
    0 0 10px 1px rgb(255 200 87 / 80%);
}

.dot.starting {
  background: var(--glow);
  box-shadow: none;
  animation: wake 1.1s ease-in-out infinite;
}

.dot.failed {
  background: var(--ember);
  box-shadow: 0 0 0 3px rgb(238 123 106 / 16%);
}

@keyframes wake {
  0%,
  100% {
    opacity: 0.25;
  }
  50% {
    opacity: 1;
  }
}

/* ------------------------------------- the selected machine, in the menu */

#machine-bar {
  margin-top: 10px;
  padding: 12px 6px 4px;
  border-top: 1px solid rgb(255 255 255 / 7%);
}

.machine-line {
  display: flex;
  align-items: center;
  gap: 10px;
}

.machine-line h2 {
  overflow: hidden;
  font-size: 17px;
  white-space: nowrap;
  text-overflow: ellipsis;
  color: var(--text);
}

.spacer {
  flex: 1;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex: none;
  height: 26px;
  padding: 0 12px 0 10px;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--muted);
  background: rgb(255 255 255 / 3%);
  border: 1px solid var(--line);
  border-radius: 999px;
}

.pill::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

.pill.ready {
  color: var(--glow);
  background: rgb(255 200 87 / 7%);
  border-color: rgb(255 200 87 / 32%);
}

.pill.ready::before {
  box-shadow: 0 0 8px var(--glow);
}

.pill.booting {
  color: var(--straw);
}

.pill.booting::before {
  animation: wake 1.1s ease-in-out infinite;
}

.pill.failed {
  color: var(--ember);
  background: rgb(238 123 106 / 8%);
  border-color: rgb(238 123 106 / 40%);
}

.pill.stopped::before {
  background: none;
  box-shadow: inset 0 0 0 1.5px currentColor;
}

.facts {
  display: flex;
  flex-wrap: wrap;
  gap: 0 16px;
  margin-top: 9px;
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--muted);
}

.fact {
  white-space: nowrap;
}

.fact.bad {
  white-space: normal;
}

.fact.bad {
  color: var(--ember);
}

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

main {
  flex: 1;
  min-height: 0;
}

.view {
  position: relative;
  height: 100%;
}

.terminal {
  position: absolute;
  inset: 0;
}

/* The top padding is the strip the handle hangs in. */
.terminal .xterm {
  height: 100%;
  padding: 31px 4px 8px 14px;
}

/* xterm paints these black by default, which shows as a seam around the text. */
.terminal .xterm,
.terminal .xterm .xterm-viewport {
  background-color: var(--void) !important;
}

h2 {
  margin: 0;
  font: 600 15px/1.2 var(--serif);
  letter-spacing: 0.015em;
  color: var(--straw);
}

.keys {
  display: block;
  margin: 12px 6px 0;
  padding-top: 10px;
  font-size: 11px;
  color: var(--faint);
  border-top: 1px solid rgb(255 255 255 / 7%);
}

.keys i::before {
  content: "·";
  margin: 0 6px;
  font-style: normal;
}

kbd {
  margin-right: 3px;
  padding: 1px 5px;
  font: 10.5px var(--sans);
  color: var(--muted);
  background: rgb(255 255 255 / 4%);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
}

/* What the terminal's place says while the machine is not running. */
.term-cover {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 8px;
  padding: 24px;
  text-align: center;
  background: var(--void);
}

.term-cover .spark {
  width: 26px;
  height: 26px;
  margin-bottom: 10px;
  fill: var(--faint);
  filter: none;
}

.term-cover[data-phase="starting"] .spark {
  fill: var(--glow);
  filter: drop-shadow(0 0 8px rgb(255 200 87 / 80%));
  animation: wake 1.1s ease-in-out infinite;
}

.term-cover[data-phase="failed"] .spark {
  fill: var(--ember);
}

.cover-title {
  margin: 0;
  font: 22px/1.3 var(--serif);
}

.cover-detail {
  max-width: 52ch;
  font-size: 13px;
  color: var(--muted);
}

.cover-detail:empty {
  display: none;
}

.cover-start {
  margin-top: 14px;
}

/* ---------------------------------------------------------- the rest */

#empty {
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 6px;
  height: 100%;
  color: var(--faint);
}

#empty .spark {
  width: 26px;
  height: 26px;
  margin-bottom: 10px;
}

#empty p {
  margin: 0;
  font: 22px var(--serif);
  color: var(--text);
}

#empty small:empty {
  display: none;
}

#empty button {
  margin-top: 16px;
}

dialog {
  width: min(410px, 92vw);
  padding: 0;
  color: var(--text);
  background: linear-gradient(180deg, #1b2245, #121730);
  border: 1px solid #303b6e;
  border-radius: 16px;
  box-shadow:
    inset 0 1px 0 rgb(255 255 255 / 6%),
    0 30px 90px rgb(0 0 0 / 65%);
}

dialog::backdrop {
  background: rgb(4 5 12 / 66%);
  backdrop-filter: blur(3px);
}

dialog form {
  padding: 24px 24px 20px;
}

dialog h2 {
  font-size: 22px;
  color: var(--text);
}

dialog .hint {
  margin: 6px 0 18px;
  font-size: 13px;
  color: var(--muted);
}

dialog label {
  display: grid;
  gap: 6px;
  margin-bottom: 14px;
  font-size: 12px;
  letter-spacing: 0.02em;
  color: var(--muted);
}

dialog input,
dialog select {
  padding: 9px 11px;
  font: 14px var(--sans);
  color: var(--text);
  background: var(--void);
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: 0;
  transition:
    border-color 0.15s,
    box-shadow 0.15s;
}

dialog input::placeholder {
  color: var(--faint);
}

dialog select {
  padding-right: 36px;
  appearance: none;
  background: var(--void)
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' fill='none' stroke='%239094b2' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M1.5 1.5 6 6l4.5-4.5'/%3E%3C/svg%3E")
    no-repeat right 13px center;
}

dialog input:focus,
dialog select:focus {
  outline: 0;
  border-color: rgb(255 200 87 / 50%);
  box-shadow: 0 0 0 3px rgb(255 200 87 / 9%);
}

dialog menu {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin: 22px 0 0;
  padding: 0;
}

#toasts {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: min(370px, calc(100vw - 36px));
}

.toast {
  padding: 11px 14px 11px 15px;
  font-size: 13px;
  overflow-wrap: anywhere;
  background: linear-gradient(180deg, #1d2549, #151b39);
  border: 1px solid #303b6e;
  border-left: 3px solid var(--glow);
  border-radius: 10px;
  box-shadow: 0 16px 44px rgb(0 0 0 / 55%);
  animation: rise 0.22s ease-out;
}

@keyframes rise {
  from {
    opacity: 0;
    translate: 0 8px;
  }
}

.toast.ask {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
  align-items: center;
}

.toast.ask div,
.toast.ask strong {
  grid-column: 1 / -1;
}

.toast.ask div {
  color: var(--muted);
}

.toast.ask strong {
  margin-bottom: 6px;
  font: 600 14px var(--mono);
}

.toast.ask a {
  font-weight: 600;
  color: var(--glow);
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}
