/* ─────────────────────────────────────────────────────────────
   Menjitsu motion: the cloth comes alive, quietly.
   Stitches sew themselves in, thread runs, the hanko is stamped. Transform, opacity and clip-path only, so it
   stays smooth on phones. Everything is off under reduced motion,
   and nothing is hidden unless JavaScript is there to reveal it.
   ───────────────────────────────────────────────────────────── */

/* ── Reading thread: a topstitch sewn along under the header as you read ── */
.read-thread {
    position: fixed; left: 0; right: 0; top: var(--thread-top, 72px); z-index: 39; height: 4px; pointer-events: none;
    opacity: 0; transition: opacity 0.4s ease;
}
.read-thread.on { opacity: 1; }
.read-thread i {
    position: absolute; inset: 0 0 auto 0; height: 3px;
    background: repeating-linear-gradient(90deg, var(--thread) 0 8px, transparent 8px 12px);
    clip-path: inset(0 calc((1 - var(--read, 0)) * 100%) 0 0);
}
/* The needle rides the end of the seam. It only moves when you scroll. */
.read-thread b {
    position: absolute; top: -3px; left: 0; width: 22px; height: 9px;
    transform: translateX(calc(var(--read, 0) * (100vw - 22px)));
    background: linear-gradient(90deg, #8e98a3, #d5dbe1 70%, #8e98a3) center / 100% 2px no-repeat;
    border-radius: 2px;
}
.read-thread b::after { content: ''; position: absolute; left: 3px; top: 2px; width: 5px; height: 5px; border: 1.2px solid #8e98a3; border-radius: 50%; }
/* ── Sewn in on scroll: once per page. Never re-runs, never moves text you're reading. ── */
.motion [data-sew] { opacity: 0; transform: translateY(28px); transition: opacity 0.8s cubic-bezier(0.2, 0.7, 0.2, 1), transform 0.8s cubic-bezier(0.2, 0.7, 0.2, 1); transition-delay: calc(var(--sew-i, 0) * 90ms); }
.motion [data-sew].sewn { opacity: 1; transform: none; }

/* Eyebrow dash and section rules draw across like a seam */
.motion [data-sew] .eyebrow::before, .motion .eyebrow[data-sew]::before { transform: scaleX(0); transform-origin: left; transition: transform 1s 0.25s cubic-bezier(0.2, 0.7, 0.2, 1); }
.motion [data-sew].sewn .eyebrow::before, .motion .eyebrow[data-sew].sewn::before { transform: none; }

/* The selvedge ID at the foot of each card weaves in from the left */
.motion .card[data-sew] .selvedge { clip-path: inset(0 100% 0 0); transition: clip-path 1.2s cubic-bezier(0.5, 0, 0.2, 1); transition-delay: calc(var(--sew-i, 0) * 90ms + 300ms); }
.motion .card[data-sew].sewn .selvedge { clip-path: inset(0 0 0 0); }

/* ── Thread that runs when you look closely ── */
@keyframes thread-run { to { stroke-dashoffset: -1.04; } }
.card:hover .stitches, .card:focus-visible .stitches, .hanger:hover .stitches, .fit-tile:hover .stitches { animation: thread-run 0.9s linear infinite; opacity: 1; stroke-width: 0.13; }

/* ── Things you can pick up lift toward you ── */
.card:hover { transform: translateY(-6px); }
.card .plate svg { transition: transform 0.4s cubic-bezier(0.3, 0.7, 0.3, 1); }
.card:hover .plate svg { transform: scale(1.05) rotate(-1deg); }
.fit-tile { transition: transform 0.3s cubic-bezier(0.3, 0.7, 0.3, 1), box-shadow 0.3s ease, border-color 0.2s; }
.fit-tile:hover { transform: translateY(-5px); }
.fit-tile svg { transition: transform 0.4s cubic-bezier(0.3, 0.7, 0.3, 1); transform-origin: 50% 0; }
.fit-tile:hover svg { transform: rotate(-2.5deg); }
.newbie-steps a:hover { transform: translateY(-3px); box-shadow: inset 0 0 0 1.5px var(--ai-600), var(--shadow); }
.newbie-steps a .arrow, .maker, .topic-row, .hemmer { transition: transform 0.25s cubic-bezier(0.3, 0.7, 0.3, 1), background-color 0.2s, box-shadow 0.2s; }
.newbie-steps a:hover .arrow { transform: translateX(4px); }
.maker:hover { transform: translateY(-3px); box-shadow: var(--shadow); position: relative; z-index: 1; }
.topic-row:hover { transform: translateX(4px); }
.hemmer:hover { transform: translateY(-3px); }

/* Copper rivets catch the light */
.card .rivet { transition: filter 0.3s ease; }
.card:hover .rivet { filter: brightness(1.3) saturate(1.1); }

/* The detail page's flat is sewn top to bottom on arrival */
@keyframes sew-down { from { clip-path: inset(0 0 100% 0); } to { clip-path: inset(0 0 0 0); } }
.motion .drawing .stitches { animation: sew-down 2.4s 0.5s cubic-bezier(0.45, 0, 0.2, 1) both; }
@keyframes cloth-in { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }
.motion .drawing svg { animation: cloth-in 0.9s cubic-bezier(0.2, 0.7, 0.2, 1) both; }
.motion .drawing.restitch svg { animation: none; }
.motion .drawing.restitch .stitches { animation: none; }

/* ── Hanko: a small wiggle on each page you open, settling back to straight ── */
@keyframes stamp {
    0%, 100% { transform: rotate(0deg); }
    18% { transform: rotate(7deg); }
    38% { transform: rotate(-6deg); }
    56% { transform: rotate(4deg); }
    72% { transform: rotate(-2deg); }
    86% { transform: rotate(1deg); }
}
.motion.stamp .site-header .hanko { animation: stamp 0.9s 0.2s ease-in-out; }
.brand .hanko { transition: transform 0.25s cubic-bezier(0.3, 0.7, 0.3, 1), box-shadow 0.25s ease; }
.brand:hover .hanko { transform: rotate(-4deg) scale(1.05); box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.32), 0 3px 10px -4px rgba(184, 50, 42, 0.55); }
/* The red ID under the wordmark draws itself out on hover */
.wordmark .selv { transform-origin: left; transition: transform 0.45s cubic-bezier(0.2, 0.7, 0.2, 1); }
.brand:hover .wordmark .selv { animation: selv-draw 0.6s cubic-bezier(0.2, 0.7, 0.2, 1); }
@keyframes selv-draw { from { transform: scaleX(0.15); } to { transform: none; } }

/* ── Denim notes: kraft swing tags between catalogue cards ── */
.denim-note {
    position: relative; display: flex; flex-direction: column; justify-content: center; gap: 6px;
    padding: 34px 26px 26px; border-radius: 3px 3px 3px 3px;
    background: var(--kraft) var(--fibre); color: var(--leather-2);
    box-shadow: var(--shadow); transform: rotate(-0.8deg);
    transition: transform 0.35s cubic-bezier(0.3, 0.7, 0.3, 1);
}
.denim-note:nth-of-type(2n) { transform: rotate(0.7deg); }
.denim-note:hover { transform: rotate(0deg) translateY(-2px); }
.denim-note::after { content: ''; position: absolute; inset: 7px; border: 1.3px dashed rgba(77, 44, 23, 0.4); border-radius: 2px; pointer-events: none; }
.dn-hole { position: absolute; top: 12px; left: 50%; width: 12px; height: 12px; margin-left: -6px; border-radius: 50%; background: var(--canvas); box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.35), 0 0 0 3px rgba(245, 239, 226, 0.6); }
.dn-string { position: absolute; top: -14px; left: calc(50% - 30px); width: 60px; height: 40px; overflow: visible; }
.dn-string path { fill: none; stroke: rgba(77, 44, 23, 0.45); stroke-width: 1.4; stroke-linecap: round; }
.dn-k { position: absolute; right: 18px; bottom: 12px; font-family: var(--serif); font-weight: 800; font-size: 3.4rem; line-height: 1; color: rgba(77, 44, 23, 0.13); }
.dn-eyebrow { font-family: var(--work); font-weight: 600; font-size: 0.78rem; letter-spacing: 0.18em; text-transform: uppercase; color: var(--aka); }
.denim-note h3 { font-family: var(--serif); font-size: 1.35rem; line-height: 1.2; margin: 0; color: var(--sumi); }
.denim-note p { margin: 0; font-size: 0.93rem; line-height: 1.55; color: var(--leather-2); position: relative; }
.dn-more { align-self: flex-start; margin-top: 6px; font-family: var(--work); font-weight: 600; font-size: 0.86rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--sumi); text-decoration: none; position: relative; }
.dn-more:hover { color: var(--aka); }

/* ── Recently viewed: pairs you've looked at, kept on this device ── */
.recent { margin: 0 0 22px; }
.recent[hidden] { display: none; }
.recent-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.recent-head h2, .recent-head h3 { font-family: var(--work); font-weight: 600; font-size: 0.86rem; letter-spacing: 0.16em; text-transform: uppercase; color: var(--sumi-3); margin: 0; }
.recent-head button { background: none; border: 0; padding: 0; font: inherit; font-size: 0.82rem; color: var(--sumi-3); cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.recent-rail { display: flex; gap: 10px; overflow-x: auto; padding: 8px 2px 10px; scroll-snap-type: x proximity; scrollbar-width: thin; }
.recent-tag {
    position: relative; flex: none; scroll-snap-align: start; display: flex; flex-direction: column; gap: 2px;
    min-width: 150px; padding: 10px 14px 10px 26px; text-decoration: none; color: var(--sumi);
    background: #fbf8f1; border-radius: 2px 6px 6px 2px; box-shadow: inset 0 0 0 1.5px var(--line-strong);
    transition: transform 0.25s cubic-bezier(0.3, 0.7, 0.3, 1), box-shadow 0.2s;
    animation: tag-in 0.45s calc(var(--i, 0) * 60ms) cubic-bezier(0.2, 0.7, 0.2, 1) backwards;
}
.recent-tag::before { content: ''; position: absolute; left: 9px; top: 50%; width: 7px; height: 7px; margin-top: -3.5px; border-radius: 50%; background: var(--canvas); box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.3), 0 0 0 1.5px var(--line-strong); }
.recent-tag:hover { transform: translateY(-2px) rotate(-1deg); box-shadow: inset 0 0 0 1.5px var(--ai-700); }
.recent-tag small { font-family: var(--work); font-weight: 600; font-size: 0.74rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--sumi-3); }
.recent-tag b { font-family: var(--work); font-weight: 700; font-size: 1.15rem; letter-spacing: 0.02em; line-height: 1.1; }
.recent-tag em { font-style: normal; font-size: 0.78rem; color: var(--aka); }
@keyframes tag-in { from { opacity: 0; transform: translateX(10px); } to { opacity: 1; transform: none; } }

/* ── Numbers that count up ── */
[data-count] { font-variant-numeric: tabular-nums; }

/* ── Buttons: the arrow nudges, the press sinks like a snap ── */
.btn:active { transform: translateY(1px) scale(0.985); }

/* Everything above, off for people who've asked for less motion */
@media (prefers-reduced-motion: reduce) {
    .motion [data-sew], .motion .card[data-sew] .selvedge { opacity: 1 !important; transform: none !important; clip-path: none !important; }
    .read-thread b { display: none; }
}
