/*
 * MeetFolks PWA. Mobile-first; this is used one-handed at a noisy table.
 *
 * The visual language is a measurement notebook: a serif face for the things a
 * person reads (screen titles, the wordmark), monospace caps for instrument
 * labels (field labels, stats, panel headings), and the sans body for everything
 * between. The bars from the icon recur in exactly two places -- the boot loader
 * and the live level meter -- and nowhere else.
 *
 * Everything is a system font. That is a constraint, not thrift: the server sends
 * COEP `require-corp`, so a cross-origin font would silently fail to load, and a
 * vendored one would grow the shell every phone re-downloads on each deploy.
 */

:root {
  color-scheme: light dark;
  --bg: #f1ebdf;
  --surface: #faf6ee;
  --surface-2: #f3ecdd;
  --ink: #221e17;
  --ink-soft: #6e6656;
  --line: #ded4c0;
  --line-strong: #c9bda4;
  --accent: #b04b28;
  --accent-soft: rgba(176, 75, 40, 0.1);
  --accent-ink: #fff6ec;
  --ok: #2e6b4a;
  --warn: #8a6413;
  --radius: 16px;
  --radius-s: 12px;
  --pad: 1.1rem;
  --shadow: 0 1px 2px rgba(34, 30, 23, 0.04), 0 10px 28px -18px rgba(34, 30, 23, 0.25);
  --font-display: ui-serif, "New York", Georgia, "Times New Roman", serif;
  --font-body: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131110;
    --surface: #1d1a15;
    --surface-2: #262218;
    --ink: #f1eadb;
    --ink-soft: #a79d89;
    --line: #332d23;
    --line-strong: #47402f;
    --accent: #e0714a;
    --accent-soft: rgba(224, 113, 74, 0.14);
    --accent-ink: #1c130e;
    --ok: #82c79c;
    --warn: #dcb05e;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.25), 0 10px 28px -18px rgba(0, 0, 0, 0.6);
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 var(--font-body);
  -webkit-font-smoothing: antialiased;
  padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* -- header ---------------------------------------------------------- */

header {
  max-width: 34rem;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 1.4rem) var(--pad) 0.9rem;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.brand .mark {
  width: 30px;
  height: 30px;
  flex: none;
  display: block;
}

h1 {
  font: 600 1.3rem/1.1 var(--font-display);
  letter-spacing: -0.015em;
  margin: 0;
}

/* The tagline is a disclosure, not a slogan -- `boot` rewrites it from /v1/config
   to say what this deployment actually does with audio and transcripts. */
.tagline {
  margin: 0.5rem 0 0;
  color: var(--ink-soft);
  font-size: 0.82rem;
  line-height: 1.45;
}

main {
  max-width: 34rem;
  margin: 0 auto;
  padding: 0.75rem var(--pad) 4rem;
}

/* Each screen slides in once when shown. `hidden` is display:none, so toggling it
   restarts the animation -- no JS involvement. */
main > section {
  animation: screen-in 0.28s ease both;
}

@keyframes screen-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}

/* -- type roles ------------------------------------------------------ */

h2 {
  font: 600 1.45rem/1.25 var(--font-display);
  letter-spacing: -0.015em;
  margin: 1.7rem 0 0.5rem;
}

/* Panel headings: mono caps, the instrument-label register. */
h3 {
  font: 600 0.75rem/1.3 var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--ink-soft);
  margin: 1.8rem 0 0.6rem;
}

.lede {
  color: var(--ink-soft);
  font-size: 0.9rem;
  margin: 0 0 1rem;
}

.hint {
  color: var(--ink-soft);
  font-size: 0.8rem;
  margin: 0.55rem 0 0;
}

.muted {
  color: var(--ink-soft);
  font-size: 0.85rem;
}

/* Copy uses <em> for measured numbers, not for stress. */
em {
  font-style: normal;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  font-weight: 600;
}

hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 2.2rem 0 0;
}

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

button {
  font: 600 1rem/1.2 var(--font-body);
  border-radius: var(--radius-s);
  border: 1px solid transparent;
  padding: 0.8rem 1.1rem;
  cursor: pointer;
  color: var(--ink);
  /* Comfortable one-handed target at a table. */
  min-height: 48px;
  transition: transform 80ms ease, opacity 120ms ease, background-color 120ms ease;
}

button:active:not(:disabled) {
  transform: scale(0.98);
}

button:disabled {
  opacity: 0.45;
  cursor: default;
}

button.primary {
  background: var(--accent);
  color: var(--accent-ink);
  width: 100%;
  box-shadow: var(--shadow);
}

button.ghost {
  background: var(--surface);
  border-color: var(--line-strong);
}

button.link {
  background: none;
  border: 0;
  color: var(--ink-soft);
  text-decoration: underline;
  text-underline-offset: 3px;
  padding: 0.3rem;
  min-height: 0;
  font-size: 0.85rem;
  font-weight: 500;
}

button.danger {
  background: transparent;
  border-color: var(--accent);
  color: var(--accent);
}

button.primary.danger {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: transparent;
}

.row {
  display: flex;
  gap: 0.6rem;
  margin-top: 1rem;
}

.row > * {
  flex: 1;
}

.field {
  display: block;
  margin: 0.9rem 0;
}

.field > span {
  display: block;
  font: 600 0.72rem/1.3 var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--ink-soft);
  margin-bottom: 0.35rem;
}

input {
  font: inherit;
  width: 100%;
  padding: 0.75rem 0.85rem;
  border-radius: var(--radius-s);
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  min-height: 48px;
}

input::placeholder {
  color: var(--ink-soft);
  opacity: 0.6;
}

input:focus-visible,
button:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

input:focus-visible {
  border-color: var(--accent);
  outline-offset: 0;
  outline-width: 1px;
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.code-input {
  font: 600 1.6rem/1 var(--font-mono);
  letter-spacing: 0.35em;
  text-align: center;
  text-transform: uppercase;
}

/* -- cards ----------------------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--pad);
  margin: 1rem 0;
  box-shadow: var(--shadow);
}

.who {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.who strong {
  display: block;
  font-family: var(--font-display);
  font-size: 1.05rem;
}

/* The session code is what gets read across a table, so it is the largest thing
   in the app: a boarding-pass panel, code first, beacon toggle beneath. */
.code-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.8rem;
  text-align: center;
  padding: 1.4rem var(--pad);
}

.code-card .muted {
  font: 600 0.72rem/1.3 var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.09em;
}

.code-card > button {
  align-self: stretch;
}

.code {
  font: 600 clamp(2.4rem, 13vw, 3.1rem)/1.1 var(--font-mono);
  letter-spacing: 0.18em;
  /* Recentre the glyphs: tracking pads only the right of each character. */
  margin-right: -0.18em;
  font-variant-numeric: tabular-nums;
}

.doors {
  display: grid;
  gap: 1rem;
}

.door {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--pad);
  box-shadow: var(--shadow);
}

/* Both doors look the same on purpose: typing a code is a normal path, not a
   failure, so it gets no error styling and no apology. */

.takes {
  list-style: none;
  padding: 0;
  margin: 1rem 0;
  display: grid;
  gap: 0.5rem;
}

.takes li {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  padding: 0.7rem 0.9rem;
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}

.takes li .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--ok) 20%, transparent);
  flex: none;
}

/* -- recording ------------------------------------------------------- */

/*
 * The level meter, drawn as discrete bars rather than a smooth fill -- the icon's
 * mark, live. JS still just sets `width` on `.meter-fill` every animation frame;
 * the segmentation is an overlay of card-coloured gaps, so it costs nothing and
 * changes no contract. No transition on the fill: `startMeter` smooths the fall
 * itself, and an interpolation here would only make the meter lag the voice.
 */
.meter {
  position: relative;
  height: 38px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}

.meter-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, color-mix(in oklab, var(--accent) 82%, var(--warn)), var(--accent));
}

.meter::after {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(90deg, transparent 0 5px, var(--surface) 5px 8px);
  pointer-events: none;
}

.stats {
  display: flex;
  justify-content: space-between;
  margin-top: 1.1rem;
  gap: 0.5rem;
}

.stats div {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.stats span {
  font: 600 1.35rem/1.2 var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.stats small {
  color: var(--ink-soft);
  font: 600 0.62rem/1.3 var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.09em;
}

/* -- result ---------------------------------------------------------- */

.summary {
  font-size: 0.95rem;
}

.timeline {
  display: grid;
  gap: 0.35rem;
  font: 0.82rem/1.45 var(--font-mono);
}

.seg {
  display: grid;
  grid-template-columns: 5.5rem 1fr;
  gap: 0.6rem;
  align-items: baseline;
  padding: 0.55rem 0.75rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
}

.seg.residual {
  border-style: dashed;
  background: transparent;
  color: var(--ink-soft);
}

.seg .t {
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}

.seg .who-name {
  font-weight: 700;
}

.person-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--pad);
  margin: 0.8rem 0;
  box-shadow: var(--shadow);
}

.person-card h4 {
  margin: 0 0 0.15rem;
  font: 600 1.1rem/1.3 var(--font-display);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin: 0.6rem 0;
}

.chip {
  font-size: 0.78rem;
  padding: 0.25rem 0.65rem;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 99px;
  color: var(--ink-soft);
}

.person-card ul {
  margin: 0.4rem 0;
  padding-left: 1.1rem;
  font-size: 0.9rem;
}

.draft {
  border-left: 3px solid var(--accent);
  padding-left: 0.8rem;
  margin: 0.7rem 0 0;
  font-size: 0.9rem;
  color: var(--ink-soft);
}

.caveats {
  margin-top: 1.5rem;
  border-top: 1px solid var(--line);
  padding-top: 0.8rem;
}

.caveats summary {
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 600;
}

.caveats ul {
  padding-left: 1.1rem;
  font-size: 0.83rem;
  color: var(--ink-soft);
}

.caveats li {
  margin: 0.45rem 0;
}

/* -- status ---------------------------------------------------------- */

.status {
  margin-top: 1rem;
  font-size: 0.85rem;
  min-height: 1.2rem;
}

.status.err {
  color: var(--accent);
  font-weight: 500;
}

.status.warn {
  color: var(--warn);
}

.status.ok {
  color: var(--ok);
}

.diag {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.45rem 1rem;
  font-size: 0.85rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--pad);
  box-shadow: var(--shadow);
}

.diag dt {
  color: var(--ink-soft);
}

.diag dd {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  overflow-wrap: anywhere;
}

.diag dd.bad {
  color: var(--accent);
  font-weight: 600;
}

.diag dd.good {
  color: var(--ok);
}

/* The chirp beacon while it is broadcasting. A steady state, not an alarm --
   leaving it on is a legitimate choice, it just has to be visible that it is on.
   The pulse period matches CHIRP_REPEAT_SEC, so the dot blinks when a burst goes out. */
#btn-chirp.on {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}

#btn-chirp.on::before {
  content: "";
  display: inline-block;
  width: 0.5em;
  height: 0.5em;
  margin-right: 0.45em;
  border-radius: 50%;
  background: var(--accent);
  animation: chirp-pulse 6s ease-in-out infinite;
}

@keyframes chirp-pulse {
  0%,
  16% {
    opacity: 1;
  }
  17%,
  100% {
    opacity: 0.25;
  }
}

@media (prefers-reduced-motion: reduce) {
  #btn-chirp.on::before {
    animation: none;
  }
  main > section {
    animation: none;
  }
}

/* Subheadings inside diagnostics: quieter than the section's own h2/h3. */
#screen-diagnostics h4 {
  margin: 1.5rem 0 0.3rem;
  font-size: 0.95rem;
}

.hint code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 0.05em 0.35em;
}

/* -- footer ---------------------------------------------------------- */

/* Legal notices, not navigation: on every screen, prominent on none. The caption
   register -- same colour and size as a `.hint` -- is deliberate; a person
   deciding whether to record should be able to find these without them competing
   with the button that starts the recording. */
.site-foot {
  max-width: 34rem;
  margin: 0 auto;
  padding: 0 var(--pad) calc(env(safe-area-inset-bottom) + 1.6rem);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.78rem;
  color: var(--ink-soft);
}

.site-foot a {
  color: var(--ink-soft);
  text-underline-offset: 0.18em;
}

.site-foot a:hover {
  color: var(--accent);
}

/* -- boot ------------------------------------------------------------ */

.boot {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.9rem;
  padding: 2rem;
  text-align: center;
  z-index: 20;
}

.boot[hidden] {
  display: none;
}

/* The icon's bars as the loading state: the mark, breathing. */
.eq {
  display: flex;
  align-items: center;
  gap: 5px;
  height: 44px;
}

.eq i {
  width: 6px;
  height: 100%;
  border-radius: 3px;
  background: var(--ink-soft);
  transform-origin: center;
  animation: eq-breathe 1.1s ease-in-out infinite;
}

.eq i:nth-child(1) { transform: scaleY(0.4); background: var(--accent); }
.eq i:nth-child(2) { transform: scaleY(0.75); animation-delay: 0.12s; }
.eq i:nth-child(3) { transform: scaleY(0.55); animation-delay: 0.24s; }
.eq i:nth-child(4) { transform: scaleY(0.85); animation-delay: 0.36s; }
.eq i:nth-child(5) { transform: scaleY(0.45); background: var(--accent); animation-delay: 0.48s; }

@keyframes eq-breathe {
  0%,
  100% {
    transform: scaleY(0.35);
  }
  50% {
    transform: scaleY(1);
  }
}

/* Still used by the inline `?reset=` hatch in index.html, which injects its own
   markup and must depend on nothing else. Do not remove. */
.spinner {
  width: 26px;
  height: 26px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation-duration: 2.4s;
  }
  .eq i {
    animation: none;
  }
  button:active:not(:disabled) {
    transform: none;
  }
}

.progress {
  width: min(18rem, 80vw);
  height: 5px;
  background: var(--line);
  border-radius: 99px;
  overflow: hidden;
}

.progress > div {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 150ms linear;
}

@media (min-width: 40rem) {
  .doors {
    grid-template-columns: 1fr 1fr;
  }
}

/* The summary arrives after the transcript, so it has a waiting state. Muted and
   italic rather than a spinner: the page around it is already complete and useful,
   and a spinner would suggest otherwise. */
#result-summary.pending {
  color: var(--ink-soft);
  font-style: italic;
}

/* Wrapping up after Stop. The bar is determinate while this phone is scoring -- that is
   the one stage whose remaining work is actually known -- and indeterminate for the
   server, where a percentage would be invented. */
.wrapup {
  display: grid;
  gap: 0.75rem;
}

/* Same trap `.boot[hidden]` guards: an author `display` beats the UA's
   `[hidden] { display: none }`, so without this the empty wrap-up card sat
   visible under the buttons for the whole session. */
.wrapup[hidden] {
  display: none;
}

.wrapup .progress {
  width: 100%;
}

#wrapup-bar.indeterminate {
  width: 35%;
  animation: wrapup-slide 1.1s ease-in-out infinite;
}

/* `transform`, not `margin-left`.
   Margin is layout, so that animation needed the main thread on every frame -- and this is
   the indeterminate bar shown while the *final* claim chunk is scored, which is the longest
   main-thread block in the app. The one animation whose whole job is to say "still working"
   was the one that froze exactly when the work was happening. `transform` runs on the
   compositor and keeps moving regardless.
   The bar is 35% of its track, so translating by its own width is the old -35% margin, and
   100/35 = 285.7% of its own width puts its left edge at the far end. */
@keyframes wrapup-slide {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(285.7%); }
}

.wrapup ol {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.4rem;
}

.wrapup li {
  display: flex;
  gap: 0.5rem;
  align-items: baseline;
  color: var(--ink-soft);
  font-size: 0.85rem;
}

.wrapup li .tick {
  width: 1rem;
  flex: none;
  text-align: center;
  font-family: var(--font-mono);
}

.wrapup li.active {
  color: var(--ink);
  font-weight: 600;
}

.wrapup li.done .tick {
  color: var(--accent);
}

@media (prefers-reduced-motion: reduce) {
  #wrapup-bar.indeterminate {
    animation: none;
    width: 100%;
    opacity: 0.5;
  }
}
