/*
 * VirtualFrame Portal: the only stylesheet.
 *
 * Quiet and minimal: one centred column, modest type, neutral greys and no
 * accent colour. Red is reserved for danger (form errors and the
 * reprovisioning notice), a muted green for success (a hash that matches),
 * each always next to words that say the same. Light by default, dark when the system asks for
 * it, and either one forced by <html data-theme> (the vf_theme cookie).
 * No shadows, no gradients, no animation.
 */

@font-face {
  font-family: "Instrument Sans";
  src: url("/fonts/instrument-sans-latin-wdth-wght.woff2") format("woff2");
  font-weight: 400 700;
  font-stretch: 75% 100%;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "JetBrains Mono";
  src: url("/fonts/jetbrains-mono-latin-400.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: light;

  --bg: #f7f7f6;
  --surface: #ffffff;
  --rule: #e2e2df;
  --mute: #66665f;
  --text: #171717;
  --danger: #c4282d;
  --ok: #3d7458;

  --sans: "Instrument Sans", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;

  --step--1: 0.875rem;
  --step-0: 1rem;
  --step-1: 1.25rem;
  --step-2: 1.5rem;
  /* Page and release titles: 1.25rem on a phone, 1.5rem from a tablet up. */
  --step-title: clamp(1.25rem, 1rem + 1.2vw, 1.5rem);

  --gutter: clamp(1rem, 4vw, 2rem);
  --frame: 64rem;
  --column: 40rem;
  --card-pad: clamp(1.25rem, 4vw, 2rem);
  --target: 2.75rem; /* 44px touch target */
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;

    --bg: #121212;
    --surface: #1a1a1a;
    --rule: #2c2c2c;
    --mute: #9d9d98;
    --text: #ececea;
    --danger: #f0686c;
    --ok: #6fae8c;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;

  --bg: #121212;
  --surface: #1a1a1a;
  --rule: #2c2c2c;
  --mute: #9d9d98;
  --text: #ececea;
  --danger: #f0686c;
  --ok: #6fae8c;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: var(--step-0);
  line-height: 1.5;
  font-kerning: normal;
  -webkit-font-smoothing: antialiased;
  /* Its own stacking context, so the z-index -1 layers (rails, login
     backdrop) paint above the page colour and below all content. */
  isolation: isolate;
}

p,
h1,
h2,
h3,
dl,
dd {
  margin: 0;
}

h1,
h2,
h3 {
  font-size: inherit;
  font-weight: inherit;
}

a {
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 2px;
}

/* Read by screen readers only: the copy announcer (copy.js). */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ---------------------------------------------------------------- frame */

.site-header,
.site-footer {
  width: 100%;
  max-width: var(--frame);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

.site-header {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  column-gap: 1rem;
  padding-block: 0.5rem;
  border-bottom: 1px solid var(--rule);
}

.brand {
  margin-right: auto;
  white-space: nowrap;
}

.brand-link {
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
  min-height: var(--target);
  text-decoration: none;
}

.brand-mark {
  width: auto;
  height: 1.75rem;
  margin-right: 0.25em;
}

.brand-name {
  font-weight: 600;
}

.brand-sub {
  color: var(--mute);
}

.switch,
.account,
.prefs {
  display: flex;
  align-items: center;
}

/* Language and theme, printed in the header and in the footer
   (partials/prefs): the header copy on wide screens, the footer one below
   48rem, so the header keeps to one line on phones and tablets. */
.prefs {
  column-gap: 1rem;
}

.prefs-footer {
  display: none;
}

/* In the footer the links are sized by their padding, not centred in a 44px
   minimum, so the spaces between them are even and EN starts flush with the
   footer text. They stay 44px tall and about as wide. */
.prefs-footer .switch a {
  min-width: 0;
  padding-inline: 0.75rem;
}

.prefs-footer .switch:first-child a:first-child {
  padding-left: 0;
}

.prefs-footer {
  column-gap: 0.5rem;
}

.switch a,
.account-link,
.signout-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: var(--target);
  min-height: var(--target);
  padding: 0 0.375rem;
  color: var(--mute);
  font-size: var(--step--1);
  text-decoration: none;
}

.switch a:hover,
.account-link:hover,
.signout-button:hover,
.switch a[aria-current] {
  color: var(--text);
}

.switch a[aria-current] {
  font-weight: 600;
}

.account {
  gap: 0.75rem;
}

/* The panel (admins) or two-step verification (clients): quiet, like the switches. */
.account-link {
  min-width: 0;
}

.account-email {
  color: var(--mute);
  font-size: var(--step--1);
}

.signout {
  margin: 0;
}

.signout-button {
  border: 0;
  background: none;
  font-family: inherit;
  cursor: pointer;
}

/* Inside a card ("Use another account") it lines up with the card's text. */
.card > .signout {
  align-self: flex-start;
}

.card .signout-button {
  min-width: 0;
  padding-inline: 0;
}

.site-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2.5rem;
  width: 100%;
  max-width: calc(var(--column) + 2 * var(--gutter));
  margin-inline: auto;
  padding: clamp(2rem, 6vw, 4rem) var(--gutter);
}

.site-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  column-gap: 2rem;
  padding-block: 0.5rem;
  border-top: 1px solid var(--rule);
  color: var(--mute);
  font-size: var(--step--1);
}

/* Side rails: a faint 1px line down each outer edge of the frame, the same
   box as the header and footer (width 100%, at most --frame), so their rules
   end exactly on the rails. Behind everything and fixed, so they run the whole
   height on every page. Only when the viewport is wider than the frame. */
@media (min-width: 64rem) {
  body::after {
    content: "";
    position: fixed;
    top: 0;
    bottom: 0;
    left: 50%;
    z-index: -1;
    width: min(var(--frame), 100%);
    border-inline: 1px solid color-mix(in srgb, var(--rule) 70%, transparent);
    transform: translateX(-50%);
    pointer-events: none;
  }
}

.footer-contact {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.footer-contact a {
  display: inline-flex;
  align-items: center;
  min-height: var(--target);
  color: var(--text);
  text-decoration: none;
}

.footer-contact a:hover {
  text-decoration: underline;
  text-underline-offset: 0.2em;
}

/* -------------------------------------------------------------- controls */

.card {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  padding: var(--card-pad);
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--surface);
}

.page-title {
  font-size: var(--step-title);
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -0.01em;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--target);
  padding: 0 1.25rem;
  border: 0;
  border-radius: 4px;
  background: var(--text);
  color: var(--surface);
  font-family: inherit;
  font-size: var(--step-0);
  font-weight: 600;
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
}

.button:hover {
  opacity: 0.88;
}

.form-error,
.release-notice {
  padding-left: 0.75rem;
  border-left: 2px solid var(--danger);
}

/* ----------------------------------------------------------------- login */

/* Signed out only, and only with <html data-backdrop="on"> (the vf_backdrop
   cookie, set from the panel; off by default): the night landscape, barely
   there and fading out to the right, behind everything. Every rule that names
   an image file is under that attribute, so with it absent no rule matches,
   the pseudo-element is not even generated and the browser downloads nothing:
   that is the point for clients on slow links.
   Each theme's file is already composited onto that theme's --bg, faded and
   dithered (tools/build-backdrop.py): opacity or a mask here would make the
   browser quantise a ~10% alpha layer to a few grey levels, which shows as
   vertical bands. The rails (body::after) paint above it, being later in the
   same stacking context. */
:root[data-backdrop="on"] {
  --backdrop: url("/img/backdrop-light.webp");
}

@media (prefers-color-scheme: dark) {
  :root[data-backdrop="on"]:not([data-theme="light"]) {
    --backdrop: url("/img/backdrop-dark.webp");
  }
}

:root[data-backdrop="on"][data-theme="dark"] {
  --backdrop: url("/img/backdrop-dark.webp");
}

:root[data-backdrop="on"] body:has(.login)::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background: var(--bg) var(--backdrop) left center / cover no-repeat;
  pointer-events: none;
}

/* Two widths in the whole portal: a form or a message is 28rem, a release
   takes the column (40rem). Standalone states (sign in, the code step, a 404,
   an expired form) sit in the middle of the page; the pages inside start at
   the top. */
.login,
.security,
.message {
  width: 100%;
  max-width: 28rem;
  margin-inline: auto;
}

.login,
.message {
  margin-block: auto;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.field-label {
  font-size: var(--step--1);
  font-weight: 500;
}

.field-input {
  width: 100%;
  min-height: var(--target);
  padding: 0 0.75rem;
  border: 1px solid var(--rule);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: var(--step-0);
}

.field-input:hover {
  border-color: var(--mute);
}

.field-input:focus {
  border-color: var(--text);
  outline: none;
}

.field-input:-webkit-autofill {
  -webkit-text-fill-color: var(--text);
  box-shadow: inset 0 0 0 100px var(--surface);
  caret-color: var(--text);
}

.login-form .button {
  margin-top: 0.5rem;
}

/* A one-time code, as in the panel: spaced and centred, read digit by digit. */
.field-input.code {
  font-family: var(--mono);
  font-size: var(--step-1);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.3em;
  text-align: center;
}

/* -------------------------------------------------------------- security */

.form-notice {
  padding-left: 0.75rem;
  border-left: 2px solid var(--rule);
}

.field-hint,
.security-note {
  color: var(--mute);
  font-size: var(--step--1);
}

/* Turning it off is the quieter action: outlined, not filled. */
.button-quiet {
  border: 1px solid var(--rule);
  background: transparent;
  color: var(--text);
}

.button-quiet:hover {
  border-color: var(--mute);
  opacity: 1;
}

/* Dark modules on white whatever the theme: authenticator cameras expect it. */
.qr {
  display: block;
  width: 12rem;
  height: 12rem;
  margin-inline: auto;
  border-radius: 4px;
  background: #ffffff;
}

.qr[hidden] {
  display: none;
}

.secret {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

/* Groups of 4 with no whitespace between them in the markup (see hash-groups),
   spaced by the gap, so a group that wraps starts flush with the rest. */
.secret-groups {
  display: flex;
  flex-wrap: wrap;
  column-gap: 0.6ch;
  font-family: var(--mono);
  font-size: var(--step-0);
  line-height: 1.6;
}

.secret-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

/* Always alone in its paragraph, so it can be a full touch target. */
.text-link {
  display: inline-flex;
  align-items: center;
  min-height: var(--target);
  color: var(--mute);
  font-size: var(--step--1);
}

.text-link:hover {
  color: var(--text);
}

/* --------------------------------------------------------------- release */

/* Application icon to the left of the title and the facts. */
.release-head {
  display: grid;
  grid-template-columns: 3rem minmax(0, 1fr);
  align-items: center;
  column-gap: 1rem;
}

.release-icon {
  grid-row: span 2;
  width: 3rem;
  height: 3rem;
}

.release-title {
  font-size: var(--step-title);
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -0.01em;
  font-variant-numeric: lining-nums;
}

.release-facts {
  display: flex;
  flex-wrap: wrap;
  gap: 0 1.5rem;
  color: var(--mute);
  font-size: var(--step--1);
  font-variant-numeric: tabular-nums;
}

.release-fact {
  display: flex;
  gap: 0.35em;
}

.release-fact dd {
  color: var(--text);
}

.release-summary,
.release-notice,
.release-changelog {
  max-width: 60ch;
  text-wrap: pretty;
}

/* Rendered from the changelog's Markdown subset (ChangelogMarkdown): small
   muted section headings, each followed by its paragraph or list. */
.release-changelog {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.release-changelog h2 {
  margin-top: 0.5rem;
  color: var(--mute);
  font-size: var(--step--1);
  font-weight: 600;
}

.release-changelog h2:first-child {
  margin-top: 0;
}

.release-changelog ul,
.release-changelog ol {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  margin: 0;
  padding-left: 1.25rem;
}

.release-changelog li::marker {
  color: var(--mute);
}

.release-changelog code {
  font-family: var(--mono);
  font-size: 0.875em;
  overflow-wrap: anywhere;
}

.release-changelog strong {
  font-weight: 600;
}

.release-empty {
  color: var(--mute);
}

/* Extra releases granted to the account: same card, quieter head, no icon. */
.others {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.release-other .release-head {
  grid-template-columns: minmax(0, 1fr);
}

.release-other .release-title {
  font-size: var(--step-1);
}

/* ------------------------------------------------------------------ hash */

.hash {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--rule);
}

/* Section labels in the text colour and 600; field labels below them stay mute. */
.hash-label {
  font-size: var(--step--1);
  font-weight: 600;
}

.hash-hint {
  color: var(--mute);
  font-size: var(--step--1);
}

.hash-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem 1.5rem;
}

/* 16 inline groups with no whitespace between them in the markup, so a
   manual selection copies the 64 characters and nothing else. Each group is
   an atomic inline (a wrap opportunity, but no block box). A line holds 8
   groups of 4ch with 0.6ch between them, 36.2ch; max-width lets no ninth
   group in. Below 34rem it holds 4 (18.4ch). */
.hash-groups {
  max-width: 37ch;
  font-family: var(--mono);
  font-size: var(--step--1);
  line-height: 1.6;
  user-select: all;
}

.hash-group {
  display: inline-block;
}

.hash-group + .hash-group {
  margin-left: 0.6ch;
}

.hash-group:nth-child(8n + 1) {
  margin-left: 0;
}

/* min-width holds the box when "Copy" becomes "Copied", so the row never jumps. */
.hash-copy {
  min-width: 6.5rem;
  min-height: var(--target);
  padding: 0 1rem;
  border: 1px solid var(--rule);
  border-radius: 4px;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: var(--step--1);
  font-weight: 500;
  cursor: pointer;
}

.hash-copy:hover {
  border-color: var(--mute);
}

/* "Does it match?": the pasted hash and the verdict, in words and colour. */
.hash-compare {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding-top: 0.25rem;
}

.hash-compare[hidden] {
  display: none;
}

.hash-input {
  font-family: var(--mono);
  font-size: var(--step--1);
}

.hash-result:empty {
  display: none;
}

.hash-result {
  padding-left: 0.75rem;
  border-left: 2px solid var(--rule);
  font-size: var(--step--1);
}

.hash-result.is-ok {
  border-left-color: var(--ok);
  color: var(--ok);
}

.hash-result.is-bad {
  border-left-color: var(--danger);
  color: var(--danger);
}

/* ------------------------------------------------------------------ keys */

.keys {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--rule);
  scroll-margin-top: 1rem;
}

.keys-label {
  font-size: var(--step--1);
  font-weight: 600;
}

/* The silent install templates are a section of their own, with its own rule. */
.keys-label:not(:first-child) {
  margin-top: 0.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--rule);
}

.key-name,
.key-missing {
  color: var(--mute);
  font-size: var(--step--1);
}

/* Every copyable value has one shape: its label, then the value in a quiet
   box with Copy at the right end of the row. A command takes the full width
   and Copy goes under it, still on the right; a key is short enough to keep
   Copy beside it, down to a phone. */
.key {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.key-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 0.5rem 1rem;
}

.key-row > code {
  flex: 1 1 14rem;
  min-width: 0;
}

.key-row > .silent-command {
  flex-basis: 100%;
}

.key-row > .hash-copy {
  margin-left: auto;
}

.key-value,
.silent-command {
  display: block;
  padding: 0.625rem 0.75rem;
  border: 1px solid var(--rule);
  border-radius: 4px;
  background: var(--bg);
  line-height: 1.55;
}

.key-value {
  font-family: var(--mono);
  font-size: var(--step--1);
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  user-select: all;
}

.key-reveal {
  margin: 0;
  align-self: flex-start;
}

.silent {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.silent-command {
  font-family: var(--mono);
  font-size: 0.8125rem;
  overflow-wrap: anywhere;
  user-select: all;
}

/* ------------------------------------------------------------------- log */

.log {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.log-heading {
  font-size: var(--step-0);
  font-weight: 600;
}

.log-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--step--1);
  font-variant-numeric: tabular-nums;
}

.log-table th,
.log-table td {
  padding: 0.625rem 1rem 0.625rem 0;
  border-bottom: 1px solid var(--rule);
  text-align: left;
  vertical-align: top;
}

.log-table th {
  color: var(--mute);
  font-weight: 400;
}

.log-table td {
  overflow-wrap: anywhere;
}

.log-table :is(th, td):last-child {
  padding-right: 0;
}

/* ------------------------------------------------------- not found, expired */

.message {
  align-items: flex-start;
}

/* ----------------------------------------------------------------- small */

/* The account email only where the header holds it on one line. */
@media (max-width: 64rem) {
  .account-email {
    display: none;
  }
}

@media (max-width: 48rem) {
  .site-header {
    flex-wrap: nowrap;
  }

  .brand {
    min-width: 0;
  }

  .prefs-header {
    display: none;
  }

  .prefs-footer {
    display: flex;
  }

  .site-footer {
    flex-direction: column;
    align-items: flex-start;
  }
}

@media (max-width: 40rem) {
  .site-main {
    gap: 2rem;
    padding-top: 1.25rem;
  }

  /* No frame inside a frame: a card reaches the screen edges, with its rules
     above and below, and its content keeps the page gutter. */
  .card {
    width: auto;
    max-width: none;
    margin-inline: calc(-1 * var(--gutter));
    padding-inline: var(--gutter);
    border-inline: 0;
    border-radius: 0;
  }

  /* Sign in and the messages sit high, where the on-screen keyboard leaves them in view. */
  .login,
  .message {
    margin-block: 0.5rem auto;
  }

  /* The eight groups of the secret on one line at 360px. */
  .secret-groups {
    font-size: var(--step--1);
  }

  /* The main action is thumb-wide, like Sign in already is. */
  .release-download .button {
    width: 100%;
  }

  .release-head {
    grid-template-columns: 2.5rem minmax(0, 1fr);
    column-gap: 0.75rem;
  }

  .release-icon {
    width: 2.5rem;
    height: 2.5rem;
  }

  /* The log stacks: date and status on one line, the rest beneath in mute. */
  .log-table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }

  .log-table,
  .log-table tbody {
    display: block;
  }

  .log-table tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    column-gap: 1rem;
    padding: 0.625rem 0;
    border-bottom: 1px solid var(--rule);
  }

  .log-table td {
    padding: 0;
    border: 0;
  }

  .log-table td:first-child {
    grid-area: 1 / 1;
  }

  .log-table td:last-child {
    grid-area: 1 / 2;
    text-align: right;
  }

  .log-table td:not(:first-child, :last-child) {
    grid-column: 1 / -1;
    color: var(--mute);
  }
}

@media (max-width: 34rem) {
  .hash-groups {
    max-width: 18.4ch;
  }

  .hash-group:nth-child(8n + 1) {
    margin-left: 0.6ch;
  }

  .hash-group:nth-child(4n + 1) {
    margin-left: 0;
  }
}

@media (max-width: 26rem) {
  .brand-sub {
    display: none;
  }
}
