/* QR Coder ---------------------------------------------------------------*/

:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-2: #eef0f5;
  --surface-3: #e4e7ef;
  --text: #13151b;
  --text-2: #5a6070;
  --text-3: #8a90a0;
  --border: #e0e3eb;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-ink: #ffffff;
  --accent-soft: #eceeff;
  --accent-text: #4338ca;
  --selected: #ffffff;
  --ok: #0e8a4f;
  --ok-soft: #e3f6ec;
  --warn: #a45a06;
  --warn-soft: #fdf1df;
  --danger: #c62828;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 4px 16px rgb(16 24 40 / 6%);
  --shadow-lg: 0 12px 40px rgb(16 24 40 / 18%);
  --radius: 16px;
  --radius-sm: 10px;
  --topbar: 60px;
  --tabbar: 0px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1015;
    --surface: #171a21;
    --surface-2: #1f232c;
    --surface-3: #2a2f3a;
    --text: #eceef3;
    --text-2: #a2a8b8;
    --text-3: #737a8c;
    --border: #2a2f3a;
    --accent: #8d88ff;
    --accent-hover: #a29eff;
    --accent-ink: #11131a;
    --accent-soft: #25254a;
    --accent-text: #b1adff;
    --selected: #353b4a;
    --ok: #4ccf8a;
    --ok-soft: #14301f;
    --warn: #f0b35a;
    --warn-soft: #3a2a12;
    --danger: #ff7b7b;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 4px 16px rgb(0 0 0 / 25%);
    --shadow-lg: 0 12px 40px rgb(0 0 0 / 50%);
    color-scheme: dark;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.25;
  letter-spacing: -0.01em;
}

a {
  color: var(--accent-text);
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

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

.icon {
  width: 20px;
  height: 20px;
  flex: none;
}

.sr-only {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.muted {
  color: var(--text-2);
  margin: 2px 0 0;
  font-size: 13px;
}

/* Top bar and tabs ------------------------------------------------------*/

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: var(--topbar);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(1.4) blur(14px);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.01em;
}

.brand img {
  border-radius: 8px;
}

.tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  border-radius: 999px;
  background: var(--surface-2);
}

.tab {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 16px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--text-2);
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.tab .icon {
  width: 18px;
  height: 18px;
}

.tab:hover {
  color: var(--text);
}

.tab[aria-selected="true"] {
  background: var(--selected);
  color: var(--text);
  box-shadow: var(--shadow);
}

main {
  flex: 1;
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: 20px max(16px, env(safe-area-inset-right)) 24px max(16px, env(safe-area-inset-left));
}

.footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 16px;
  padding: 18px 16px calc(18px + var(--tabbar));
  color: var(--text-3);
  font-size: 13px;
}

.footer a {
  color: var(--text-2);
}

/* Phones: tabs become a bottom bar within thumb reach. */
@media (max-width: 719px) {
  :root {
    --tabbar: calc(64px + env(safe-area-inset-bottom));
  }

  /* backdrop-filter would make the header the containing block of the
     fixed tab bar inside it, pinning the bar to the header instead of the
     bottom of the screen. */
  .topbar {
    justify-content: center;
    height: 52px;
    background: var(--bg);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }

  .tabs {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    height: var(--tabbar);
    padding: 6px 8px env(safe-area-inset-bottom);
    border-radius: 0;
    background: color-mix(in srgb, var(--surface) 88%, transparent);
    backdrop-filter: saturate(1.4) blur(14px);
    -webkit-backdrop-filter: saturate(1.4) blur(14px);
    border-top: 1px solid var(--border);
    gap: 0;
  }

  .tab {
    flex: 1;
    flex-direction: column;
    justify-content: center;
    gap: 2px;
    padding: 4px;
    border-radius: 12px;
    font-size: 12px;
  }

  .tab .icon {
    width: 22px;
    height: 22px;
  }

  .tab[aria-selected="true"] {
    background: transparent;
    box-shadow: none;
    color: var(--accent-text);
  }

  main {
    padding-top: 12px;
  }
}

/* Buttons and controls ---------------------------------------------------*/

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.08s;
  -webkit-tap-highlight-color: transparent;
}

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

.btn:active {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.45;
  cursor: default;
  transform: none;
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.btn.primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-2);
}

.btn.ghost:hover {
  background: var(--surface-2);
  color: var(--text);
}

.btn.danger {
  color: var(--danger);
}

.btn.lg {
  min-height: 48px;
  padding: 12px 22px;
  font-size: 16px;
  border-radius: 14px;
}

.btn.sm {
  min-height: 34px;
  padding: 6px 12px;
  font-size: 14px;
  border-radius: 10px;
}

.btn.sm .icon {
  width: 18px;
  height: 18px;
}

.round {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgb(20 22 28 / 55%);
  color: #fff;
  cursor: pointer;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: background 0.15s, transform 0.08s;
  -webkit-tap-highlight-color: transparent;
}

.round:hover {
  background: rgb(20 22 28 / 75%);
}

.round:active {
  transform: scale(0.94);
}

.round[aria-pressed="true"] {
  background: #ffd84d;
  color: #1a1400;
}

.round.ghost {
  width: 36px;
  height: 36px;
  background: transparent;
  color: var(--text-2);
  backdrop-filter: none;
}

.round.ghost:hover {
  background: var(--surface-2);
  color: var(--text);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.field {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.field > span {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
}

.field small {
  color: var(--text-3);
  font-size: 12px;
}

.field.inline {
  display: flex;
  align-items: center;
  gap: 8px;
}

input:not([type]),
input[type="text"],
input[type="url"],
input[type="email"],
input[type="tel"],
select,
textarea {
  width: 100%;
  min-height: 42px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 16px; /* 16px keeps iOS from zooming on focus */
  transition: border-color 0.15s, box-shadow 0.15s;
}

textarea {
  resize: vertical;
  line-height: 1.45;
}

select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5 6 6.5l5-5' fill='none' stroke='%238a90a0' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}

.field.inline select {
  width: auto;
  min-height: 38px;
  font-size: 14px;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}

/* Segmented control built from radio buttons. */
.seg {
  display: inline-flex;
  padding: 3px;
  border-radius: 12px;
  background: var(--surface-2);
  gap: 2px;
  max-width: 100%;
}

.seg label {
  position: relative;
  flex: 1;
}

.seg input {
  position: absolute;
  opacity: 0;
  inset: 0;
  margin: 0;
  cursor: pointer;
}

.seg span {
  display: block;
  padding: 6px 14px;
  border-radius: 9px;
  text-align: center;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-2);
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}

.seg input:checked + span {
  background: var(--selected);
  color: var(--text);
  box-shadow: var(--shadow);
}

.seg input:focus-visible + span {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* Toggle switch. */
.switch {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 36px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}

.switch input {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  flex: none;
  width: 42px;
  height: 26px;
  margin: 0;
  border-radius: 999px;
  background: var(--surface-3);
  cursor: pointer;
  transition: background 0.2s;
}

.switch input::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgb(0 0 0 / 30%);
  transition: transform 0.2s;
}

.switch input:checked {
  background: var(--accent);
}

.switch input:checked::after {
  transform: translateX(16px);
}

/* Scan -------------------------------------------------------------------*/

.scan-grid {
  display: grid;
  gap: 20px;
  align-items: start;
}

@media (min-width: 900px) {
  .scan-grid {
    grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr);
  }
}

.viewport {
  position: relative;
  overflow: hidden;
  width: 100%;
  aspect-ratio: 3 / 4;
  max-height: calc(100dvh - var(--topbar) - var(--tabbar) - 40px);
  border-radius: 22px;
  background: radial-gradient(120% 90% at 50% 0%, #252a37 0%, #111318 60%, #0b0c10 100%);
  color: #fff;
  box-shadow: var(--shadow);
  isolation: isolate;
}

@media (min-width: 720px) {
  .viewport {
    aspect-ratio: 4 / 3;
  }
}

.viewport video,
.viewport #still,
.viewport canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.viewport video {
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.3s;
}

.viewport[data-state="live"] video,
.viewport[data-state="found"] video {
  opacity: 1;
}

.viewport video.mirrored {
  transform: scaleX(-1);
}

.viewport #still {
  object-fit: contain;
  background: #0b0c10;
}

.viewport canvas {
  pointer-events: none;
  z-index: 2;
}

.reticle {
  position: absolute;
  z-index: 1;
  left: 50%;
  top: 50%;
  width: min(62%, 62cqh, 340px);
  aspect-ratio: 1;
  translate: -50% -52%;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
}

.viewport {
  container-type: size;
}

.viewport[data-state="live"] .reticle {
  opacity: 1;
  animation: breathe 2.4s ease-in-out infinite;
}

.reticle i {
  position: absolute;
  width: 22%;
  height: 22%;
  border: 4px solid rgb(255 255 255 / 92%);
  filter: drop-shadow(0 0 6px rgb(0 0 0 / 35%));
}

.reticle i:nth-child(1) {
  top: 0;
  left: 0;
  border-right: 0;
  border-bottom: 0;
  border-top-left-radius: 18px;
}

.reticle i:nth-child(2) {
  top: 0;
  right: 0;
  border-left: 0;
  border-bottom: 0;
  border-top-right-radius: 18px;
}

.reticle i:nth-child(3) {
  bottom: 0;
  right: 0;
  border-left: 0;
  border-top: 0;
  border-bottom-right-radius: 18px;
}

.reticle i:nth-child(4) {
  bottom: 0;
  left: 0;
  border-right: 0;
  border-top: 0;
  border-bottom-left-radius: 18px;
}

@keyframes breathe {
  50% {
    scale: 1.035;
  }
}

.idle {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 28px;
  text-align: center;
}

.idle h1 {
  font-size: 24px;
}

.idle p {
  max-width: 34ch;
  margin: 0;
  color: rgb(255 255 255 / 72%);
}

.idle .hint {
  font-size: 13px;
  color: rgb(255 255 255 / 50%);
}

.idle .idle-error {
  max-width: 38ch;
  padding: 8px 14px;
  border-radius: 12px;
  background: rgb(255 90 90 / 16%);
  color: #ffc2c2;
  font-weight: 500;
}

.idle-mark {
  display: grid;
  place-items: center;
  width: 76px;
  height: 76px;
  margin-bottom: 4px;
  border-radius: 24px;
  background: linear-gradient(145deg, #6d66ff, #4338ca);
  box-shadow: 0 10px 30px rgb(79 70 229 / 45%);
}

.idle-mark .icon {
  width: 40px;
  height: 40px;
  color: #fff;
}

.idle-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 6px;
}

.idle .btn:not(.primary) {
  background: rgb(255 255 255 / 10%);
  border-color: rgb(255 255 255 / 18%);
  color: #fff;
}

.idle .btn:not(.primary):hover {
  background: rgb(255 255 255 / 18%);
}

.idle .btn.primary {
  background: #fff;
  border-color: #fff;
  color: #15171d;
}

.idle .btn.primary:hover {
  background: #e9eaf0;
}

.viewport-bar {
  position: absolute;
  z-index: 3;
  left: 50%;
  bottom: 16px;
  translate: -50% 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px;
  border-radius: 999px;
  background: rgb(10 11 15 / 35%);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.zoom {
  display: flex;
  align-items: center;
  padding: 0 8px;
}

.zoom input {
  width: 110px;
  accent-color: #fff;
}

.scan-status {
  position: absolute;
  z-index: 3;
  left: 50%;
  top: 16px;
  translate: -50% 0;
  max-width: calc(100% - 32px);
  margin: 0;
  padding: 6px 14px;
  border-radius: 999px;
  background: rgb(10 11 15 / 55%);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  font-size: 14px;
  font-weight: 500;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.scan-status:empty {
  display: none;
}

.drop-hint {
  position: absolute;
  inset: 10px;
  z-index: 4;
  display: grid;
  place-items: center;
  border: 2px dashed rgb(255 255 255 / 70%);
  border-radius: 16px;
  background: rgb(79 70 229 / 35%);
  font-weight: 600;
  font-size: 18px;
}

.scan-side {
  display: grid;
  gap: 16px;
  min-width: 0;
}

.placeholder {
  padding: 22px;
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  color: var(--text-2);
}

.placeholder h2 {
  font-size: 17px;
  color: var(--text);
  margin-bottom: 10px;
}

.placeholder ul {
  margin: 0;
  padding-left: 18px;
  display: grid;
  gap: 6px;
  font-size: 14px;
}

.settings summary,
.style-card summary,
.payload summary {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
  user-select: none;
  -webkit-user-select: none;
}

.settings summary::-webkit-details-marker,
.style-card summary::-webkit-details-marker,
.payload summary::-webkit-details-marker {
  display: none;
}

.settings summary::after,
.style-card summary::after,
.payload summary::after {
  content: "";
  margin-left: auto;
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--text-3);
  border-bottom: 2px solid var(--text-3);
  rotate: 45deg;
  translate: 0 -2px;
  transition: rotate 0.2s, translate 0.2s;
}

details[open] > summary::after {
  rotate: 225deg;
  translate: 0 2px;
}

.settings-body {
  display: grid;
  gap: 4px;
  padding: 0 18px 14px;
}

/* Result card ------------------------------------------------------------*/

.result {
  padding: 18px;
  display: grid;
  gap: 14px;
  min-width: 0;
  animation: rise 0.25s ease-out;
}

@keyframes rise {
  from {
    opacity: 0;
    translate: 0 8px;
  }
}

.result-head {
  display: flex;
  align-items: center;
  gap: 12px;
}

.result-kind {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  flex: none;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent-text);
}

.result-title {
  min-width: 0;
}

.result-title h2 {
  font-size: 17px;
}

.result-title p {
  margin: 0;
  color: var(--text-3);
  font-size: 13px;
}

.result-head .round {
  margin-left: auto;
}

.result-text {
  margin: 0;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--surface-2);
  font: 15px/1.5 var(--mono);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-height: 240px;
  overflow: auto;
}

.result-link {
  display: grid;
  gap: 4px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--surface-2);
}

.result-link .host {
  font-weight: 700;
  font-size: 17px;
  overflow-wrap: anywhere;
}

.result-link .full {
  font: 13px/1.45 var(--mono);
  color: var(--text-2);
  overflow-wrap: anywhere;
}

.kv {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 2px 12px;
  margin: 0;
  padding: 6px 4px;
  align-items: center;
}

.kv dt {
  color: var(--text-3);
  font-size: 13px;
}

.kv dd {
  margin: 0;
  overflow-wrap: anywhere;
  font-weight: 500;
}

.kv .copy-inline {
  justify-self: end;
}

.kv .secret {
  font-family: var(--mono);
}

.note {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin: 0;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--warn-soft);
  color: var(--warn);
  font-size: 13px;
}

.note .icon {
  width: 18px;
  height: 18px;
  margin-top: 1px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.actions .btn {
  flex: 1 1 auto;
}

.tech {
  font-size: 13px;
  color: var(--text-2);
}

.tech summary {
  cursor: pointer;
  color: var(--text-3);
  width: fit-content;
}

.tech dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 14px;
  margin: 8px 0 0;
}

.tech dt {
  color: var(--text-3);
}

.tech dd {
  margin: 0;
}

/* Create -----------------------------------------------------------------*/

.create-grid {
  display: grid;
  gap: 20px;
  align-items: start;
}

/* One column: the preview goes right under the fields being typed into,
   ahead of the style options. */
@media (max-width: 899px) {
  .create-grid > .create-form {
    display: contents;
  }

  .types {
    order: 1;
  }

  .fields-card {
    order: 2;
  }

  .preview-col {
    order: 3;
  }

  .style-card {
    order: 4;
  }
}

@media (min-width: 900px) {
  .create-grid {
    grid-template-columns: minmax(0, 1fr) minmax(320px, 400px);
  }

  .preview-col {
    position: sticky;
    top: calc(var(--topbar) + 20px);
  }
}

.create-form {
  display: grid;
  gap: 16px;
  min-width: 0;
}

.types {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0;
  padding: 0;
  border: 0;
  min-width: 0;
}

.chip {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  font-weight: 600;
  font-size: 14px;
  color: var(--text-2);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.chip input {
  position: absolute;
  inset: 0;
  opacity: 0;
  margin: 0;
  cursor: pointer;
}

.chip .icon {
  width: 18px;
  height: 18px;
}

.chip:hover {
  color: var(--text);
}

.chip:has(input:checked) {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.chip:has(input:focus-visible) {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.fields-card {
  padding: 18px;
}

.fields {
  display: grid;
  gap: 14px;
}

@media (min-width: 560px) {
  .fields.two {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .fields.two .wide {
    grid-column: 1 / -1;
  }
}

.field-switch {
  align-self: end;
}

.style-grid {
  display: grid;
  gap: 18px;
  padding: 0 18px 18px;
}

.colors {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 18px;
}

.color-field {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 14px;
  color: var(--text-2);
  cursor: pointer;
}

.color-field input {
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: none;
  cursor: pointer;
}

.color-field input::-webkit-color-swatch-wrapper {
  padding: 4px;
}

.color-field input::-webkit-color-swatch {
  border: 0;
  border-radius: 8px;
}

.color-field input::-moz-color-swatch {
  border: 0;
  border-radius: 8px;
}

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

.field output {
  color: var(--text);
}

.logo-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

#logo-thumb {
  width: 40px;
  height: 40px;
  object-fit: contain;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
}

.preview-card {
  padding: 18px;
  display: grid;
  gap: 14px;
}

.preview-box {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  border-radius: 14px;
  background:
    repeating-conic-gradient(var(--surface-2) 0% 25%, var(--surface) 0% 50%) 50% / 18px 18px;
  overflow: hidden;
}

#qr-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.preview-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 10px;
  padding: 24px;
  background: var(--surface);
  color: var(--text-3);
  text-align: center;
}

.preview-empty .icon {
  width: 48px;
  height: 48px;
  opacity: 0.6;
}

.preview-meta {
  margin: 0;
  color: var(--text-2);
  font-size: 13px;
  text-align: center;
}

.preview-meta.error {
  color: var(--danger);
  font-weight: 600;
}

.verify {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 0;
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
}

.verify .icon {
  width: 18px;
  height: 18px;
}

.verify.ok {
  background: var(--ok-soft);
  color: var(--ok);
}

.verify.warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.verify.pending {
  background: var(--surface-2);
  color: var(--text-2);
}

.export {
  display: grid;
  gap: 12px;
}

.export-buttons {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(84px, 1fr));
  gap: 8px;
}

.payload {
  border-top: 1px solid var(--border);
  margin: 0 -18px -18px;
}

.payload pre {
  margin: 0 18px 18px;
  padding: 12px;
  border-radius: 10px;
  background: var(--surface-2);
  font: 13px/1.45 var(--mono);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-height: 200px;
  overflow: auto;
}

/* History ----------------------------------------------------------------*/

.history-head {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.history-head h1 {
  font-size: 24px;
}

.history-tools {
  display: flex;
  align-items: center;
  gap: 8px;
}

.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 10px 10px 12px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
}

.history-item .open {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
  padding: 0;
  border: 0;
  background: none;
  text-align: left;
  cursor: pointer;
}

.history-item .result-kind {
  width: 38px;
  height: 38px;
  border-radius: 11px;
}

.history-item .result-kind .icon {
  width: 18px;
  height: 18px;
}

.history-item .body {
  min-width: 0;
  display: grid;
}

.history-item .line {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-item .meta {
  color: var(--text-3);
  font-size: 13px;
}

.history-item:hover {
  border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
}

.empty {
  display: grid;
  justify-items: center;
  gap: 10px;
  padding: 48px 16px;
  color: var(--text-3);
  text-align: center;
}

.empty .icon {
  width: 44px;
  height: 44px;
}

/* Dialog and toast -------------------------------------------------------*/

.sheet {
  width: min(520px, calc(100% - 24px));
  max-height: min(88dvh, 760px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
}

.sheet::backdrop {
  background: rgb(8 10 14 / 45%);
  backdrop-filter: blur(2px);
}

.sheet[open] {
  animation: rise 0.2s ease-out;
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 14px 0 20px;
}

.sheet-head h2 {
  font-size: 17px;
}

.sheet-body .result {
  animation: none;
  border: 0;
  box-shadow: none;
  background: transparent;
  padding-top: 10px;
}

.toast {
  position: fixed;
  z-index: 50;
  left: 50%;
  bottom: calc(24px + var(--tabbar));
  translate: -50% 20px;
  max-width: calc(100% - 32px);
  padding: 10px 18px;
  border-radius: 999px;
  background: #1c1f27;
  color: #fff;
  font-weight: 500;
  font-size: 14px;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, translate 0.2s;
}

.toast.show {
  opacity: 1;
  translate: -50% 0;
}

@media (prefers-color-scheme: dark) {
  .toast {
    background: #eceef3;
    color: #11131a;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
