:root {
  color-scheme: dark;
  --bg: #0b0f14;
  --panel: #121821;
  --panel-2: #1a222d;
  --border: #232d3a;
  --text: #d7e0ea;
  --muted: #7b8794;
  --accent: #3fa9f5;
  --accent-2: #22c55e;
  --danger: #ef4444;
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

input, button, textarea {
  font-family: inherit;
  font-size: 16px; /* evita auto-zoom de iOS al enfocar inputs */
}

button {
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  border-radius: var(--radius);
  padding: 10px 14px;
}
button:active { transform: translateY(1px); }
button.primary { background: var(--accent); border-color: var(--accent); color: #04121f; font-weight: 600; }
button.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
button.ghost { background: transparent; }

/* ---------- Auth (login / enroll) ---------- */
.auth-wrap {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px calc(24px + env(safe-area-inset-bottom));
}
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px 24px;
}
.auth-card h1 { font-size: 20px; margin: 0 0 4px; }
.auth-card p.sub { color: var(--muted); margin: 0 0 20px; font-size: 14px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field input {
  width: 100%;
  padding: 11px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
}
.field input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.auth-error {
  background: #2a1418; border: 1px solid #4a1f26; color: #ffb4bd;
  padding: 10px 12px; border-radius: var(--radius); font-size: 13px; margin-bottom: 14px;
}
.auth-card button[type="submit"] { width: 100%; padding: 12px; }
.qr-box { background: #fff; padding: 10px; border-radius: 8px; display: inline-block; margin: 6px 0 14px; }
.secret-fallback { font-size: 12px; color: var(--muted); word-break: break-all; margin-bottom: 14px; }

/* ---------- Terminal shell ---------- */
.app {
  height: 100%;
  display: flex;
  flex-direction: column;
}
.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.topbar .status { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.status-dot.ok { background: var(--accent-2); }
.status-dot.bad { background: var(--danger); }
.topbar .spacer { flex: 1; }
.topbar button { padding: 8px 10px; font-size: 13px; }

.term-area {
  flex: 1;
  min-height: 0;
  position: relative;
  background: #000;
}
#terminal { position: absolute; inset: 0; padding: 6px; }

/* Sugerencias inline de snippets, mientras se escribe — es un panel más
   del layout (empuja la terminal hacia arriba), no flota encima de ella,
   así nunca tapa la línea que estás escribiendo. */
.inline-suggest {
  flex-shrink: 0;
  margin: 0 6px;
  background: var(--panel);
  border: 1px solid var(--accent);
  border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0;
  max-height: 34vh;
  overflow-y: auto;
  display: none;
  box-shadow: 0 -6px 20px rgba(0,0,0,.4);
}
.inline-suggest.show { display: block; }
.inline-suggest .item {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.inline-suggest .item:last-child { border-bottom: none; }
.inline-suggest .item .label { font-size: 13px; color: var(--muted); }
.inline-suggest .item .cmd { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 14px; }
.inline-suggest .item.active { background: var(--panel-2); }

/* Fila de teclas extra (esenciales en celular) */
.extra-keys {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 8px 10px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  background: var(--panel);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  -webkit-overflow-scrolling: touch;
}
.extra-keys button {
  flex: 0 0 auto;
  padding: 8px 12px;
  font-size: 13px;
  white-space: nowrap;
}
.extra-keys button.active { background: var(--accent); color: #04121f; border-color: var(--accent); }

/* D-pad flotante (mantener presionado sobre la terminal) */
.dpad {
  position: fixed;
  width: 132px;
  height: 132px;
  border-radius: 50%;
  background: rgba(18, 24, 33, .92);
  border: 1px solid var(--border);
  display: none;
  z-index: 50;
  touch-action: none;
  box-shadow: 0 8px 24px rgba(0,0,0,.5);
}
.dpad.show { display: grid; grid-template-columns: 1fr 1fr 1fr; grid-template-rows: 1fr 1fr 1fr; }
.dpad .dp-btn {
  display: flex; align-items: center; justify-content: center;
  color: var(--text); font-size: 20px; user-select: none;
  border-radius: 8px;
}
.dpad .dp-btn.hit { background: var(--accent); color: #04121f; }
.dpad .dp-up { grid-column: 2; grid-row: 1; }
.dpad .dp-left { grid-column: 1; grid-row: 2; }
.dpad .dp-right { grid-column: 3; grid-row: 2; }
.dpad .dp-down { grid-column: 2; grid-row: 3; }

/* ---------- Modal de gestión de snippets ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.55);
  display: none; align-items: flex-end; justify-content: center;
  z-index: 100;
}
.modal-backdrop.show { display: flex; }
.modal {
  width: 100%;
  max-width: 520px;
  max-height: 88vh;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px 16px 0 0;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
}
@media (min-width: 640px) {
  .modal-backdrop { align-items: center; }
  .modal { border-radius: 16px; max-height: 80vh; }
}
.modal-head {
  display: flex; align-items: center; gap: 8px;
  padding: 14px 14px 8px;
  border-bottom: 1px solid var(--border);
}
.modal-head h2 { font-size: 16px; margin: 0; flex: 1; }
.modal-search { padding: 10px 14px; }
.modal-list { overflow-y: auto; padding: 0 14px 14px; flex: 1; }
.snip-row {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 8px;
  background: var(--panel-2);
}
.snip-row .top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.snip-row .label { font-weight: 600; font-size: 14px; }
.snip-row .cmd { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; color: var(--muted); margin-top: 4px; word-break: break-all; }
.snip-row .actions { display: flex; gap: 6px; flex-shrink: 0; }
.snip-row .actions button { padding: 6px 8px; font-size: 12px; }
.snip-form { padding: 12px 14px; border-top: 1px solid var(--border); }
.snip-form .row { display: flex; gap: 8px; }
.snip-form .row button { flex: 1; }
.empty-hint { color: var(--muted); font-size: 13px; text-align: center; padding: 24px 0; }
