:root {
  --bg: #fff;
  --surface: #fff;
  --button: #000;
  --button-text: #fff;
  --button-muted: #9ba2ae;
  --line: #cdd1d8;
  --text: #111317;
  --muted: #5f6672;
  --accent: #f4b740;
  --focus: #e8a524;
  color-scheme: light;
  color: var(--text);
  background: var(--bg);
  font: 16px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  min-height: 100dvh;
  margin: 0;
  padding: max(24px, env(safe-area-inset-top)) 16px 32px;
  display: grid;
  justify-items: center;
  align-items: start;
  background: var(--bg);
}

.app {
  width: min(100%, 420px);
  padding-top: clamp(16px, 7vh, 56px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}

.field, .storage, .sizes { width: min(100%, 320px); }
.field { display: grid; gap: 6px; }
.field-label { margin-left: 2px; color: var(--muted); font-size: 14px; font-weight: 700; }
.input-wrap { position: relative; display: block; }

/* the real input text is hidden; the masked copy is drawn on top of it */
.field input {
  width: 100%;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 52px 0 12px;
  color: transparent;
  caret-color: var(--text);
  background: var(--surface);
  font: inherit;
}
.field input::placeholder { color: #7a818d; }

.masked {
  position: absolute;
  inset: 50% 52px auto 12px;
  transform: translateY(-50%);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  line-height: 1;
  pointer-events: none;
}

.reveal {
  position: absolute;
  top: 50%;
  right: 6px;
  width: 32px;
  height: 32px;
  border: 1px solid var(--button);
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--button-text);
  background: var(--button);
  transform: translateY(-50%);
  cursor: pointer;
}
.reveal svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.reveal[aria-pressed="true"] .slash { display: none; }

.storage {
  margin-top: -8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  font-size: 14px;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  cursor: pointer;
  user-select: none;
}
.toggle input { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.track {
  width: 38px;
  height: 22px;
  border-radius: 999px;
  padding: 2px;
  background: var(--line);
  transition: background-color 160ms ease;
}
.track span {
  display: block;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
  transition: transform 160ms ease;
}
.toggle input:checked + .track { background: var(--accent); }
.toggle input:checked + .track span { transform: translateX(16px); }

.clear {
  min-height: 32px;
  border: 1px solid var(--button);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--button-text);
  background: var(--button);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.sizes { display: flex; gap: 10px; }
.sizes button {
  flex: 1;
  min-height: 42px;
  border: 2px solid var(--button);
  border-radius: 8px;
  color: var(--button-muted);
  background: var(--button);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: border-color 160ms ease, color 160ms ease, transform 120ms ease;
}
.sizes button:hover { color: #d5d8de; }
.sizes button[aria-pressed="true"] { color: var(--button-text); box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--button); }
.sizes button:active { transform: scale(0.96); }

.field input:focus-visible, .reveal:focus-visible, .clear:focus-visible,
.sizes button:focus-visible, .toggle input:focus-visible + .track {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.updated { min-height: 22px; margin: -8px 0 0; color: var(--muted); font-size: 14px; }

.qr-box {
  width: 100%;
  min-height: var(--qr-size, 240px);
  display: grid;
  place-items: center;
}

/* gray card with faint corner squares where the real QR's finder patterns will appear */
.placeholder {
  --m: calc(var(--qr-size, 240px) / 27);
  position: relative;
  width: var(--qr-size, 240px);
  height: var(--qr-size, 240px);
  border-radius: 14px;
  background: #f1f2f4;
}
.placeholder span {
  position: absolute;
  width: calc(var(--m) * 7);
  height: calc(var(--m) * 7);
  border: var(--m) solid #d7dae0;
  background: linear-gradient(#d7dae0, #d7dae0) center / calc(var(--m) * 3) calc(var(--m) * 3) no-repeat;
}
.placeholder span:nth-child(1) { top: calc(var(--m) * 3); left: calc(var(--m) * 3); }
.placeholder span:nth-child(2) { top: calc(var(--m) * 3); right: calc(var(--m) * 3); }
.placeholder span:nth-child(3) { bottom: calc(var(--m) * 3); left: calc(var(--m) * 3); }

/* white card: the padding is a 3-module quiet zone so scanners always find the code */
#qr {
  display: block;
  width: var(--qr-size, 240px);
  height: var(--qr-size, 240px);
  padding: calc(var(--qr-size, 240px) * 3 / 27);
  border-radius: 14px;
  background: #fff;
  image-rendering: pixelated;
}
