/* Site search. Uses the page's own variables when they exist.
   The button is fixed, so it never shifts layout. */

/* Only the site's own top bars make room for the magnifier (a bare `nav` selector also hit the hubs'
   side rail, nav.worldRail, and in-app navs). Not class-gated: this file only loads where search runs,
   and the home page, /academy/ and the subject hubs link it in <head>, so the room is there from the
   first paint and the bar never shifts when the button arrives. */
nav.subjectNav,
#bar[data-ae-profile-nav] {
  padding-right: calc(58px + env(safe-area-inset-right, 0px)) !important;
}
/* The home/shelf bar (nav#nav) is full on a phone narrower than 390px: reserving the corner there
   wraps its menu button onto a row of its own. Below 390px the corner button hides on those pages
   and Search is the first entry in the ≡ menu instead (search.js, menuEntry). */
@media (min-width: 390px) {
  nav#nav { padding-right: calc(58px + env(safe-area-inset-right, 0px)) !important; }
}
@media (max-width: 389.98px) {
  html.ae-search-menu #aeSearchBtn { display: none !important; }
}
.ae-ns-search { cursor: pointer; }

#aeSearchBtn {
  position: fixed;
  top: calc(8px + env(safe-area-inset-top, 0px) + var(--ae-search-drop, 0px));
  right: calc(8px + env(safe-area-inset-right, 0px));
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  z-index: 2147483003;
  margin: 0;
  padding: 0;
  border: 1px solid rgba(110, 231, 255, .58);
  border-radius: 13px;
  background: rgba(5, 9, 24, .88);
  color: var(--fg, #e8ecff);
  box-shadow: 0 4px 22px rgba(0, 0, 0, .5);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  cursor: pointer;
  pointer-events: auto;
  opacity: 1;
  visibility: visible;
  transform: none;
  -webkit-tap-highlight-color: transparent;
}
#aeSearchBtn[hidden] { display: none !important; }
#aeSearchBtn svg { width: 26px; height: 26px; display: block; pointer-events: none; }
#aeSearchBtn:hover { background: #162441; border-color: var(--gold, #ffd97a); }
#aeSearchBtn:focus-visible { outline: 3px solid var(--gold, #ffd97a); outline-offset: 3px; }
#aeSearchBtn[aria-expanded="true"] {
  border-color: var(--gold, #ffd97a);
  background: #162441;
}

.ae-search-root {
  position: fixed;
  inset: 0;
  z-index: 2147483001;
  background: rgba(3, 3, 12, .62);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}
.ae-search-root[hidden] { display: none !important; }

.ae-search-panel {
  position: fixed;
  z-index: 2147483002;
  left: 50%;
  top: 11vh;
  transform: translateX(-50%);
  width: min(640px, calc(100vw - 48px));
  max-height: min(72vh, 680px);
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  padding: 14px;
  border-radius: 22px;
  border: 1px solid var(--line, rgba(120, 140, 220, .28));
  background: rgba(8, 10, 28, .97);
  color: var(--fg, #e8ecff);
  box-shadow: 0 30px 80px rgba(0, 0, 0, .55), 0 0 0 1px rgba(110, 231, 255, .08);
  font-family: "Space Grotesk", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.4;
}

.ae-search-head {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
}
.ae-search-field {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 48px;
  padding: 0 4px 0 0;
  border-radius: 14px;
  border: 1px solid rgba(110, 231, 255, .45);
  background: rgba(255, 255, 255, .04);
}
.ae-search-field:focus-within { outline: 3px solid var(--gold, #ffd97a); outline-offset: 2px; }
.ae-search-input {
  flex: 1 1 auto;
  min-width: 0;
  width: 100%;
  min-height: 48px;
  margin: 0;
  padding: 0 14px;
  border: 0;
  border-radius: 14px;
  background: transparent;
  color: var(--fg, #e8ecff);
  font: 500 16px/1.2 "Space Grotesk", system-ui, sans-serif;
  letter-spacing: .01em;
}
.ae-search-input::placeholder { color: #c5cdee; opacity: 1; }
.ae-search-input:focus { outline: none; }
.ae-search-input::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; }

.ae-search-clear,
.ae-search-close {
  flex: none;
  min-width: 44px;
  min-height: 44px;
  margin: 0;
  padding: 0 12px;
  border-radius: 12px;
  border: 1px solid var(--line, rgba(120, 140, 220, .35));
  background: rgba(255, 255, 255, .04);
  color: var(--fg, #e8ecff);
  font: 600 13px/1 "Space Grotesk", system-ui, sans-serif;
  cursor: pointer;
}
.ae-search-clear[hidden] { display: none !important; }
.ae-search-close { color: #071018; background: var(--gold, #ffd97a); border-color: var(--gold, #ffd97a); }
.ae-search-clear:focus-visible,
.ae-search-close:focus-visible,
.ae-sr:focus-visible,
.ae-shelf:focus-visible,
.ae-suggest:focus-visible { outline: 3px solid var(--gold, #ffd97a); outline-offset: 2px; }
.ae-search-clear:hover,
.ae-search-close:hover { filter: brightness(1.06); }

.ae-search-list {
  overflow: auto;
  overscroll-behavior: contain;
  margin-top: 12px;
  padding-right: 2px;
  min-height: 0;
}
.ae-search-kicker {
  margin: 2px 2px 8px;
  color: #c5cdee;
  font: 700 14px/1.3 "Space Grotesk", system-ui, sans-serif;
  letter-spacing: .02em;
}
.ae-search-note {
  margin: 8px 2px 12px;
  color: var(--fg, #e8ecff);
  font-size: 16px;
}
.ae-search-live {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.ae-sg { margin: 0 0 12px; }
.ae-sg-h {
  margin: 8px 2px 6px;
  color: var(--cyan, #6ee7ff);
  font: 700 14px/1.3 "Space Grotesk", system-ui, sans-serif;
  letter-spacing: .04em;
}
.ae-sg[data-shelf="games"] .ae-sg-h { color: #3dffc8; }
.ae-sg[data-shelf="interactive"] .ae-sg-h { color: #8ec8ff; }
.ae-sg[data-shelf="animations"] .ae-sg-h { color: #ffb86b; }
.ae-sg[data-shelf="simulations"] .ae-sg-h { color: #c9a6ff; }
.ae-sg[data-shelf="music"] .ae-sg-h { color: #ffb0e4; }
.ae-sg[data-shelf="pages"] .ae-sg-h { color: var(--gold, #ffd97a); }

.ae-sr {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  grid-template-areas: "badge title beta open" "desc desc desc desc" "why why why why";
  gap: 4px 8px;
  align-items: center;
  min-height: 44px;
  margin: 0 0 6px;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid rgba(120, 140, 220, .22);
  background: rgba(255, 255, 255, .03);
  color: inherit;
  text-decoration: none;
  box-sizing: border-box;
}
.ae-sr[aria-selected="true"],
.ae-sr:hover {
  border-color: rgba(110, 231, 255, .7);
  background: rgba(110, 231, 255, .1);
}
.ae-badge {
  grid-area: badge;
  color: #071018;
  background: var(--cyan, #6ee7ff);
  border-radius: 999px;
  padding: 3px 8px;
  font: 700 11px/1.2 "Space Grotesk", system-ui, sans-serif;
  letter-spacing: .02em;
  white-space: nowrap;
}
.ae-badge[data-shelf="games"] { background: #3dffc8; }
.ae-badge[data-shelf="interactive"] { background: #8ec8ff; }
.ae-badge[data-shelf="animations"] { background: #ffb86b; }
.ae-badge[data-shelf="simulations"] { background: #c9a6ff; }
.ae-badge[data-shelf="music"] { background: #ffb0e4; }
.ae-badge[data-shelf="pages"] { background: var(--gold, #ffd97a); }
.ae-title {
  grid-area: title;
  min-width: 0;
  font-weight: 600;
  font-size: 16px;
  letter-spacing: .01em;
  color: var(--fg, #e8ecff);
}
.ae-beta {
  grid-area: beta;
  justify-self: end;
  color: #1a1404;
  background: var(--gold, #ffd97a);
  border-radius: 999px;
  padding: 4px 8px;
  font: 800 12px/1.2 "Space Grotesk", system-ui, sans-serif;
  letter-spacing: .01em;
  white-space: nowrap;
}
.ae-open {
  grid-area: open;
  justify-self: end;
  color: #ffd97a;
  font: 800 14px/1 "Space Grotesk", system-ui, sans-serif;
  letter-spacing: .04em;
}
.ae-why {
  grid-area: why;
  color: #c5cdee;
  font-size: 14px;
}
.ae-desc {
  grid-area: desc;
  color: #d5dcf4;
  font-size: 15px;
  font-weight: 400;
}
.ae-sr mark {
  background: transparent;
  color: var(--gold, #ffd97a);
  font-weight: 700;
  padding: 0;
}
.ae-try .ae-desc { color: var(--cyan, #6ee7ff); font-weight: 600; }

.ae-shelves {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.ae-shelf {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid rgba(120, 140, 220, .35);
  background: rgba(255, 255, 255, .04);
  color: var(--fg, #e8ecff);
  text-decoration: none;
  font: 600 14px/1 "Space Grotesk", system-ui, sans-serif;
}
.ae-shelf[data-shelf="academy"] { border-color: rgba(110, 231, 255, .55); }
.ae-shelf[data-shelf="games"] { border-color: rgba(61, 255, 200, .55); }
.ae-shelf[data-shelf="interactive"] { border-color: rgba(142, 200, 255, .55); }
.ae-shelf[data-shelf="animations"] { border-color: rgba(255, 184, 107, .55); }
.ae-shelf[data-shelf="simulations"] { border-color: rgba(201, 166, 255, .55); }
.ae-shelf[data-shelf="music"] { border-color: rgba(255, 176, 228, .55); }
.ae-shelf:hover,
.ae-suggest:hover { background: rgba(110, 231, 255, .12); }
.ae-note-go {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 44px;
  margin: 0 0 12px;
  padding: 0 16px;
  border-radius: 14px;
  background: var(--gold, #ffd97a);
  color: #071018;
  text-decoration: none;
  font: 800 16px/1.2 "Space Grotesk", system-ui, sans-serif;
}
.ae-note-go:focus-visible { outline: 3px solid #6ee7ff; outline-offset: 2px; }
.ae-note-go:hover { filter: brightness(1.06); }
.ae-suggest {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 44px;
  margin: 0 0 10px;
  padding: 0 14px;
  border-radius: 14px;
  border: 1px solid rgba(255, 217, 122, .7);
  background: rgba(255, 217, 122, .1);
  color: var(--fg, #e8ecff);
  font: 700 16px/1.2 "Space Grotesk", system-ui, sans-serif;
  text-align: left;
  cursor: pointer;
}

html.ae-search-open,
html.ae-search-open body { overflow: hidden; }

@media (max-width: 700px) {
  .ae-search-panel {
    left: 0;
    right: 0;
    top: calc(60px + env(safe-area-inset-top, 0px));
    transform: none;
    width: 100%;
    max-width: 100%;
    max-height: calc(100dvh - 68px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
    border-radius: 0 0 22px 22px;
    border-left: 0;
    border-right: 0;
    padding: 12px 12px calc(12px + env(safe-area-inset-bottom, 0px));
  }
  .ae-title { font-size: 16.5px; }
  .ae-sr {
    grid-template-columns: 1fr auto;
    grid-template-areas: "badge open" "title title" "beta beta" "desc desc" "why why";
  }
  .ae-beta { justify-self: start; white-space: normal; }
  .ae-badge { justify-self: start; }
}

@media (prefers-reduced-motion: reduce) {
  #aeSearchBtn, .ae-search-root, .ae-search-panel, .ae-sr { transition: none !important; animation: none !important; }
}
html.nomo .ae-search-panel,
html[data-motion="off"] .ae-search-panel,
html.nomo #aeSearchBtn,
html[data-motion="off"] #aeSearchBtn { transition: none !important; animation: none !important; }

@media (prefers-reduced-motion: no-preference) {
  html:not(.nomo):not([data-motion="off"]) .ae-search-root:not([hidden]) .ae-search-panel {
    animation: aeSearchIn .18s ease;
  }
}
@keyframes aeSearchIn {
  from { opacity: 0; transform: translateX(-50%) translateY(-8px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}
@media (max-width: 700px) and (prefers-reduced-motion: no-preference) {
  html:not(.nomo):not([data-motion="off"]) .ae-search-root:not([hidden]) .ae-search-panel {
    animation-name: aeSearchInPhone;
  }
}
@keyframes aeSearchInPhone {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: none; }
}

@media print {
  #aeSearchBtn, .ae-search-root { display: none !important; }
}
