@layer reset, tokens, base, layout, components, utilities, overrides;

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

  :where(body, h1, h2, h3, p, ul, ol, dl, dd) {
    margin: 0;
  }

  :where(ul[role="list"], ol[role="list"]) {
    padding-inline-start: 0;
    list-style: none;
  }

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

  :where(fieldset) {
    margin: 0;
    min-inline-size: 0;
  }

  :where(legend) {
    padding: 0;
  }

  :where(button, label) {
    cursor: pointer;
  }
}

@layer tokens {
  :root {
    color-scheme: light dark;

    --black: oklch(0% 0 0);
    --white: oklch(100% 0 0);

    --leather-300: oklch(52% 0.06 160);
    --leather-500: oklch(40% 0.055 162);
    --leather-700: oklch(30% 0.045 165);
    --leather-900: oklch(19% 0.03 168);
    --leather-950: oklch(14% 0.022 170);

    --buff-50: oklch(98% 0.018 95);
    --buff-100: oklch(95% 0.035 90);
    --buff-200: oklch(91% 0.045 86);
    --buff-300: oklch(85% 0.05 82);
    --buff-400: oklch(78% 0.05 80);

    --ink-700: oklch(38% 0.05 255);
    --ink-900: oklch(26% 0.04 258);

    --red-500: oklch(52% 0.18 27);
    --red-600: oklch(46% 0.17 27);

    --mustard-300: oklch(88% 0.13 92);

    --color-desk: light-dark(var(--leather-500), var(--leather-900));
    --color-desk-edge: light-dark(var(--leather-700), var(--leather-950));
    --color-desk-glow: light-dark(var(--leather-300), var(--leather-700));
    --color-paper: light-dark(var(--buff-100), var(--buff-300));
    --color-paper-fiber: color-mix(in oklch, var(--buff-400) 22%, transparent);
    --color-tape: light-dark(var(--buff-50), var(--buff-200));
    --color-ink: var(--ink-900);
    --color-ink-soft: var(--ink-700);
    --color-stamp: light-dark(var(--red-500), var(--red-600));
    --color-tag: var(--color-tape);
    --color-focus-desk: var(--mustard-300);
    --color-focus-paper: var(--red-600);
    --color-shadow: color-mix(in oklch, var(--black) 45%, transparent);
    --color-shadow-soft: color-mix(in oklch, var(--black) 18%, transparent);
    --color-rule: color-mix(in oklch, var(--ink-700) 25%, transparent);
    --color-backdrop: color-mix(in oklch, var(--leather-950) 70%, transparent);

    --font-print: "Oswald", "Arial Narrow", "Helvetica Neue", Arial, sans-serif;
    --font-tape: "Courier Prime", "Courier New", ui-monospace, monospace;

    --step--2: 0.75rem;
    --step--1: 0.8125rem;
    --step-0: 1rem;
    --step-1: clamp(1rem, 0.92rem + 0.45vw, 1.2rem);
    --step-3: clamp(1.6rem, 0.8rem + 4cqi, 2.8rem);

    --leading-tight: 1;
    --leading-snug: 1.25;
    --leading-body: 1.5;

    --tracking-wide: 0.08em;
    --tracking-wider: 0.18em;
    --tracking-widest: 0.6em;
    --tracking-slight: 0.02em;

    --space-3xs: 0.125rem;
    --space-2xs: 0.25rem;
    --space-xs: 0.5rem;
    --space-s: 0.75rem;
    --space-m: 1rem;
    --space-l: 1.5rem;
    --space-xl: 2rem;
    --space-2xl: 3rem;
    --space-page: clamp(1rem, 4vw, 3rem);
    --space-blank: clamp(1rem, 5cqi, 2.75rem);

    --size-blank: 46rem;
    --size-arrow: 3.4rem;
    --size-box: 0.7rem;
    --size-receipt: 38rem;
    --size-rule: 2px;
    --size-rule-thin: 1px;
    --size-target-min: 1.5rem;
    --size-focus: 3px;

    --radius-paper: 3px;
    --radius-tag: 2px;

    --shadow-blank:
      0 1px 0 var(--color-shadow-soft),
      0 1.5rem 3rem -1rem var(--color-shadow);
    --shadow-tape: 0 1px 1px var(--color-shadow-soft);
    --shadow-tag: 0 2px 4px var(--color-shadow);

    --tilt-a: 0.4deg;
    --tilt-b: -0.35deg;
    --tilt-c: 0.15deg;
    --tilt-tag-a: -2deg;
    --tilt-tag-b: 1.5deg;
    --tilt-stamp: -12deg;

    --duration-telegram: 4200ms;
    --duration-paste: 140ms;
    --duration-stamp: 220ms;
    --duration-hover: 120ms;
    --steps-print: 22;
    --ease-stamp: linear(0, 0.7 40%, 1.06 70%, 1);
  }
}

@layer base {
  html {
    scroll-padding-block-start: var(--space-xl);
  }

  body {
    min-block-size: 100dvh;
    font-family: var(--font-print);
    line-height: var(--leading-body);
    color: var(--color-ink);
    background:
      radial-gradient(70% 55% at 50% 30%, var(--color-desk-glow), transparent),
      radial-gradient(140% 100% at 50% 40%, var(--color-desk) 55%, var(--color-desk-edge));
  }

  :where(a) {
    color: inherit;
  }

  :where(a:focus-visible) {
    outline: var(--size-focus) solid var(--color-focus-paper);
    outline-offset: var(--size-rule);
  }
}

@layer layout {
  .desk {
    display: grid;
    justify-items: center;
    padding: var(--space-l) var(--space-page) var(--space-2xl);
  }
}

@layer components {
  .skip-link {
    position: absolute;
    inset-block-start: var(--space-s);
    inset-inline-start: var(--space-s);
    padding: var(--space-xs) var(--space-m);
    background: var(--color-tag);
    color: var(--color-ink);
    translate: 0 -200%;

    &:focus-visible {
      translate: 0 0;
      outline: var(--size-focus) solid var(--color-focus-desk);
    }
  }

  .stamps {
    padding: var(--space-xl) var(--space-page) 0;

    & :where(ul) {
      display: flex;
      flex-wrap: wrap;
      justify-content: center;
      gap: var(--space-s) var(--space-l);
    }

    & :where(li:nth-child(odd)) {
      rotate: var(--tilt-tag-a);
    }

    & :where(li:nth-child(even)) {
      rotate: var(--tilt-tag-b);
    }

    & :where(a) {
      display: block;
      min-block-size: var(--size-target-min);
      padding: var(--space-2xs) var(--space-s);
      border: var(--size-rule) solid var(--color-stamp);
      border-radius: var(--radius-tag);
      outline: var(--size-rule-thin) solid var(--color-stamp);
      outline-offset: calc(var(--size-rule) * -2.5);
      background: var(--color-tag);
      box-shadow: var(--shadow-tag);
      color: var(--color-stamp);
      font-size: var(--step--1);
      font-weight: 700;
      letter-spacing: var(--tracking-wider);
      line-height: var(--leading-snug);
      text-decoration: none;
      text-transform: uppercase;
      transition: translate var(--duration-hover) ease-out;

      &:focus-visible {
        outline: var(--size-focus) solid var(--color-focus-desk);
        outline-offset: var(--size-rule);
      }

      &[aria-current="page"] {
        background: var(--color-stamp);
        color: var(--color-tag);
        outline-color: var(--color-tag);
      }
    }

    @media (hover: hover) {
      & :where(a:hover) {
        translate: 0 calc(var(--space-3xs) * -2);
      }
    }
  }

  .telegram {
    --strip-count: 10;
    --duration-strip: calc(var(--duration-telegram) / var(--strip-count));

    color-scheme: light;
    container-type: inline-size;
    position: relative;
    inline-size: min(var(--size-blank), 100%);
    padding: var(--space-blank);
    border-radius: var(--radius-paper);
    background:
      repeating-linear-gradient(
        93deg,
        transparent 0 0.4rem,
        var(--color-paper-fiber) 0.4rem calc(0.4rem + 1px)
      ),
      var(--color-paper);
    box-shadow: var(--shadow-blank);
    color: var(--color-ink);

    & :where(.label) {
      font-size: var(--step--2);
      font-weight: 700;
      letter-spacing: var(--tracking-wider);
      line-height: var(--leading-snug);
      text-transform: uppercase;
    }

    & :where(.blank-head) {
      display: grid;
      grid-template-columns: minmax(0, 1fr) minmax(0, 2.4fr) minmax(0, 1fr);
      grid-template-areas: "service wordmark symbols";
      align-items: start;
      gap: var(--space-l);
      padding-block-end: var(--space-m);
      border-block-end: calc(var(--size-rule) * 2) double var(--color-ink);

      @container (inline-size < 36rem) {
        grid-template-columns: 1fr 1fr;
        grid-template-areas:
          "wordmark wordmark"
          "service symbols";
      }
    }

    & :where(.service, .symbols) {
      display: grid;
      gap: var(--space-2xs);
      padding: var(--space-xs);
      border: var(--size-rule-thin) solid var(--color-ink);
      font-size: var(--step--2);
      line-height: var(--leading-snug);
    }

    & :where(.service) {
      grid-area: service;

      & :where(legend) {
        float: inline-start;
        inline-size: 100%;
      }

      & :where(ul) {
        display: grid;
        gap: var(--space-3xs);
      }

      & :where(li:not(:has(input))) {
        display: flex;
        align-items: center;
        gap: var(--space-2xs);

        &::before {
          content: "";
          flex: none;
          inline-size: var(--size-box);
          aspect-ratio: 1;
          border: var(--size-rule-thin) solid var(--color-ink);
        }
      }

      & :where(li[data-checked])::before {
        background:
          linear-gradient(45deg, transparent 44%, var(--color-stamp) 44% 56%, transparent 56%),
          linear-gradient(-45deg, transparent 44%, var(--color-stamp) 44% 56%, transparent 56%);
      }

      & :where(label) {
        display: flex;
        align-items: center;
        gap: var(--space-2xs);
        min-block-size: var(--size-target-min);
      }

      & :where(input) {
        margin: 0;
        accent-color: var(--color-stamp);
      }
    }

    & :where(.note) {
      color: var(--color-ink-soft);
      font-size: var(--step--2);
      line-height: var(--leading-snug);
    }

    & :where(.symbols) {
      grid-area: symbols;

      & :where(dl) {
        display: grid;
        grid-template-columns: var(--symbols-columns, max-content 1fr);
        gap: var(--space-3xs) var(--space-xs);
      }

      &[data-layout="stacked"] {
        --symbols-columns: 1fr;
      }

      &[data-layout="stacked"] :where(div + div > dt) {
        margin-block-start: var(--space-2xs);
      }

      & :where(dl > div) {
        display: contents;
      }

      & :where(dt) {
        font-weight: 700;
      }
    }

    & :where(.wordmark) {
      grid-area: wordmark;
      display: grid;
      justify-items: center;
      text-align: center;
      text-transform: uppercase;

      & :where(.carrier) {
        font-size: var(--step-3);
        font-weight: 700;
        letter-spacing: var(--tracking-wide);
        line-height: var(--leading-tight);
        text-wrap: balance;
      }

      & :where(.company) {
        display: flex;
        align-items: center;
        gap: var(--space-s);
        inline-size: 100%;
        font-size: var(--step-0);
        font-weight: 500;
        letter-spacing: var(--tracking-widest);

        &::before,
        &::after {
          content: "";
          flex: 1;
          border-block-start: var(--size-rule) solid var(--color-ink);
        }
      }

      & :where(.lines) {
        margin-block-start: var(--space-2xs);
        font-size: var(--step--2);
        letter-spacing: var(--tracking-wider);
        color: var(--color-ink-soft);
      }
    }

    & :where(.arrow) {
      inline-size: var(--size-arrow);
      aspect-ratio: 3 / 1;
      margin-block-end: var(--space-2xs);
      background: var(--color-ink);
      clip-path: polygon(0 18%, 14% 50%, 0 82%, 20% 82%, 30% 60%, 70% 60%, 70% 88%, 100% 50%, 70% 12%, 70% 40%, 30% 40%, 20% 18%);
    }

    & :where(.fields) {
      display: grid;
      grid-template-columns: 2fr 1fr 1fr 1.2fr;
      gap: var(--space-s) var(--space-m);
      padding-block: var(--space-s) var(--space-l);

      @container (inline-size < 30rem) {
        grid-template-columns: 1fr 1fr;
      }

      & :where(dt) {
        font-size: var(--step--2);
        font-weight: 700;
        letter-spacing: var(--tracking-wider);
        text-transform: uppercase;
      }

      & :where(dd) {
        padding-block-start: var(--space-3xs);
        border-block-start: var(--size-rule-thin) solid var(--color-ink);
        font-family: var(--font-tape);
        font-weight: 700;
        text-transform: uppercase;
        font-variant-numeric: tabular-nums;
      }
    }

    & :where(.charge dd) {
      position: relative;
    }

    & :where(.paid) {
      position: absolute;
      inset-block-start: 50%;
      inset-inline-start: 40%;
      padding: var(--space-3xs) var(--space-xs);
      border: calc(var(--size-rule) * 1.5) solid var(--color-stamp);
      border-radius: var(--radius-tag);
      outline: var(--size-rule-thin) solid var(--color-stamp);
      outline-offset: var(--size-rule);
      color: var(--color-stamp);
      font-family: var(--font-print);
      font-size: var(--step-1);
      letter-spacing: var(--tracking-wider);
      line-height: var(--leading-tight);
      opacity: 0.85;
      mix-blend-mode: multiply;
      translate: 0 -50%;
      rotate: var(--tilt-stamp);
      pointer-events: none;
    }

    & :where(.tapes) {
      display: grid;
      justify-items: start;
      gap: var(--space-xs);
    }

    & :where(.tape) {
      --strip: 0;

      position: relative;
      max-inline-size: 100%;
      padding: var(--space-3xs) var(--space-s);
      background: var(--color-tape);
      box-shadow: var(--shadow-tape);
      font-family: var(--font-tape);
      font-size: var(--step-1);
      font-weight: 700;
      letter-spacing: var(--tracking-wide);
      line-height: var(--leading-snug);
      rotate: var(--tilt-c);

      &:nth-child(3n + 1) {
        rotate: var(--tilt-a);
      }

      &:nth-child(3n + 2) {
        rotate: var(--tilt-b);
        margin-inline-start: var(--space-2xs);
      }

      &[data-kind="check"] {
        margin-block-end: var(--space-xs);
        font-size: var(--step--1);
        font-weight: 400;
      }

      &[data-kind="address"] {
        margin-block-end: var(--space-s);
      }

      &[data-kind="signature"] {
        justify-self: end;
        margin-block-start: var(--space-xs);
      }
    }

    & :where(.tape:nth-child(2)) { --strip: 1; }
    & :where(.tape:nth-child(3)) { --strip: 2; }
    & :where(.tape:nth-child(4)) { --strip: 3; }
    & :where(.tape:nth-child(5)) { --strip: 4; }
    & :where(.tape:nth-child(6)) { --strip: 5; }
    & :where(.tape:nth-child(7)) { --strip: 6; }
    & :where(.tape:nth-child(8)) { --strip: 7; }
    & :where(.tape:nth-child(9)) { --strip: 8; }
    & :where(.tape:nth-child(10)) { --strip: 9; }
    & :where(.tape:nth-child(11)) { --strip: 10; }
    & :where(.tape:nth-child(12)) { --strip: 11; }
    & :where(.tape:nth-child(13)) { --strip: 12; }
    & :where(.tape:nth-child(14)) { --strip: 13; }
    & :where(.tape:nth-child(15)) { --strip: 14; }
    & :where(.tape:nth-child(16)) { --strip: 15; }

    & :where(.entry) {
      display: grid;
      gap: var(--space-2xs);
      margin-block-end: var(--space-l);
    }

    & :where(textarea, input[type="text"]) {
      inline-size: 100%;
      padding: 0 var(--space-xs);
      border: 0;
      border-block-end: var(--size-rule) solid var(--color-ink);
      background: var(--color-tape);
      font-family: var(--font-tape);
      font-size: var(--step-1);
      font-weight: 700;
      letter-spacing: var(--tracking-wide);
      line-height: var(--leading-body);
      text-transform: uppercase;

      &:focus-visible {
        outline: var(--size-focus) solid var(--color-focus-paper);
        outline-offset: var(--size-rule);
      }

      &:user-invalid {
        border-block-end-color: var(--color-stamp);
        border-block-end-style: dashed;
      }
    }

    & :where(textarea) {
      display: block;
      resize: vertical;
      background:
        repeating-linear-gradient(
          180deg,
          transparent 0 calc(1lh - var(--size-rule-thin)),
          var(--color-rule) 0 1lh
        ),
        var(--color-tape);
      background-attachment: local;
    }

    & :where(.entry:has(:user-invalid) .note) {
      color: var(--color-stamp);
      font-weight: 700;
    }

    & :where(.send-row) {
      display: flex;
      flex-wrap: wrap;
      align-items: center;
      gap: var(--space-s) var(--space-l);
    }

    & :where(.send) {
      min-block-size: var(--size-target-min);
      padding: var(--space-xs) var(--space-l);
      border: calc(var(--size-rule) * 1.5) solid var(--color-stamp);
      border-radius: var(--radius-tag);
      outline: var(--size-rule-thin) solid var(--color-stamp);
      outline-offset: calc(var(--size-rule) * -3);
      background: var(--color-stamp);
      color: var(--color-tag);
      font-family: var(--font-print);
      font-size: var(--step-1);
      font-weight: 700;
      letter-spacing: var(--tracking-wider);
      text-transform: uppercase;
      rotate: var(--tilt-tag-a);
      box-shadow: var(--shadow-tag);
      transition: rotate var(--duration-hover) ease-out;

      &:focus-visible {
        outline: var(--size-focus) solid var(--color-focus-paper);
        outline-offset: var(--size-rule);
      }

      &:active {
        rotate: 0deg;
        box-shadow: none;
      }
    }

    @media (hover: hover) {
      & :where(.send:hover) {
        rotate: 0deg;
      }
    }

    & :where(.reply) {
      display: flex;
      flex-wrap: wrap;
      align-items: center;
      gap: var(--space-xs) var(--space-m);
      margin-block-start: var(--space-xl);

      & :where(ul) {
        display: flex;
        flex-wrap: wrap;
        gap: var(--space-xs) var(--space-s);
      }

      & :where(a, button) {
        display: block;
        min-block-size: var(--size-target-min);
        padding: var(--space-2xs) var(--space-s);
        border: calc(var(--size-rule) * 1.5) double var(--color-ink);
        background: transparent;
        font-family: var(--font-tape);
        font-weight: 700;
        letter-spacing: var(--tracking-wide);
        text-decoration: none;
        text-transform: uppercase;
        transition: background-color var(--duration-hover) ease-out;
      }

      & :where(button:focus-visible) {
        outline: var(--size-focus) solid var(--color-focus-paper);
        outline-offset: var(--size-rule);
      }

      @media (hover: hover) {
        & :where(a:hover, button:hover) {
          background: var(--color-tape);
        }
      }
    }

    & :where(.fine-print) {
      columns: 18rem 2;
      column-gap: var(--space-l);
      margin-block-start: var(--space-xl);
      padding-block-start: var(--space-s);
      border-block-start: var(--size-rule-thin) solid var(--color-ink);
      color: var(--color-ink-soft);
      font-size: var(--step--2);
      line-height: var(--leading-snug);
      text-transform: uppercase;
      letter-spacing: var(--tracking-slight);

      & :where(p + p) {
        margin-block-start: var(--space-xs);
      }
    }

    &:where([data-strips="3"]) { --strip-count: 3; }
    &:where([data-strips="4"]) { --strip-count: 4; }
    &:where([data-strips="5"]) { --strip-count: 5; }
    &:where([data-strips="6"]) { --strip-count: 6; }
    &:where([data-strips="7"]) { --strip-count: 7; }
    &:where([data-strips="8"]) { --strip-count: 8; }
    &:where([data-strips="9"]) { --strip-count: 9; }
    &:where([data-strips="11"]) { --strip-count: 11; }
    &:where([data-strips="12"]) { --strip-count: 12; }
    &:where([data-strips="13"]) { --strip-count: 13; }
    &:where([data-strips="14"]) { --strip-count: 14; }
    &:where([data-strips="15"]) { --strip-count: 15; }
    &:where([data-strips="16"]) { --strip-count: 16; }
  }

  .receipt {
    position: fixed;
    inline-size: min(var(--size-receipt), 100% - var(--space-xl));
    max-block-size: calc(100dvh - var(--space-xl));
    border: 0;
    overflow: auto;
    overscroll-behavior: contain;

    & :where(h2) {
      margin-block-end: var(--space-s);
      padding-block-end: var(--space-xs);
      border-block-end: calc(var(--size-rule) * 2) double var(--color-ink);
    }

    &::backdrop {
      background: var(--color-backdrop);
    }
  }

  @keyframes paste {
    from {
      opacity: 0;
      translate: 0 calc(var(--space-2xs) * -1);
    }
  }

  @keyframes print {
    from {
      scale: 1 1;
    }

    to {
      scale: 0 1;
    }
  }

  @keyframes stamp {
    from {
      opacity: 0;
      scale: 1.8;
    }
  }

  @media (prefers-reduced-motion: no-preference) {
    .telegram {
      & :where(.tape) {
        animation: paste var(--duration-paste) ease-out calc(var(--strip) * var(--duration-strip)) both;

        &::after {
          content: "";
          position: absolute;
          inset: 0;
          background: var(--color-tape);
          transform-origin: right center;
          animation: print var(--duration-strip) steps(var(--steps-print), end)
            calc(var(--strip) * var(--duration-strip)) both;
        }
      }

      & :where(.paid) {
        animation: stamp var(--duration-stamp) var(--ease-stamp)
          calc(var(--strip-count) * var(--duration-strip)) both;
      }
    }
  }
}

@layer utilities {
  .visually-hidden {
    position: absolute;
    inline-size: 1px;
    block-size: 1px;
    margin: -1px;
    padding: 0;
    overflow: clip;
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
  }
}

@layer overrides {
  @media (forced-colors: active) {
    .telegram :where(.tape) {
      border: var(--size-rule-thin) solid CanvasText;

      &::after {
        content: none;
      }
    }
  }

  @media print {
    body {
      background: none;
    }

    .stamps,
    .skip-link {
      display: none;
    }

    .telegram {
      box-shadow: none;
      break-inside: avoid;
    }
  }
}
