:root {
  --bg: #0b0d12;
  --panel: #141822;
  --key: #1b2130;
  --key-edge: #2a3246;
  --key-down: #2c3f66;
  --text: #e8ecf4;
  --muted: #8b95a8;
  --accent: #4f8cff;
  --ok: #34d399;
  --warn: #fbbf24;
  --bad: #f87171;
  --radius: 18px;
  --gap: 10px;
  --cols: 3;
  --rows: 3;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

button { font: inherit; color: inherit; }

/* ---------- pair screen ---------- */
.pair {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 18px;
  padding: 28px;
  max-width: 420px;
  width: 100%;
  margin: 0 auto;
}
.pair .logo { width: 72px; height: 72px; }
.pair h1 { margin: 0; font-size: 30px; }
.pair p { margin: 0; color: var(--muted); }
.pair input {
  width: 100%;
  padding: 16px;
  border-radius: 14px;
  border: 1px solid var(--key-edge);
  background: var(--panel);
  color: var(--text);
  font: 600 26px/1 ui-monospace, "SF Mono", Menlo, monospace;
  letter-spacing: 0.12em;
  text-align: center;
  text-transform: uppercase;
  -webkit-user-select: text;
  user-select: text;
}
.pair input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn {
  padding: 15px;
  border: 0;
  border-radius: 14px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 17px;
}
.btn:disabled { opacity: 0.5; }
.btn.ghost { background: transparent; color: var(--muted); padding: 8px; font-weight: 500; font-size: 15px; }
.msg { min-height: 1.4em; font-size: 15px; }
.msg.bad { color: var(--bad); }
.hint {
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--panel);
  color: var(--muted);
  font-size: 14px;
}

/* ---------- keypad screen ---------- */
.bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px 6px;
  min-height: 44px;
}
.status { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); flex: 1; min-width: 0; }
.status span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.direct { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.dot.web { background: var(--warn); }
.dot.connecting { background: var(--accent); animation: pulse 1.2s ease-in-out infinite; }
.dot.offline { background: #4b5263; }
@keyframes pulse { 50% { opacity: 0.3; } }
.more { border: 0; background: transparent; color: var(--muted); font-size: 22px; line-height: 1; padding: 4px 6px; }

.grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  grid-template-rows: repeat(var(--rows), minmax(0, 1fr));
  gap: var(--gap);
  padding: 6px 12px 12px;
  touch-action: none;
}
.grid.offline .key { opacity: 0.45; }
.key {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 0;
  padding: 6px;
  border: 1px solid var(--key-edge);
  border-radius: var(--radius);
  background: var(--key);
  transition: transform 80ms ease, background 80ms ease;
}
.key.down { transform: scale(0.94); background: var(--key-down); }
.key.failed { border-color: var(--bad); }
.key.empty { background: transparent; border-style: dashed; border-color: #1d2230; }
.glyph { font-size: clamp(24px, 9vmin, 46px); line-height: 1; }
.label {
  max-width: 100%;
  font-size: clamp(11px, 3.2vmin, 15px);
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.empty-state { flex: 1; display: flex; align-items: center; justify-content: center; color: var(--muted); padding: 24px; text-align: center; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 10px 14px;
  border-radius: 12px;
  background: #2a1717;
  border: 1px solid #5c2626;
  color: #ffd7d7;
  font-size: 14px;
  opacity: 0;
  transition: opacity 160ms ease;
  pointer-events: none;
}
.toast.show { opacity: 1; }

.sheet {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: flex-end;
  background: rgba(0, 0, 0, 0.55);
}
.sheet .panel {
  width: 100%;
  padding: 18px 18px calc(18px + env(safe-area-inset-bottom));
  border-radius: 20px 20px 0 0;
  background: var(--panel);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.sheet .panel p { margin: 0 0 6px; color: var(--muted); font-size: 14px; }
.btn.danger { background: #3a1c1c; color: var(--bad); }
.btn.plain { background: var(--key); }
