/* Draco Network · Postulaciones
   Mundo: la noche del gato. Vacío casi negro teñido de verde, esmeralda del logo para
   acciones y progreso, violeta de los ojos reservado para lo que "mira" (foco, estado vivo).
   Esquinas en escalón de píxel solo en controles; los paneles son superficies lisas. */

:root {
  color-scheme: dark;

  --void: #030706;
  --surface: #08130f;
  --surface-2: #0c1b15;
  --surface-3: #11251d;
  --line: #17322a;
  --line-strong: #24503d;
  --ink: #e4f3ea;
  --ink-2: #a3c0b2;
  --ink-3: #739586;
  --emerald: #3ee08f;
  --emerald-ink: #03140b;
  --emerald-dim: #1d7a4c;
  --violet: #b56cff;
  --violet-soft: #d9b6ff;
  --danger: #ff7a8a;
  --warn: #f2c65c;
  --info: #7cc7ff;

  --font-display: 'Pixelify Sans', 'Silkscreen', ui-monospace, monospace;
  --font-body: 'Geologica', 'Segoe UI', system-ui, sans-serif;
  --font-data: 'JetBrains Mono', ui-monospace, 'Cascadia Mono', Consolas, monospace;

  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);
  --radius: 14px;

  /* Escalón de píxel de 4px en cada esquina */
  --px-corners: polygon(
    0 8px, 4px 8px, 4px 4px, 8px 4px, 8px 0,
    calc(100% - 8px) 0, calc(100% - 8px) 4px, calc(100% - 4px) 4px, calc(100% - 4px) 8px, 100% 8px,
    100% calc(100% - 8px), calc(100% - 4px) calc(100% - 8px), calc(100% - 4px) calc(100% - 4px), calc(100% - 8px) calc(100% - 4px), calc(100% - 8px) 100%,
    8px 100%, 8px calc(100% - 4px), 4px calc(100% - 4px), 4px calc(100% - 8px), 0 calc(100% - 8px)
  );
  --px-corners-sm: polygon(
    0 4px, 2px 4px, 2px 2px, 4px 2px, 4px 0,
    calc(100% - 4px) 0, calc(100% - 4px) 2px, calc(100% - 2px) 2px, calc(100% - 2px) 4px, 100% 4px,
    100% calc(100% - 4px), calc(100% - 2px) calc(100% - 4px), calc(100% - 2px) calc(100% - 2px), calc(100% - 4px) calc(100% - 2px), calc(100% - 4px) 100%,
    4px 100%, 4px calc(100% - 2px), 2px calc(100% - 2px), 2px calc(100% - 4px), 0 calc(100% - 4px)
  );
}

*, *::before, *::after { box-sizing: border-box; }

html { height: 100%; -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100%;
  background: var(--void);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

img { max-width: 100%; display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

::selection { background: var(--violet); color: #12041f; }
:focus-visible { outline: 2px solid var(--violet); outline-offset: 3px; }
input, textarea { caret-color: var(--emerald); }

* { scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line-strong); border: 3px solid var(--void); }

a { color: var(--emerald); text-underline-offset: 3px; text-decoration-thickness: 1px; }
a:hover { color: var(--ink); }

h1, h2, h3 { text-wrap: balance; margin: 0; font-weight: 600; }
p { margin: 0; text-wrap: pretty; }

.num, .mono { font-family: var(--font-data); font-variant-numeric: tabular-nums; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ------------------------------------------------------------------ */
/* Cielo                                                              */
/* ------------------------------------------------------------------ */

.sky { position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; background: var(--void); }
.sky-city {
  /* Se baja unos píxeles para recortar la última fila del webp, que trae ruido de compresión */
  position: absolute; inset: auto 0 -12px 0; width: 100%; height: calc(78vh + 12px);
  object-fit: cover; object-position: 70% 100%;
  opacity: 0.42;
  -webkit-mask-image: linear-gradient(to top, #000 0%, #000 35%, transparent 100%);
          mask-image: linear-gradient(to top, #000 0%, #000 35%, transparent 100%);
  image-rendering: pixelated;
}
.sky::after {
  content: ""; position: absolute; inset: 0;
  background:
    radial-gradient(60% 50% at 50% 0%, rgba(62, 224, 143, 0.10), transparent 70%),
    radial-gradient(40% 35% at 85% 20%, rgba(181, 108, 255, 0.08), transparent 70%);
}
#stars { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 1; }

/* ------------------------------------------------------------------ */
/* Botones                                                            */
/* ------------------------------------------------------------------ */

.btn {
  --bg: var(--surface-3);
  --fg: var(--ink);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px;
  border: 0; background: var(--bg); color: var(--fg);
  font-weight: 500; font-size: 15px; letter-spacing: 0.005em; white-space: nowrap;
  clip-path: var(--px-corners);
  transition: transform 160ms var(--ease-out), background-color 160ms var(--ease-out), filter 160ms var(--ease-out);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.btn svg { width: 18px; height: 18px; flex: none; }
.btn:focus-visible { outline: none; box-shadow: inset 0 0 0 2px var(--violet); }
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-primary { --bg: var(--emerald); --fg: var(--emerald-ink); font-weight: 600; }
.btn-primary:focus-visible { box-shadow: inset 0 0 0 2px var(--emerald-ink), inset 0 0 0 4px var(--violet-soft); }
.btn-ghost { --bg: transparent; --fg: var(--ink-2); }
.btn-danger { --bg: rgba(255, 122, 138, 0.14); --fg: var(--danger); }
.btn-sm { min-height: 34px; padding: 0 12px; font-size: 14px; clip-path: var(--px-corners-sm); }
.btn-lg { min-height: 56px; padding: 0 28px; font-size: 17px; }
.btn-icon { width: 36px; min-height: 36px; padding: 0; clip-path: var(--px-corners-sm); }

@media (hover: hover) and (pointer: fine) {
  .btn:hover:not(:disabled) { --bg: #173327; }
  .btn-primary:hover:not(:disabled) { --bg: #63f0a8; }
  .btn-ghost:hover:not(:disabled) { --bg: var(--surface-3); --fg: var(--ink); }
  .btn-danger:hover:not(:disabled) { --bg: rgba(255, 122, 138, 0.24); }
}

.btn .spinner { width: 16px; height: 16px; }
.spinner {
  display: inline-block; width: 18px; height: 18px;
  background:
    linear-gradient(currentColor 0 0) 0 0 / 6px 6px,
    linear-gradient(currentColor 0 0) 100% 0 / 6px 6px,
    linear-gradient(currentColor 0 0) 100% 100% / 6px 6px,
    linear-gradient(currentColor 0 0) 0 100% / 6px 6px;
  background-repeat: no-repeat;
  animation: pixel-spin 900ms steps(4) infinite;
}
@keyframes pixel-spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------------------------ */
/* Campos                                                             */
/* ------------------------------------------------------------------ */

.field {
  width: 100%;
  min-height: 48px;
  padding: 12px 14px;
  background: rgba(3, 7, 6, 0.6);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  color: var(--ink);
  font-size: 16px;
  transition: border-color 160ms var(--ease-out), box-shadow 160ms var(--ease-out), background-color 160ms var(--ease-out);
}
.field::placeholder { color: var(--ink-3); }
.field:hover { border-color: #2f6a51; }
.field:focus { outline: none; border-color: var(--violet); box-shadow: 0 0 0 4px rgba(181, 108, 255, 0.18); background: rgba(3, 7, 6, 0.85); }
.field[aria-invalid="true"] { border-color: var(--danger); }
.field[aria-invalid="true"]:focus { box-shadow: 0 0 0 4px rgba(255, 122, 138, 0.18); }
textarea.field { min-height: 120px; resize: vertical; line-height: 1.55; }
select.field {
  appearance: none; -webkit-appearance: none; padding-right: 44px; cursor: pointer;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--ink-2) 50%),
    linear-gradient(135deg, var(--ink-2) 50%, transparent 50%);
  background-position: calc(100% - 22px) 50%, calc(100% - 16px) 50%;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
}
select.field option { background: var(--surface); color: var(--ink); }
input[type="date"].field::-webkit-calendar-picker-indicator { filter: invert(0.85) sepia(1) hue-rotate(90deg); cursor: pointer; }
input[type="number"].field { font-family: var(--font-data); font-variant-numeric: tabular-nums; }

/* Interruptor */
.switch { position: relative; display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-track {
  position: relative; width: 44px; height: 24px; flex: none;
  background: var(--surface-3); border: 1px solid var(--line-strong);
  clip-path: var(--px-corners-sm);
  transition: background-color 200ms var(--ease-out), border-color 200ms var(--ease-out);
}
.switch-track::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px;
  background: var(--ink-2);
  transition: transform 220ms var(--ease-out), background-color 200ms var(--ease-out);
}
.switch input:checked + .switch-track { background: rgba(62, 224, 143, 0.2); border-color: var(--emerald-dim); }
.switch input:checked + .switch-track::after { transform: translateX(20px); background: var(--emerald); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--violet); outline-offset: 2px; }

/* Ojo de estado vivo */
.live-dot { position: relative; width: 8px; height: 8px; background: var(--emerald); flex: none; }
.live-dot::after {
  content: ""; position: absolute; inset: -4px; border: 1px solid var(--emerald);
  animation: live 2.4s var(--ease-out) infinite;
}
.live-dot.off { background: var(--ink-3); }
.live-dot.off::after { display: none; }
@keyframes live { 0% { opacity: 0.9; transform: scale(0.6); } 100% { opacity: 0; transform: scale(1.8); } }

/* Toasts */
.toasts {
  position: fixed; z-index: 60; display: grid; gap: 8px; justify-items: end;
  right: max(16px, env(safe-area-inset-right, 0px)); bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  left: max(16px, env(safe-area-inset-left, 0px)); pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: 10px; max-width: 420px;
  padding: 12px 16px; background: var(--surface-3); color: var(--ink);
  border: 1px solid var(--line-strong); border-radius: 10px;
  box-shadow: 0 12px 32px -8px rgba(0, 0, 0, 0.7);
  font-size: 14px; pointer-events: auto;
  animation: toast-in 280ms var(--ease-out);
}
.toast.err { border-color: rgba(255, 122, 138, 0.5); }
.toast.err .live-dot { background: var(--danger); }
.toast.leaving { animation: toast-out 180ms ease-in forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px) scale(0.98); filter: blur(4px); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(6px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; }
  .live-dot::after { display: none; }
}
