/* Preset: Perjalanan. What each moment depicts: docs/plans/template-motion-plan.md §10. */

html[data-motion-preset="perjalanan"] {
  --m-dur: 720ms;
  --m-step: 90ms;
  --m-rise: 0px;
  /* An Edmondson karcis is card stock, whatever the design's paper: cream, tinted by the accent */
  --m-stock: color-mix(in srgb, var(--m-accent) 8%, #f1e7cf);
  --m-line: color-mix(in srgb, var(--m-accent) 55%, #222);
  --m-buka-pieces: 6;
  --m-buka-total: 1900;
  --m-buka-reveal: 1150;
}

/* ── Masuk ── */

html[data-motion="full"][data-motion-preset="perjalanan"] [data-m~="masuk"]:not(.m-in) [data-m-item] {
  translate: 30px 0;
}

html[data-motion="full"][data-motion-preset="perjalanan"] [data-m~="masuk"].m-in:not(.m-done) [data-m-item] {
  transition-timing-function: cubic-bezier(.25, 1.25, .45, 1) !important;
}

html[data-motion="full"][data-motion-preset="perjalanan"] [data-m~="masuk"]:not(.m-in) [data-m-item="card"] {
  translate: 0 -10px;
  clip-path: inset(0 0 100% 0);
}

html[data-motion="full"][data-motion-preset="perjalanan"] [data-m~="masuk"].m-in:not(.m-done) [data-m-item="card"] {
  clip-path: inset(-20% -20% -20% -20%);
  transition-timing-function: steps(6, end), var(--m-ease-out) !important;
}

html[data-motion="full"][data-motion-preset="perjalanan"] [data-m~="masuk"]:not(.m-in) [data-m-item="photo"] {
  translate: 0 12px;
  rotate: 5deg;
  scale: .92;
}

/* ── Hidup ── */

html[data-motion-preset="perjalanan"] [data-m~="hidup"]:is([data-m-v="frame"], [data-m-v="float"]) {
  animation: m-perjalanan-drift 12s ease-in-out infinite;
}

@keyframes m-perjalanan-drift {
  0%, 100% { translate: -5px 0; }
  50%      { translate: 5px 0; }
}

html[data-motion-preset="perjalanan"] [data-m~="hidup"][data-m-v="sway"] {
  animation: m-perjalanan-rock 2.4s ease-in-out infinite;
}

@keyframes m-perjalanan-rock {
  0%, 100% { rotate: -.6deg; translate: 0 0; }
  25%      { translate: 0 -1px; }
  50%      { rotate: .6deg; translate: 0 0; }
  75%      { translate: 0 -1px; }
}

/* ── Sorot ── */

html[data-motion="full"][data-motion-preset="perjalanan"] [data-m~="sorot"][data-m-v="names"].m-in {
  animation: m-perjalanan-board 1000ms steps(9, end) both;
}

@keyframes m-perjalanan-board {
  from { opacity: 1; clip-path: inset(-20% 100% -20% 0); }
  to   { opacity: 1; clip-path: inset(-20% 0 -20% 0); }
}

html[data-motion="full"][data-motion-preset="perjalanan"] [data-m~="sorot"][data-m-v="count"].m-in {
  animation: none;
  opacity: 1;
}

html[data-motion="full"][data-motion-preset="perjalanan"] [data-m~="sorot"][data-m-v="count"]:not(.m-in) > * {
  opacity: 0;
}

html[data-motion="full"][data-motion-preset="perjalanan"] [data-m~="sorot"][data-m-v="count"].m-in > [data-m-u] {
  animation: m-perjalanan-flap 600ms steps(4, end) calc(var(--m-u, 0) * 120ms) both;
}

@keyframes m-perjalanan-flap {
  from { opacity: .2; translate: 0 60%; clip-path: inset(0 0 60% 0); }
  to   { opacity: 1; translate: 0 0; clip-path: inset(0); }
}

/* ── Buka ── */

/* 1, 2: the ticket, stub (left) and main part, split at a perforation */
.m-buka-layer--perjalanan > i:nth-child(-n+2) {
  top: 0;
  bottom: 0;
  background: var(--m-stock);
  animation: m-perjalanan-ticket 1900ms var(--m-ease) both;
}

.m-buka-layer--perjalanan > i:nth-child(1) {
  left: 0;
  width: 28.5%;
  --m-out: translate(-112%, 4%) rotate(-7deg);
}

.m-buka-layer--perjalanan > i:nth-child(2) {
  right: 0;
  width: 72%;
  border-left: 3px dotted var(--m-line);
  --m-out: translateX(104%);
}

@keyframes m-perjalanan-ticket {
  0%       { transform: translateY(100%); }
  14%, 60% { transform: none; }
  92%, to  { transform: var(--m-out); }
}

/* 3: the route, drawn from A to B across the ticket */
.m-buka-layer--perjalanan > i:nth-child(3) {
  left: 36%;
  right: 12%;
  top: 50%;
  height: 3px;
  background: repeating-linear-gradient(90deg, var(--m-line) 0 10px, transparent 10px 16px);
  animation: m-perjalanan-route 1900ms linear both;
}

@keyframes m-perjalanan-route {
  0%, 16% { clip-path: inset(0 100% 0 0); opacity: 1; }
  40%     { clip-path: inset(0 0 0 0); opacity: 1; }
  58%     { opacity: 1; }
  64%, to { clip-path: inset(0 0 0 0); opacity: 0; }
}

/* 4, 5: the stations A and B */
.m-buka-layer--perjalanan > i:nth-child(4),
.m-buka-layer--perjalanan > i:nth-child(5) {
  top: 50%;
  width: 18px;
  height: 18px;
  margin: -8px 0 0 -9px;
  border-radius: 50%;
  border: 4px solid var(--m-line);
  background: var(--m-stock);
  animation: m-perjalanan-stop 1900ms var(--m-ease) both;
}

.m-buka-layer--perjalanan > i:nth-child(4) { left: 36%; }
.m-buka-layer--perjalanan > i:nth-child(5) { left: 88%; animation-name: m-perjalanan-stop-b; }

@keyframes m-perjalanan-stop {
  0%, 16% { opacity: 0; transform: scale(0); }
  22%     { opacity: 1; transform: scale(1.3); }
  26%, 58% { opacity: 1; transform: scale(1); }
  64%, to { opacity: 0; transform: scale(1); }
}

@keyframes m-perjalanan-stop-b {
  0%, 38% { opacity: 0; transform: scale(0); }
  44%     { opacity: 1; transform: scale(1.3); }
  48%, 58% { opacity: 1; transform: scale(1); }
  64%, to { opacity: 0; transform: scale(1); }
}

/* 6: the conductor's punch through the perforation */
.m-buka-layer--perjalanan > i:nth-child(6) {
  left: 28.5%;
  top: 50%;
  width: 26px;
  height: 26px;
  margin: -13px 0 0 -13px;
  border-radius: 50%;
  background: #1d1d1d;
  animation: m-perjalanan-punch 1900ms cubic-bezier(.3, 1.6, .5, 1) both;
}

@keyframes m-perjalanan-punch {
  0%, 48% { opacity: 0; transform: scale(2.2); }
  53%, 60% { opacity: 1; transform: scale(1); }
  64%, to { opacity: 0; transform: scale(1); }
}
