:root {
  --bg: #0f0f0f;
  --surface: #161616;
  --text: #ffffff;
  --text-2: rgba(255, 255, 255, 0.62);
  --text-3: rgba(255, 255, 255, 0.42);
  --border: rgba(255, 255, 255, 0.1);
  --border-strong: rgba(255, 255, 255, 0.2);
  --teal: #2bb3b3;
  --warn: #e8a34a;
  --bad: #e8674a;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

header {
  display: flex;
  flex-wrap: wrap;
  gap: 16px 40px;
  align-items: flex-end;
  justify-content: space-between;
  padding: 24px 28px 20px;
  border-bottom: 1px solid var(--border);
}

h1 {
  margin: 0;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.02em;
  text-wrap: balance;
}

.sub { margin: 4px 0 0; color: var(--text-2); max-width: 60ch; }

.status { display: flex; flex-wrap: wrap; gap: 8px 28px; margin: 0; }
.status dt {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-3);
}
.status dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; }
.status dd[data-tone="ok"] { color: var(--teal); }
.status dd[data-tone="warn"] { color: var(--warn); }
.status dd[data-tone="bad"] { color: var(--bad); }

main {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  min-height: 0;
}

.term-wrap {
  min-width: 0;
  min-height: 420px;
  padding: 16px 12px 16px 20px;
  background: #000;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
#term { flex: 1; min-height: 0; }
#unsupported { color: var(--warn); padding: 12px; white-space: pre-wrap; }

aside {
  padding: 20px 24px 28px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

h2 {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-2);
}

.hint { margin: 8px 0 0; font-size: 13px; color: var(--text-3); }
h2 + .hint { margin: 0 0 12px; }

.buttons { display: flex; flex-direction: column; gap: 8px; }

button {
  font: inherit;
  color: var(--text);
  background: transparent;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 9px 12px;
  text-align: left;
  cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--text-2); background: var(--surface); }
button:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }
button:disabled { opacity: 0.4; cursor: not-allowed; }

button .label { display: block; font-weight: 600; }
button code {
  display: block;
  margin-top: 2px;
  font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--text-3);
  overflow-wrap: anywhere;
}

button.quiet { color: var(--text-2); border-color: var(--border); }
button.link {
  border: 0;
  padding: 0;
  margin-top: 8px;
  font-size: 13px;
  color: var(--text-3);
  text-decoration: underline;
}
button.link:hover:not(:disabled) { background: none; color: var(--text-2); }

#log {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 13px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
#log li {
  display: grid;
  grid-template-columns: 62px minmax(0, 1fr);
  gap: 8px;
  color: var(--text-2);
  overflow-wrap: anywhere;
}
#log time { color: var(--text-3); font-variant-numeric: tabular-nums; }
#log li[data-kind="break"] { color: var(--bad); }
#log li[data-kind="safe"], #log li[data-kind="fail"] { color: var(--warn); }
#log li[data-kind="boot"] { color: var(--text); }
#log:empty::after { content: "Nothing yet."; color: var(--text-3); }

footer {
  padding: 14px 28px 18px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-3);
}
footer p { margin: 0 0 4px; max-width: 110ch; }
footer a { color: var(--text-2); }

button.link.inline {
  display: inline;
  margin: 0;
  min-height: 0;
  font-size: inherit;
  color: var(--teal);
  white-space: nowrap;
}
button.link.inline:hover:not(:disabled) { color: var(--text); }
.inline-link { color: var(--teal); white-space: nowrap; }
.inline-link:hover { color: var(--text); }

dialog#how {
  width: min(640px, calc(100vw - 24px));
  max-height: min(86dvh, 760px);
  padding: 0;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  overflow: hidden;
}
dialog#how[open] { display: flex; flex-direction: column; }
dialog#how::backdrop { background: rgba(0, 0, 0, 0.7); }
.how-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.how-head h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
  text-transform: none;
  color: var(--text);
}
.how-head button { text-align: center; padding: 6px 14px; }
.how-body { padding: 4px 20px 20px; overflow-y: auto; overscroll-behavior: contain; }
.how-body h3 {
  margin: 20px 0 6px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-3);
}
.how-body p { margin: 0 0 8px; color: var(--text-2); max-width: 62ch; }
.how-body ul { margin: 0; padding-left: 18px; color: var(--text-2); max-width: 62ch; }
.how-body li { margin-bottom: 6px; }
.how-body strong { color: var(--text); font-weight: 600; }
.how-body a { color: var(--teal); }
.how-credit { margin-top: 20px !important; font-size: 13px; color: var(--text-3) !important; }

/* Touch keys for what a phone keyboard lacks. Shown on touch devices only. */
.keys { display: none; gap: 6px; padding-top: 8px; }
.keys button {
  flex: 1;
  min-height: 44px;
  padding: 0 4px;
  text-align: center;
  font: 600 13px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--text-2);
  background: var(--surface);
  border-color: var(--border);
  touch-action: manipulation;
}
@media (pointer: coarse) {
  .keys { display: flex; }
  button { min-height: 44px; touch-action: manipulation; }
  button.link { min-height: 44px; margin-top: 0; }
  /* iOS zooms the page when a focused input is under 16px. */
  .xterm .xterm-helper-textarea { font-size: 16px; }
}

@media (max-width: 860px) {
  html, body { height: auto; }
  body { display: block; min-height: 100dvh; }
  header { padding: 16px 16px 14px; gap: 12px 24px; }
  h1 { font-size: 24px; }
  .status { gap: 6px 20px; }
  main { display: block; }
  /* The terminal stays in view while the controls scroll under it. */
  .term-wrap {
    position: sticky;
    top: 0;
    z-index: 2;
    height: 46dvh;
    min-height: 240px;
    padding: 8px 8px 8px 10px;
    border-right: 0;
    border-bottom: 1px solid var(--border-strong);
  }
  aside { padding: 20px 16px 24px; overflow: visible; }
  footer {
    padding: 14px 16px calc(18px + env(safe-area-inset-bottom));
  }
}
