/* TOKENS */
:root {
  --background: #eceff5;
  --foreground: #272728;
  --card: #fff;
  --card-accent: #eeeff3;
  --muted: #545960;
  --muted-foreground: #5d5f65;
  --border: #d1d5d8;
  --border-focus: #788188;
  --printer: #e6edf1;
  --primary: #018370;
  --primary-focus: #008c77;
  --primary-shadow: #037866;
  --primary-soft: #effffa;
  --primary-border: rgb(20 247 194 / 0.4);
  --brand: #444;
  --error: #d91c38;
  --foreground-soft: rgb(94 97 100 / 0.1);
  --accent-soft: rgb(81 96 117 / 0.3);
  --selection: rgb(1 169 143 / 0.2);
  --radius-card: 2.15rem;
  --radius-control: 1.05rem;
}

/*
BREAKPOINTS
  390px: minimum app width
  512px: tablet
  1024px: desktop
*/

/* RESET */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

*::selection {
  color: var(--foreground);
  background-color: var(--selection);
}

button {
  padding: 0;
  border: 0;
  border-radius: 0;
  color: inherit;
  background: none;
  box-shadow: none;
  font: inherit;
  text-align: inherit;
  cursor: pointer;
}

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

img,
picture,
video,
canvas,
svg {
  display: block;
  max-width: 100%;
}

h1,
h2,
h3,
h4,
h5,
h6 {
  text-wrap: balance;
}

p {
  text-wrap: pretty;
}

/* BASE */
body {
  min-width: 390px;
  min-height: 100vh;
  padding-inline: 1rem;
  color: var(--foreground);
  background: var(--background);
  font-family: 'Plus Jakarta Sans', system-ui, sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;

  @media (width >= 390px) {
    background:
      radial-gradient(
        circle at 12% 18%,
        var(--primary-soft),
        transparent 21rem
      ),
      radial-gradient(circle at 88% 78%, var(--accent-soft), transparent 40rem),
      var(--background);
  }
}

/* UTILS */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* LAYOUT */
.app {
  display: grid;
  grid-template-columns: 1fr;
  gap: clamp(1.5rem, 5vw, 5rem);
  align-items: start;
  width: min(100% - 1rem, 72rem);
  min-height: 100vh;
  margin-inline: auto;
  padding-block: clamp(1.5rem, 5vw, 4rem);

  @media (width >= 512px) {
    width: min(72rem, calc(100% - 2rem));
  }

  @media (width >= 1024px) {
    grid-template-columns: minmax(0, 0.92fr) minmax(21rem, 1.08fr);
    align-items: center;
  }
}

/* INTRO */
.panel {
  display: grid;
  gap: 1.25rem;
  justify-self: center;
  width: 100%;
  max-width: 35rem;

  @media (width >= 1024px) {
    justify-self: stretch;
    max-width: none;
  }

  .brand {
    width: clamp(7rem, 24vw, 8rem);
  }

  .brand-logo {
    width: 100%;
    height: auto;
    filter: brightness(0.9);
  }

  h1 {
    max-width: 13ch;
    font-size: clamp(2.75rem, 7vw, 5.35rem);
    line-height: 0.92;

    @media (width >= 1024px) {
      max-width: 12.5ch;
    }
  }

  .intro {
    max-width: 34rem;
    color: var(--muted-foreground);
    font-size: 1.08rem;
    font-weight: 600;
  }
}

/* FORM */
.form {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
  max-width: 40rem;
  margin-top: 0.75rem;

  @media (width >= 512px) {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .field {
    display: grid;
    gap: 0.5rem;
  }

  label {
    color: var(--muted-foreground);
    font-size: 0.82rem;
    font-weight: 800;
  }

  input,
  select,
  .button {
    min-height: 4rem;
    border-radius: var(--radius-control);
    color: var(--foreground);
    outline: none;
  }

  input,
  select {
    width: 100%;
    padding: 0.9rem 1.05rem;
    border: 1.5px solid var(--border);
    background-color: var(--card);
    transition:
      border-color 160ms ease,
      box-shadow 160ms ease,
      transform 160ms ease;

    &:focus {
      border-color: var(--border-focus);
      box-shadow: 0 0 0 3px var(--primary-soft);
      transform: translateY(-1px);
    }
  }

  select {
    cursor: pointer;

    /* Custom Select Arrow */
    appearance: none;
    background-image:
      linear-gradient(45deg, transparent 50%, var(--muted-foreground) 50%),
      linear-gradient(135deg, var(--muted-foreground) 50%, transparent 50%);
    background-position:
      calc(100% - 1.35rem) 50%,
      calc(100% - 1rem) 50%;
    background-repeat: no-repeat;
    background-size:
      0.35rem 0.35rem,
      0.35rem 0.35rem;

    &:invalid {
      color: var(--muted-foreground);
    }

    option {
      color: var(--foreground);
    }
  }

  input {
    &:not(:focus, :placeholder-shown):invalid {
      border-color: var(--error);
    }
  }

  .button {
    grid-column: 1 / -1;
    padding: 0.9rem 1.2rem;
    border: 2px solid var(--primary-border);
    background-color: var(--primary);
    color: var(--card);
    font-weight: 900;
    text-align: center;
    box-shadow: 0 4px 0 var(--primary-shadow);
    transition:
      background-color 160ms ease,
      box-shadow 160ms ease,
      transform 160ms ease;

    &:hover,
    &:focus-visible {
      transform: translateY(1px);
      background-color: var(--primary-focus);
      box-shadow: 0 3px 0 var(--primary-shadow);
    }

    &:active {
      transform: translateY(4px);
      box-shadow: 0 1px 0 var(--primary-shadow);
    }
  }
}

.error {
  min-height: 1.5rem;
  color: var(--error);
  font-weight: 800;
}

.ticket-stage {
  position: relative;
  justify-self: center;
  width: 100%;
  max-width: 35rem;

  @media (width >= 1024px) {
    justify-self: stretch;
    max-width: none;
  }

  .printer-slot {
    position: absolute;
    inset: 0 -1px auto;
    z-index: 3;
    height: 0.3rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--printer);
    box-shadow:
      inset 0 2px 5px rgb(0 0 0 / 0.14),
      0 3px 10px rgb(0 0 0 / 0.08);
    transform: translateY(-45%);

    /* Printer slot shadow */
    &::after {
      content: '';
      position: absolute;
      inset: 100% 0 auto;
      height: 1rem;
      background: linear-gradient(rgb(17 17 18 / 0.05), transparent);
      pointer-events: none;
    }
  }
}

.ticket-viewport {
  overflow: hidden;
}

.ticket {
  --ticket-padding-block: clamp(1.5rem, 4vw, 2rem);
  --ticket-padding-inline: clamp(2rem, 4vw, 2.5rem);
  --ticket-top-radius: 0.45rem;
  --ticket-bottom-radius: 1.55rem;

  isolation: isolate;
  position: relative;
  display: grid;
  gap: 1.25rem;
  width: 100%;
  min-height: 31rem;
  padding: var(--ticket-padding-block) var(--ticket-padding-inline);
  overflow: hidden;
  border-radius: var(--ticket-top-radius) var(--ticket-top-radius)
    var(--ticket-bottom-radius) var(--ticket-bottom-radius);
  transform-origin: top;

  @media (width >= 512px) {
    min-height: 32rem;
  }

  @media (width >= 1024px) {
    --ticket-bottom-radius: var(--radius-card);

    min-height: 31rem;
  }

  &.is-skeleton {
    opacity: 0.58;
  }

  &.is-printing {
    animation: ticket-print 1150ms cubic-bezier(0.2, 0, 0.2, 1) both;
  }

  .ticket-shape {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;

    path {
      vector-effect: non-scaling-stroke;
    }
  }

  .ticket-fill {
    z-index: 0;

    path {
      fill: var(--card);
      stroke: none;
    }
  }

  .ticket-outline {
    z-index: 2;

    path {
      fill: none;
      stroke: var(--foreground-soft);
      stroke-width: 2;
    }
  }

  > :not(.ticket-shape) {
    position: relative;
    z-index: 1;
  }

  .ticket-header {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.2rem 0.75rem;
    align-items: center;

    @media (width >= 512px) {
      grid-template-columns: auto 1fr auto;
      gap: 0.55rem 0.75rem;
    }

    .icon {
      display: grid;
      place-items: center;
      width: 2.7rem;
      aspect-ratio: 1;
      color: var(--foreground);
      font-size: 1.7rem;
    }

    p,
    strong {
      font-size: clamp(1.1rem, 2.6vw, 1.5rem);
      font-weight: 900;
    }

    p {
      min-width: 0;
    }

    strong {
      grid-column: 1 / -1;
      justify-self: end;
      color: var(--muted-foreground);
      font-size: clamp(0.92rem, 2vw, 1.08rem);
      letter-spacing: 0.08em;
      text-align: right;
      text-transform: uppercase;

      @media (width >= 512px) {
        grid-column: auto;
      }
    }
  }

  .ticket-route {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    gap: 0.9rem;
    align-items: center;
    padding-block: 1.35rem;
    border-block: 1.5px dashed var(--border);

    > span:not(.route-line, .route-point) {
      min-width: 0;
      font-size: clamp(2.2rem, 5.6vw, 3.75rem);
      font-weight: 900;
      line-height: 0.9;
    }

    > span:last-child {
      text-align: right;
    }

    .route-line {
      display: grid;
      gap: 0.25rem;
      place-items: center;
      min-width: clamp(3.5rem, 10vw, 5rem);
      color: var(--muted-foreground);
      font-weight: 900;
      white-space: nowrap;

      i {
        color: var(--foreground);
        font-size: clamp(1.3rem, 3.2vw, 2.2rem);
        line-height: 0.9;
      }

      small {
        font-size: clamp(0.82rem, 2vw, 0.95rem);
      }
    }

    .route-point {
      display: grid;
      gap: 0.45rem;
    }

    .route-point strong {
      min-width: 0;
      font-size: clamp(1.3rem, 3.2vw, 2.2rem);
      font-weight: 900;
      letter-spacing: 0;
      line-height: 0.9;
      text-transform: uppercase;
    }

    .route-point small {
      color: var(--muted-foreground);
      font-size: clamp(0.82rem, 2vw, 0.95rem);
      font-weight: 900;
    }
  }

  .details {
    display: grid;
    gap: 1rem;

    .details-list {
      display: grid;
      grid-template-columns: repeat(auto-fit, minmax(7.25rem, 1fr));
      gap: 1.2rem 1rem;
    }

    .details-list > div {
      display: grid;
      gap: 0.25rem;
    }

    dt {
      color: var(--muted);
      font-size: 0.84rem;
      font-weight: 700;
    }

    dd {
      font-size: clamp(1.18rem, 2.4vw, 1.55rem);
      font-weight: 900;
    }

    .price-summary {
      display: flex;
      gap: 0.75rem;
      align-items: center;
      min-height: 1.3rem;
      font-size: clamp(0.95rem, 2.2vw, 1.15rem);
      font-weight: 900;
    }

    .base-price {
      color: var(--muted-foreground);
      text-decoration: line-through;
    }

    .base-price.is-empty {
      text-decoration: none;
    }

    .discount {
      color: var(--primary-focus);
    }

    .discount.is-empty {
      display: none;
    }

    .price {
      grid-column: 1 / -1;

      dd {
        display: grid;
        color: var(--brand);
      }

      .final-price {
        display: flex;
        gap: 0.8rem;
        align-items: end;
        justify-content: space-between;
      }

      .final-price > span {
        padding-bottom: 0.4rem;
        color: var(--muted-foreground);
        font-size: clamp(0.88rem, 2vw, 1rem);
        font-weight: 900;
        white-space: nowrap;
      }

      .saving {
        display: grid;
        gap: 0.15rem;
        text-align: right;
      }

      .saving.is-empty {
        display: none;
      }

      .saving strong {
        color: var(--primary-focus);
        font-size: clamp(1rem, 2.4vw, 1.25rem);
        line-height: 1;
      }

      .final-price > strong {
        font-size: clamp(2.5rem, 7vw, 4.2rem);
        line-height: 0.92;
      }
    }
  }

  .barcode {
    display: grid;
    place-items: center;
    align-self: end;
    min-height: 4.75rem;
    margin: auto calc(var(--ticket-padding-inline) * -1)
      calc(var(--ticket-padding-block) * -1);
    padding: 0.65rem var(--ticket-padding-inline);
    overflow: hidden;
    border-top: 1.5px solid var(--border);
    border-radius: 0 0 var(--ticket-bottom-radius) var(--ticket-bottom-radius);
    background-color: var(--card-accent);
    opacity: 0.8;

    @media (width >= 1024px) {
      padding-block: 0.85rem;
    }

    &::before {
      content: '';
      width: min(100%, 28rem);
      height: 3.1rem;
      background-image: url('../img/barcode.png');
      background-repeat: no-repeat;
      background-position: center;
      background-size: contain;
    }
  }
}

/* ANIMATIONS */
@keyframes ticket-print {
  0% {
    transform: translateY(-120%);
  }

  34% {
    transform: translateY(-60%);
  }

  42% {
    transform: translateY(-60%);
  }

  74% {
    transform: translateY(-12%);
  }

  100% {
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .ticket.is-printing {
    animation: none;
  }
}
