* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #0b0e14;
  --panel: #131821;
  --panel-2: #1a202b;
  --border: #262d3a;
  --text: #e8ecf2;
  --muted: #98a2b3;
  --faint: #5b6577;
  --accent: #f6821f;
  --accent-strong: #ff9d3d;
  --ok: #2ea043;
  --info: #58a6ff;
  --warn: #d29922;
  --bad: #da3633;
  --mono: "SF Mono", "Cascadia Mono", Consolas, "Liberation Mono", monospace;
  --radius: 12px;
  color-scheme: dark;
}

html { scroll-behavior: smooth; }
/* An element that is hidden stays hidden, whatever display its class gives it */
[hidden] { display: none !important; }

body {
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

a { color: inherit; }
button, input, select { font: inherit; color: inherit; }

button, .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.15s;
}
button:hover:not(:disabled), .button:hover { border-color: var(--accent); }
button:disabled { opacity: 0.6; cursor: default; }
.primary { background: var(--accent); border-color: var(--accent); color: #1a0f02; font-weight: 650; }
.primary:hover:not(:disabled) { background: var(--accent-strong); border-color: var(--accent-strong); }
.danger:hover:not(:disabled) { border-color: var(--bad); color: #ff7b72; }
.large { padding: 11px 22px; font-size: 15px; border-radius: 10px; }

input, select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 14px;
}
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--muted);
  white-space: nowrap;
}
.badge.good { color: #6fdd8b; border-color: #1f5f31; background: #10291a; }
.badge.warn { color: #e3b341; border-color: #5a4610; background: #271f08; }

/* Landing page */

body.home {
  background:
    radial-gradient(900px 420px at 78% -80px, rgba(246, 130, 31, 0.16), transparent 70%),
    radial-gradient(700px 380px at 0% 0%, rgba(88, 166, 255, 0.06), transparent 70%),
    var(--bg);
  background-repeat: no-repeat;
}

.home main, .top, .home footer { max-width: 1120px; margin: 0 auto; padding: 0 24px; }

.top { display: flex; align-items: center; justify-content: space-between; padding-top: 18px; padding-bottom: 6px; }
.logo img { height: 46px; display: block; }
.top nav { display: flex; gap: 22px; font-size: 14px; }
.top nav a { color: var(--muted); text-decoration: none; }
.top nav a:hover { color: var(--text); }

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
  gap: 48px;
  align-items: center;
  padding: 56px 0 64px;
}
.hero h1 { font-size: clamp(34px, 5vw, 54px); line-height: 1.06; letter-spacing: -0.03em; font-weight: 750; }
.hero h1 span { color: var(--accent); }
.hero p { color: var(--muted); font-size: 17px; margin-top: 18px; max-width: 34em; }
.hero-actions { display: flex; gap: 12px; margin-top: 28px; flex-wrap: wrap; }
.facts { display: flex; gap: 28px; list-style: none; margin-top: 34px; color: var(--muted); font-size: 13px; flex-wrap: wrap; }
.facts b { display: block; color: var(--text); font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }

/* A screen: a picture, or the text of a text mode, in a frame like a monitor */
.screen {
  aspect-ratio: 4 / 3;
  background: #000;
  border-radius: 6px;
  overflow: hidden;
  display: flex;
}
.screen img { width: 100%; height: 100%; object-fit: cover; object-position: top left; image-rendering: auto; }
.screen pre {
  flex: 1;
  padding: 8px 10px;
  font-family: var(--mono);
  font-size: 9px;
  line-height: 1.35;
  color: #b9c0cc;
  white-space: pre;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}
.no-screen { margin: auto; color: var(--faint); font-size: 12px; }

.monitor {
  background: linear-gradient(180deg, #232a36, #171c25);
  border: 1px solid #333c4b;
  border-radius: 16px;
  padding: 14px 14px 10px;
  box-shadow: 0 30px 80px -30px rgba(246, 130, 31, 0.35), 0 10px 30px rgba(0, 0, 0, 0.5);
}
.monitor .screen pre { font-size: 11px; }
.monitor figcaption { font-size: 11px; color: var(--faint); text-align: center; padding-top: 8px; }

.home section { padding: 28px 0; }
.home h2 { font-size: 22px; letter-spacing: -0.02em; font-weight: 700; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.section-head input { width: 220px; }

.chips { display: flex; gap: 8px; margin: 16px 0 20px; flex-wrap: wrap; }
.chip { border-radius: 999px; color: var(--muted); }
.chip[aria-pressed="true"] { background: var(--text); border-color: var(--text); color: var(--bg); }

.systems { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 16px; }
.system {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  text-align: left;
  padding: 10px;
  gap: 12px;
  background: var(--panel);
  border-radius: var(--radius);
  font-weight: 400;
}
.system.unready { opacity: 0.6; }
.system.unready:hover { opacity: 1; }
.system:hover:not(:disabled) { transform: translateY(-2px); background: var(--panel-2); }
.system-text { padding: 0 4px 4px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.system h3 { font-size: 15px; font-weight: 650; }
.system p { font-size: 13px; color: var(--muted); line-height: 1.4; flex: 1; }
.system-meta { display: flex; align-items: center; gap: 8px; font-size: 11px; color: var(--faint); flex-wrap: wrap; }
.empty { color: var(--muted); padding: 24px 0; }

.mine { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.mine-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
}
.mine-name { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.mine-name code { font-family: var(--mono); font-size: 11px; color: var(--faint); }

.own {
  margin-top: 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}
.own p { grid-column: 1 / -1; color: var(--muted); font-size: 14px; }
.own label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); }
.own .wide { grid-column: 1 / -1; }
.own .check { flex-direction: row; align-items: center; gap: 8px; font-size: 14px; color: var(--text); }
.own .row { grid-column: 1 / -1; display: flex; align-items: center; gap: 14px; }
.own .error { color: #ff7b72; font-size: 13px; }

.how { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; margin-top: 14px; }
.how article { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.how h3 { font-size: 15px; margin-bottom: 6px; }
.how p { font-size: 14px; color: var(--muted); }

.home footer { color: var(--faint); font-size: 13px; padding-top: 28px; padding-bottom: 48px; }
.home footer a { color: var(--muted); }

/* Machine page */

body.machine { height: 100vh; display: flex; flex-direction: column; overflow: hidden; }

body.machine header {
  padding: 6px 12px;
  min-height: 46px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  flex-wrap: wrap;
}
body.machine .logo img { height: 30px; }
.tools { display: flex; gap: 6px; flex-wrap: wrap; }
.tools button { padding: 5px 10px; font-size: 12px; }
#keyboard { display: none; }
#keyboard[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
@media (pointer: coarse) {
  #keyboard { display: inline-flex; }
  /* A finger moves the pointer without capturing it */
  #hint { display: none; }
}
/* Out of sight, but focusable: it only brings up the keyboard of a phone */
#soft-keyboard { position: fixed; left: 0; bottom: 0; width: 1px; height: 1px; opacity: 0; border: 0; padding: 0; resize: none; }
#hint {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(19, 24, 33, 0.9);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 14px;
  font-size: 12px;
  color: var(--muted);
  pointer-events: none;
  white-space: nowrap;
}
#name { font-size: 13px; font-weight: 600; }
#status {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 12px;
  background: var(--bad);
  color: #fff;
  white-space: nowrap;
}
#status[data-state="running"] { background: var(--ok); }
#status[data-state="restoring"], #status[data-state="optimizing"] { background: var(--info); color: #000; }
#status[data-state="starting"], #status[data-state="saving"] { background: var(--warn); color: #000; }
#status[data-state="stopped"] { background: var(--faint); }
#speed { font-size: 11px; color: var(--muted); font-family: var(--mono); }
.spacer { flex: 1; }

body.machine main { flex: 1; display: flex; min-height: 0; }
#display {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  min-width: 0;
  position: relative;
}
#screen {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
  background: #000;
  outline: none;
}
#overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(11, 14, 20, 0.86);
  backdrop-filter: blur(3px);
  text-align: center;
  padding: 24px;
}
#overlay-title { font-size: 16px; font-weight: 600; }
#overlay-detail { font-size: 13px; color: var(--muted); max-width: 520px; line-height: 1.5; }
.spinner {
  width: 26px;
  height: 26px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

aside {
  width: 250px;
  flex-shrink: 0;
  background: var(--panel);
  border-left: 1px solid var(--border);
  padding: 12px;
  overflow-y: auto;
  font-family: var(--mono);
  font-size: 11px;
}
aside h3 {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 12px 0 6px;
}
aside h3:first-child { margin-top: 0; }
aside div { display: flex; justify-content: space-between; padding: 2px 0; color: var(--muted); }
aside div span:last-child { color: var(--text); }

#serial {
  flex-shrink: 0;
  height: 190px;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border-top: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 12px;
}
#serial-output { flex: 1; overflow-y: auto; padding: 8px 12px; white-space: pre-wrap; word-break: break-all; color: #c9d1d9; }
#serial-input { border: none; border-top: 1px solid var(--border); border-radius: 0; font-family: var(--mono); font-size: 12px; }

@media (max-width: 820px) {
  .hero { grid-template-columns: 1fr; gap: 32px; padding: 32px 0 40px; }
  .top nav a:not(:last-child) { display: none; }
  .own, .how { grid-template-columns: 1fr; }
  .section-head input { width: 150px; }
}
/* On a narrow screen the stats lie over the display, below the toolbar */
@media (max-width: 720px) {
  body.machine main { position: relative; }
  aside { position: absolute; right: 0; top: 0; bottom: 0; z-index: 2; }
}
