* {
  box-sizing: border-box;
}

:root {
  /* Dark-only: night base from the gate sky; coral = logo, the one primary action */
  --bg-light: #0a1628;
  --text-primary: #e5f0fa;
  --text-secondary: #88a9c5;
  --coral: #f75c61;
  --coral-ink: #0a1628;
  --font-ui: "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-display: Syne, var(--font-ui);
  --space-outer: clamp(20px, 6vw, 28px);
  --menu-pad-y: clamp(16px, 4.2vw, 28px);
  --menu-pad-x: clamp(14px, 4vw, 22px);
  --grid-gap: clamp(8px, 2.2vw, 11px);
  --cat-min-h: clamp(48px, 12.5vw, 56px);
  --cat-size: clamp(13px, 3.4vw, 15px);
  --menu-max: 320px;
  --dawn-ms: 1.6s;
  --ease-soft: cubic-bezier(0.22, 1, 0.36, 1);
}

html,
body {
  color-scheme: dark;
  margin: 0;
  width: 100%;
  min-height: 100%;
  background: var(--bg-light);
  color: var(--text-primary);
  font-family: var(--font-ui);
}

body {
  min-height: 100svh;
  min-height: 100dvh;
  overflow: hidden;
}

.gate-bg {
  position: fixed;
  inset: -2%;
  background-position: center center;
  background-repeat: no-repeat;
  background-size: cover;
  transform: scale(1.02);
  pointer-events: none;
}

.gate-bg--night {
  z-index: 1;
  background-color: #0a1628;
  background-image: url("./gate-bg.jpg");
  opacity: 1;
  filter: brightness(0.78) contrast(1.04);
}

.gate-bg--night::after,
.gate-bg--day::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    180deg,
    rgba(10, 22, 40, 0.35) 0%,
    rgba(10, 22, 40, 0.12) 45%,
    rgba(10, 22, 40, 0.45) 100%
  );
}

.gate-bg--day {
  z-index: 0;
  background-color: var(--bg-light);
  background-image: none;
  opacity: 0;
  filter: brightness(0.78) contrast(1.04);
}

/* Circle reveal: day opens from bear center over night */
.gate-dawn-mask {
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  opacity: 0;
  background-color: var(--bg-light);
  background-position: center center;
  background-repeat: no-repeat;
  background-size: cover;
  clip-path: circle(0% at var(--dawn-x, 50%) var(--dawn-y, 50%));
  -webkit-clip-path: circle(0% at var(--dawn-x, 50%) var(--dawn-y, 50%));
}

.gate-dawn-mask.is-active {
  opacity: 1;
  animation: dawn-circle-grow var(--dawn-dur, 2.7s) cubic-bezier(0.33, 0, 0.2, 1) forwards;
}

@keyframes dawn-circle-grow {
  from {
    clip-path: circle(0% at var(--dawn-x, 50%) var(--dawn-y, 50%));
    -webkit-clip-path: circle(0% at var(--dawn-x, 50%) var(--dawn-y, 50%));
  }
  to {
    clip-path: circle(150% at var(--dawn-x, 50%) var(--dawn-y, 50%));
    -webkit-clip-path: circle(150% at var(--dawn-x, 50%) var(--dawn-y, 50%));
  }
}

#snow,
#snow-front {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

#snow {
  z-index: 2;
}

#snow-front {
  z-index: 50;
}

.gate-shell {
  position: relative;
  z-index: 4;
  display: grid;
  place-items: center;
  width: 100%;
  min-height: 100svh;
  min-height: 100dvh;
  padding:
    max(var(--space-outer), env(safe-area-inset-top))
    max(var(--space-outer), env(safe-area-inset-right))
    max(var(--space-outer), env(safe-area-inset-bottom))
    max(var(--space-outer), env(safe-area-inset-left));
}

.gate-panel {
  position: relative;
  width: min(78vw, var(--menu-max));
  max-height: calc(
    100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) -
      (var(--space-outer) * 2)
  );
  overflow: visible;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: var(--menu-pad-y) var(--menu-pad-x);
  border-radius: clamp(30px, 8vw, 40px);
  background-color: transparent;
  background-image: none;
  box-shadow: none;
}

body.is-choreo .gate-panel {
  overflow: visible;
  overflow-x: visible;
}

/* Gate frost stays off — React menu owns the single panel reveal */
.gate-panel::before {
  content: none;
  display: none;
}

.gate-form,
.gate-error,
.brand {
  position: relative;
  z-index: 1;
}

.brand {
  display: flex;
  align-items: center;
  flex-direction: column;
  margin-bottom: clamp(14px, 4vw, 24px);
  text-align: center;
}

.brand-type {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.bear-slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: clamp(56px, 15vw, 88px);
  margin: 0 0 clamp(4px, 1.4vw, 8px);
  z-index: 3;
}

.gate-encrypt {
  margin: 8px 0 0;
  padding: 0;
  font-family: var(--font-ui, "Segoe UI", sans-serif);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.14em;
  line-height: 1.2;
  text-transform: lowercase;
  color: rgba(232, 242, 250, 0.88);
  text-align: center;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
}

.gate-encrypt.is-on {
  opacity: 1;
  transition: opacity 0.2s ease;
}

.gate-encrypt-dots {
  display: inline-block;
  width: 0;
  overflow: hidden;
  vertical-align: bottom;
  animation: encrypt-dots 1.25s steps(4, end) infinite;
}

.gate-encrypt.is-on .gate-encrypt-dots {
  animation-play-state: running;
}

@keyframes encrypt-dots {
  to {
    width: 1.15em;
  }
}

.bear-slot.is-pinned,
.gate-field-wrap.is-pinned,
.brand-type.is-pinned,
.gate-start.is-pinned {
  pointer-events: none;
  overflow: visible;
}

.bear-slot.is-pinned {
  overflow: visible;
}

.bear-slot--flying {
  z-index: 70 !important;
}

/* Keep snow behind choreographed pins (pins live on body at z≥60) */
body.is-choreo #snow-front {
  z-index: 45;
}

.bear {
  display: block;
  width: 100%;
  height: auto;
  margin: 0;
  user-select: none;
  -webkit-user-drag: none;
  transform-origin: center center;
}

@keyframes bear-spin {
  to {
    transform: rotate(360deg);
  }
}

/* Spin only on the img — slot moves via WAAPI */
body.is-bear-busy .bear {
  animation: bear-spin 1.05s linear infinite;
}

.wordmark {
  margin: 0;
  padding: 0;
  color: #f2f7fc;
  font-family: var(--font-display);
  font-size: clamp(1.35rem, 6vw, 1.7rem);
  font-weight: 700;
  letter-spacing: 0.2em;
  line-height: 1;
  text-indent: 0.2em;
  white-space: nowrap;
  text-transform: uppercase;
  text-shadow:
    0 0 14px rgba(255, 255, 255, 0.45),
    0 1px 0 rgba(255, 255, 255, 0.85),
    0 2px 10px rgba(10, 22, 40, 0.55);
}

.drop {
  margin: clamp(2px, 1vw, 6px) 0 0;
  padding: 0;
  color: #c5d9ec;
  font-family: var(--font-ui);
  font-size: clamp(0.7rem, 2.9vw, 0.82rem);
  font-weight: 600;
  letter-spacing: 0.32em;
  line-height: 1.2;
  text-indent: 0.32em;
  text-transform: uppercase;
  text-shadow: 0 1px 6px rgba(10, 22, 40, 0.45);
}

.gate-form {
  display: grid;
  gap: 10px;
  width: min(100%, 300px);
  margin: 0 auto;
  justify-items: center;
}

.gate-field-wrap {
  position: relative;
  z-index: 2;
  width: 100%;
  overflow: hidden;
  border-radius: 999px;
}

.category {
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: var(--cat-min-h);
  padding: 0.55em 0.9em;
  margin: 0;
  border: 1px solid rgba(136, 169, 197, 0.35);
  border-radius: 15px;
  background: linear-gradient(
    180deg,
    rgba(30, 52, 78, 0.88) 0%,
    rgba(23, 42, 65, 0.88) 100%
  );
  box-shadow: 0 2px 6px rgba(5, 15, 32, 0.4);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: var(--cat-size);
  font-weight: 700;
  letter-spacing: 0.08em;
  line-height: 1.15;
  text-align: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.12s ease-out;
}

.category:active {
  transform: scale(0.98);
}

/* Idle: password is the hero */
.gate-field {
  width: 100%;
  margin: 0;
  padding: 16px 22px;
  min-height: 54px;
  border: 0;
  border-radius: 999px;
  background: rgba(15, 30, 51, 0.82);
  box-shadow:
    0 4px 16px rgba(5, 15, 32, 0.45),
    0 0 0 1px rgba(136, 169, 197, 0.35);
  color: var(--text-primary);
  font: inherit;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.08em;
  outline: none;
  -webkit-appearance: none;
}

.gate-field::placeholder {
  color: var(--text-secondary);
  letter-spacing: 0.1em;
  font-weight: 500;
}

.gate-field:focus {
  box-shadow:
    0 0 0 2px var(--coral),
    0 4px 16px rgba(5, 15, 32, 0.45);
}

/* Idle: Start secondary / smaller */
.gate-start {
  width: min(100%, 168px);
  min-height: 40px;
  padding: 0.45em 1.1em;
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  border-color: transparent;
  background: var(--coral);
  box-shadow: 0 2px 10px rgba(247, 92, 97, 0.25);
  color: var(--coral-ink);
  position: relative;
  z-index: 1;
}

.gate-start:disabled {
  cursor: wait;
}

body.is-choreo .gate-error {
  opacity: 0;
}

.gate-error {
  min-height: 1.2em;
  margin: 12px 0 0;
  text-align: center;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: #f69a9d;
  transition: opacity 0.25s ease;
}

.gate-error:empty {
  visibility: hidden;
}

#root {
  position: fixed;
  inset: 0;
  z-index: 3;
  min-height: 100svh;
  min-height: 100dvh;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

#root.is-ready {
  visibility: visible;
}

#root.is-visible {
  opacity: 1;
  pointer-events: auto;
}

/* ——— Travel / Build: hide gate chrome; only flying bear remains ——— */
body.is-dawn .gate-form,
body.is-dawn .gate-error,
body.is-dawn .brand-type {
  opacity: 0 !important;
  pointer-events: none;
  visibility: hidden;
}

body.is-dawn .gate-panel {
  background: transparent;
  box-shadow: none;
}

body.is-dawn .gate-shell--handoff {
  pointer-events: none;
}

body.is-dawn .gate-shell--handoff .bear-slot:not(.is-pinned) {
  opacity: 0;
  visibility: hidden;
}

body.is-choreo .brand-type:not(.is-pinned) {
  visibility: hidden;
}

/* Day/night crossfade handled by snowflake mask in JS — no opacity race */

/* Root visible for layout/FLIP; menu held until is-reveal */
body.is-dawn #root.is-ready.is-visible {
  opacity: 1;
  pointer-events: none;
}

body.is-reveal #root.is-ready.is-visible {
  pointer-events: auto;
}

body.is-unlocked .gate-bg--day {
  opacity: 1;
}

@media (max-width: 390px) {
  :root {
    --menu-pad-y: 16px;
    --menu-pad-x: 14px;
    --grid-gap: 9px;
    --cat-min-h: 52px;
    --cat-size: 13.5px;
  }

  .wordmark {
    font-size: clamp(1.7rem, 7.8vw, 2rem);
    letter-spacing: 0.24em;
    text-indent: 0.24em;
  }

  .drop {
    font-size: 0.7rem;
    letter-spacing: 0.28em;
    text-indent: 0.28em;
  }
}

@media (max-width: 360px) {
  :root {
    --space-outer: 18px;
    --menu-pad-y: 14px;
    --menu-pad-x: 12px;
    --grid-gap: 8px;
    --cat-min-h: 50px;
    --cat-size: 13px;
  }

  .gate-panel {
    border-radius: 30px;
  }

  .brand {
    margin-bottom: 12px;
  }
}

@media (max-height: 740px) {
  :root {
    --menu-pad-y: 14px;
    --grid-gap: 8px;
    --cat-min-h: 48px;
  }

  .bear {
    width: clamp(48px, 14vw, 64px);
  }

  .brand {
    margin-bottom: 12px;
  }

  .wordmark {
    font-size: clamp(1.25rem, 5.6vw, 1.5rem);
  }

  .drop {
    margin-top: 3px;
  }

  .gate-field {
    min-height: 50px;
    padding: 14px 18px;
  }
}

@media (max-height: 640px) {
  :root {
    --cat-min-h: 46px;
    --cat-size: 12.5px;
  }

  .bear {
    width: 44px;
    margin-bottom: 4px;
  }

  .brand {
    margin-bottom: 10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  :root {
    --dawn-ms: 0.3s;
  }

  body.is-bear-busy .bear {
    animation: none;
  }

  .gate-dawn-mask.is-active {
    animation-duration: 0.12s;
  }

  .gate-encrypt-dots {
    animation: none;
    width: 1.15em;
  }
}
