/* Knot — iPhone 側 UI */
:root {
  --bg: #08080a;
  --bg-elev: #141418;
  --bg-elev2: #1c1c22;
  --line: #2a2a32;
  --fg: #f2f3f7;
  --fg-dim: #9a9aa8;
  --accent: #7f8cff;
  --accent2: #4be0c0;
  --danger: #ff5f6d;
  --ok: #45d483;
  --radius: 18px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

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

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", system-ui, sans-serif;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-text-size-adjust: 100%;
}

body { overflow: hidden; }

#app { height: 100dvh; width: 100vw; position: relative; overflow: hidden; }

.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  padding: calc(var(--safe-t) + 12px) 20px calc(var(--safe-b) + 12px);
  overflow: hidden;
}
.screen.active { display: flex; }

/* ---------- ペアリング ---------- */
#screen-pair { overflow-y: auto; -webkit-overflow-scrolling: touch; gap: 18px; }

.brand { text-align: center; padding-top: 8vh; }
.logo { display: flex; justify-content: center; filter: drop-shadow(0 8px 24px rgba(127, 140, 255, .35)); }
.brand h1 {
  font-size: 34px; font-weight: 650; letter-spacing: -0.02em;
  margin: 12px 0 4px;
}
.tagline { color: var(--fg-dim); font-size: 14px; margin: 0; }

.card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
}
.card.flat { background: transparent; border-style: dashed; }

.label { display: block; font-size: 12px; color: var(--fg-dim); margin-bottom: 8px; letter-spacing: .02em; }

.code-input {
  width: 100%;
  background: var(--bg-elev2);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px 14px;
  color: var(--fg);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 22px;
  letter-spacing: .12em;
  text-align: center;
  text-transform: uppercase;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.code-input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(127,140,255,.14); }
.code-input::placeholder { color: #4b4b58; letter-spacing: .1em; }

.hint { color: var(--fg-dim); font-size: 12.5px; margin: 10px 2px 0; line-height: 1.5; }

.btn {
  width: 100%;
  border: none;
  border-radius: 14px;
  padding: 16px;
  font-size: 16px;
  font-weight: 600;
  font-family: inherit;
  color: #0b0b10;
  background: var(--fg);
  transition: transform .12s, opacity .15s, background .15s;
}
.btn:active { transform: scale(.98); }
.btn.primary {
  background: linear-gradient(135deg, var(--accent), #6d7cff 40%, var(--accent2));
  color: #06060a;
  margin-top: 16px;
}
.btn.primary:disabled { opacity: .35; }
.btn.ghost { background: var(--bg-elev2); color: var(--fg); }
.btn.small { width: auto; padding: 10px 16px; font-size: 14px; }

.advanced summary { color: var(--fg-dim); font-size: 13px; cursor: pointer; }
.advanced[open] summary { margin-bottom: 14px; }
.field { margin-bottom: 16px; }
.field:last-child { margin-bottom: 0; }
textarea {
  width: 100%;
  background: var(--bg-elev2);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--fg);
  padding: 10px 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  line-height: 1.6;
  resize: vertical;
  -webkit-user-select: text;
  user-select: text;
}
.row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 9px 2px; font-size: 14px; color: var(--fg);
}
.row + .row { border-top: 1px solid rgba(255,255,255,.04); }
input[type=range] { width: 140px; accent-color: var(--accent); }
input.switch {
  appearance: none;
  width: 46px; height: 28px; border-radius: 14px;
  background: var(--bg-elev2); border: 1px solid var(--line);
  position: relative; transition: background .18s;
}
input.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 22px; height: 22px; border-radius: 50%;
  background: #8c8c9a; transition: transform .18s, background .18s;
}
input.switch:checked { background: rgba(127,140,255,.28); border-color: var(--accent); }
input.switch:checked::after { transform: translateX(18px); background: var(--accent); }

.foot { color: #5c5c68; font-size: 11.5px; line-height: 1.8; text-align: center; margin-top: auto; padding-top: 12px; }

/* ---------- 接続中 ---------- */
.connect-wrap { margin: auto; width: 100%; max-width: 420px; text-align: center; }
.spinner {
  width: 44px; height: 44px; margin: 0 auto 22px;
  border-radius: 50%;
  border: 3px solid rgba(255,255,255,.1);
  border-top-color: var(--accent);
  animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.connect-wrap h2 { font-size: 19px; font-weight: 600; margin: 0 0 22px; }

.steps { list-style: none; padding: 0; margin: 0 0 20px; text-align: left; }
.steps li {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 4px; font-size: 14px; color: var(--fg-dim);
  border-bottom: 1px solid rgba(255,255,255,.04);
}
.steps li i {
  width: 9px; height: 9px; border-radius: 50%;
  background: #3a3a44; flex: 0 0 auto; transition: background .2s, box-shadow .2s;
}
.steps li em { margin-left: auto; font-style: normal; font-size: 12px; color: var(--fg-dim); }
.steps li.active { color: var(--fg); }
.steps li.active i { background: var(--accent); box-shadow: 0 0 0 4px rgba(127,140,255,.16); }
.steps li.done i { background: var(--ok); }
.steps li.done em { color: var(--ok); }
.steps li.fail i { background: var(--danger); }

.error { color: var(--danger); font-size: 13px; min-height: 18px; margin: 0 0 16px; line-height: 1.6; }

/* ---------- トラックパッド ---------- */
#screen-pad { padding: calc(var(--safe-t) + 6px) 10px calc(var(--safe-b) + 8px); }

.hud {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 8px 8px; font-size: 12px; color: var(--fg-dim);
}
.hud .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
.hud .dot.warn { background: #ffb02e; }
.hud .dot.bad { background: var(--danger); }
.hud .spacer { flex: 1; }
.metric { font-variant-numeric: tabular-nums; font-family: ui-monospace, monospace; }
.icon-btn {
  background: transparent; border: none; color: var(--fg-dim);
  padding: 6px; display: flex; border-radius: 8px;
}
.icon-btn:active { background: var(--bg-elev2); }

.pad {
  flex: 1;
  border-radius: 22px;
  background:
    radial-gradient(120% 80% at 50% 0%, rgba(127,140,255,.07), transparent 60%),
    var(--bg-elev);
  border: 1px solid var(--line);
  position: relative;
  overflow: hidden;
  touch-action: none;
  display: flex;
  align-items: center;
  justify-content: center;
}
.pad.dragging { border-color: var(--accent); box-shadow: inset 0 0 0 1px rgba(127,140,255,.35); }
.pad-hint { text-align: center; color: #4a4a56; font-size: 12px; line-height: 2; pointer-events: none; }
.pad-hint p { margin: 0; }
.pad.active .pad-hint { opacity: 0; transition: opacity .3s; }

.toolbar {
  display: flex; gap: 8px; padding-top: 10px;
}
.tb {
  flex: 1;
  height: 52px;
  border-radius: 14px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  color: var(--fg);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  display: flex; align-items: center; justify-content: center;
  transition: background .12s, transform .1s;
}
.tb:active { background: var(--bg-elev2); transform: scale(.97); }
.tb.on { background: rgba(127,140,255,.22); border-color: var(--accent); color: #cfd3ff; }
.tb b { font-weight: 600; }

.gesture-sheet, .keyboard-sheet {
  position: absolute;
  left: 10px; right: 10px;
  bottom: calc(var(--safe-b) + 74px);
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  display: none;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  z-index: 10;
  box-shadow: 0 18px 50px rgba(0,0,0,.5);
}
.gesture-sheet.open, .keyboard-sheet.open { display: grid; }
.gesture-sheet button, .keyboard-sheet button[data-key] {
  background: var(--bg-elev2); border: 1px solid var(--line); color: var(--fg);
  border-radius: 12px; padding: 14px 10px; font-size: 13px; font-family: inherit;
}
.gesture-sheet button:active, .keyboard-sheet button[data-key]:active { background: #26262f; }

.keyboard-sheet { grid-template-columns: 1fr; }
.kb-row { display: flex; gap: 8px; }
.kb-row.keys { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.kb-row.keys button { font-size: 12px; padding: 11px 4px; }
#kb-input {
  flex: 1; background: var(--bg-elev2); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px; color: var(--fg); font-size: 16px;
  -webkit-user-select: text; user-select: text; min-width: 0;
}

.toast {
  position: absolute;
  left: 50%; bottom: calc(var(--safe-b) + 96px);
  transform: translate(-50%, 12px);
  background: rgba(30,30,38,.96);
  border: 1px solid var(--line);
  color: var(--fg);
  font-size: 13px;
  padding: 11px 18px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .22s, transform .22s;
  z-index: 50;
  max-width: 84vw;
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- 設定オーバーレイ ---------- */
.overlay {
  position: absolute; inset: 0; display: none;
  background: rgba(4,4,7,.72);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  z-index: 60; padding: calc(var(--safe-t) + 16px) 16px calc(var(--safe-b) + 16px);
  overflow-y: auto;
}
.overlay.open { display: block; }
.overlay-card {
  background: var(--bg-elev); border: 1px solid var(--line);
  border-radius: 20px; padding: 18px; max-width: 460px; margin: 6vh auto 0;
}
.overlay-card h3 { margin: 0 0 12px; font-size: 16px; font-weight: 600; }
