/* Hallmark · genre: playful · component: site search ("the typewriter") · theme: custom (site tokens) · tone: playful-bold
 * Loaded on every page (header.php), with search.js.
 * idea: searching is typing. A sheet feeds out of the roller of a Tiga Titik typewriter, you
 * type on it, and the answers are typed back line by line — then the bell. The machine's keys
 * go down as you type. On phones only the sheet shows.
 * type: Courier Prime (the typewriter) on the paper; Anton on the name plate.
 */

/* The header button ----------------------------------------------------------------------- */

.search-toggle {
  display: inline-grid;
  flex: none;
  place-items: center;
  width: 2.5rem;
  height: 2.5rem;
  margin-inline-start: var(--space-sm);
  border: var(--rule-hair) solid color-mix(in oklch, currentColor 30%, transparent);
  border-radius: 50%;
  color: inherit;
  transition: border-color var(--dur-short) var(--ease-out), background-color var(--dur-short) var(--ease-out);
}

.search-toggle__icon {
  width: 1.1rem;
  height: 1.1rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  transition: rotate var(--dur-long) var(--ease-out);
}

.search-toggle:focus-visible {
  outline: 2px solid var(--color-focus);
  outline-offset: 2px;
}

@media (hover: hover) {
  .search-toggle:hover {
    border-color: currentColor;
    background-color: color-mix(in oklch, currentColor 10%, transparent);
  }

  .search-toggle:hover .search-toggle__icon {
    rotate: -12deg;
  }
}

/* The modal --------------------------------------------------------------------------------- */

html.is-search-open {
  overflow: hidden;
}

.tw {
  --tw-ink: var(--color-ink);
  --tw-paper: oklch(98.8% 0.012 95);           /* warm, slightly creamy sheet */
  --tw-line: oklch(88% 0.03 255 / 0.45);       /* faint blue rules on the sheet */
  --tw-metal: oklch(80% 0.01 264);             /* the key rims */
  position: fixed;
  inset: 0;
  z-index: calc(var(--z-modal) + 50);
  display: grid;
  place-items: center;
  padding: var(--space-xl) var(--gutter);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.tw[hidden] {
  display: none;
}

.tw__backdrop {
  position: fixed;
  inset: 0;
  background-color: color-mix(in oklch, var(--color-ink) 74%, transparent);
  -webkit-backdrop-filter: blur(10px) saturate(1.2);
  backdrop-filter: blur(10px) saturate(1.2);
}

.tw__machine {
  position: relative;
  display: grid;
  justify-items: center;
  width: min(44rem, 100%);
}

.tw__close {
  position: absolute;
  inset-block-start: -0.5rem;
  inset-inline-end: -0.5rem;
  z-index: 3;
  display: grid;
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
  padding: 0;
  border: var(--rule-hair) solid color-mix(in oklch, var(--color-paper) 30%, transparent);
  border-radius: 50%;
  background-color: color-mix(in oklch, var(--color-ink) 55%, transparent);
  color: var(--color-paper);
  --color-focus: var(--color-lime);
}

.tw__close svg {
  width: 1.1rem;
  height: 1.1rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

@media (hover: hover) {
  .tw__close:hover {
    background-color: var(--color-paper);
    color: var(--color-ink);
  }
}

/* The sheet: tucked behind the roller, it feeds up when the modal opens. */
.tw__paper {
  position: relative;
  z-index: 1;
  width: 84%;
  margin-block-end: -1.4rem;
  filter: drop-shadow(0 1.25rem 1.5rem color-mix(in oklch, var(--color-ink) 45%, transparent));
}

/* A fixed height, so the machine stays put as the answers come and go; the key hints sit at
 * the foot of the sheet. */
.tw__sheet {
  display: flex;
  flex-direction: column;
  height: min(56dvh, 31rem);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--space-lg) var(--space-xl) calc(var(--space-xl) + 1rem);
  border-radius: 0.3rem 0.3rem 0 0;
  background:
    repeating-linear-gradient(to bottom, transparent 0 calc(1.9rem - 1px), var(--tw-line) calc(1.9rem - 1px) 1.9rem) 0 3.6rem / 100% 100% no-repeat,
    var(--tw-paper);
  color: var(--tw-ink);
  font-family: "Courier Prime", ui-monospace, "Cascadia Code", Menlo, Consolas, monospace;
  font-size: 1rem;
  line-height: 1.9rem;
  scrollbar-width: thin;
}

.tw.is-opening .tw__paper {
  animation: tw-feed 0.7s var(--ease-out) both;
}

.tw.is-closing .tw__paper {
  animation: tw-feed 0.28s var(--ease-in) reverse both;
}

.tw.is-closing .tw__machine {
  animation: tw-drop 0.28s var(--ease-in) both;
}

.tw.is-opening .tw__machine {
  animation: tw-rise var(--dur-long) var(--ease-out) both;
}

.tw.is-closing .tw__backdrop {
  animation: tw-fade 0.28s var(--ease-in) reverse both;
}

.tw.is-opening .tw__backdrop {
  animation: tw-fade var(--dur-long) var(--ease-out) both;
}

@keyframes tw-feed {
  from {
    clip-path: inset(100% 0 0 0);
    translate: 0 4rem;
  }

  to {
    clip-path: inset(0 0 0 0);
    translate: 0 0;
  }
}

@keyframes tw-rise {
  from {
    opacity: 0;
    translate: 0 2rem;
  }
}

@keyframes tw-drop {
  to {
    opacity: 0;
    translate: 0 2rem;
  }
}

@keyframes tw-fade {
  from {
    opacity: 0;
  }
}

/* Every keystroke strikes the sheet: a tiny jolt. */
.tw__paper.is-strike {
  animation: tw-strike 90ms steps(2) both;
}

@keyframes tw-strike {
  50% {
    translate: 0 -2px;
  }
}

.tw__head {
  display: flex;
  justify-content: space-between;
  gap: var(--space-md);
  padding-block-end: 0.3rem;
  border-block-end: 2px dashed color-mix(in oklch, var(--tw-ink) 30%, transparent);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.tw__date {
  color: color-mix(in oklch, var(--tw-ink) 60%, transparent);
}

/* The typing line: a prompt, and the input with a block caret. */
.tw__line {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-block: var(--space-md) var(--space-xs);
  padding-block: 0.25rem;
  border-block-end: 2px solid var(--tw-ink);
  cursor: text;
}

.tw__prompt {
  color: var(--color-blue);
  font-size: 1.5rem;
  font-weight: 700;
}

.tw__input {
  flex: 1;
  min-width: 0;
  padding: 0;
  border: 0;
  background: none;
  color: var(--tw-ink);
  font: inherit;
  font-size: clamp(1.25rem, 3.6vw, 1.75rem);
  font-weight: 700;
  line-height: 2.4rem;
  caret-color: var(--color-blue);
  caret-shape: block;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

.tw__input::placeholder {
  color: color-mix(in oklch, var(--tw-ink) 30%, transparent);
  font-weight: 400;
}

.tw__input::-webkit-search-cancel-button {
  display: none;
}

.tw__label {
  color: color-mix(in oklch, var(--tw-ink) 55%, transparent);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

/* The answers, typed back. */
.tw__results {
  display: grid;
  margin: 0;
  padding: 0;
  list-style: none;
}

.tw-result {
  display: grid;
  grid-template-columns: 2.4ch minmax(0, 1fr) auto;
  gap: 0 0.9ch;
  align-items: baseline;
  padding: 0.05rem 0.5rem;
  margin-inline: -0.5rem;
  border-radius: 0.25rem;
  color: inherit;
  text-decoration: none;
}

.tw-result__no {
  position: relative;
  color: color-mix(in oklch, var(--tw-ink) 45%, transparent);
  font-size: 0.85rem;
}

.tw__empty {
  color: color-mix(in oklch, var(--tw-ink) 60%, transparent);
  font-style: italic;
}

.tw-result__text {
  display: grid;
  min-width: 0;
}

.tw-result__title {
  overflow: hidden;
  font-weight: 700;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.tw-result__desc {
  margin-block-start: -0.55rem;
  overflow: hidden;
  color: color-mix(in oklch, var(--tw-ink) 60%, transparent);
  font-size: 0.82rem;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.tw-result__desc:empty {
  display: none;
}

.tw-result__kind {
  color: var(--color-blue-deep);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  opacity: 0;
  transition: opacity var(--dur-short) var(--ease-out);
}

.tw-result.is-typed .tw-result__kind {
  opacity: 1;
}

/* The block caret rides along the line being typed. */
.tw-result.is-typing .tw-result__title::after,
.tw__label.is-typing::after {
  content: "";
  display: inline-block;
  width: 0.6ch;
  height: 1em;
  margin-inline-start: 1px;
  background-color: var(--color-blue);
  vertical-align: -0.12em;
}

/* The line you'd open: highlighted, as with a marker. */
.tw-result[aria-selected="true"] {
  background-color: color-mix(in srgb, var(--color-lime) 55%, var(--tw-paper));
}

.tw-result[aria-selected="true"] .tw-result__no::before {
  content: "▸";
  position: absolute;
  margin-inline-start: -1.1ch;
  color: var(--color-blue);
}

.tw-result:focus-visible {
  outline: 2px solid var(--color-blue);
  outline-offset: 1px;
}

.tw-result mark {
  background: none;
  color: inherit;
  text-decoration: underline;
  text-decoration-color: var(--color-blue);
  text-decoration-thickness: 0.18em;
  text-underline-offset: 0.18em;
}

.tw__hint {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1.5rem;
  margin-block-start: auto;
  padding-block-start: 0.3rem;
  border-block-start: 2px dashed color-mix(in oklch, var(--tw-ink) 22%, transparent);
  color: color-mix(in oklch, var(--tw-ink) 50%, transparent);
  font-size: 0.75rem;
}

/* The roller (platen) with its knobs, and the bell ------------------------------------------ */

.tw__roller {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  width: 96%;
  height: 2.8rem;
}

.tw__platen {
  flex: 1;
  height: 2.3rem;
  border-radius: 1.2rem;
  background: linear-gradient(to bottom, var(--color-ink-3) 0%, oklch(10% 0.02 264) 45%, var(--color-ink-2) 75%, var(--color-ink-3) 100%);
  box-shadow: 0 0.6rem 1rem -0.4rem var(--color-shadow);
}

.tw__knob {
  flex: none;
  width: 2.4rem;
  height: 2.8rem;
  margin-inline: -0.3rem;
  border-radius: 0.8rem;
  background:
    repeating-linear-gradient(to bottom, color-mix(in oklch, var(--color-paper) 18%, transparent) 0 2px, transparent 2px 5px),
    linear-gradient(to right, var(--color-ink-2), var(--color-ink-3) 50%, var(--color-ink-2));
  box-shadow: 0 0.4rem 0.8rem -0.3rem var(--color-shadow);
}

/* The bell: a lime dot that rings when the answers are done. */
.tw__bell {
  position: absolute;
  inset-block-start: -0.75rem;
  inset-inline-end: 0.55rem; /* on the right knob */
  width: 1.3rem;
  height: 1.3rem;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, oklch(97% 0.12 128), var(--color-lime) 55%, oklch(70% 0.18 128));
  box-shadow: 0 0.2rem 0.5rem -0.1rem var(--color-shadow);
  transform-origin: 50% 100%;
}

.tw__bell.is-ringing {
  animation: tw-ding 0.6s var(--ease-out);
}

@keyframes tw-ding {
  15% { rotate: -22deg; }
  35% { rotate: 18deg; }
  55% { rotate: -10deg; }
  75% { rotate: 5deg; }
}

/* The body: ink, with a blue band and the name plate ---------------------------------------- */

.tw__body {
  display: grid;
  justify-items: center;
  gap: var(--space-md);
  width: 100%;
  margin-block-start: -0.9rem;
  padding: 1.7rem var(--space-lg) var(--space-lg);
  border-radius: 1.6rem 1.6rem 2.2rem 2.2rem;
  background:
    linear-gradient(to bottom, var(--color-blue) 0 0.55rem, transparent 0.55rem) 0 1.1rem / 100% 100% no-repeat,
    linear-gradient(to bottom, var(--color-ink-2), var(--color-ink) 60%);
  box-shadow:
    inset 0 1px 0 color-mix(in oklch, var(--color-paper) 14%, transparent),
    0 2.5rem 3rem -1.5rem oklch(0% 0 0 / 0.6);
}

.tw__plate {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.3rem 0.9rem;
  border-radius: 0.4rem;
  background: linear-gradient(to bottom, oklch(92% 0.01 264), oklch(80% 0.01 264));
  color: var(--color-ink);
  font-family: var(--font-display);
  font-size: 0.85rem;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  box-shadow: inset 0 -2px 0 oklch(70% 0.01 264);
}

.tw__plate-mark {
  width: 1rem;
  height: auto;
  color: var(--color-blue);
}

/* The keys: round, rimmed, with a little travel. */
.tw__keyboard {
  display: grid;
  justify-items: center;
  gap: 0.45rem;
}

.tw__row {
  display: flex;
  gap: 0.45rem;
}

.tw__row--2 {
  padding-inline-start: 1.2rem;
}

.tw__row--3 {
  padding-inline-end: 1.6rem;
}

.tw__key {
  display: grid;
  place-items: center;
  width: 2.3rem;
  height: 2.3rem;
  border: 2px solid var(--tw-metal);
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, var(--color-ink-3), var(--color-ink) 70%);
  color: var(--color-paper);
  font-family: "Courier Prime", ui-monospace, monospace;
  font-size: 0.85rem;
  font-weight: 700;
  box-shadow: 0 0.3rem 0 oklch(5% 0.01 264), 0 0.45rem 0.6rem -0.2rem oklch(0% 0 0 / 0.5);
  cursor: pointer;
  user-select: none;
  transition: translate 70ms var(--ease-out), box-shadow 70ms var(--ease-out), background 70ms var(--ease-out);
}

.tw__key--fn {
  width: auto;
  min-width: 2.9rem;
  padding: 0 0.5rem;
  border-radius: var(--radius-pill);
  color: var(--color-lime);
  font-size: 0.75rem;
}

.tw__key--space {
  width: min(18rem, 50vw);
  height: 1.6rem;
  border-radius: var(--radius-pill);
}

.tw__key.is-down {
  background: radial-gradient(circle at 40% 35%, var(--color-blue), var(--color-blue-deep) 75%);
  translate: 0 0.25rem;
  box-shadow: 0 0.05rem 0 oklch(5% 0.01 264), 0 0.15rem 0.3rem -0.1rem oklch(0% 0 0 / 0.5);
}

/* Short screens: the keys go, the sheet keeps its room. */
@media (max-height: 46rem) {
  .tw__keyboard {
    display: none;
  }
}

/* Phones: just the sheet, from the top of the screen — the phone has its own keyboard. */
@media (max-width: 39.99rem) {
  .tw {
    place-items: start stretch;
    padding: 0;
  }

  .tw__machine {
    width: 100%;
  }

  .tw__paper {
    width: 100%;
    margin: 0;
  }

  .tw__sheet {
    height: auto;
    min-height: 60dvh;
    max-height: 100dvh;
    padding: calc(var(--space-lg) + 0.5rem) var(--space-lg) var(--space-lg);
    border-radius: 0 0 1rem 1rem;
  }

  .tw__roller,
  .tw__body {
    display: none;
  }

  .tw__close {
    inset-block-start: var(--space-xs);
    inset-inline-end: var(--space-xs);
    width: 2.5rem;
    height: 2.5rem;
    border-color: var(--color-rule);
    background-color: var(--tw-paper);
    color: var(--color-ink);
  }

  .tw__head {
    padding-inline-end: 2.5rem;
  }

  .tw__hint {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .tw *,
  .tw {
    animation: none !important;
  }
}
