/* ============================================================
   simai.quest — bold cosmonaut, neubrutalist black-slab on cream
   Single-instance glassmorphism. Hand-cut punched stars only.
   Palette: Star-Black #0a0a0a, Page Cream #f4f3ee, Glass Mist
   #e8e6df, Iron Grey #3a3a38, Quiet Grey #bcbab2.
   ============================================================ */

:root {
    --star-black: #0a0a0a;
    --page-cream: #f4f3ee;
    --glass-mist: #e8e6df;
    --iron-grey: #3a3a38;
    --quiet-grey: #bcbab2;
    --paper-white: #ffffff;

    --rail-x: 5vw;
    --rail-width: 3px;
    --card-w: 420px;
    --card-h: 540px;

    --punched-star: polygon(
        50% 0%,
        56% 35%,
        87% 12%,
        66% 44%,
        100% 50%,
        65% 58%,
        88% 90%,
        54% 64%,
        50% 100%,
        46% 64%,
        12% 90%,
        35% 56%,
        0% 50%,
        34% 44%,
        13% 13%,
        44% 36%
    );
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
    background: var(--page-cream);
    color: var(--star-black);
    font-family: 'Inter', system-ui, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

html {
    scroll-snap-type: y mandatory;
    scroll-behavior: smooth;
    overflow-y: scroll;
}

body {
    min-height: 100vh;
    line-height: 1.55;
    letter-spacing: -0.005em;
    overflow-x: hidden;
}

/* ============================================================
   The quest spine — 3px black rail at left:5vw
   ============================================================ */
.rail {
    position: fixed;
    top: 0;
    left: var(--rail-x);
    width: 60px;
    height: 100vh;
    z-index: 30;
    pointer-events: none;
}

.rail-line {
    position: absolute;
    top: 8vh;
    bottom: 8vh;
    left: 8px;
    width: var(--rail-width);
    background: var(--star-black);
}

.rail-marker {
    position: absolute;
    left: -10px;
    width: 38px;
    height: 38px;
    background: transparent;
    border: 0;
    padding: 0;
    cursor: pointer;
    pointer-events: auto;
    display: flex;
    align-items: center;
    gap: 14px;
    font-family: 'Space Mono', monospace;
}

.rail-marker[data-leg="1"] { top: calc(8vh + 0% - 9px); }
.rail-marker[data-leg="2"] { top: calc(8vh + (84vh / 4) * 1 - 9px); }
.rail-marker[data-leg="3"] { top: calc(8vh + (84vh / 4) * 2 - 9px); }
.rail-marker[data-leg="4"] { top: calc(8vh + (84vh / 4) * 3 - 9px); }
.rail-marker[data-leg="5"] { top: calc(8vh + 84vh - 9px); }

.rail-star {
    display: block;
    width: 18px;
    height: 18px;
    clip-path: var(--punched-star);
    background: var(--star-black);
    transition: background 0.3s ease-out;
    flex-shrink: 0;
}

.rail-marker[data-state="active"] .rail-star {
    background: var(--star-black);
}

.rail-marker[data-state="passed"] .rail-star {
    background: var(--star-black);
    transform: scale(0.7);
}

.rail-marker[data-state="future"] .rail-star {
    background: var(--quiet-grey);
}

.rail-numeral {
    font-family: 'Space Mono', monospace;
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--iron-grey);
    letter-spacing: 0.06em;
    transition: color 0.3s ease-out, font-weight 0.3s ease-out;
    user-select: none;
}

.rail-marker[data-state="active"] .rail-numeral {
    color: var(--star-black);
    font-weight: 700;
}

.rail-marker[data-state="future"] .rail-numeral {
    color: var(--quiet-grey);
}

/* ============================================================
   The constellation card — the page's single glass surface
   ============================================================ */
.constellation-card {
    position: fixed;
    right: 8vw;
    top: 50%;
    width: var(--card-w);
    height: var(--card-h);
    transform: translateY(-50%);
    background: rgba(232, 230, 223, 0.55);
    backdrop-filter: blur(18px) saturate(1.1);
    -webkit-backdrop-filter: blur(18px) saturate(1.1);
    border: 2px solid var(--star-black);
    box-shadow: 4px 4px 0 0 var(--star-black);
    z-index: 25;
    display: flex;
    flex-direction: column;
    padding: 22px 26px 18px;
    transition:
        transform 0.7s cubic-bezier(.36,.07,.19,.97),
        right 0.7s cubic-bezier(.36,.07,.19,.97);
    will-change: transform;
}

.card-header {
    display: flex;
    align-items: baseline;
    gap: 10px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--quiet-grey);
}

.card-eyebrow {
    font-family: 'Space Mono', monospace;
    font-weight: 700;
    font-size: 0.7rem;
    color: var(--iron-grey);
    text-transform: uppercase;
    letter-spacing: 0.16em;
}

.card-leg {
    font-family: 'Space Mono', monospace;
    font-weight: 700;
    font-size: 1.2rem;
    color: var(--star-black);
    letter-spacing: 0.04em;
}

.card-divider {
    flex-shrink: 0;
    width: 1px;
    height: 14px;
    background: var(--star-black);
    margin: 0 4px;
}

.card-title {
    font-family: 'Inter', sans-serif;
    font-weight: 800;
    font-size: 1rem;
    color: var(--star-black);
    letter-spacing: -0.01em;
    text-transform: lowercase;
}

.card-diagram {
    flex: 1;
    position: relative;
    margin: 14px 0;
    overflow: visible;
}

.constellation-svg {
    width: 100%;
    height: 100%;
    overflow: visible;
}

.constellation-svg .lines line {
    stroke: var(--quiet-grey);
    stroke-width: 1;
    fill: none;
    transition:
        x1 0.6s ease-out 0.05s,
        y1 0.6s ease-out 0.05s,
        x2 0.6s ease-out 0.05s,
        y2 0.6s ease-out 0.05s,
        opacity 0.6s ease-out;
}

.constellation-svg .stars .star {
    transition:
        transform 0.6s ease-out 0.05s,
        opacity 0.6s ease-out;
}

.constellation-svg .stars .star path {
    fill: var(--star-black);
}

.card-legend {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    padding-top: 14px;
    border-top: 1px solid var(--quiet-grey);
    font-family: 'Space Mono', monospace;
    font-weight: 700;
    font-size: 0.75rem;
    color: var(--star-black);
    text-transform: uppercase;
    letter-spacing: 0.12em;
}

.legend-item { white-space: nowrap; }
.legend-arrow { color: var(--iron-grey); font-weight: 400; }

.card-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 10px;
    font-family: 'Space Mono', monospace;
    font-size: 0.65rem;
    color: var(--iron-grey);
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.card-coords { font-weight: 400; }
.card-mark { font-weight: 700; color: var(--star-black); }

/* ============================================================
   Main: the immersive scroll
   ============================================================ */
main {
    position: relative;
    z-index: 5;
}

.leg {
    position: relative;
    width: 100vw;
    height: 100vh;
    scroll-snap-align: start;
    scroll-snap-stop: always;
    padding-left: calc(var(--rail-x) + 90px);
    padding-right: calc(8vw + var(--card-w) + 60px);
    padding-top: 10vh;
    padding-bottom: 6vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.leg-numeral-bleed {
    position: absolute;
    top: 5vh;
    left: calc(var(--rail-x) + 30px);
    font-family: 'Space Mono', monospace;
    font-weight: 700;
    font-size: clamp(6rem, 9vw, 9rem);
    line-height: 0.85;
    color: var(--star-black);
    letter-spacing: -0.02em;
    user-select: none;
    pointer-events: none;
    opacity: 0.08;
    z-index: 1;
}

.leg-content {
    position: relative;
    z-index: 2;
    max-width: 720px;
}

.leg-content--centered { margin: auto; }

.eyebrow {
    font-family: 'Space Mono', monospace;
    font-weight: 700;
    font-size: 0.78rem;
    color: var(--iron-grey);
    text-transform: uppercase;
    letter-spacing: 0.18em;
    margin-bottom: 28px;
    display: flex;
    align-items: center;
    gap: 14px;
}

.eyebrow::before {
    content: "";
    display: inline-block;
    width: 36px;
    height: 1px;
    background: var(--star-black);
}

.hero {
    font-family: 'Inter', sans-serif;
    font-weight: 900;
    font-size: clamp(3rem, 7.5vw, 6.5rem);
    line-height: 0.92;
    letter-spacing: -0.02em;
    color: var(--star-black);
    text-transform: lowercase;
}

.leg-h {
    font-family: 'Inter', sans-serif;
    font-weight: 900;
    font-size: clamp(2.25rem, 5vw, 3.8rem);
    line-height: 0.96;
    letter-spacing: -0.02em;
    color: var(--star-black);
    text-transform: lowercase;
    margin-bottom: 36px;
    max-width: 12ch;
}

.lede {
    margin-top: 32px;
    max-width: 36ch;
    font-family: 'Inter', sans-serif;
    font-weight: 400;
    font-size: 1.0625rem;
    line-height: 1.55;
    color: var(--iron-grey);
    letter-spacing: -0.005em;
}

.lede em { font-style: italic; color: var(--star-black); }

/* ============================================================
   Leg II — The Map (grid + hero punched star)
   ============================================================ */
.leg-ii .leg-grid {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    gap: 24px;
    width: 100%;
    align-items: center;
}

.leg-grid-star {
    grid-column: 2 / span 6;
    display: flex;
    align-items: center;
    justify-content: center;
}

.leg-grid-manifesto {
    grid-column: 8 / span 5;
    max-width: 460px;
}

.punched-star {
    background: var(--star-black);
    clip-path: var(--punched-star);
    flex-shrink: 0;
}

.punched-star--hero {
    width: 48vh;
    height: 48vh;
    max-width: 520px;
    max-height: 520px;
}

.punched-star--closer {
    width: 70vh;
    height: 70vh;
    max-width: 640px;
    max-height: 640px;
    margin: 0 auto 32px;
    transform: rotate(-7deg);
}

.manifesto {
    list-style: none;
    padding: 0;
    margin: 0;
}

.manifesto li {
    display: flex;
    gap: 18px;
    padding: 14px 0;
    border-top: 1px solid var(--quiet-grey);
    font-size: 1.25rem;
    font-weight: 600;
    line-height: 1.4;
    letter-spacing: -0.01em;
    text-transform: lowercase;
}

.manifesto li:last-child { border-bottom: 1px solid var(--quiet-grey); }

.manifesto .mn {
    font-family: 'Space Mono', monospace;
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--iron-grey);
    letter-spacing: 0.08em;
    min-width: 28px;
    padding-top: 4px;
    text-transform: uppercase;
}

.manifesto .mt {
    flex: 1;
    color: var(--star-black);
}

/* ============================================================
   Leg III — The Trial (input + slab button + printout)
   ============================================================ */
.trial-form {
    display: flex;
    gap: 0;
    margin-top: 8px;
    margin-bottom: 36px;
    max-width: 700px;
    width: 100%;
}

.trial-input {
    flex: 1;
    background: var(--page-cream);
    border: 3px solid var(--star-black);
    border-right: 0;
    padding: 22px 26px;
    font-family: 'Inter', sans-serif;
    font-weight: 600;
    font-size: 1.1rem;
    color: var(--star-black);
    letter-spacing: -0.005em;
    outline: none;
    border-radius: 0;
    box-shadow: 4px 4px 0 0 var(--star-black);
    transition: box-shadow 0.18s ease-out, transform 0.18s ease-out;
}

.trial-input::placeholder {
    color: var(--quiet-grey);
    font-weight: 400;
    text-transform: lowercase;
    letter-spacing: -0.005em;
}

.trial-input:focus {
    box-shadow: 6px 6px 0 0 var(--star-black);
}

.slab-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--star-black);
    color: var(--page-cream);
    border: 3px solid var(--star-black);
    box-shadow: 4px 4px 0 0 var(--star-black);
    padding: 22px 36px;
    font-family: 'Inter', sans-serif;
    font-weight: 900;
    font-size: 1rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    cursor: pointer;
    border-radius: 0;
    transition:
        transform 0.16s ease-out,
        box-shadow 0.16s ease-out,
        background 0.16s ease-out;
}

.slab-btn:hover {
    transform: translate(-4px, -4px);
    box-shadow: 8px 8px 0 0 var(--star-black);
}

.slab-btn:active {
    transform: translate(0, 0);
    box-shadow: 0 0 0 0 var(--star-black);
}

.trial-submit { min-width: 140px; }

.trial-printout {
    background: var(--page-cream);
    border: 3px solid var(--star-black);
    box-shadow: 4px 4px 0 0 var(--star-black);
    padding: 22px 26px;
    font-family: 'Space Mono', monospace;
    font-weight: 400;
    font-size: 0.95rem;
    line-height: 1.65;
    color: var(--iron-grey);
    white-space: pre-wrap;
    max-width: 700px;
    min-height: 140px;
    overflow: hidden;
    transition: border-color 0.3s ease-out;
}

.trial-printout[data-state="answered"] { color: var(--star-black); }

.trial-line { display: block; }
.trial-line--prompt { color: var(--star-black); font-weight: 700; }

/* ============================================================
   Leg IV — The Companions (offset chamfered black rectangles)
   ============================================================ */
.companions {
    display: flex;
    flex-wrap: wrap;
    gap: 18px;
    align-items: center;
    max-width: 1100px;
}

.companion {
    --offset: 0;
    position: relative;
    width: 220px;
    height: 140px;
    background: var(--star-black);
    color: var(--page-cream);
    padding: 22px;
    transform: translateY(var(--offset));
    clip-path: polygon(
        14px 0,
        calc(100% - 14px) 0,
        100% 14px,
        100% calc(100% - 14px),
        calc(100% - 14px) 100%,
        14px 100%,
        0 calc(100% - 14px),
        0 14px
    );
    box-shadow: 4px 4px 0 0 var(--iron-grey);
    transition: transform 0.18s cubic-bezier(.36,.07,.19,.97), box-shadow 0.18s cubic-bezier(.36,.07,.19,.97);
    cursor: default;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.companion::before {
    content: "";
    position: absolute;
    inset: 6px;
    border: 1px solid rgba(244, 243, 238, 0.18);
    clip-path: polygon(
        10px 0,
        calc(100% - 10px) 0,
        100% 10px,
        100% calc(100% - 10px),
        calc(100% - 10px) 100%,
        10px 100%,
        0 calc(100% - 10px),
        0 10px
    );
    pointer-events: none;
}

.companion:hover {
    transform: translate(-6px, calc(var(--offset) - 6px));
    box-shadow: 0 0 0 0 var(--iron-grey);
}

.companion-numeral {
    font-family: 'Space Mono', monospace;
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--quiet-grey);
    letter-spacing: 0.08em;
}

.companion-title {
    font-family: 'Inter', sans-serif;
    font-weight: 800;
    font-size: 1.15rem;
    line-height: 1.1;
    letter-spacing: -0.015em;
    color: var(--page-cream);
    text-transform: lowercase;
    max-width: 18ch;
}

/* ============================================================
   Leg V — The Return
   ============================================================ */
.leg-content--return {
    text-align: left;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
}

.leg-v .punched-star--closer {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(-7deg);
    z-index: 1;
    opacity: 0.92;
}

.leg-v .eyebrow {
    position: relative;
    z-index: 3;
}

.closer {
    position: relative;
    z-index: 3;
    font-family: 'Inter', sans-serif;
    font-weight: 900;
    font-size: clamp(2.5rem, 6vw, 5rem);
    line-height: 0.95;
    letter-spacing: -0.02em;
    color: var(--page-cream);
    mix-blend-mode: difference;
    text-transform: lowercase;
    text-align: center;
    margin-bottom: 40px;
}

.slab-btn--start {
    position: relative;
    z-index: 4;
    padding: 28px 64px;
    font-size: 1.2rem;
    background: var(--page-cream);
    color: var(--star-black);
    border-color: var(--star-black);
    box-shadow: 6px 6px 0 0 var(--star-black);
    letter-spacing: 0.18em;
}

.slab-btn--start:hover {
    transform: translate(-6px, -6px);
    box-shadow: 12px 12px 0 0 var(--star-black);
    background: var(--star-black);
    color: var(--page-cream);
}

.slab-btn--start:active {
    transform: translate(0, 0);
    box-shadow: 0 0 0 0 var(--star-black);
}

/* ============================================================
   Shake — the only error feedback in the design
   ============================================================ */
@keyframes shake {
    0%   { transform: translate3d(0, 0, 0); }
    10%  { transform: translate3d(-12px, 0, 0); }
    20%  { transform: translate3d(10px, 0, 0); }
    35%  { transform: translate3d(-8px, 0, 0); }
    50%  { transform: translate3d(8px, 0, 0); }
    65%  { transform: translate3d(-6px, 0, 0); }
    80%  { transform: translate3d(4px, 0, 0); }
    100% { transform: translate3d(0, 0, 0); }
}

main.shaking {
    animation: shake 0.42s cubic-bezier(.36,.07,.19,.97) both;
}

/* ============================================================
   Constellation card travel states (rotate/translate per leg)
   ============================================================ */
.constellation-card[data-leg="1"] {
    transform: translateY(-50%) translateX(0) rotate(-1.2deg);
}
.constellation-card[data-leg="2"] {
    transform: translateY(-50%) translateX(-22px) rotate(2.5deg);
}
.constellation-card[data-leg="3"] {
    transform: translateY(-50%) translateX(18px) rotate(-2.5deg);
}
.constellation-card[data-leg="4"] {
    transform: translateY(-50%) translateX(-18px) rotate(1.8deg);
}
.constellation-card[data-leg="5"] {
    transform: translateY(-50%) translateX(8px) rotate(-0.6deg);
}

/* ============================================================
   Tablet / smaller heights
   ============================================================ */
@media (max-width: 1180px) {
    :root { --card-w: 340px; --card-h: 440px; }
    .leg {
        padding-right: calc(8vw + var(--card-w) + 30px);
    }
}

@media (max-width: 960px) {
    :root { --card-w: 280px; --card-h: 360px; }
    .constellation-card {
        right: 4vw;
        padding: 16px 18px 12px;
    }
    .leg {
        padding-right: calc(4vw + var(--card-w) + 24px);
        padding-left: calc(var(--rail-x) + 70px);
    }
    .leg-ii .leg-grid {
        grid-template-columns: repeat(6, 1fr);
    }
    .leg-grid-star { grid-column: 1 / span 6; }
    .leg-grid-manifesto { grid-column: 1 / span 6; }
    .punched-star--hero { width: 28vh; height: 28vh; }
}

@media (max-height: 720px) {
    html { scroll-snap-type: none; }
    .leg { height: auto; min-height: 100vh; padding-top: 14vh; }
    .rail {
        position: absolute;
        top: 0;
        width: 100%;
        height: 60px;
        left: 0;
    }
    .rail-line {
        top: 30px;
        bottom: auto;
        left: 10vw;
        right: 10vw;
        width: auto;
        height: 3px;
    }
    .rail-marker {
        top: 12px !important;
        flex-direction: column;
        gap: 6px;
    }
    .rail-marker[data-leg="1"] { left: 10vw; }
    .rail-marker[data-leg="2"] { left: 30vw; }
    .rail-marker[data-leg="3"] { left: 50vw; }
    .rail-marker[data-leg="4"] { left: 70vw; }
    .rail-marker[data-leg="5"] { left: 90vw; }
    .constellation-card {
        position: relative;
        right: auto;
        top: auto;
        transform: none !important;
        margin: 40px auto;
    }
}

@media (max-width: 640px) {
    .leg {
        padding-left: 8vw;
        padding-right: 8vw;
    }
    .constellation-card {
        max-width: 90vw;
    }
    .trial-form { flex-direction: column; gap: 12px; }
    .trial-input { border-right: 3px solid var(--star-black); }
    .companion { width: 100%; }
    .leg-v .punched-star--closer { width: 60vw; height: 60vw; }
}
