/* Jhome Authenticator. See DESIGN.md for the token contract.
   Every value here is listed there. Adding one means adding it there too.

   A strict CSP (no unsafe-inline) means this file holds every style in the app.
   Nothing may be set from a `style` attribute in markup; JS reaches the two
   values it must animate through CSSOM (`element.style.setProperty`), which CSP
   does not restrict. */

:root {
  /* Ground */
  --ja-bg: #070910;
  --ja-bg-top: #0a0e18;

  /* Glass */
  --ja-glass: #151a26;
  --ja-row: #141926;
  --ja-line: rgba(150, 176, 214, .14);
  --ja-line-hi: rgba(150, 176, 214, .30);

  /* Ink */
  --ja-text: #eef2f9;
  --ja-muted: #a7b7cf;
  --ja-faint: #8194ae;

  /* The single accent */
  --ja-accent: #3fbfad;
  --ja-accent-hi: #71e2d1;
  --ja-accent-soft: rgba(63, 191, 173, .14);
  --ja-on-accent: #04231e;

  /* Warm counterpoint */
  --ja-warm: #f0a868;
  --ja-warm-soft: rgba(240, 168, 104, .12);
  --ja-danger: #ff7784;

  /* Shape */
  --r-panel: 16px;
  --r-modal: 20px;
  --r-ctl: 11px;

  /* Motion */
  --e-out: cubic-bezier(.2, .8, .25, 1);
  --e-in: cubic-bezier(.4, 0, .9, .3);
  --t-micro: 160ms;
  --t-state: 220ms;
  --t-tick: 1000ms;
}

* { box-sizing: border-box; }

/* Must outrank any author `display` below it: the app hides the drift notice,
   the empty state, the camera preview, and three messages with this attribute,
   and a stray `display` rule turns one of them back on with no other symptom
   than a hole in the layout. */
[hidden] { display: none !important; }

body {
  margin: 0;
  /* svh, not vh: on mobile Safari 100vh exceeds the visible viewport and pushes
     the brand credit under the browser chrome. */
  min-height: 100vh;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  background: var(--ja-bg);
  color: var(--ja-text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 17px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* The lit night field. Fixed and static: it is the surface the glass sits on, so
   it must not scroll with the content or animate under a backdrop-filter. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(135% 105% at -12% -26%,
                    rgba(56, 196, 176, .16) 0%,
                    rgba(56, 196, 176, .07) 30%,
                    rgba(56, 196, 176, .02) 52%,
                    transparent 74%),
    linear-gradient(180deg, var(--ja-bg-top) 0%, var(--ja-bg) 44%, #04060c 100%);
}

/* flex:1 rather than min-height:100vh, so the brand credit is never pushed below
   the fold on a short viewport. */
#app {
  flex: 1;
  width: 100%;
  max-width: 820px;
  margin: 0 auto;
  padding: 20px 16px 32px;
}

/* ---------- glass surfaces ---------------------------------------------- */

/* Opaque base first. The blur below is an enhancement, never the contrast
   strategy, so the app is fully readable with zero blur applied. */
.ja-panel {
  background: rgba(21, 26, 38, .90);
  border: 1px solid var(--ja-line);
  border-radius: var(--r-panel);
}

@supports (backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px)) {
  .ja-panel {
    background: rgba(21, 26, 38, .62);
    -webkit-backdrop-filter: blur(20px) saturate(150%);
    backdrop-filter: blur(20px) saturate(150%);
  }
}

/* ---------- hero panel --------------------------------------------------- */

.ja-hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px 20px;
  padding: 20px;
}

.ja-hero h1 {
  margin: 0;
  font-size: 26px;
  line-height: 1.25;
  letter-spacing: -.015em;
  font-weight: 700;
}

.ja-hero-sub {
  margin: 6px 0 0;
  font-size: 17px;
  line-height: 1.5;
  color: var(--ja-muted);
}

.ja-hero-aside {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
}

.ja-clock {
  margin: 0;
  text-align: right;
}

.ja-clock-label {
  display: block;
  font-size: 12px;
  line-height: 1;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--ja-faint);
}

.ja-clock-value {
  display: block;
  margin-top: 5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 20px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--ja-text);
}

/* ---------- controls ----------------------------------------------------- */

.ja-primary,
.ja-secondary {
  border-radius: var(--r-ctl);
  padding: 11px 18px;
  min-height: 44px;
  font: inherit;
  font-size: 16px;
  line-height: 1.2;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color var(--t-micro) var(--e-out),
              border-color var(--t-micro) var(--e-out),
              transform var(--t-micro) var(--e-out);
}

.ja-primary {
  background: var(--ja-accent);
  color: var(--ja-on-accent);
  border: 1px solid var(--ja-accent);
  font-weight: 700;
}

.ja-primary:hover { background: var(--ja-accent-hi); border-color: var(--ja-accent-hi); }
.ja-primary:active { transform: scale(.98); }

.ja-secondary {
  background: transparent;
  color: var(--ja-text);
  border: 1px solid var(--ja-line-hi);
}

.ja-secondary:hover { background: var(--ja-accent-soft); border-color: var(--ja-accent); }
.ja-secondary:active { transform: scale(.98); }

:focus-visible {
  outline: 2px solid var(--ja-accent-hi);
  outline-offset: 3px;
}

/* ---------- drift notice ------------------------------------------------- */

.ja-drift {
  margin: 16px 0 0;
  background: var(--ja-warm-soft);
  border: 1px solid rgba(240, 168, 104, .34);
  color: var(--ja-warm);
  border-radius: var(--r-panel);
  padding: 14px 16px;
  font-size: 16px;
  line-height: 1.5;
}

/* ---------- code list ---------------------------------------------------- */

.ja-codes {
  list-style: none;
  margin: 24px 0 0;
  padding: 0;
  display: grid;
  gap: 10px;
}

@media (min-width: 768px) {
  .ja-codes { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
}

/* Rows are tinted, not blurred. backdrop-filter on every row of a list is the
   compositing cost the glass guardrail warns about; a translucent tint over the
   fixed field reads the same and costs nothing. */
.ja-row {
  position: relative;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, .075), rgba(255, 255, 255, .018) 42%,
                    rgba(255, 255, 255, 0)),
    rgba(26, 33, 49, .70);
  border: 1px solid var(--ja-line);
  border-radius: var(--r-panel);
  transition: border-color var(--t-micro) var(--e-out);
}

.ja-row:hover { border-color: var(--ja-line-hi); }

/* The copy control fills the whole card, and delete floats over its right end.
   Splitting the card into two columns instead left the hover fill stopping at a
   hard vertical seam partway across the row. Delete stays a sibling, never a
   button nested inside another button. */
.ja-copy {
  display: grid;
  width: 100%;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    "name  timer"
    "code  timer";
  align-items: center;
  column-gap: 14px;
  row-gap: 4px;
  min-width: 0;
  padding: 15px 80px 15px 16px;
  background: none;
  border: 0;
  border-radius: 15px;   /* concentric: 16px shell minus its 1px border */
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background-color var(--t-micro) var(--e-out);
}

.ja-copy:hover { background: rgba(255, 255, 255, .04); }
.ja-copy:active { background: rgba(255, 255, 255, .07); }

/* Two labels share one cell: the account name, and the transient copy
   confirmation that replaces it. */
.ja-row-name {
  grid-area: name;
  display: grid;
  min-width: 0;
}

.ja-issuer,
.ja-account,
.ja-copied {
  grid-area: 1 / 1;
  margin: 0;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ja-row-name { grid-template-rows: auto auto; }
.ja-issuer { grid-row: 1; font-size: 17px; line-height: 1.35; font-weight: 650; }

/* Truncate rather than wrap. A long address is identifying at a glance from its
   first few characters; a six-line stack of single letters is not. */
.ja-account {
  grid-row: 2;
  font-size: 15px;
  line-height: 1.4;
  color: var(--ja-muted);
  transition: opacity var(--t-state) var(--e-out);
}

.ja-copied {
  grid-row: 2;
  font-size: 15px;
  line-height: 1.4;
  color: var(--ja-accent);
  font-weight: 650;
  opacity: 0;
  transition: opacity var(--t-state) var(--e-out);
}

.ja-row[data-copied="yes"] .ja-account { opacity: 0; }
.ja-row[data-copied="yes"] .ja-copied { opacity: 1; }

.ja-code {
  grid-area: code;
  margin: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 34px;
  line-height: 1.05;
  letter-spacing: .08em;
  font-weight: 600;
  color: var(--ja-accent);
  font-variant-numeric: tabular-nums;   /* digits must not shift width as they change */
  transition: color var(--t-state) var(--e-out);
}

.ja-row[data-expiring="yes"] .ja-code { color: var(--ja-warm); }

/* ---------- the rotation ring -------------------------------------------- */

.ja-timer {
  grid-area: timer;
  position: relative;
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  flex: none;
}

.ja-ring { width: 46px; height: 46px; grid-area: 1 / 1; }
.ja-ring circle { fill: none; stroke-width: 3; }
.ja-ring .track { stroke: rgba(150, 176, 214, .18); }

.ja-ring .value {
  stroke: var(--ja-accent);
  stroke-linecap: round;
  transform: rotate(-90deg);
  transform-origin: 50% 50%;
  transition: stroke-dashoffset var(--t-tick) linear,
              stroke var(--t-state) var(--e-out);
}

.ja-row[data-expiring="yes"] .ja-ring .value { stroke: var(--ja-warm); }

/* Set for the one frame where the period wraps, so the ring refills instantly
   instead of sweeping backwards through the whole circle. */
.ja-ring .value.ja-ring-jump { transition: none; }

.ja-secs {
  grid-area: 1 / 1;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--ja-muted);
}

.ja-row[data-expiring="yes"] .ja-secs { color: var(--ja-warm); }

/* Names the copy control for a screen reader without an aria-label, which would
   otherwise suppress the issuer, account, and code inside the button. */
.ja-sr {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ---------- delete ------------------------------------------------------- */

.ja-delete {
  position: absolute;
  top: 8px;
  right: 8px;
  bottom: 8px;
  display: grid;
  place-items: center;
  min-width: 56px;
  padding: 0 10px;
  background: none;
  border: 0;
  border-radius: 9px;
  color: var(--ja-faint);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  transition: color var(--t-micro) var(--e-out),
              background-color var(--t-micro) var(--e-out);
}

.ja-delete:hover { color: var(--ja-danger); background: rgba(255, 119, 132, .12); }

/* ---------- empty state -------------------------------------------------- */

.ja-empty {
  margin-top: 24px;
  padding: 32px 24px;
  text-align: center;
}

.ja-empty h2 { margin: 0; font-size: 20px; line-height: 1.3; font-weight: 700; }
.ja-empty p {
  margin: 10px auto 0;
  max-width: 46ch;
  font-size: 17px;
  line-height: 1.6;
  color: var(--ja-muted);
}

/* ---------- install banner ----------------------------------------------- */

/* Sits after the list rather than above it, so offering the install never
   pushes the codes down the screen. */
.ja-install {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 20px;
  margin-top: 24px;
  padding: 18px 20px;
  border-color: var(--ja-accent-soft);
}

.ja-install-main { flex: 1 1 220px; min-width: 0; }
.ja-install h2 { margin: 0; font-size: 20px; line-height: 1.3; font-weight: 700; }
.ja-install p { margin: 6px 0 0; font-size: 17px; line-height: 1.5; color: var(--ja-muted); }

.ja-install-actions { display: flex; gap: 10px; flex: none; }

/* ---------- add dialog --------------------------------------------------- */

.ja-dialog {
  width: min(94vw, 480px);
  padding: 20px;
  border: 0;
  border-radius: var(--r-modal);
  background: rgba(21, 26, 38, .94);
  color: var(--ja-text);
  /* A modal needs real elevation, so it carries a shadow instead of a border;
     the inset hairline gives it the lit top edge without pairing the two. */
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .09),
    0 28px 64px rgba(0, 0, 0, .62);
}

@supports (backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px)) {
  .ja-dialog {
    background: rgba(21, 26, 38, .78);
    -webkit-backdrop-filter: blur(28px) saturate(150%);
    backdrop-filter: blur(28px) saturate(150%);
  }
}

.ja-dialog::backdrop { background: rgba(4, 6, 12, .68); }

.ja-dialog h2 { margin: 0 0 16px; font-size: 20px; line-height: 1.3; font-weight: 700; }

.ja-dialog label {
  display: block;
  margin-top: 16px;
  font-size: 15px;
  line-height: 1.4;
  color: var(--ja-muted);
}

.ja-dialog input {
  width: 100%;
  margin-top: 6px;
  padding: 12px 14px;
  min-height: 46px;
  font: inherit;
  font-size: 17px;
  background: rgba(6, 9, 16, .70);
  color: var(--ja-text);
  border: 1px solid var(--ja-line);
  border-radius: var(--r-ctl);
  transition: border-color var(--t-micro) var(--e-out);
}

.ja-dialog input::placeholder { color: var(--ja-faint); }
.ja-dialog input:hover { border-color: var(--ja-line-hi); }
.ja-dialog input:focus { border-color: var(--ja-accent); }

.ja-scan { width: 100%; justify-content: center; }

/* 20px shell radius minus its 20px padding would be square; 12px keeps the
     preview from reading as a corner-flush inset it is not. */
#scan-video { display: block; width: 100%; border-radius: 12px; margin-top: 14px; }

.ja-rule {
  display: block;
  margin: 20px 0 0;
  padding-top: 18px;
  border-top: 1px solid var(--ja-line);
  font-size: 14px;
  line-height: 1.5;
  color: var(--ja-faint);
}

.ja-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 24px;
}

.ja-error, .ja-warn {
  margin: 10px 0 0;
  font-size: 15px;
  line-height: 1.5;
}
.ja-error { color: var(--ja-danger); }
.ja-warn  { color: var(--ja-warm); }

/* ---------- offline page ------------------------------------------------- */

.ja-offline { margin-top: 24px; padding: 32px 24px; }
.ja-offline h1 { margin: 0; font-size: 26px; line-height: 1.25; font-weight: 700; }
.ja-offline p { margin: 14px 0 0; font-size: 17px; line-height: 1.6; color: var(--ja-muted); }
.ja-offline a { color: var(--ja-accent); }

/* ---------- brand credit ------------------------------------------------- */

.ja-credit {
  text-align: center;
  font-size: 14px;
  line-height: 1.5;
  color: var(--ja-faint);
  padding: 16px 12px calc(16px + env(safe-area-inset-bottom));
}

.ja-credit a { color: inherit; text-decoration: none; }
.ja-credit a:hover { color: var(--ja-muted); text-decoration: underline; }

/* ---------- narrow screens ----------------------------------------------- */

@media (max-width: 460px) {
  .ja-hero { grid-template-columns: minmax(0, 1fr); }
  .ja-hero-aside {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    width: 100%;
  }
  .ja-clock { text-align: left; }
  .ja-code { font-size: 30px; }
}

/* ---------- user preferences --------------------------------------------- */

/* Apple shipped a user opacity control for its own glass; the web equivalent is
   this media query, so honour it by dropping every surface to solid. */
@media (prefers-reduced-transparency: reduce) {
  .ja-panel, .ja-dialog {
    background: var(--ja-glass);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
  .ja-row { background: var(--ja-row); }
  body::before { background: var(--ja-bg); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-delay: .001ms !important;
    transition-duration: .001ms !important;
    transition-delay: .001ms !important;
  }
}

@media (prefers-contrast: more) {
  :root {
    --ja-muted: #d3dcea;
    --ja-faint: #b6c4d8;
    --ja-line: rgba(150, 176, 214, .34);
  }
  .ja-panel, .ja-dialog { background: var(--ja-glass); backdrop-filter: none; }
  .ja-row { background: var(--ja-row); }
}
