/* ==========================================================================
   COSMOS 2027 — дизайн-система Mirror Lux
   Глибокий космос · аврора · скло другого покоління · світіння
   ========================================================================== */

:root {
  color-scheme: dark;

  --bg-0: #04050b;
  --bg-1: #080b17;
  --ink: #eef2ff;
  --ink-2: #b4bedd;
  --ink-3: #8993b8;
  --line: rgba(160, 180, 255, 0.16);
  --line-strong: rgba(160, 180, 255, 0.32);

  --glass: rgba(14, 18, 40, 0.58);
  --glass-hi: rgba(28, 34, 72, 0.66);
  --glass-solid: #0d1128;

  --cyan: #5ad7ff;
  --violet: #9b7bff;
  --magenta: #ff6bd6;
  --mint: #4be3b0;
  --amber: #ffc861;
  --coral: #ff7a8a;

  --grad: linear-gradient(120deg, var(--cyan), var(--violet) 55%, var(--magenta));
  --grad-soft: linear-gradient(120deg, rgba(90, 215, 255, .18), rgba(155, 123, 255, .18) 55%, rgba(255, 107, 214, .18));

  --r-sm: 12px;
  --r-md: 18px;
  --r-lg: 28px;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --shadow-glow: 0 0 0 1px rgba(155, 123, 255, .25), 0 12px 40px -12px rgba(110, 90, 255, .55);

  --font: ui-sans-serif, -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI Variable", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

@supports (color: oklch(0.8 0.1 200)) {
  :root {
    --cyan: oklch(0.84 0.13 214);
    --violet: oklch(0.70 0.19 293);
    --magenta: oklch(0.74 0.21 345);
    --mint: oklch(0.85 0.15 165);
    --amber: oklch(0.86 0.14 85);
    --coral: oklch(0.74 0.17 20);
  }
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.4;
  color: var(--ink);
  background: var(--bg-0);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; }
a { color: var(--cyan); text-decoration: none; }
a:hover { text-decoration: underline; }
[hidden] { display: none !important; }
h1, h2, h3 { line-height: 1.15; letter-spacing: -0.02em; font-weight: 700; }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-2); }
.dim { color: var(--ink-3); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

:focus-visible { outline: 2px solid var(--cyan); outline-offset: 3px; border-radius: 8px; }

/* ---------- Космічний фон ---------- */
.cosmos { position: fixed; inset: 0; z-index: -1; overflow: hidden; background:
  radial-gradient(120% 90% at 50% 120%, #14173a 0%, var(--bg-1) 45%, var(--bg-0) 100%); }
.cosmos .aurora {
  position: absolute; width: 70vmax; height: 70vmax; border-radius: 50%;
  filter: blur(80px); opacity: .42; mix-blend-mode: screen;
  animation: drift 28s var(--ease) infinite alternate;
}
.cosmos .aurora.a1 { background: radial-gradient(circle, #3b6bff 0%, transparent 62%); top: -30vmax; left: -20vmax; }
.cosmos .aurora.a2 { background: radial-gradient(circle, #8a3dff 0%, transparent 62%); bottom: -35vmax; right: -25vmax; animation-duration: 36s; animation-delay: -9s; }
.cosmos .aurora.a3 { background: radial-gradient(circle, #00c8d6 0%, transparent 60%); top: 25vh; left: 45vw; width: 45vmax; height: 45vmax; opacity: .22; animation-duration: 44s; animation-delay: -18s; }
.cosmos canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.cosmos::after { /* ніжне зерно, щоб градієнти не «смугували» */
  content: ""; position: absolute; inset: 0; opacity: .05; pointer-events: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}
@keyframes drift { to { transform: translate3d(8vmax, 6vmax, 0) scale(1.15) rotate(25deg); } }

/* ---------- Скло ---------- */
.glass {
  position: relative;
  background:
    linear-gradient(var(--glass), var(--glass)) padding-box,
    linear-gradient(140deg, rgba(150, 190, 255, .45), rgba(155, 123, 255, .12) 40%, rgba(255, 107, 214, .25)) border-box;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  -webkit-backdrop-filter: blur(22px) saturate(140%);
  backdrop-filter: blur(22px) saturate(140%);
  box-shadow: 0 10px 40px -20px rgba(0, 0, 0, .8);
}
.glass.hi { background:
    linear-gradient(var(--glass-hi), var(--glass-hi)) padding-box,
    linear-gradient(140deg, rgba(150, 190, 255, .6), rgba(155, 123, 255, .2) 40%, rgba(255, 107, 214, .4)) border-box; }
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .glass { background: linear-gradient(var(--glass-solid), var(--glass-solid)) padding-box, linear-gradient(140deg, rgba(150,190,255,.4), rgba(255,107,214,.25)) border-box; }
}

/* ---------- Кнопки ---------- */
.btn {
  --h: 44px;
  display: inline-flex; align-items: center; justify-content: center; gap: .55rem;
  min-height: var(--h); padding: 0 1.4rem; border-radius: 999px;
  font-weight: 600; letter-spacing: .01em; white-space: nowrap;
  transition: transform .25s var(--ease), box-shadow .25s var(--ease), background .25s, opacity .2s;
  user-select: none; -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(.97); }
.btn[disabled] { opacity: .45; cursor: not-allowed; transform: none; }
.btn-primary {
  color: #060814; background: var(--grad); background-size: 160% 100%;
  box-shadow: var(--shadow-glow);
}
.btn-primary:hover:not([disabled]) { background-position: 100% 0; box-shadow: 0 0 0 1px rgba(255,255,255,.35), 0 16px 48px -10px rgba(120, 100, 255, .8); text-decoration: none; }
.btn-ghost { background: rgba(255, 255, 255, .05); border: 1px solid var(--line); color: var(--ink); }
.btn-ghost:hover:not([disabled]) { background: rgba(255, 255, 255, .1); border-color: var(--line-strong); text-decoration: none; }
.btn-danger { background: rgba(255, 122, 138, .12); border: 1px solid rgba(255, 122, 138, .45); color: var(--coral); }
.btn-danger:hover:not([disabled]) { background: rgba(255, 122, 138, .22); }
.btn-sm { --h: 34px; padding: 0 .9rem; font-size: .8125rem; }
.btn-icon { --h: 40px; width: 40px; padding: 0; }
.btn-icon.btn-sm { --h: 34px; width: 34px; }
.btn-block { width: 100%; }

/* ---------- Поля ---------- */
.field { display: grid; gap: .3rem; }
.field > span, .label { font-size: .8125rem; color: var(--ink-2); font-weight: 500; letter-spacing: .02em; }
.input, .select, .textarea {
  width: 100%; min-height: 44px; padding: .55rem .85rem; border-radius: var(--r-sm); font-size: 16px;
  background: rgba(8, 11, 26, .7); border: 1px solid var(--line); color: var(--ink);
  transition: border-color .2s, box-shadow .2s, background .2s;
}
.textarea { min-height: 72px; resize: none; }
.input::placeholder, .textarea::placeholder { color: var(--ink-3); }
.input:hover, .select:hover, .textarea:hover { border-color: var(--line-strong); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--cyan); box-shadow: 0 0 0 4px rgba(90, 215, 255, .16); background: rgba(8, 11, 26, .9); }
.input[aria-invalid="true"] { border-color: var(--coral); box-shadow: 0 0 0 4px rgba(255, 122, 138, .14); }
.select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--ink-2) 50%), linear-gradient(135deg, var(--ink-2) 50%, transparent 50%); background-position: calc(100% - 20px) 55%, calc(100% - 14px) 55%; background-size: 6px 6px; background-repeat: no-repeat; padding-right: 2.4rem; }
.select option { background: var(--glass-solid); }
.field-error { color: var(--coral); font-size: .8125rem; min-height: 1.2em; }
.hp { position: absolute !important; left: -9999px; width: 1px; height: 1px; opacity: 0; }
.switch { position: relative; width: 48px; height: 28px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; cursor: pointer; margin: 0; }
.switch i { position: absolute; inset: 0; border-radius: 999px; background: rgba(255,255,255,.1); border: 1px solid var(--line); transition: .25s var(--ease); pointer-events: none; }
.switch i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: var(--ink-2); transition: .25s var(--ease); }
.switch input:checked + i { background: var(--grad); border-color: transparent; }
.switch input:checked + i::after { transform: translateX(20px); background: #060814; }
.switch input:focus-visible + i { outline: 2px solid var(--cyan); outline-offset: 3px; }

/* ---------- Дрібні компоненти ---------- */
.chip { display: inline-flex; align-items: center; gap: .35rem; padding: .2rem .7rem; border-radius: 999px; font-size: .75rem; font-weight: 600; border: 1px solid var(--line); background: rgba(255,255,255,.05); color: var(--ink-2); }
.chip.ok { color: var(--mint); border-color: rgba(75, 227, 176, .4); background: rgba(75, 227, 176, .1); }
.chip.warn { color: var(--amber); border-color: rgba(255, 200, 97, .4); background: rgba(255, 200, 97, .1); }
.chip.bad { color: var(--coral); border-color: rgba(255, 122, 138, .4); background: rgba(255, 122, 138, .1); }
.chip.info { color: var(--cyan); border-color: rgba(90, 215, 255, .4); background: rgba(90, 215, 255, .1); }
.orb { width: var(--s, 44px); height: var(--s, 44px); border-radius: 50%; flex: none; display: grid; place-items: center; font-weight: 700; color: #060814;
  background: radial-gradient(circle at 30% 25%, #fff 0%, hsl(var(--hue, 200) 90% 70%) 28%, hsl(calc(var(--hue, 200) + 60) 80% 48%) 100%);
  box-shadow: 0 0 22px -2px hsl(var(--hue, 200) 90% 60% / .65); }
.divider { height: 1px; background: var(--line); border: 0; margin: 1rem 0; }
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--line-strong); border-top-color: var(--cyan); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty { text-align: center; padding: 2.5rem 1rem; color: var(--ink-3); }

/* ---------- Тости ---------- */
.toasts { position: fixed; z-index: 100; left: 50%; bottom: calc(1.25rem + var(--safe-b)); transform: translateX(-50%); display: grid; gap: .5rem; width: min(92vw, 420px); pointer-events: none; }
.toast { padding: .8rem 1.1rem; border-radius: var(--r-sm); background: var(--glass-solid); border: 1px solid var(--line-strong); box-shadow: 0 12px 40px rgba(0,0,0,.6); animation: toast-in .35s var(--ease); pointer-events: auto; }
.toast.ok { border-color: rgba(75,227,176,.55); } .toast.err { border-color: rgba(255,122,138,.6); }
@keyframes toast-in { from { opacity: 0; transform: translateY(14px) scale(.96); } }

/* ---------- Шторки (bottom sheet) ---------- */
.modal-back { position: fixed; inset: 0; z-index: 90; display: grid; place-items: end center; background: rgba(2, 3, 10, .6); -webkit-backdrop-filter: blur(5px); backdrop-filter: blur(5px); animation: fade .25s; }
.modal { width: min(100%, 520px); max-height: 88dvh; display: flex; flex-direction: column; border-radius: 22px 22px 0 0; animation: sheet .38s var(--ease); overscroll-behavior: contain;
  background: linear-gradient(var(--glass-solid), var(--glass-solid)) padding-box, linear-gradient(160deg, rgba(150,190,255,.5), rgba(155,123,255,.12) 40%, rgba(255,107,214,.28)) border-box; border: 1px solid transparent; border-bottom: 0; }
.modal.wide { width: min(100%, 640px); }
.modal::before { content: ""; width: 36px; height: 4px; border-radius: 4px; background: var(--line-strong); margin: 8px auto 0; flex: none; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: .8rem; padding: .5rem .9rem .3rem 1.1rem; }
.modal-head h2 { font-size: 1.05rem; }
.modal-body { padding: .4rem 1.1rem .9rem; overflow: auto; -webkit-overflow-scrolling: touch; display: grid; gap: .8rem; align-content: start; }
.modal-foot { display: flex; gap: .5rem; justify-content: flex-end; flex-wrap: wrap; padding: .7rem 1.1rem calc(.8rem + var(--safe-b)); border-top: 1px solid var(--line); }
.modal-foot .btn { flex: 1 1 auto; }
@media (min-width: 720px) { .modal-back { place-items: center; } .modal { border-radius: 22px; border-bottom: 1px solid transparent; } .modal::before { display: none; } }
@keyframes sheet { from { opacity: 0; transform: translateY(40px); } }
@keyframes fade { from { opacity: 0; } }

/* ---------- Анімація появи ---------- */
.rise { animation: rise .6s var(--ease) both; animation-delay: calc(var(--i, 0) * 55ms); }
@keyframes rise { from { opacity: 0; transform: translateY(16px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}
@media (forced-colors: active) {
  .glass, .modal, .toast, .input, .select, .textarea { border: 1px solid CanvasText; }
  .btn-primary { background: ButtonText; color: ButtonFace; }
}


/* ===== ЛЁГКИЙ РЕЖИМ (html.lite): телефон не гріється ===== */
.lite .cosmos .aurora { animation: none; filter: none; mix-blend-mode: normal; opacity: .3; }
.lite .glass, .lite .glass.hi, .lite .toast, .lite .modal { -webkit-backdrop-filter: none; backdrop-filter: none; }
.lite .modal-back { -webkit-backdrop-filter: none; backdrop-filter: none; background: rgba(2, 3, 10, .78); }
.lite .btn-primary { background-size: 100% 100%; }
.lite .btn, .lite .glass { transition-duration: .12s; }
.lite .spinner { animation-duration: 1.2s; }
