/* The train ticket with the platform that changes: the mobile ticket of a rail app, ivory paper on a black page.
   .ticket takes the entrance, .ticket__tilt leans toward the pointer, .ticket__flip turns the two faces. Each face is
   cut by a mask (the two notches at the perforation, at --cut, which the script measures), carries a grain, a gloss
   that sweeps as the ticket turns and a rim of light (a conic gradient at the angle --ea) that walks round the edge. */
:root {
  --page: #000000;          /* the page */
  --paper: #f3eee4;         /* the ticket's paper */
  --paper-deep: #e7e0d2;    /* the paper in the shade, at the foot of the ticket */
  --ink: #17171a;           /* the words and the code */
  --muted: #7b766c;         /* the small words */
  --rule: rgba(23, 23, 26, 0.13); /* the hairlines */
  --accent: #f2a31b;        /* the amber of the notice */
  --accent-ink: #2b1b02;    /* the words on the amber */
  --flap: #1d1e22;          /* the split-flap tiles */
  --flap-ink: #f6f2e9;      /* the number on the tiles */
  --rim: #ffffff;           /* the light on the edge */
}

* {
  box-sizing: border-box;
}

html {
  touch-action: manipulation;
}

html,
body {
  margin: 0;
  overflow-x: clip;
}

body {
  min-height: 100svh;
  background: var(--page);
  color: var(--ink);
  font-family: 'Mona Sans Variable', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.stage {
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: 14px;
  overflow: hidden;
}

.ticket {
  position: relative;
  width: min(88vw, 340px);
  perspective: 1100px;
  visibility: hidden;
}

/* the paper's own light on the floor, a warm haze under the ticket */
.ticket__floor {
  position: absolute;
  left: 8%;
  right: 8%;
  bottom: -26px;
  height: 46px;
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(243, 238, 228, 0.16), rgba(243, 238, 228, 0));
  filter: blur(8px);
  pointer-events: none;
}

.ticket__tilt,
.ticket__flip {
  position: relative;
  transform-style: preserve-3d;
}

.ticket__flip {
  --cut: 60%;
  --notch: 10px;
  --ea: 210deg;
  --eo: 0.55;
  --ec: var(--rim);
  --gl: -1;
  cursor: pointer;
  outline: none;
  border-radius: 20px;
  -webkit-tap-highlight-color: transparent;
}

.ticket__flip:focus-visible .face__rim {
  --eo: 1;
  box-shadow: 0 0 0 2px var(--accent);
}

.face {
  position: relative;
  display: flex;
  flex-direction: column;
  padding: clamp(14px, 4vh, 20px) clamp(15px, 4.6vw, 20px) clamp(13px, 3.6vh, 18px);
  border-radius: 20px;
  background:
    radial-gradient(circle calc(var(--notch) + 0.5px) at 0 var(--cut), transparent calc(var(--notch) - 0.6px), rgba(23, 23, 26, 0.16) var(--notch), transparent calc(var(--notch) + 0.8px)),
    radial-gradient(circle calc(var(--notch) + 0.5px) at 100% var(--cut), transparent calc(var(--notch) - 0.6px), rgba(23, 23, 26, 0.16) var(--notch), transparent calc(var(--notch) + 0.8px)),
    linear-gradient(180deg, #fbf8f1 0%, var(--paper) 38%, var(--paper-deep) 100%);
  -webkit-mask-image:
    radial-gradient(circle var(--notch) at 0 var(--cut), transparent calc(var(--notch) - 0.5px), #000 var(--notch)),
    radial-gradient(circle var(--notch) at 100% var(--cut), transparent calc(var(--notch) - 0.5px), #000 var(--notch));
  -webkit-mask-composite: source-in;
  mask-image:
    radial-gradient(circle var(--notch) at 0 var(--cut), transparent calc(var(--notch) - 0.5px), #000 var(--notch)),
    radial-gradient(circle var(--notch) at 100% var(--cut), transparent calc(var(--notch) - 0.5px), #000 var(--notch));
  mask-composite: intersect;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  overflow: hidden;
}

.face--back {
  position: absolute;
  inset: 0;
  transform: rotateY(180deg);
}

:where(.face > *) {
  position: relative;
}

/* the grain of the paper */
.face__grain {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.5;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.45 0 0 0 0 0.4 0 0 0 0 0.32 0 0 0 0.55 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 160px 160px;
}

/* the gloss: a soft band of light that crosses the paper as the ticket turns, or follows the pointer */
.face__gloss {
  position: absolute;
  inset: -2px;
  pointer-events: none;
  background: linear-gradient(105deg, rgba(255, 255, 255, 0) 38%, rgba(255, 255, 255, 0.55) 50%, rgba(255, 255, 255, 0) 62%);
  background-size: 260% 100%;
  background-position: calc(50% + var(--gl) * 60%) 0;
  opacity: 0.7;
}

/* the rim of light on the edge */
.face__rim {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  padding: 1.2px;
  pointer-events: none;
  background: conic-gradient(from var(--ea), transparent 0deg, transparent 230deg, var(--ec) 300deg, transparent 350deg, transparent 360deg);
  opacity: var(--eo);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0);
}

/* ---------------------------------------------------------------- the head */
.t-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

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

.t-brand__mark {
  width: 20px;
  height: 20px;
  fill: var(--ink);
  stroke: none;
}

.t-brand__mark path {
  fill: none;
  stroke: var(--paper);
  stroke-width: 1.5;
  stroke-linecap: round;
}

.t-brand__name {
  font-size: 13px;
  font-weight: 640;
  font-variation-settings: 'wdth' 104;
  letter-spacing: 0.005em;
}

.t-chip {
  font-size: 10.5px;
  font-weight: 540;
  color: var(--muted);
  padding: 3px 9px;
  border-radius: 999px;
  box-shadow: inset 0 0 0 1px var(--rule);
}

/* ---------------------------------------------------------------- the route */
.t-route {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: end;
  gap: 10px;
  margin-top: clamp(10px, 3vh, 18px);
}

.t-stop {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.t-stop--end {
  text-align: right;
}

.t-time {
  font-size: clamp(24px, min(8vw, 7.4vh), 31px);
  line-height: 1;
  font-weight: 660;
  font-variation-settings: 'wdth' 88;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}

.t-city {
  font-size: 11px;
  color: var(--muted);
  font-weight: 500;
  white-space: nowrap;
}

.t-mid {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding-bottom: 2px;
  min-width: 0;
}

.t-mid__dur,
.t-mid__train {
  font-size: 9.5px;
  color: var(--muted);
  font-weight: 520;
  white-space: nowrap;
}

.t-mid__line {
  display: block;
  width: 100%;
  height: 8px;
}

.t-mid__line svg {
  display: block;
  width: 100%;
  height: 8px;
  overflow: visible;
}

.t-mid__line path {
  fill: none;
  stroke: var(--ink);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
  opacity: 0.55;
}

/* ---------------------------------------------------------------- the status and the amber band */
.t-status {
  position: relative;
  height: clamp(30px, 8vh, 36px);
  margin-top: clamp(10px, 2.8vh, 16px);
  border-radius: 10px;
  box-shadow: inset 0 0 0 1px var(--rule);
}

.t-status__rest {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 0 11px;
  font-size: 11.5px;
  color: var(--muted);
}

.t-status__rest b {
  color: var(--ink);
  font-weight: 620;
}

.t-status__rest svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: var(--ink);
  stroke-width: 1.3;
  stroke-linecap: round;
  flex: none;
}

.t-band {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 0 11px;
  border-radius: 10px;
  overflow: hidden;
  background: linear-gradient(180deg, color-mix(in srgb, var(--accent) 88%, #fff) 0%, var(--accent) 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.45), inset 0 -1px 0 rgba(0, 0, 0, 0.08), 0 6px 14px -8px color-mix(in srgb, var(--accent) 80%, #000);
  color: var(--accent-ink);
  font-size: 11.5px;
  clip-path: inset(0 100% 0 0 round 10px);
}

.t-band__shine {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 46%;
  background: linear-gradient(100deg, rgba(255, 255, 255, 0), rgba(255, 255, 255, 0.6), rgba(255, 255, 255, 0));
  transform: translateX(-120%);
  pointer-events: none;
}

.t-band__icon {
  position: relative;
  width: 14px;
  height: 14px;
  flex: none;
  fill: none;
  stroke: var(--accent-ink);
  stroke-width: 1.4;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.t-band__text {
  position: relative;
  flex: 1;
  white-space: nowrap;
}

.t-band__text b {
  font-weight: 660;
}

.t-band__time {
  position: relative;
  font-variant-numeric: tabular-nums;
  font-weight: 560;
  opacity: 0.75;
}

/* ---------------------------------------------------------------- the grid */
.t-grid {
  display: grid;
  grid-template-columns: 1.35fr 0.8fr 0.9fr 0.95fr;
  gap: 8px;
  margin-top: clamp(10px, 2.8vh, 16px);
}

.t-cell {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}

.t-label {
  font-size: 9.5px;
  font-weight: 560;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
}

.t-platrow {
  display: flex;
  align-items: center;
  gap: 6px;
}

.t-was {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  white-space: nowrap;
  letter-spacing: 0.01em;
  color: color-mix(in srgb, var(--accent) 62%, var(--accent-ink));
  opacity: 0;
}

.t-val {
  font-size: clamp(16px, 5vh, 20px);
  line-height: clamp(26px, 7.4vh, 32px);
  font-weight: 640;
  font-variation-settings: 'wdth' 92;
  letter-spacing: -0.01em;
}

/* the split-flap tiles */
.t-flaps {
  display: flex;
  gap: 2px;
}

.flap {
  --fh: clamp(26px, 7.4vh, 32px);
  position: relative;
  width: calc(var(--fh) * 0.72);
  height: var(--fh);
  border-radius: 4px;
  perspective: 140px;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.6), 0 3px 6px -2px rgba(0, 0, 0, 0.35);
  font-size: calc(var(--fh) * 0.74);
  font-weight: 680;
  font-variation-settings: 'wdth' 80;
  font-variant-numeric: tabular-nums;
  color: var(--flap-ink);
}

.flap__half {
  position: absolute;
  left: 0;
  right: 0;
  height: 50%;
  overflow: hidden;
  background: var(--flap);
}

.flap__top {
  top: 0;
  border-radius: 4px 4px 0 0;
  background: linear-gradient(180deg, color-mix(in srgb, var(--flap) 80%, #fff) 0%, var(--flap) 100%);
}

.flap__bot {
  top: 50%;
  border-radius: 0 0 4px 4px;
  border-top: 1px solid rgba(0, 0, 0, 0.55);
}

.flap__ch {
  display: block;
  height: var(--fh);
  line-height: var(--fh);
  text-align: center;
}

.flap__bot .flap__ch {
  transform: translateY(calc(var(--fh) * -0.5 - 1px));
}

.flap__shade {
  position: absolute;
  inset: 0;
  background: #000;
  opacity: 0;
  pointer-events: none;
}

.flap__leaf-top,
.flap__leaf-bot {
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}

/* the two pins of the hinge */
.flap::before,
.flap::after {
  content: '';
  position: absolute;
  top: calc(50% - 2px);
  width: 2px;
  height: 4px;
  border-radius: 1px;
  background: #050506;
  z-index: 3;
}

.flap::before {
  left: -1px;
}

.flap::after {
  right: -1px;
}

/* ---------------------------------------------------------------- the perforation */
.t-perf {
  display: block;
  height: 1px;
  margin: clamp(12px, 3.4vh, 18px) calc(var(--notch) * -0.2);
  background-image: linear-gradient(90deg, var(--rule) 0 55%, transparent 55% 100%);
  background-size: 7px 1px;
}

/* ---------------------------------------------------------------- the stub */
.t-stub {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: clamp(12px, 4vw, 16px);
  align-items: stretch;
}

.t-qr {
  position: relative;
  display: block;
  padding: 6px;
  border-radius: 10px;
  background: #fffdf8;
  box-shadow: inset 0 0 0 1px var(--rule), 0 1px 0 rgba(255, 255, 255, 0.8);
}

.t-qr canvas {
  display: block;
}

.t-who {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.t-name {
  font-size: 15px;
  font-weight: 640;
  font-variation-settings: 'wdth' 100;
  margin-top: 2px;
}

.t-small {
  font-size: 11px;
  color: var(--muted);
}

.t-ref {
  font-size: 10.5px;
  font-weight: 560;
  font-variation-settings: 'wdth' 78;
  letter-spacing: 0.08em;
  font-variant-numeric: tabular-nums;
  margin-top: 1px;
}

.t-updated {
  font-size: 10px;
  color: color-mix(in srgb, var(--accent) 55%, var(--accent-ink));
  font-weight: 560;
  opacity: 0;
}

.t-hint {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-top: auto;
  font-size: 10.5px;
  font-weight: 560;
  color: var(--ink);
  opacity: 0.7;
}

.t-hint svg {
  width: 12px;
  height: 12px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------------------------------------------------------------- the back */
.t-terms {
  margin: clamp(10px, 3vh, 16px) 0 0;
  display: flex;
  flex-direction: column;
}

.t-terms div {
  display: grid;
  grid-template-columns: 74px 1fr;
  gap: 10px;
  padding: clamp(5px, 1.6vh, 8px) 0;
  border-bottom: 1px solid var(--rule);
}

.t-terms div:last-child {
  border-bottom: 0;
}

.t-terms dt {
  font-size: 9.5px;
  font-weight: 560;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  padding-top: 2px;
}

.t-terms dd {
  margin: 0;
  font-size: 12px;
  line-height: 1.3;
  font-weight: 500;
}

.t-perf--back {
  position: absolute;
  left: 0;
  right: 0;
  top: var(--cut);
  margin: 0;
}

.t-bars {
  display: block;
  width: 100%;
  height: clamp(18px, 5vh, 26px);
  margin-top: auto;
  margin-bottom: clamp(10px, 2.8vh, 14px);
  opacity: 0.85;
}

.t-bars path {
  fill: var(--ink);
}

.t-fare {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 10px;
}

.t-fare__left {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.t-fare__sum {
  font-size: clamp(22px, 6.6vh, 28px);
  line-height: 1.05;
  font-weight: 660;
  font-variation-settings: 'wdth' 90;
  letter-spacing: -0.02em;
}

.t-fare .t-hint {
  margin-top: 0;
}

@media (hover: hover) {
  .ticket__flip:hover .t-hint {
    opacity: 1;
  }
}
