:root {
  --bg: #04060f;
  --ink: #e2e8ff;
  --ink-dim: #8a93b8;
  --accent: #7c8cff;
  --accent2: #b07cff;
  --glass: rgba(16, 22, 48, 0.55);
  --glass-border: rgba(140, 155, 255, 0.18);
  --glow: 0 0 24px rgba(124, 140, 255, 0.35);
  --radius: 18px;
  --font-ui: 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

#space {
  position: fixed;
  inset: 0;
  display: block;
  touch-action: none;
}

/* ---------- shared glass ---------- */
.glass {
  background: var(--glass);
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  box-shadow: 0 8px 40px rgba(0, 0, 6, 0.55), inset 0 1px 0 rgba(180, 190, 255, 0.08);
}

button {
  font-family: var(--font-ui);
  color: var(--ink);
  background: none;
  border: none;
  cursor: pointer;
}

textarea, input[type="text"], input[type="url"] {
  width: 100%;
  background: rgba(8, 12, 30, 0.6);
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 16px; /* prevents iOS zoom */
  padding: 12px 14px;
  outline: none;
  resize: none;
}
textarea:focus, input:focus { border-color: rgba(124, 140, 255, 0.55); box-shadow: var(--glow); }

/* ---------- HUD ---------- */
#hud {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  left: 12px;
  right: 12px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  pointer-events: none;
  z-index: 10;
}
#hud-title {
  padding: 8px 14px;
  border-radius: 14px;
  font-size: 12px;
  letter-spacing: 0.22em;
  font-weight: 600;
  color: var(--ink-dim);
}
#hud-title .where {
  display: block;
  letter-spacing: 0.02em;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  margin-top: 2px;
  max-width: 46vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#hud-actions { display: flex; gap: 8px; pointer-events: auto; }
.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  color: var(--ink);
  transition: box-shadow 0.2s, transform 0.15s;
}
.icon-btn:active { transform: scale(0.92); }
.icon-btn svg { width: 21px; height: 21px; stroke: currentColor; fill: none; stroke-width: 1.7; }

/* ---------- capture ---------- */
#capture-btn {
  position: fixed;
  bottom: max(22px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  width: 60px;
  height: 60px;
  border-radius: 50%;
  font-size: 30px;
  font-weight: 300;
  color: #fff;
  background: linear-gradient(135deg, rgba(124, 140, 255, 0.85), rgba(176, 124, 255, 0.85));
  box-shadow: 0 0 32px rgba(124, 140, 255, 0.5), 0 4px 18px rgba(0, 0, 10, 0.5);
  z-index: 10;
  transition: transform 0.15s;
}
#capture-btn:active { transform: translateX(-50%) scale(0.9); }

.sheet {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translate(-50%, 110%);
  width: min(560px, calc(100vw - 20px));
  margin-bottom: max(10px, env(safe-area-inset-bottom));
  padding: 16px;
  z-index: 20;
  transition: transform 0.32s cubic-bezier(0.22, 1, 0.36, 1);
}
.sheet.open { transform: translate(-50%, 0); }

.sheet h3 {
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-dim);
  margin-bottom: 10px;
  font-weight: 600;
}

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.chip {
  padding: 7px 13px;
  border-radius: 999px;
  border: 1px solid var(--glass-border);
  background: rgba(10, 15, 36, 0.5);
  font-size: 13px;
  color: var(--ink-dim);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: all 0.15s;
}
.chip.sel {
  color: #fff;
  border-color: rgba(124, 140, 255, 0.7);
  background: rgba(124, 140, 255, 0.22);
  box-shadow: var(--glow);
}

.row { display: flex; gap: 10px; align-items: center; margin-top: 12px; }
.btn {
  padding: 11px 20px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  border: 1px solid var(--glass-border);
  background: rgba(10, 15, 36, 0.5);
  color: var(--ink);
  transition: all 0.15s;
}
.btn.primary {
  background: linear-gradient(135deg, rgba(124, 140, 255, 0.8), rgba(176, 124, 255, 0.8));
  border-color: transparent;
  color: #fff;
  box-shadow: var(--glow);
}
.btn.danger { color: #ff8f9e; border-color: rgba(255, 110, 130, 0.35); }
.btn:active { transform: scale(0.96); }
.btn.small { padding: 7px 12px; font-size: 12.5px; }

/* ---------- detail panel ---------- */
#detail .type-badge {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  padding: 3px 9px;
  border-radius: 6px;
  border: 1px solid var(--glass-border);
  color: var(--accent);
  margin-bottom: 10px;
}
#detail .meta {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--ink-dim);
  margin-top: 10px;
  line-height: 1.7;
}
#detail textarea { min-height: 88px; max-height: 34vh; line-height: 1.5; }
#detail .actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

/* ---------- overlays (telescope / settings) ---------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(3, 5, 14, 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding: max(60px, 12vh) 12px 12px;
}
.overlay.open { display: flex; }
.overlay .panel {
  width: min(520px, 100%);
  padding: 18px;
  max-height: 72vh;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#scope-results { overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.scope-hit {
  text-align: left;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid transparent;
  display: flex;
  flex-direction: column;
  gap: 3px;
  transition: all 0.15s;
}
.scope-hit:hover, .scope-hit:active { background: rgba(124, 140, 255, 0.12); border-color: var(--glass-border); }
.scope-hit .t { font-size: 14.5px; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scope-hit .w { font-family: var(--font-mono); font-size: 10.5px; color: var(--ink-dim); }

.field label {
  display: block;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-dim);
  margin-bottom: 6px;
  font-weight: 600;
}
.mono { font-family: var(--font-mono); font-size: 12px; }
.field .keyrow {
  display: flex;
  gap: 8px;
  align-items: center;
}
.field .keyrow code {
  flex: 1;
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--accent);
  background: rgba(8, 12, 30, 0.6);
  border: 1px solid var(--glass-border);
  border-radius: 10px;
  padding: 10px 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#sync-status { font-family: var(--font-mono); font-size: 11px; color: var(--ink-dim); }

/* ---------- toast ---------- */
#toast {
  position: fixed;
  top: max(64px, calc(env(safe-area-inset-top) + 54px));
  left: 50%;
  transform: translate(-50%, -12px);
  padding: 10px 18px;
  border-radius: 12px;
  font-size: 13.5px;
  z-index: 40;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- hint ---------- */
#hint {
  position: fixed;
  bottom: max(100px, calc(env(safe-area-inset-bottom) + 92px));
  left: 50%;
  transform: translateX(-50%);
  font-size: 12.5px;
  color: var(--ink-dim);
  padding: 8px 16px;
  border-radius: 999px;
  z-index: 5;
  pointer-events: none;
  transition: opacity 1.2s;
  text-align: center;
  max-width: 88vw;
}
#hint.hide { opacity: 0; }
