@font-face { font-family: 'Space Grotesk'; src: url('../fonts/SpaceGrotesk-VF.ttf') format('truetype'); font-weight: 300 700; font-display: swap; }
@font-face { font-family: 'Share Tech Mono'; src: url('../fonts/ShareTechMono-400.ttf') format('truetype'); font-display: swap; }

:root {
  --bg: #0b0d1c;
  --bg2: #12142a;
  --panel: rgba(140, 160, 255, 0.05);
  --line: rgba(150, 170, 255, 0.14);
  --line2: rgba(150, 170, 255, 0.26);
  --t1: #e9ecff;
  --t2: #a9b0d6;
  --t3: #6b7299;
  --cyan: #5fe3ff;
  --ice: #a9cbff;
  --lilac: #c8b4ff;
  --violet: #c98bff;
  --amber: #ffc46b;
  --red: #ff6b8a;
  --green: #6bffb8;
  --accent: var(--cyan);
  --accent2: var(--violet);
  --r: 14px;
  --ui: 'Space Grotesk', system-ui, -apple-system, sans-serif;
  --mono: 'Share Tech Mono', ui-monospace, Menlo, monospace;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--t1); font-family: var(--ui); }
body {
  background: radial-gradient(120% 80% at 50% -10%, #1b1a3a 0%, var(--bg) 60%) fixed;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none; user-select: none;
  overscroll-behavior: none;
  touch-action: manipulation;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }

.screen { position: fixed; inset: 0; padding: calc(var(--safe-t) + 16px) calc(var(--safe-r) + 16px) calc(var(--safe-b) + 16px) calc(var(--safe-l) + 16px); overflow-y: auto; }

/* ---------------------------------------------------------- pair screen */
#pair { display: flex; flex-direction: column; gap: 16px; max-width: 520px; margin: 0 auto; }
.brand { text-align: center; padding: 24px 0 8px; }
.mark {
  font-weight: 300; font-size: 44px; letter-spacing: 0.32em; padding-left: 0.32em;
  background: linear-gradient(90deg, #5fe3ff, #a9cbff 35%, #c8b4ff 65%, #c98bff);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.sub { font-family: var(--mono); color: var(--t2); letter-spacing: 0.4em; font-size: 12px; margin-top: 6px; }
.mk { color: var(--lilac); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.card h2, .sheet h3 { margin: 0; font-weight: 500; font-size: 17px; letter-spacing: 0.02em; }
.hint { margin: 0; color: var(--t2); font-size: 14px; line-height: 1.45; }
.msg { min-height: 1.4em; text-align: center; color: var(--amber); font-size: 14px; margin: 0; }
.foot { margin-top: auto; text-align: center; color: var(--t3); font-family: var(--mono); font-size: 11px; letter-spacing: 0.2em; }

.btn {
  appearance: none; border: 1px solid var(--line2); background: rgba(255,255,255,0.04); color: var(--t1);
  border-radius: 12px; padding: 13px 16px; font-size: 15px; font-weight: 500; cursor: pointer; letter-spacing: 0.02em;
}
.btn:active { transform: translateY(1px); background: rgba(255,255,255,0.08); }
.btn.primary { border-color: transparent; color: #0b0d1c; background: linear-gradient(90deg, var(--cyan), var(--lilac)); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--red); border-color: rgba(255,107,138,0.35); background: transparent; }

.code-row { display: flex; gap: 8px; }
.code-row input {
  flex: 1; min-width: 0; background: rgba(0,0,0,0.35); border: 1px solid var(--line2); border-radius: 12px; color: var(--t1);
  font-family: var(--mono); font-size: 22px; letter-spacing: 0.18em; padding: 10px 12px; text-transform: uppercase; text-align: center;
  -webkit-user-select: text; user-select: text;
}
.code-row input:focus { outline: none; border-color: var(--cyan); }
.scan { display: flex; flex-direction: column; gap: 8px; }
.scan video { width: 100%; border-radius: 12px; background: #000; aspect-ratio: 1; object-fit: cover; }

.known { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.known li { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: rgba(0,0,0,0.2); cursor: pointer; }
.known li .k-name { flex: 1; font-weight: 500; }
.known li .k-sub { color: var(--t3); font-family: var(--mono); font-size: 12px; }
.known li.on { border-color: var(--cyan); }

/* ------------------------------------------------------------ connecting */
#connecting { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 14px; }
#connecting h2 { margin: 0; font-weight: 400; letter-spacing: 0.06em; }
.pulse { width: 72px; height: 72px; border-radius: 50%; border: 2px solid var(--cyan); box-shadow: 0 0 24px rgba(95,227,255,0.4); animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { transform: scale(0.85); opacity: 0.5; } 50% { transform: scale(1.05); opacity: 1; } }
.sas { border: 1px solid var(--line2); border-radius: var(--r); padding: 14px 22px; background: var(--panel); }
.sas-label { color: var(--t2); font-size: 13px; }
.sas-value { font-family: var(--mono); font-size: 34px; letter-spacing: 0.12em; color: var(--cyan); margin-top: 4px; }

/* --------------------------------------------------------------- surface */
#surface { display: flex; flex-direction: column; padding: calc(var(--safe-t) + 6px) calc(var(--safe-r) + 10px) calc(var(--safe-b) + 10px) calc(var(--safe-l) + 10px); overflow: hidden; gap: 8px; }
.bar { display: flex; align-items: center; gap: 10px; min-height: 40px; }
.icon-btn { background: transparent; border: 1px solid var(--line); border-radius: 10px; width: 40px; height: 36px; font-size: 18px; cursor: pointer; color: var(--t2); }
.bar-title { flex: 1; min-width: 0; }
.bar-title .name { font-weight: 500; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-title .layout { color: var(--t3); font-size: 12px; font-family: var(--mono); letter-spacing: 0.08em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.link { display: flex; align-items: center; gap: 6px; font-family: var(--mono); font-size: 12px; color: var(--t2); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--t3); }
.dot[data-mode="p2p"] { background: var(--green); box-shadow: 0 0 8px var(--green); }
.dot[data-mode="relay"] { background: var(--amber); box-shadow: 0 0 8px var(--amber); }
.dot[data-mode="local"] { background: var(--ice); box-shadow: 0 0 8px var(--ice); }
.dot[data-mode="lost"] { background: var(--red); }

.tabs { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.tabs:empty { display: none; }
.tabs button { flex: 0 0 auto; background: transparent; border: 1px solid var(--line); color: var(--t2); border-radius: 999px; padding: 6px 14px; font-family: var(--mono); font-size: 12px; letter-spacing: 0.12em; cursor: pointer; }
.tabs button.on { color: #0b0d1c; background: var(--accent); border-color: transparent; }

.page { flex: 1; min-height: 0; display: grid; gap: var(--gap, 8px); }

/* ------------------------------------------------------------- controls */
.ctl {
  position: relative; min-width: 0; min-height: 0; border-radius: var(--r); background: var(--panel); border: 1px solid var(--line);
  overflow: hidden; touch-action: none; display: flex; flex-direction: column;
}
.ctl canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.ctl .cap { position: absolute; left: 10px; top: 8px; font-family: var(--mono); font-size: 11px; letter-spacing: 0.14em; color: var(--t2); pointer-events: none; z-index: 1; white-space: nowrap; }
.ctl .val { position: absolute; right: 10px; top: 8px; font-family: var(--mono); font-size: 12px; color: var(--accent); pointer-events: none; z-index: 1; }
.ctl.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset, 0 0 18px rgba(95,227,255,0.15); }
.ctl.button { align-items: center; justify-content: center; cursor: pointer; font-weight: 500; letter-spacing: 0.08em; font-size: 14px; }
.ctl.button.on { background: linear-gradient(135deg, rgba(95,227,255,0.28), rgba(201,139,255,0.28)); border-color: var(--accent); }
.ctl.button .btxt { position: relative; z-index: 1; text-align: center; padding: 0 6px; }
.ctl.clutch { align-items: center; justify-content: center; font-family: var(--mono); font-size: 12px; letter-spacing: 0.14em; color: var(--t2); }
.ctl.clutch.on { color: #0b0d1c; background: var(--accent); border-color: transparent; }
.ctl.clutch.off-sensor { opacity: 0.5; }
.ctl.label { background: transparent; border: none; justify-content: center; padding: 0 6px; color: var(--t2); font-size: 13px; }
.ctl.pads { display: grid; gap: 6px; padding: 6px; background: transparent; border: none; }
.pad { border-radius: 10px; border: 1px solid var(--line2); background: rgba(255,255,255,0.03); display: flex; align-items: flex-end; justify-content: flex-start; padding: 6px 8px; font-family: var(--mono); font-size: 10px; color: var(--t3); letter-spacing: 0.1em; touch-action: none; transition: background 80ms; }
.pad.hit { background: linear-gradient(135deg, rgba(95,227,255,0.55), rgba(201,139,255,0.45)); color: #0b0d1c; border-color: transparent; }
.ctl.keys { flex-direction: row; padding: 0; gap: 0; }

.toast { pointer-events: none; position: fixed; left: 50%; bottom: calc(var(--safe-b) + 18px); transform: translateX(-50%); background: rgba(20,22,44,0.95); border: 1px solid var(--line2); color: var(--t1); padding: 10px 16px; border-radius: 12px; font-size: 14px; max-width: 90vw; z-index: 20; }

/* ------------------------------------------------------------------ menu */
.sheet { position: fixed; inset: 0; background: rgba(5,6,14,0.7); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); z-index: 30; display: flex; align-items: flex-end; justify-content: center; }
.sheet-card { width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto; background: var(--bg2); border: 1px solid var(--line2); border-radius: 20px 20px 0 0; padding: 20px 18px calc(var(--safe-b) + 18px); display: flex; flex-direction: column; gap: 10px; }
.update { position: fixed; left: 12px; right: 12px; bottom: calc(var(--safe-b) + 12px); display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px; background: var(--bg2); border: 1px solid var(--line2); border-radius: 14px; z-index: 40; font-size: 14px; }

@media (min-width: 900px) { .ctl .cap { font-size: 12px; } }

.check { display: flex; align-items: center; gap: 10px; color: var(--t1); font-size: 15px; padding: 6px 0; }
.check input { width: 22px; height: 22px; accent-color: var(--cyan); }
