:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #1c1e21;
  --muted: #5f6672;
  --border: #d5d9e0;
  --accent: #2463eb;
  --accent-text: #ffffff;
  --ok: #1a7f37;
  --warn: #b26a00;
  --bad: #c62828;
  --idle: #8a919c;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171a;
    --surface: #1e2125;
    --text: #e8eaed;
    --muted: #a0a6b0;
    --border: #353a41;
    --accent: #5b8cff;
    --accent-text: #0b0d10;
    --ok: #4cc26a;
    --warn: #e0a243;
    --bad: #ff6b6b;
    --idle: #7d848e;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
h1 { font-size: 1.25rem; margin: 0; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hidden { display: none !important; }
button {
  font: inherit;
  border: 0;
  border-radius: 8px;
  padding: .55rem 1rem;
  background: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
}
button.secondary { background: transparent; color: var(--text); border: 1px solid var(--border); }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem 1.25rem;
}

/* login */
.login-body { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-card { width: 100%; max-width: 360px; }
.login-card form { display: grid; gap: .4rem; margin-top: .5rem; }
.login-card label { font-weight: 600; margin-top: .4rem; }
.login-card input {
  font: inherit; padding: .55rem .7rem; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
}
.login-card button { margin-top: .9rem; }
.error { color: var(--bad); margin: .5rem 0 0; }

/* app */
.topbar {
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  padding: .75rem 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar .user { margin-left: auto; }
.layout { max-width: 960px; margin: 0 auto; padding: 16px; display: grid; gap: 14px; }
.status-row { display: flex; flex-wrap: wrap; gap: .5rem; }
.pill {
  display: inline-flex; align-items: center; gap: .45rem;
  padding: .35rem .8rem; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border); font-size: .92rem;
}
.dot { width: .65rem; height: .65rem; border-radius: 50%; background: var(--idle); flex: none; }
.pill[data-state="ok"] .dot { background: var(--ok); }
.pill[data-state="warn"] .dot { background: var(--warn); }
.pill[data-state="bad"] .dot { background: var(--bad); }
.hint { margin: 0; color: var(--muted); }

.pad-wrap { position: relative; }
#pad {
  width: 100%; min-height: 280px; resize: vertical;
  font: 1.1rem/1.5 ui-monospace, "Cascadia Mono", Consolas, monospace;
  padding: 1rem; border-radius: 12px;
  border: 2px solid var(--border); background: var(--surface); color: var(--text);
}
#pad:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 25%, transparent); }
.pad-overlay {
  position: absolute; inset: 0; width: 100%;
  display: grid; place-items: center;
  border-radius: 12px; font-size: 1.05rem;
  background: color-mix(in srgb, var(--surface) 80%, transparent);
  color: var(--text); border: 2px dashed var(--border);
}
.pad-wrap.focused .pad-overlay { display: none; }
.pad-actions { display: flex; align-items: center; gap: 1rem; justify-content: space-between; flex-wrap: wrap; }
.notice { min-height: 1.4em; }
.notice[data-kind="error"] { color: var(--bad); }
.notice[data-kind="warn"] { color: var(--warn); }
.notice[data-kind="ok"] { color: var(--ok); }

details summary { cursor: pointer; font-weight: 600; }
.diag { display: grid; grid-template-columns: max-content 1fr; gap: .3rem 1rem; margin: .8rem 0; }
.diag dt { color: var(--muted); }
.diag dd { margin: 0; font-variant-numeric: tabular-nums; }

.devices { list-style: none; padding: 0; margin: 0 0 1rem; display: grid; gap: .5rem; }
.devices li { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }
.devices .name { font-weight: 600; }
.devices button { margin-left: auto; padding: .3rem .8rem; }
.pair-box { margin-top: .8rem; }
.pair-box code {
  font-size: 1.6rem; letter-spacing: .12em; padding: .1rem .5rem;
  border-radius: 6px; background: var(--bg); border: 1px solid var(--border);
}
@media (max-width: 600px) {
  .diag { grid-template-columns: 1fr; }
  .diag dd { margin-bottom: .4rem; }
  #pad { min-height: 200px; }
}

/* test fields page */
.testpad { display: grid; gap: .4rem; }
.testpad label { font-weight: 600; margin-top: .5rem; }
.testpad input, .testpad textarea {
  font: inherit; padding: .55rem .7rem; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
}
