:root {
  --paper: #E7ECEE;
  --stock: #F3F5F4;
  --ink: #16233F;
  --ink-soft: #4A5875;
  --engrave: #2E4A78;
  --valid: #1D7458;
  --invalid: #B0283F;
  --rule: rgba(22, 35, 63, 0.18);

  --serif: "Bodoni Moda", "Didot", "Bodoni 72", Georgia, serif;
  --mono: "Martian Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;

  --gutter: clamp(16px, 4vw, 48px);
  --max: 1180px;
}

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

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

body {
  margin: 0;
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 18px;
  line-height: 1.55;
  font-optical-sizing: auto;
  overflow-x: hidden;
}

#backdrop {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
  transition: opacity 260ms ease;
}
#backdrop.fading { opacity: 0; }

.bar, main, .foot { position: relative; z-index: 1; }

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

/* Header */

.bar {
  max-width: var(--max);
  margin: 0 auto;
  padding: 22px var(--gutter);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.wordmark {
  font-size: 24px;
  font-weight: 600;
  color: var(--ink);
  text-decoration: none;
  letter-spacing: -0.01em;
}
.wordmark em { font-weight: 500; }

.bg-controls { display: flex; align-items: center; gap: 8px; }

.switch {
  display: flex;
  margin: 0;
  padding: 3px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: rgba(243, 245, 244, 0.8);
}
.switch legend {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}
.switch label { position: relative; cursor: pointer; }
.switch input {
  position: absolute;
  opacity: 0;
  inset: 0;
  margin: 0;
  cursor: pointer;
}
.switch span {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 14px 6px 11px;
  border-radius: 999px;
  font-family: var(--mono);
  font-size: 12px;
  font-stretch: 87.5%;
  color: var(--ink-soft);
  transition: background-color 160ms ease, color 160ms ease;
}
.switch svg {
  width: 20px;
  height: 14px;
  fill: currentColor;
  stroke: currentColor;
  stroke-width: 1;
}
.switch svg text { font-family: var(--mono); stroke: none; font-weight: 600; }
.switch input:checked + span { background: var(--ink); color: var(--stock); }
.switch input:focus-visible + span { outline: 2px solid var(--engrave); outline-offset: 2px; }

.pause {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 1px solid var(--rule);
  border-radius: 50%;
  background: rgba(243, 245, 244, 0.8);
  color: var(--ink);
  cursor: pointer;
}
.pause svg { width: 12px; height: 12px; fill: currentColor; }
.pause .i-play, .pause[aria-pressed="true"] .i-pause { display: none; }
.pause[aria-pressed="true"] .i-play { display: block; }

/* Hero */

main {
  max-width: var(--max);
  margin: 0 auto;
  padding: 0 var(--gutter);
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
  gap: clamp(32px, 6vw, 88px);
  align-items: start;
  padding: clamp(24px, 6vh, 72px) 0 clamp(56px, 10vh, 112px);
}

h1 {
  margin: 0;
  max-width: 15ch;
  font-size: clamp(42px, 5.6vw, 76px);
  font-weight: 500;
  line-height: 1.02;
  letter-spacing: -0.02em;
  text-wrap: balance;
}

.lede, .verdict, .steps li, .card-caption, .samples p {
  text-shadow: 0 0 6px var(--paper), 0 0 2px var(--paper);
}

.lede {
  max-width: 34em;
  margin: 28px 0 0;
  color: var(--ink-soft);
  font-size: 19px;
}

.entry { margin-top: 40px; }

.entry label {
  display: block;
  margin-bottom: 10px;
  font-size: 16px;
  font-style: italic;
  color: var(--ink-soft);
}

#number {
  width: 100%;
  padding: 18px 20px;
  border: 1.5px solid var(--ink);
  border-radius: 10px;
  background: var(--stock);
  color: var(--ink);
  font-family: var(--mono);
  font-size: clamp(19px, 2.3vw, 26px);
  font-weight: 500;
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
  box-shadow: inset 0 2px 0 rgba(22, 35, 63, 0.06);
  transition: border-color 200ms ease, box-shadow 200ms ease;
}
#number::placeholder { color: rgba(74, 88, 117, 0.45); }
#number:focus { outline: none; box-shadow: inset 0 2px 0 rgba(22, 35, 63, 0.06), 0 0 0 4px rgba(46, 74, 120, 0.18); }
.entry[data-verdict="valid"] #number { border-color: var(--valid); }
.entry[data-verdict="invalid"] #number { border-color: var(--invalid); }

.verdict {
  min-height: 3.1em;
  margin: 12px 0 0;
  font-size: 17px;
  line-height: 1.5;
  color: var(--ink-soft);
}
.entry[data-verdict="valid"] .verdict strong { color: var(--valid); }
.entry[data-verdict="invalid"] .verdict strong { color: var(--invalid); }

.samples { margin-top: 18px; }
.samples p {
  margin: 0 0 10px;
  font-size: 16px;
  font-style: italic;
  color: var(--ink-soft);
}
.samples ul {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.samples button {
  padding: 7px 13px;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  font-family: var(--mono);
  font-size: 12px;
  font-stretch: 87.5%;
  cursor: pointer;
  transition: background-color 140ms ease, border-color 140ms ease;
}
.samples button:hover { background: rgba(243, 245, 244, 0.9); border-color: var(--ink-soft); }

/* Card */

.card-wrap { perspective: 1400px; padding-top: clamp(0px, 4vw, 56px); }

.card {
  position: relative;
  aspect-ratio: 85.6 / 53.98;
  width: 100%;
  max-width: 520px;
  margin-left: auto;
  padding: 6.5% 7%;
  border-radius: 4.2% / 6.6%;
  background: var(--stock);
  border: 1px solid rgba(22, 35, 63, 0.22);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.9),
    0 1px 2px rgba(22, 35, 63, 0.12),
    0 30px 60px -28px rgba(22, 35, 63, 0.45);
  overflow: hidden;
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  container-type: inline-size;
  transform: rotateX(4deg) rotateY(-9deg) rotateZ(1deg);
  transition: border-color 300ms ease, transform 500ms cubic-bezier(.2, .8, .2, 1);
}
.card:hover { transform: rotateX(0) rotateY(0) rotateZ(0); }
.card[data-verdict="valid"] { border-color: var(--valid); }
.card[data-verdict="invalid"] { border-color: var(--invalid); }

.guilloche {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  fill: none;
  stroke: var(--engrave);
  stroke-width: 0.6;
  opacity: 0.32;
  transition: stroke 400ms ease;
}
.card[data-verdict="valid"] .guilloche { stroke: var(--valid); }
.card[data-verdict="invalid"] .guilloche { stroke: var(--invalid); }

.card > *:not(.guilloche):not(.stamp) { position: relative; }

.card-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
}
.issuer { font-size: 5.2cqi; font-weight: 600; font-style: italic; letter-spacing: -0.01em; }
.brand {
  font-family: var(--mono);
  font-size: 2.7cqi;
  font-stretch: 87.5%;
  color: var(--ink-soft);
  text-align: right;
}
.brand.known { color: var(--ink); font-weight: 600; }

.chip {
  align-self: center;
  width: 15%;
  aspect-ratio: 1.3;
  border-radius: 14%;
  background: linear-gradient(135deg, #D9C79A 0%, #B49A62 45%, #E3D4AA 70%, #A88D55 100%);
  box-shadow: inset 0 0 0 1px rgba(90, 70, 30, 0.35);
  display: grid;
  grid-template-rows: 1fr 1fr 1fr;
  overflow: hidden;
}
.chip i { border-bottom: 1px solid rgba(90, 70, 30, 0.35); }
.chip i:nth-child(2) { border-left: 1px solid rgba(90, 70, 30, 0.35); border-right: 1px solid rgba(90, 70, 30, 0.35); margin: 0 30%; }

.holo {
  position: absolute !important;
  right: 7%;
  top: 38%;
  width: 14%;
  aspect-ratio: 1.25;
  border-radius: 10%;
  background:
    repeating-radial-gradient(circle at 30% 40%, rgba(255,255,255,.55) 0 1px, transparent 1px 3px),
    conic-gradient(from 210deg, #b9d7e8, #d9c2e6, #f0dcc0, #c4e6d2, #b9d7e8);
  box-shadow: inset 0 0 0 1px rgba(22, 35, 63, 0.18);
  opacity: 0.9;
}

.card-number {
  margin: 0 0 4.5%;
  font-family: var(--mono);
  font-size: 6.4cqi;
  font-weight: 500;
  font-stretch: 100%;
  letter-spacing: 0.06em;
  white-space: nowrap;
  color: #3A4560;
  text-shadow:
    0 1px 0 rgba(255, 255, 255, 0.95),
    0 -1px 0 rgba(22, 35, 63, 0.35);
  font-variant-numeric: tabular-nums;
}
.card-number .gap { display: inline-block; width: 0.55em; }
.card-number .ph { color: rgba(58, 69, 96, 0.28); text-shadow: none; }
.card-number .check {
  position: relative;
  color: var(--engrave);
}
.card-number .check::after {
  content: "";
  position: absolute;
  inset: -0.12em -0.18em;
  border: 1.5px solid currentColor;
  border-radius: 50%;
}
.card[data-verdict="valid"] .card-number .check { color: var(--valid); }
.card[data-verdict="invalid"] .card-number .check { color: var(--invalid); }

.card-bottom {
  display: flex;
  gap: 10%;
  font-family: var(--mono);
  font-size: 2.2cqi;
  font-stretch: 87.5%;
  color: var(--ink-soft);
}
.card-bottom span { display: grid; gap: 0.3em; }
.card-bottom b {
  font-weight: 500;
  font-size: 3.1cqi;
  color: #3A4560;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.95), 0 -1px 0 rgba(22, 35, 63, 0.3);
}

.stamp {
  position: absolute;
  right: 6%;
  bottom: 5%;
  padding: 2.2% 4.5%;
  border: 0.9cqi double currentColor;
  border-radius: 1.6cqi;
  font-family: var(--serif);
  font-size: 7.4cqi;
  font-style: italic;
  font-weight: 700;
  line-height: 1;
  mix-blend-mode: multiply;
  filter: url(#ink-rough);
  opacity: 0;
  transform: rotate(-11deg) scale(1.6);
  pointer-events: none;
}
.stamp.show {
  animation: stamp 420ms cubic-bezier(.3, 1.4, .5, 1) forwards;
}
.stamp.valid { color: var(--valid); }
.stamp.invalid { color: var(--invalid); }

@keyframes stamp {
  0% { opacity: 0; transform: rotate(-4deg) scale(1.7); }
  55% { opacity: 0.92; transform: rotate(-11deg) scale(0.96); }
  100% { opacity: 0.88; transform: rotate(-11deg) scale(1); }
}

.card-caption {
  max-width: 520px;
  margin: 22px 0 0 auto;
  font-size: 16px;
  font-style: italic;
  color: var(--ink-soft);
}

/* Method */

.method {
  padding: clamp(48px, 8vh, 88px) 0;
  border-top: 1px solid var(--rule);
}

h2 {
  margin: 0 0 36px;
  font-size: clamp(32px, 4vw, 48px);
  font-weight: 500;
  line-height: 1.1;
  letter-spacing: -0.015em;
}

.method-grid {
  display: grid;
  grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr);
  gap: clamp(32px, 5vw, 72px);
  align-items: start;
}

.steps {
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: step;
}
.steps li {
  counter-increment: step;
  position: relative;
  padding-left: 52px;
  margin-bottom: 26px;
  max-width: 30em;
  color: var(--ink-soft);
}
.steps li::before {
  content: counter(step);
  position: absolute;
  left: 0;
  top: -0.1em;
  font-size: 34px;
  font-style: italic;
  font-weight: 500;
  line-height: 1;
  color: var(--engrave);
}
.steps strong { display: block; color: var(--ink); font-weight: 600; }

.workings {
  padding: clamp(18px, 3vw, 32px);
  border: 1px solid var(--rule);
  border-radius: 14px;
  background: rgba(243, 245, 244, 0.86);
  backdrop-filter: blur(2px);
}

.strip {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.strip:empty { display: none; }

.tile {
  display: grid;
  grid-template-rows: auto 18px auto;
  justify-items: center;
  align-items: center;
  width: 2.7em;
  padding: 8px 0 7px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}
.tile .d { font-size: 18px; font-weight: 500; }
.tile .op { font-size: 10px; font-stretch: 80%; color: var(--engrave); }
.tile .v {
  font-size: 15px;
  padding-top: 4px;
  border-top: 1px solid var(--rule);
  width: 70%;
  text-align: center;
  color: var(--ink-soft);
}
.tile.dbl { background: rgba(46, 74, 120, 0.09); border-color: rgba(46, 74, 120, 0.2); }
.tile.dbl .v { color: var(--engrave); font-weight: 600; }
.tile.last { border-color: var(--ink-soft); border-style: dashed; }

.total {
  margin: 20px 0 0;
  font-size: 18px;
}
.strip:empty + .total { margin: 0; color: var(--ink-soft); font-style: italic; }
.total .sum { font-family: var(--mono); font-weight: 600; font-size: 17px; }
.total.valid .sum { color: var(--valid); }
.total.invalid .sum { color: var(--invalid); }

/* Footer */

.foot {
  max-width: var(--max);
  margin: 0 auto;
  padding: 0 var(--gutter) 48px;
  font-size: 15px;
  color: var(--ink-soft);
}
.foot::before {
  content: "";
  display: block;
  margin-bottom: 28px;
  border-top: 1px solid var(--rule);
}
.foot p { margin: 0 0 6px; max-width: 60em; }

/* Responsive */

@media (max-width: 900px) {
  .hero { grid-template-columns: 1fr; }
  .card { margin: 0 auto; transform: none; }
  .card-caption { margin: 18px auto 0; }
  .method-grid { grid-template-columns: 1fr; }
}

@media (max-width: 520px) {
  body { font-size: 17px; }
  .bar { padding-top: 16px; padding-bottom: 16px; }
  .switch span { padding: 6px 10px; font-size: 11px; }
  .switch svg { display: none; }
  .lede { font-size: 17px; }
  .tile { width: 2.35em; }
  .tile .d { font-size: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  .card, .card:hover { transform: none; transition: none; }
  .stamp.show { animation: none; opacity: 0.88; transform: rotate(-11deg); }
  #backdrop { transition: none; }
}
