/* Material 3 tokens, Google's light-blue-grey surface family. */
:root {
  --primary: #0b57d0;
  --on-primary: #ffffff;
  --primary-container: #d3e3fd;
  --on-primary-container: #041e49;
  --surface: #ffffff;
  --surface-container: #f0f4f9;
  --surface-container-high: #e9eef6;
  --on-surface: #1f1f1f;
  --on-surface-variant: #444746;
  --outline: #747775;
  --outline-variant: #c4c7c5;
  --received: #0b57d0;
  --pending: #d5dade;
  --scrim: rgba(0, 0, 0, 0.08);

  --radius-s: 8px;
  --radius-m: 16px;
  --radius-l: 28px;
  --ease: cubic-bezier(0.2, 0, 0, 1);

  --font: "Google Sans", "Product Sans", Roboto, system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --primary: #a8c7fa;
    --on-primary: #062e6f;
    --primary-container: #0842a0;
    --on-primary-container: #d3e3fd;
    --surface: #131314;
    --surface-container: #1e1f20;
    --surface-container-high: #282a2c;
    --on-surface: #e3e3e3;
    --on-surface-variant: #c4c7c5;
    --outline: #8e918f;
    --outline-variant: #444746;
    --received: #a8c7fa;
    --pending: #333537;
    --scrim: rgba(0, 0, 0, 0.4);
    color-scheme: dark;
  }
}

* {
  box-sizing: border-box;
}

/* display on .stage / section would otherwise beat the hidden attribute. */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  color: var(--on-surface);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom)
    env(safe-area-inset-left);
}

/* ------------------------------------------------------------- app bar */

.app-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 12px 24px;
}

.wordmark {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 22px;
  letter-spacing: -0.2px;
}

.mark {
  width: 24px;
  height: 24px;
  fill: var(--primary);
}

/* Material segmented button. */
.segmented {
  display: flex;
  border: 1px solid var(--outline-variant);
  border-radius: var(--radius-l);
  overflow: hidden;
}

.segmented button {
  display: flex;
  align-items: center;
  gap: 8px;
  appearance: none;
  border: 0;
  background: none;
  color: var(--on-surface-variant);
  font: 500 14px/1 var(--font);
  letter-spacing: 0.1px;
  padding: 10px 20px;
  cursor: pointer;
  transition: background 0.2s var(--ease), color 0.2s var(--ease);
}

.segmented button + button {
  border-left: 1px solid var(--outline-variant);
}

.segmented button svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.segmented button:hover {
  background: var(--surface-container);
}

.segmented button[aria-selected="true"] {
  background: var(--primary-container);
  color: var(--on-primary-container);
}

.segmented.compact {
  align-self: flex-start;
}

.segmented.compact button {
  padding: 8px 20px;
}

/* --------------------------------------------------------------- layout */

main {
  flex: 1;
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: 24px 24px 48px;
}

main > section {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* ------------------------------------------------------------- dropzone */

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  text-align: center;
  padding: 32px 24px;
  border-radius: var(--radius-m);
  background: var(--surface-container);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.2s var(--ease), border-color 0.2s var(--ease);
}

.dropzone:hover {
  background: var(--surface-container-high);
}

.dropzone:focus-within {
  border-color: var(--primary);
}

.dropzone input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.dropzone-icon {
  width: 28px;
  height: 28px;
  fill: var(--primary);
  margin-bottom: 8px;
}

.dropzone-label {
  font-size: 16px;
  font-weight: 500;
  word-break: break-word;
}

.dropzone-hint {
  font-size: 14px;
  color: var(--on-surface-variant);
  max-width: 42ch;
}

/* --------------------------------------------------------------- fields */

.field {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.field-label {
  font-size: 14px;
  font-weight: 500;
  color: var(--on-surface-variant);
  letter-spacing: 0.1px;
}

.field-hint {
  margin: 0;
  font-size: 13px;
  color: var(--on-surface-variant);
}

/* Material filter chips. */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.chip span {
  display: block;
  padding: 8px 16px;
  border: 1px solid var(--outline-variant);
  border-radius: var(--radius-s);
  font-size: 14px;
  font-weight: 500;
  color: var(--on-surface-variant);
  cursor: pointer;
  transition: background 0.2s var(--ease), color 0.2s var(--ease),
    border-color 0.2s var(--ease);
}

.chip span:hover {
  background: var(--surface-container);
}

.chip input:checked + span {
  background: var(--primary-container);
  color: var(--on-primary-container);
  border-color: transparent;
}

.chip input:focus-visible + span {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--primary);
}

output {
  font-variant-numeric: tabular-nums;
  color: var(--on-surface);
}

textarea {
  width: 100%;
  resize: vertical;
  min-height: 120px;
  padding: 16px;
  border: 1px solid var(--outline-variant);
  border-radius: var(--radius-m);
  background: var(--surface);
  color: var(--on-surface);
  font: 16px/1.5 var(--font);
}

textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: inset 0 0 0 1px var(--primary);
}

textarea::placeholder {
  color: var(--on-surface-variant);
}

#source-text {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.text-btn {
  appearance: none;
  border: 0;
  background: none;
  border-radius: var(--radius-l);
  color: var(--primary);
  font: 500 14px/1 var(--font);
  padding: 10px 16px;
  cursor: pointer;
}

.text-btn:hover {
  background: var(--surface-container);
}

/* ------------------------------------------------------ received message */

.message {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;
  padding: 20px;
  border-radius: var(--radius-m);
  background: var(--surface-container);
}

.message pre {
  margin: 0;
  width: 100%;
  max-height: 40dvh;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font: 15px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--on-surface);
}

.tonal {
  appearance: none;
  border: 0;
  border-radius: var(--radius-l);
  background: var(--primary-container);
  color: var(--on-primary-container);
  font: 500 14px/1 var(--font);
  padding: 10px 24px;
  cursor: pointer;
}

.tonal:hover {
  box-shadow: 0 1px 3px 1px var(--scrim);
}

/* -------------------------------------------------------------- buttons */

.filled {
  align-self: flex-start;
  appearance: none;
  border: 0;
  border-radius: var(--radius-l);
  background: var(--primary);
  color: var(--on-primary);
  font: 500 14px/1 var(--font);
  letter-spacing: 0.1px;
  padding: 16px 28px;
  cursor: pointer;
  transition: box-shadow 0.2s var(--ease), background 0.2s var(--ease);
}

.filled:hover:not(:disabled) {
  box-shadow: 0 1px 3px 1px var(--scrim);
}

.filled:disabled {
  background: color-mix(in srgb, var(--on-surface) 12%, transparent);
  color: color-mix(in srgb, var(--on-surface) 38%, transparent);
  cursor: default;
}

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

.status {
  margin: 0;
  font-size: 14px;
  color: var(--on-surface-variant);
  min-height: 1.5em;
  word-break: break-word;
  font-variant-numeric: tabular-nums;
}

/* The QR needs a white field to scan, in either theme. */
.stage {
  display: flex;
  justify-content: center;
  padding: 16px;
  border-radius: var(--radius-m);
  background: #fff;
}

/* The canvas fills the stage at a fixed on-screen size, whatever QR version the
   current frame happens to be — a header is v3, a 576 B data frame is v19, and
   letting the backing store drive layout made the code resize every time one
   went past. Smoothing stays ON: the backing store is always a whole number of
   pixels per module and slightly larger than the display size, so the browser
   only ever scales down. Nearest-neighbour on a non-integer ratio is what
   turned 4 px modules into a mix of 3 and 4. */
canvas#qr {
  display: block;
  width: min(100%, 70vh);
  height: auto;
}

/* Fullscreen exists to make the code physically bigger to the camera, which is
   what lets the denser settings decode. Fill the screen, nothing else. */
#qr-stage:fullscreen {
  align-items: center;
  width: 100vw;
  height: 100vh;
  padding: 0;
  border-radius: 0;
  background: #fff;
}

#qr-stage:fullscreen canvas {
  width: min(100vw, 100vh);
}

/* --------------------------------------------------------- progress */

.progress {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.track {
  height: 4px;
  border-radius: 2px;
  background: var(--pending);
  overflow: hidden;
}

.track div {
  height: 100%;
  width: 0;
  border-radius: 2px;
  background: var(--primary);
  transition: width 0.25s var(--ease);
}

.mosaic {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 0 auto;
  image-rendering: pixelated;
}

/* ----------------------------------------------------------- viewfinder */

.viewfinder {
  padding: 0;
  overflow: hidden;
  background: var(--surface-container-high);
}

video {
  display: block;
  width: 100%;
  max-height: 60dvh;
  object-fit: cover;
}

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

footer {
  padding: 24px;
  color: var(--on-surface-variant);
  font-size: 13px;
  text-align: center;
}

footer a {
  color: var(--primary);
  text-decoration: none;
}

footer a:hover {
  text-decoration: underline;
}

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

@media (max-width: 520px) {
  .app-bar {
    padding: 12px 16px;
  }
  main {
    padding: 16px 16px 32px;
  }
  .filled {
    align-self: stretch;
    text-align: center;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}
