/* =====================================================================
   SMART-CORE · Sign-in — "Moonlit Water"
   The dashboard's own living water (js/water.js) under a night sky,
   and two panes of sea glass: the flag of the Kingdom, and the sign-in
   card. Calm, flowing light — no 3D world, no loops on show.
   ===================================================================== */
:root {
  --ksa: 0 84 48; /* official flag green #005430 */
  --moon: 255 248 228;
  --gold: 214 182 118;
}

body[data-page="login"] {
  min-height: 100vh;
  min-height: 100svh;
  overflow-x: hidden;
  background: #010810;
}

/* =====================================================================
   Night over the water
   ===================================================================== */
/* Deepens the dashboard's water into night: darker above (the sky), the
   water's light still breathing below. */
.night {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background:
    radial-gradient(70% 55% at var(--mx, 58%) 18%, rgb(var(--moon) / 0.11), transparent 72%),
    linear-gradient(180deg, rgba(1, 5, 14, 0.8) 0%, rgba(1, 7, 16, 0.55) 30%, rgba(1, 10, 20, 0.16) 62%, rgba(1, 8, 16, 0.3) 100%);
}

/* A few stars, faint, each at its own pace */
.stars i {
  position: fixed;
  z-index: 1;
  width: 2px;
  height: 2px;
  border-radius: 50%;
  background: #eaf4ff;
  box-shadow: 0 0 4px rgba(220, 235, 255, 0.8);
  opacity: 0.5;
  animation: twinkle var(--d, 7s) ease-in-out var(--delay, 0s) infinite;
  pointer-events: none;
}

@keyframes twinkle {
  0%, 100% { opacity: 0.55; }
  45% { opacity: 0.15; }
  55% { opacity: 0.7; }
}

/* =====================================================================
   The flag pane — the card's twin: the same sea glass, rim, girih and
   Sadu, with the flag of the Kingdom set into it behind glass. Still.
   ===================================================================== */
.ensign {
  position: relative;
  isolation: isolate;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 34px;
  padding: 46px 40px 34px;
  overflow: hidden;
  border-radius: 24px;
  background:
    radial-gradient(130% 55% at 50% 0%, rgba(120, 220, 230, 0.1), transparent 70%),
    linear-gradient(165deg, rgba(190, 235, 255, 0.11) 0%, rgba(40, 110, 140, 0.08) 38%, rgba(2, 14, 24, 0.62) 100%);
  -webkit-backdrop-filter: blur(26px) saturate(165%);
  backdrop-filter: blur(26px) saturate(165%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.16),
    inset 0 -90px 120px -90px rgba(94, 231, 255, 0.24),
    0 60px 130px -50px rgba(0, 0, 0, 0.9),
    0 0 0 1px rgba(160, 222, 255, 0.06);
}

.ensign::before {
  /* gradient glass rim, as on the card */
  content: "";
  position: absolute;
  inset: 0;
  z-index: 4;
  border-radius: inherit;
  padding: 1px;
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.45), rgba(255, 255, 255, 0.05) 30%, rgba(255, 255, 255, 0.02) 62%, rgba(94, 231, 255, 0.4));
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0);
  pointer-events: none;
}

/* Moonlight caught in the glass, following the pointer */
.ensign__light {
  position: absolute;
  left: 0;
  top: 0;
  z-index: -1;
  width: 620px;
  height: 620px;
  margin: -310px 0 0 -310px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(170, 235, 255, 0.13) 0%, rgba(120, 210, 240, 0.04) 35%, transparent 65%);
  transform: translate(85%, 15%);
  pointer-events: none;
}

/* The window the flag sits in: a fine gold line, a dark mat, a glass edge */
.ensign__frame {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 2;
  border-radius: 10px;
  box-shadow:
    0 0 0 1px rgb(var(--gold) / 0.45),
    0 0 0 8px rgba(2, 14, 24, 0.45),
    0 0 0 9px rgba(160, 222, 255, 0.12),
    0 34px 60px -30px rgba(0, 0, 0, 0.85),
    0 0 70px -12px rgb(var(--ksa) / 0.55);
}

.ensign__flag {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  object-fit: cover;
}

/* The glass over the flag: a soft reflection, and depth at the edges */
.ensign__frame::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background:
    linear-gradient(155deg, rgba(255, 255, 255, 0.16) 0%, rgba(255, 255, 255, 0.05) 26%, transparent 44%),
    linear-gradient(0deg, rgba(1, 8, 16, 0.3), transparent 45%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.25),
    inset 0 0 0 1px rgba(255, 255, 255, 0.06),
    inset 0 -24px 40px -24px rgba(0, 0, 0, 0.45);
  pointer-events: none;
}

/* The name, set like the card's wordmark */
.ensign__caption {
  display: grid;
  justify-items: center;
  gap: 14px;
}

.ensign__line {
  width: 34px;
  height: 2px;
  border-radius: 2px;
  background: linear-gradient(90deg, transparent, #c8f6ff 30%, #fff 50%, #c8f6ff 70%, transparent);
  box-shadow: 0 0 12px rgba(94, 231, 255, 0.9), 0 0 26px rgba(94, 231, 255, 0.45);
}

.ensign__name {
  margin: 0 -0.36em 0 0;
  font: 10px var(--font-mono);
  letter-spacing: 0.36em;
  text-align: center;
  text-transform: uppercase;
  color: var(--ink-3);
}

/* =====================================================================
   Layout
   ===================================================================== */
/* Two panes side by side, always the same height */
.gate {
  position: relative;
  z-index: 3;
  display: grid;
  grid-template-columns: minmax(260px, min(36vw, 620px)) auto;
  align-content: center;
  justify-content: center;
  column-gap: clamp(80px, 13vw, 300px);
  min-height: 100vh;
  min-height: 100svh;
  padding: 48px clamp(24px, 7vw, 130px) 64px;
}

/* =====================================================================
   The monolith — a slab of sea glass
   ===================================================================== */
.monolith {
  position: relative;
  isolation: isolate;
  width: clamp(340px, 27vw, 420px);
  padding: 46px 40px 34px;
  overflow: hidden;
  border-radius: 24px;
  background:
    radial-gradient(130% 55% at 50% 0%, rgba(120, 220, 230, 0.1), transparent 70%),
    linear-gradient(165deg, rgba(190, 235, 255, 0.11) 0%, rgba(40, 110, 140, 0.08) 38%, rgba(2, 14, 24, 0.62) 100%);
  -webkit-backdrop-filter: blur(26px) saturate(165%);
  backdrop-filter: blur(26px) saturate(165%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.16),
    inset 0 -90px 120px -90px rgba(94, 231, 255, 0.24),
    0 60px 130px -50px rgba(0, 0, 0, 0.9),
    0 0 0 1px rgba(160, 222, 255, 0.06);
}

.monolith::before {
  /* gradient glass rim */
  content: "";
  position: absolute;
  inset: 0;
  z-index: 4;
  border-radius: inherit;
  padding: 1px;
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.45), rgba(255, 255, 255, 0.05) 30%, rgba(255, 255, 255, 0.02) 62%, rgba(94, 231, 255, 0.4));
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0);
  pointer-events: none;
}

.no-glass .monolith {
  background: linear-gradient(165deg, #0c2a44, #04121f);
}

/* Etched geometric star pattern, barely there */
.monolith__girih {
  position: absolute;
  inset: 0;
  z-index: -1;
  width: 100%;
  height: 100%;
  color: rgba(200, 240, 255, 0.05);
  -webkit-mask: radial-gradient(120% 80% at 50% 0%, #000 30%, transparent 85%);
  mask: radial-gradient(120% 80% at 50% 0%, #000 30%, transparent 85%);
}

/* Moonlight caught in the glass, following the pointer */
.monolith__light {
  position: absolute;
  left: 0;
  top: 0;
  z-index: -1;
  width: 620px;
  height: 620px;
  margin: -310px 0 0 -310px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(170, 235, 255, 0.13) 0%, rgba(120, 210, 240, 0.04) 35%, transparent 65%);
  transform: translate(60%, 10%);
  transition: opacity 0.6s;
  pointer-events: none;
}

/* Sadu weave woven into the top and bottom of the glass */
.monolith__sadu {
  position: absolute;
  left: 0;
  right: 0;
  height: 7px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='36' height='7'%3E%3Cpath d='M0 7 9 0 18 7Z M18 7 27 0 36 7Z' fill='%23005430'/%3E%3Cpath d='M9 7 13.5 3.5 18 7 22.5 3.5 27 7Z' fill='%23d6b676'/%3E%3Cpath d='M7.5 2 9 .5 10.5 2 9 3.5Z M25.5 2 27 .5 28.5 2 27 3.5Z' fill='%23f3ead8'/%3E%3C/svg%3E") 0 0 / 36px 7px repeat-x;
  -webkit-mask: linear-gradient(90deg, transparent, #000 20%, #000 80%, transparent);
  mask: linear-gradient(90deg, transparent, #000 20%, #000 80%, transparent);
  opacity: 0.8;
}

.monolith__sadu--top { top: 0; }
.monolith__sadu--bottom { bottom: 0; transform: scaleY(-1); }

/* ---------------- The logo ---------------- */
.mark {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 14px;
  margin-bottom: 30px;
}

/* A soft light behind the logo, so its deep blue reads on the dark glass */
.mark::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 0;
  z-index: -1;
  width: 300px;
  height: 190px;
  margin-left: -150px;
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(150, 215, 255, 0.24), rgba(110, 190, 240, 0.08) 60%, transparent);
  pointer-events: none;
}

/* js/logo-trim.js crops the file to its artwork; it shows once that is done */
.mark__logo {
  display: block;
  width: auto;
  max-width: 100%;
  height: clamp(118px, 16vh, 150px);
  visibility: hidden;
  filter: drop-shadow(0 0 16px rgba(160, 225, 255, 0.4));
  user-select: none;
  -webkit-user-drag: none;
}

.mark__logo.is-ready {
  visibility: visible;
}

.mark__sub {
  margin: 0;
  font: 10px var(--font-mono);
  letter-spacing: 0.36em;
  margin-right: -0.36em;
  text-transform: uppercase;
  color: var(--ink-3);
}

/* ---------------- Views ---------------- */
.monolith__views {
  display: grid;
}

.view {
  grid-area: 1 / 1;
  display: grid;
  gap: 18px;
}

.view[hidden] {
  display: none;
}

.view.is-entering {
  animation: view-in 0.75s var(--ease-out) both;
}

@keyframes view-in {
  from {
    opacity: 0;
    transform: translateY(18px);
    filter: blur(6px);
  }
}

.view__title {
  margin: 0;
  font: 200 clamp(40px, 3.6vw, 54px) / 1 var(--font-display);
  letter-spacing: -0.035em;
  background: linear-gradient(180deg, #ffffff 0%, #d8f7ff 50%, #8adff5 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.view__title + .lf {
  margin-top: 16px; /* breathing room where there is no lede */
}

.view__lede {
  margin: -8px 0 6px;
  font-size: 14px;
  font-weight: 300;
  line-height: 1.6;
  color: var(--ink-3);
}

/* ---------------- Line fields: a waterline that fills as you focus ---------------- */
.lf {
  position: relative;
  display: grid;
  gap: 6px;
  min-width: 0;
}

.lf label {
  font: 10.5px var(--font-mono);
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink-3);
  transition: color 0.35s;
}

.lf input {
  width: 100%;
  min-width: 0;
  height: 42px;
  padding: 0 40px 0 0;
  border: 0;
  outline: none;
  background: transparent;
  color: #fff;
  font: 300 18px var(--font-body);
  letter-spacing: 0.01em;
  caret-color: rgb(var(--cyan));
}

.lf input:-webkit-autofill {
  -webkit-text-fill-color: #fff;
  -webkit-box-shadow: 0 0 0 40px #062031 inset;
  transition: background-color 9999s;
}

.lf__line {
  position: relative;
  height: 1px;
  background: rgba(160, 222, 255, 0.22);
}

.lf__line i {
  position: absolute;
  inset: -0.5px 0;
  background: linear-gradient(90deg, rgb(var(--cyan)), #e6fcff 60%, rgb(var(--cyan)));
  box-shadow: 0 0 12px rgb(var(--cyan) / 0.9);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.7s var(--ease-out), background 0.3s;
}

.lf:focus-within label {
  color: rgb(var(--cyan));
}

.lf:focus-within .lf__line i {
  transform: scaleX(1);
}

/* Error: the line flushes red, and a ripple runs through the sea below */
.lf.is-error .lf__line i {
  transform: scaleX(1);
  background: rgb(var(--danger));
  box-shadow: 0 0 14px rgb(var(--danger) / 0.9);
  animation: line-pulse 1s var(--ease-out);
}

.lf.is-error label {
  color: rgb(var(--danger));
}

@keyframes line-pulse {
  0% { transform: scaleX(0); }
  100% { transform: scaleX(1); }
}

.lf__reveal {
  position: absolute;
  right: -6px;
  bottom: 6px;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: none;
  color: var(--ink-3);
  cursor: pointer;
}

.lf__reveal svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
}

.lf__reveal:hover,
.lf__reveal[aria-pressed="true"] {
  color: #fff;
}

.lf__reveal:focus-visible {
  outline: 2px solid rgb(var(--cyan) / 0.8);
}

.lf-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

/* ---------------- Requirements, messages, lock ---------------- */
.rules {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  margin: -4px 0 0;
  padding: 0;
  list-style: none;
}

.rules li {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--ink-3);
  transition: color 0.3s;
}

.rules li::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  box-shadow: inset 0 0 0 1.5px var(--ink-4);
  transition: background 0.3s, box-shadow 0.3s;
}

.rules li.is-met {
  color: rgb(var(--mint));
}

.rules li.is-met::before {
  background: rgb(var(--mint));
  box-shadow: 0 0 8px rgb(var(--mint) / 0.8);
}

.view__message {
  min-height: 18px;
  margin: -6px 0 -6px;
  font-size: 12.5px;
  line-height: 1.45;
  color: rgb(var(--danger));
}

.view__message.is-ok {
  color: rgb(var(--mint));
}

.lock {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 14px;
  border-radius: 14px;
  background: rgb(var(--amber) / 0.07);
  box-shadow: inset 0 0 0 1px rgb(var(--amber) / 0.3);
  animation: view-in 0.5s var(--ease-out) both;
}

.lock[hidden] {
  display: none;
}

.lock__ring {
  --p: 1;
  width: 34px;
  height: 34px;
  flex: none;
  border-radius: 50%;
  background: conic-gradient(rgb(var(--amber)) calc(var(--p) * 360deg), rgb(var(--amber) / 0.15) 0);
  -webkit-mask: radial-gradient(circle, transparent 54%, #000 56%);
  mask: radial-gradient(circle, transparent 54%, #000 56%);
}

.lock b {
  display: block;
  font: 500 13.5px var(--font-body);
  color: #fff;
}

.lock [data-lock-text] {
  display: block;
  margin-top: 2px;
  font: 12px var(--font-mono);
  color: rgb(var(--amber));
  font-variant-numeric: tabular-nums;
}

/* ---------------- Enter: water rises inside the button ---------------- */
.enter {
  position: relative;
  isolation: isolate;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  height: 56px;
  margin-top: 8px;
  overflow: hidden;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  color: #fff;
  font: 600 12px var(--font-mono);
  letter-spacing: 0.3em;
  text-transform: uppercase;
  background: linear-gradient(120deg, rgb(var(--ksa)) 0%, rgb(8 104 92) 50%, rgb(18 128 150) 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.25),
    inset 0 0 0 1px rgba(150, 240, 230, 0.3),
    0 18px 44px -18px rgba(40, 200, 200, 0.75);
  transition: transform 0.4s var(--ease-out), box-shadow 0.4s, opacity 0.3s;
}

.enter__water {
  position: absolute;
  left: 0;
  bottom: 0;
  z-index: -1;
  width: 200%;
  height: 100%;
  fill: rgba(140, 240, 240, 0.32);
  transform: translate(0, 72%);
  transition: transform 0.9s var(--ease-out);
  animation: enter-roll 6s linear infinite;
}

@keyframes enter-roll {
  to { translate: -50% 0; }
}

.enter:hover .enter__water,
.enter:focus-visible .enter__water {
  transform: translate(0, 18%);
}

.enter__arrow {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform 0.5s var(--ease-out);
}

.enter:hover .enter__arrow {
  transform: translateX(4px);
}

.enter:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 3px;
}

.enter:active {
  transform: scale(0.985);
}

.enter[disabled] {
  cursor: not-allowed;
  opacity: 0.5;
}

.enter.is-busy {
  cursor: progress;
  opacity: 0.85;
}

.enter.is-busy .enter__arrow {
  animation: spin 0.9s linear infinite;
}

.view__switch {
  justify-self: center;
  padding: 6px 10px;
  border: 0;
  background: none;
  cursor: pointer;
  font: 11px var(--font-mono);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-3);
  transition: color 0.3s;
}

.view__switch:hover,
.view__switch:focus-visible {
  outline: none;
  color: rgb(var(--cyan));
}

/* =====================================================================
   Opening and leaving (driven by js/login.js)
   ===================================================================== */
.veil {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: #00040a;
  pointer-events: none;
  animation: veil-failsafe 1s ease 4s forwards; /* if scripts never run, the veil still lifts */
}

@keyframes veil-failsafe {
  to { opacity: 0; }
}

.leave {
  position: fixed;
  inset: 0;
  z-index: 40;
  pointer-events: none;
}

/* A drop of water: the card, gathered */
.leave__drop {
  position: absolute;
  left: 0;
  top: 0;
  width: 26px;
  height: 34px;
  margin: -17px 0 0 -13px;
  border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
  opacity: 0;
  background:
    radial-gradient(circle at 36% 32%, rgba(255, 255, 255, 0.95) 0 10%, rgba(255, 255, 255, 0) 24%),
    radial-gradient(circle at 50% 62%, #d6fbff 0%, #6fd8f0 45%, #1f8cb8 85%, #0d5c84 100%);
  box-shadow: 0 0 18px rgba(140, 235, 255, 0.85), 0 0 50px rgba(60, 190, 255, 0.4);
}

/* Light that swells from where the drop meets the water */
.leave__bloom {
  position: absolute;
  left: 0;
  top: 0;
  width: 240vmax;
  height: 240vmax;
  margin: -120vmax 0 0 -120vmax;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(200, 245, 255, 0.55) 0%, rgba(80, 190, 230, 0.25) 14%, rgba(10, 60, 100, 0.12) 32%, transparent 55%);
  opacity: 0;
  transform: scale(0.02);
}

.leave__deep {
  position: absolute;
  inset: 0;
  background: radial-gradient(80% 70% at 50% 40%, #020b16 0%, #00040a 70%);
  opacity: 0;
}

/* =====================================================================
   Motion preferences and small screens
   ===================================================================== */
@media (prefers-reduced-motion: reduce) {
  .stars i,
  .enter__water { animation: none; }
  .veil { animation-delay: 0s; animation-duration: 0.3s; }
}

@media (max-width: 900px) {
  .gate {
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: center;
    gap: 14px;
    padding: max(8vh, 48px) 16px max(24px, env(safe-area-inset-bottom));
  }

  /* The flag pane becomes a slim band above the card */
  .ensign {
    width: min(440px, 100%);
    flex-direction: row;
    justify-content: flex-start;
    gap: 22px;
    padding: 18px 22px;
  }

  .ensign__frame {
    flex: none;
    width: 112px;
    border-radius: 6px;
  }

  .ensign__frame {
    box-shadow:
      0 0 0 1px rgb(var(--gold) / 0.45),
      0 0 0 5px rgba(2, 14, 24, 0.45),
      0 0 0 6px rgba(160, 222, 255, 0.12),
      0 0 40px -10px rgb(var(--ksa) / 0.55);
  }

  .ensign__frame::after {
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25);
  }

  .ensign__caption {
    justify-items: start;
    gap: 10px;
  }

  .ensign__name {
    margin: 0;
    text-align: left;
    line-height: 1.9;
  }

  .ensign__name span {
    display: block;
  }

  .monolith {
    width: min(440px, 100%);
    padding: 40px 24px 30px;
  }
}

@media (max-width: 420px) {
  .lf-pair {
    grid-template-columns: 1fr;
  }

  .mark__logo {
    height: 108px;
  }
}
