/* SPDX-License-Identifier: AGPL-3.0-or-later
 *
 * Controls: every button and field, on every screen.
 *
 * Styled by what a control is, not by where it sits. The wall had it the
 * other way round - `.drawbridge button`, `.gate input[type=text]` - so a
 * control only looked right if someone remembered the right ancestor. Worse,
 * form.submit renders an <input>, not a <button>, so the capture button on
 * the wall matched nothing at all and shipped as raw operating-system chrome.
 *
 * Element selectors here, modifiers on top. A new screen gets working
 * controls without writing CSS, which is the only way this stays consistent.
 */

:root {
  /* 44px - the smallest target a thumb reliably hits, and this vault is
     meant to be used from a phone. */
  --control-height: 2.75rem;
  --control-pad-inline: 1.1rem;
}

/* ---- Fields ----------------------------------------------------------- */

:where(input[type="text"], input[type="search"], input[type="email"],
input[type="password"], input[type="url"], textarea) {
  appearance: none; -webkit-appearance: none;
  min-block-size: var(--control-height);
  padding: .7rem .9rem;
  box-sizing: border-box;
  /* A button is raised and a field is cut into the plate, and under one fixed
     light that is not a metaphor - it is which edge is bright. The button's
     highlight is on its top edge; the field's is on its bottom, because you
     are looking into a recess and seeing the far wall of it. Every control in
     the app obeys this, which is what stops the set from looking assembled
     out of other people's widgets. */
  background: var(--background-dark);
  color: var(--foreground);
  border: var(--edge);
  border-radius: var(--radius);
  box-shadow: var(--recess);
  font-family: var(--font-ui);
  font-size: var(--step-0);
  line-height: var(--leading-ui);
  transition: border-color .15s, background .15s, box-shadow .15s;
}
input::placeholder, textarea::placeholder { color: var(--muted); }
input:hover, textarea:hover {
  border-color: color-mix(in oklab, var(--accent) 40%, transparent);
}
/* Safari paints its own magnifying glass and clear button inside a search
   field, which does not belong on a dragon's drawbridge. */
input[type="search"]::-webkit-search-decoration,
input[type="search"]::-webkit-search-cancel-button { -webkit-appearance: none; }

/* ---- Buttons ---------------------------------------------------------- */

/* :where() so the base has ZERO specificity and every modifier beats it.
   Without it input[type="submit"] is (0,1,1) and .quiet is (0,1,0), so
   `form.submit "Seek", class: "quiet"` rendered a second solid gold
   rectangle next to Hoard - the modifier was being written and ignored. */
:where(button, input[type="submit"], input[type="button"], .forge) {
  appearance: none; -webkit-appearance: none;
  min-block-size: var(--control-height);
  padding: .7rem var(--control-pad-inline);
  cursor: pointer;
  /* Brass, machined, lit from the same direction as everything else. The ramp
     is 7% across the height - enough that the key has a face, small enough
     that the darkest end is still 8.1:1 against --background-darker, so the
     label never trades legibility for the finish. */
  background:
    linear-gradient(
      color-mix(in oklab, var(--foreground-bright) 9%, var(--accent)),
      var(--accent) 52%,
      color-mix(in oklab, var(--background-darker) 7%, var(--accent)));
  /* Not --background-darker. A light theme's brass is dark enough that black
     on it lands at 3.7:1, and the label on the only button that captures
     anything would fail AA the moment the theme changed. The theme decides
     what reads on its own accent; see the derivation chain in theme.rb. */
  color: var(--on-accent);
  box-shadow: var(--bevel), var(--contact);
  border: 0;
  border-radius: var(--radius);
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: var(--step-0);
  line-height: 1.1;
  text-align: center;
  text-decoration: none;
  white-space: nowrap;
  transition: background .15s, box-shadow .15s, transform .08s;
}
/* <button> and links centre their own contents; an <input> already does. */
:where(button, .forge) {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
}
:where(input[type="submit"], input[type="button"]) { display: inline-block; }

/* Hover heats the metal. The whole ramp moves, rather than the gradient being
   replaced by a flat colour - which is what happened before and is why the
   key went from machined to painted the instant a pointer touched it. */
:where(button, input[type="submit"], input[type="button"], .forge):hover {
  background:
    linear-gradient(
      color-mix(in oklab, var(--foreground-bright) 22%, var(--accent)),
      color-mix(in oklab, var(--foreground-bright) 12%, var(--accent)) 52%,
      var(--accent));
  box-shadow:
    var(--bevel-lit),
    0 0 0 1px color-mix(in oklab, var(--accent) 45%, transparent),
    2px 5px 18px color-mix(in oklab, var(--accent) 26%, transparent);
}
/* A press you can feel. Without it a tap on a phone gives no answer at all
   until the page navigates, which reads as a dead button.
 *
 * The bevel inverts as well as the key dropping: a pressed key is lit from
 * below its own rim, and moving it 1px without changing where the light
 * catches is the animation equivalent of a sticker sliding. */
:where(button, input[type="submit"], input[type="button"], .forge):active {
  transform: translateY(1px);
  /* A pressed key is below the plate, so it is lit from inside its own rim -
     the same recess every field is cut with, which is what makes press and
     field read as the same physical state rather than two effects. */
  box-shadow: var(--recess);
}
:where(button, input, .forge[aria-disabled="true"]):disabled, :where(.forge[aria-disabled="true"]) {
  opacity: .45; cursor: not-allowed; transform: none;
}

/* Quiet: stands beside a primary action without competing with it. */
.quiet {
  background: transparent; color: var(--accent);
  box-shadow: inset 0 0 0 1px color-mix(in oklab, var(--accent) 45%, transparent);
}
.quiet:hover {
  background: color-mix(in oklab, var(--accent) 12%, transparent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

/* Bare: a button that reads as a link - Revoke, Undo. Still a control, so it
   keeps its hit area and its focus ring. */
.bare {
  background: transparent; box-shadow: none;
  color: var(--foreground-dark); font-weight: 500;
  padding-inline: .7rem;
}
.bare:hover {
  background: color-mix(in oklab, var(--foreground) 8%, transparent);
  color: var(--foreground-bright);
}
/* --danger, not --red. Brass & Soot's oxblood is 3.18:1 on soot - fine as a
   3px rule on a card, not fine as the word "Burn". Each theme names a red
   that passes as text, and the theme tests hold it to it. */
.bare.danger { color: var(--danger); }
.bare.danger:hover { background: color-mix(in oklab, var(--danger) 14%, transparent); color: var(--danger); }

/* ---- One focus ring, everywhere --------------------------------------- */
/* :where() keeps specificity at zero, so a component can still opt out. */
:where(input, textarea, select, button, a, [tabindex]):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---- A field and its button ------------------------------------------- */

.field-row { display: flex; gap: .6rem; align-items: stretch; flex-wrap: wrap; }
.field-row > input, .field-row > textarea { flex: 1 1 14rem; }
/* button_to wraps its button in a form, which would otherwise break the row. */
.field-row > form.button_to, .row > form.button_to { display: contents; }

.row { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; }
form.button_to { display: inline-block; }

/* ---- A field that says which key reaches it --------------------------- */

/* A shortcut nobody is told about is a shortcut for whoever wrote it. The
   chip is the whole reason the keyboard layer is worth shipping before the
   command palette exists.
 *
 * It lives in the field's own trailing padding rather than beside it, so the
 * row's geometry is unchanged and the hint disappears without anything
 * moving. */
.keyed { position: relative; display: flex; flex: 1 1 14rem; }
.keyed > input { flex: 1 1 auto; inline-size: 100%; padding-inline-end: 2.8rem; }

.keyed > kbd {
  position: absolute; inset-inline-end: .6rem; inset-block-start: 50%;
  translate: 0 -50%;
  pointer-events: none;
  min-inline-size: 1.5rem; padding: .1rem .35rem;
  font-family: var(--font-mono); font-size: var(--step--2);
  text-align: center;
  color: var(--muted);
  background: var(--background-lighter);
  border: 1px solid color-mix(in oklab, var(--foreground) 16%, transparent);
  border-radius: 4px;
  /* A key is a raised thing, lit from the same direction as every other
     raised thing here - so it gets a rim light on top and a hairline of
     shadow underneath, at a quarter of a button's strength. */
  box-shadow:
    inset 1px 1px 0 color-mix(in oklab, var(--foreground) 10%, transparent),
    1px 1px 0 color-mix(in oklab, var(--background-darker) 60%, transparent);
  transition: opacity .15s;
}

/* The moment the field is in use the hint has done its job. Two conditions,
   not one: focus covers reaching it by any means, and :placeholder-shown
   covers a field that already holds a query you navigated back to. */
.keyed:focus-within > kbd,
.keyed > input:not(:placeholder-shown) + kbd { opacity: 0; }

/* A phone has no `/` key in reach and no keyboard on screen until you tap the
   field anyway, so on touch the hint is noise in the one place there is least
   room for it. */
@media (hover: none) and (pointer: coarse) {
  .keyed > kbd { display: none; }
  .keyed > input { padding-inline-end: .9rem; }
}
