:root {
  --bg: #f4f4f5;
  --surface: #ffffff;
  --border: #dcdce0;
  --text: #18181b;
  --text-muted: #71717a;
  --accent: #2563eb;
  --accent-contrast: #ffffff;
  --alert: #b45309;
  --alert-bg: #fef3c7;
  --ok: #15803d;
  --ok-bg: #dcfce7;
  --key-face: #ffffff;
  --key-face-hover: #eef1f6;
  --key-face-pressed: #2563eb;
  --key-edge: #c9cbd2;
  --key-text: #3f3f46;
  --key-text-hold: #9295a1;
  --key-text-pressed: #ffffff;

  font-family: Inter, Avenir, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color-scheme: light;

  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-text-size-adjust: 100%;
}

:root[data-theme="dark"] {
  --bg: #18181b;
  --surface: #212124;
  --border: #34343a;
  --text: #f4f4f5;
  --text-muted: #a1a1aa;
  --accent: #60a5fa;
  --accent-contrast: #10131a;
  --alert: #fbbf24;
  --alert-bg: #3b2f14;
  --ok: #4ade80;
  --ok-bg: #14321f;
  --key-face: #2a2a2f;
  --key-face-hover: #35353c;
  --key-face-pressed: #60a5fa;
  --key-edge: #45454d;
  --key-text: #d4d4d8;
  --key-text-hold: #82828e;
  --key-text-pressed: #10131a;

  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

/* The app sets data-theme once wasm boots. Until then the page is empty, so
   only its background has to follow the OS to keep the first paint right. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;
  }

  :root:not([data-theme]) body {
    background: #18181b;
    color: #f4f4f5;
  }
}

.shell {
  display: grid;
  grid-template-columns: 200px 1fr;
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 20px 12px;
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 10px 20px;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.brand-tag {
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-contrast);
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.06em;
}

.brand-tag-muted {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.sidebar a {
  padding: 8px 10px;
  border-radius: 6px;
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 500;
}

.sidebar a:hover,
.sidebar a[aria-current="page"] {
  background: var(--bg);
  color: var(--text);
}

.theme-toggle {
  margin-top: auto;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.85rem;
  text-align: left;
  cursor: pointer;
}

.theme-toggle:hover {
  color: var(--text);
  border-color: var(--text-muted);
}

/* Narrow windows: the sidebar becomes a top bar so the board keeps the width. */
@media (max-width: 720px) {
  .shell {
    /* Auto rows share the leftover height by default, which would pad the bar
       out to half the viewport. */
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }

  .sidebar {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    padding: 12px;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .brand {
    padding: 0;
    width: 100%;
  }

  .theme-toggle {
    margin: 0 0 0 auto;
  }

  .content {
    padding: 20px 16px;
  }
}

.content {
  padding: 32px;
  overflow-y: auto;
}

.page {
  max-width: 720px;
}

.page-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

.page-header h1 {
  margin: 0;
  font-size: 1.4rem;
  letter-spacing: -0.02em;
}

/* Trailing control in a page header, e.g. the layout view's Disconnect. */
.header-action {
  margin-left: auto;
}

.section-title {
  margin: 0 0 10px;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.badge {
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 500;
  white-space: nowrap;
}

.badge-alert {
  border-color: transparent;
  background: var(--alert-bg);
  color: var(--alert);
}

.badge-ok {
  border-color: transparent;
  background: var(--ok-bg);
  color: var(--ok);
}

.button {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.85rem;
  white-space: nowrap;
  cursor: pointer;
}

.button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* Connection status, above the device list. */
.status {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 16px;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  background: var(--surface);
}

.status-ok {
  border-left-color: var(--ok);
}

.status-alert {
  border-left-color: var(--alert);
}

.status-muted {
  border-left-color: var(--border);
  color: var(--text-muted);
  font-size: 0.9rem;
}

.status-title {
  font-weight: 600;
}

.status-detail {
  color: var(--text-muted);
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}

/* Auto-connect pin, one board at a time. */
.pin {
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--text-muted);
  font-size: 0.8rem;
  white-space: nowrap;
  cursor: pointer;
}

.pin input {
  accent-color: var(--accent);
  cursor: pointer;
}

.device-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.device {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.device-main {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.device-name {
  font-weight: 600;
}

.device-meta {
  color: var(--text-muted);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}

.empty {
  padding: 48px 24px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  text-align: center;
}

.empty-title {
  margin: 0 0 4px;
  font-weight: 600;
}

.empty-hint {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

a {
  color: var(--accent);
}

.page-wide {
  max-width: 1100px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 20px;
}

.chip {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-muted);
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}

.chip:hover {
  color: var(--text);
}

.chip[aria-pressed="true"] {
  border-color: transparent;
  background: var(--accent);
  color: var(--accent-contrast);
}

/* The web build's connect call to action: the picker needs a click, so the
   button is the page. */
.connect {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.button-primary {
  padding: 10px 20px;
  border-color: transparent;
  background: var(--accent);
  color: var(--accent-contrast);
  font-size: 0.95rem;
  font-weight: 600;
}

.button-primary:hover {
  border-color: transparent;
  color: var(--accent-contrast);
  filter: brightness(1.08);
}

.button:disabled {
  cursor: default;
  opacity: 0.6;
  filter: none;
}

/* A non-blocking aside, e.g. legends that could not be fetched. */
.note {
  margin: 0 0 16px;
  padding: 8px 12px;
  border-radius: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.85rem;
}

.note-alert {
  border-color: transparent;
  background: var(--alert-bg);
  color: var(--alert);
}

.keyboard-stage {
  position: relative;
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}

/* Current layer, always on: the quickest way to see live layer switching. */
.layer-badge {
  position: absolute;
  right: 16px;
  bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
  box-shadow: 0 1px 3px rgb(0 0 0 / 12%);
  font-size: 0.85rem;
  line-height: 1.2;
  user-select: none;
}

.layer-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
}

.layer-number {
  color: var(--text);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.layer-title {
  color: var(--text-muted);
}

.layer-title::before {
  content: "·";
  margin-right: 6px;
}

/* The viewBox aspect drives the height; narrow boards letterbox instead of
   growing to fill the width. */
.keyboard {
  display: block;
  width: 100%;
  height: auto;
  max-height: 60vh;
}

.key-cap {
  fill: var(--key-face);
  stroke: var(--key-edge);
  stroke-width: 2;
}

.key-legend {
  fill: var(--key-text);
  font-family: inherit;
  font-size: 26px;
  font-weight: 500;
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
  user-select: none;
}

.key-legend-hold {
  fill: var(--key-text-hold);
  font-size: 20px;
  font-weight: 400;
}

/* Word-length legends step down so they stay inside the cap. */
.key-legend.is-long {
  font-size: 20px;
}

.key-legend.is-longer {
  font-size: 15px;
}

.key-legend-hold.is-long {
  font-size: 16px;
}

.key-legend-hold.is-longer {
  font-size: 13px;
}

.key:hover .key-cap {
  fill: var(--key-face-hover);
}

.key.is-pressed .key-cap {
  fill: var(--key-face-pressed);
  stroke: var(--key-face-pressed);
}

.key.is-pressed .key-legend {
  fill: var(--key-text-pressed);
}
