/* tinylogin's pages: one narrow column, calm neutral paper, white fields, one accent for actions and links. Light or
   dark follows the system: public pages offer no switch. No inline style anywhere (CSP). Starter tokens (frontend.md ›
   Starter contract). */
@layer tokens, base, compositions, components, utilities;

@layer tokens {
  :root {
    color-scheme: light dark;
    --paper: light-dark(#f3f4f6, #181b21);
    --field: light-dark(#ffffff, #23272f);
    --ink: light-dark(#1b212b, #e9ebef);
    --muted: light-dark(#4a5361, #aeb5c1);
    --line: light-dark(#7a8392, #6f7887);
    --rule: light-dark(#d5d9df, #343a45);
    --accent: light-dark(#1d5794, #9ec6ef);
    --on-accent: light-dark(#ffffff, #12161c);
    --danger: light-dark(#a3242f, #f2a7ad);
    --focus-color: light-dark(#1d5794, #f0cf86);
    --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    --small: 15px;
    --body: 17px;
    --lead: clamp(26px, 1.2rem + 1vw, 32px);
    --s1: 4px;
    --s2: 8px;
    --s3: 12px;
    --s4: 16px;
    --s6: 24px;
    --s8: 32px;
    --s12: 48px;
    --s16: 64px;
    --gutter: max(var(--s4), env(safe-area-inset-left), env(safe-area-inset-right));
    --radius: 6px;
    --focus: 3px;
    --focus-offset: 2px;
    --target: 48px;
    --measure: 27rem;
  }
}

@layer base {
  *,
  ::before,
  ::after {
    box-sizing: border-box;
  }
  :root {
    -webkit-text-size-adjust: 100%;
  }
  body {
    margin: 0;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    background: var(--paper);
    color: var(--ink);
    font: 400 var(--body) / 1.5 var(--sans);
    overflow-wrap: anywhere;
  }
  h1,
  h2,
  p,
  ul {
    margin: 0;
  }
  h1 {
    font-size: var(--lead);
    line-height: 1.15;
    letter-spacing: -0.01em;
  }
  h2 {
    font-size: var(--body);
    line-height: 1.3;
  }
  ul {
    padding-inline-start: 0;
    list-style: none;
  }
  a {
    color: var(--accent);
    text-underline-offset: 0.2em;
  }
  :focus-visible {
    outline: var(--focus) solid var(--focus-color);
    outline-offset: var(--focus-offset);
  }
  @media (prefers-reduced-motion: reduce) {
    * {
      transition: none !important;
    }
  }
}

@layer compositions {
  .column {
    width: min(var(--measure), 100% - 2 * var(--gutter));
    margin-inline: auto;
  }
  body > main {
    flex: 1;
    padding-block: var(--s8) var(--s12);
  }
  .stack > * + * {
    margin-block-start: var(--s6);
  }
  .stack > h2 + * {
    margin-block-start: var(--s2);
  }
}

@layer components {
  .skip {
    position: absolute;
    inset-inline-start: var(--s2);
    inset-block-start: var(--s2);
    padding: var(--s2) var(--s3);
    background: var(--paper);
  }
  .skip:not(:focus) {
    clip-path: inset(50%);
    width: 1px;
    height: 1px;
    overflow: hidden;
  }
  /* The sphere's name: who this login belongs to, the first thing read. */
  body > header {
    padding-block-start: max(var(--s6), env(safe-area-inset-top));
  }
  /* Desktop: the column sits a little lower, so the form is where the eye lands, not stuck to the top edge. */
  @media (min-width: 48rem) and (min-height: 40rem) {
    body > header {
      padding-block-start: 10vh;
    }
  }
  .site-name {
    padding-block-end: var(--s3);
    border-block-end: 1px solid var(--rule);
    font-weight: 700;
  }
  /* The app a login leads to, above the form. */
  .target {
    color: var(--muted);
  }
  .target strong {
    color: var(--ink);
  }
  .target .app-host {
    display: block;
    overflow-wrap: normal;
    word-break: keep-all;
  }
  form {
    display: grid;
    gap: var(--s4);
  }
  label {
    display: block;
    font-weight: 700;
  }
  .hint {
    display: block;
    color: var(--muted);
    font-size: var(--small);
  }
  label + input,
  .hint + input {
    margin-block-start: var(--s2);
  }
  input {
    width: 100%;
    min-height: var(--target);
    padding: var(--s2) var(--s3);
    border: 1.5px solid var(--line);
    border-radius: var(--radius);
    background: var(--field);
    color: var(--ink);
    font: inherit;
  }
  input[readonly] {
    border-style: dashed;
    background: transparent;
    color: var(--muted);
  }
  .code {
    font-family: var(--mono);
    font-size: 1.4em;
    letter-spacing: 0.3em;
    max-width: 10em;
  }
  button {
    justify-self: start;
    min-height: var(--target);
    padding: var(--s2) var(--s6);
    border: 1.5px solid var(--accent);
    border-radius: var(--radius);
    background: var(--accent);
    color: var(--on-accent);
    font: inherit;
    font-weight: 700;
    cursor: pointer;
  }
  button.secondary {
    background: transparent;
    color: var(--accent);
  }
  /* A way out that is no action of its own: looks like a link, keeps the target size. */
  button.plain {
    padding-inline: 0;
    border-color: transparent;
    background: transparent;
    color: var(--accent);
    font-weight: 400;
    text-decoration: underline;
    text-underline-offset: 0.2em;
  }
  /* "oder" between two ways to the same goal. */
  .or {
    display: flex;
    align-items: center;
    gap: var(--s3);
    color: var(--muted);
    font-size: var(--small);
  }
  .or::before,
  .or::after {
    content: "";
    flex: 1;
    border-block-start: 1px solid var(--rule);
  }
  .notice {
    padding: var(--s3) var(--s4);
    border-inline-start: 4px solid var(--danger);
    background: var(--field);
    border-radius: 0 var(--radius) var(--radius) 0;
  }
  .muted {
    color: var(--muted);
  }
  .small {
    font-size: var(--small);
  }
  /* The apps after login: one full-width link per app, title over host. */
  .apps {
    border-block-start: 1px solid var(--rule);
  }
  .apps li {
    border-block-end: 1px solid var(--rule);
  }
  .apps a {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    column-gap: var(--s4);
    min-height: 64px;
    padding-block: var(--s3);
    padding-inline: var(--s1);
    color: var(--ink);
    text-decoration: none;
  }
  .apps a::after {
    content: "→";
    content: "→" / "";
    grid-column: 2;
    grid-row: 1 / span 2;
    color: var(--accent);
    font-size: 1.2em;
  }
  .app-title {
    font-weight: 700;
    color: var(--accent);
  }
  .app-host {
    color: var(--muted);
    font-size: var(--small);
    hyphens: none;
  }
  .apps a:hover .app-title {
    text-decoration: underline;
    text-underline-offset: 0.2em;
  }
  /* Account link and logout at the foot of the logged-in page. */
  .account {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--s4);
    padding-block-start: var(--s6);
  }
  .account form {
    display: contents;
  }
  /* The passkey island: invisible until its script runs, its space kept; gone where the browser lacks WebAuthn. */
  tl-passkey {
    display: grid;
    gap: var(--s3);
  }
  tl-passkey:not(:defined) {
    visibility: hidden;
  }
  tl-passkey[hidden] {
    display: none;
  }
  tl-passkey [role="status"]:empty {
    display: none;
  }
  /* The TOTP setup: the QR code and the secret to type instead. */
  .qr {
    display: block;
    width: min(16rem, 100%);
    height: auto;
  }
  .secret {
    font-family: var(--mono);
    letter-spacing: 0.08em;
  }
  @media (forced-colors: active) {
    button,
    input {
      border: 1px solid ButtonText;
    }
    .apps a {
      border: 1px solid LinkText;
      padding-inline: var(--s3);
    }
  }
}
