/* Header search box. Laptops and tablets: a box between the site name and KS3/IGCSE/IAL.
   Phones: a magnifying glass that opens the box across the header. */
body > header .wrap { position: relative; }
.search { flex: 1; display: flex; justify-content: center; min-width: 0; }
.search-field { position: relative; width: 100%; max-width: 420px; }
.search-field input {
  font: inherit; font-size: 1rem; width: 100%; padding: 7px 36px 7px 38px;
  border: 2px solid var(--ink); border-radius: 999px; background: var(--paper); color: var(--ink);
  -webkit-appearance: none; appearance: none;
}
.search-field input::placeholder { color: var(--ink-2); opacity: 1; }
.search-field input::-webkit-search-cancel-button { display: none; }
.search-field input:focus { outline: none; box-shadow: 3px 3px 0 var(--hi); }
.search-icon { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--ink-2); pointer-events: none; }
.search-open, .search-close { font: inherit; background: none; border: 0; color: var(--ink); cursor: pointer; padding: 6px; border-radius: 999px; line-height: 1; }
.search-open { display: none; }
.search-close { display: none; position: absolute; right: 6px; top: 50%; transform: translateY(-50%); font-size: 1.5rem; padding: 2px 8px; color: var(--ink-2); }
.search-open:hover, .search-close:hover { background: var(--pen-soft); }

.search-results {
  position: absolute; left: 0; right: 0; top: calc(100% + 8px); z-index: 20;
  background: var(--paper); border: 2px solid var(--ink); border-radius: 12px; box-shadow: 4px 4px 0 var(--ink);
  padding: 6px; max-height: min(70vh, 520px); overflow-y: auto; overscroll-behavior: contain;
}
.search-results a { display: block; padding: 8px 12px; border-radius: 8px; text-decoration: none; color: var(--ink); line-height: 1.3; }
.search-results a[aria-selected="true"] { background: var(--pen-soft); }
.search-results .r-t { display: block; font-weight: 700; }
.search-results .r-w { display: block; font-size: 0.85rem; color: var(--ink-2); }
.search-none { padding: 10px 12px; color: var(--ink-2); font-size: 0.95rem; }

@media (max-width: 759px) {
  .search { flex: 0 0 auto; order: 3; }
  header nav { margin-left: auto; }
  .search-open { display: inline-flex; }
  .search-field { display: none; }
  body.searching .search-field {
    display: block; position: absolute; left: 0; right: 0; top: 0; bottom: 0; max-width: none;
    background: var(--paper); padding: 0 max(16px, env(safe-area-inset-left, 0px)); display: flex; align-items: center;
  }
  body.searching .search-field input { font-size: 16px; padding-block: 9px; }
  body.searching .search-icon { left: calc(max(16px, env(safe-area-inset-left, 0px)) + 13px); }
  body.searching .search-close { display: block; right: calc(max(16px, env(safe-area-inset-right, 0px)) + 4px); }
  body.searching .search-results { left: max(16px, env(safe-area-inset-left, 0px)); right: max(16px, env(safe-area-inset-right, 0px)); top: calc(100% + 6px); max-height: 70vh; }
}
@media (max-width: 400px) { .search-open { padding: 4px; } }
@media print { .search { display: none !important; } }
