/* logic.quest -- Swiss-rational logic puzzle adventure
   Stacked sections, tech-mono, earth-tones, magnetic, neon-glow, mountain-landscape */

:root {
    --stone-light: #e8e0d0;
    --stone-dark:  #d4ccc0;
    --grid-line:   #c0b8a0;
    --warm-tan:    #c0b8a0;
    --text-ink:    #2a2820;
    --text-warm:   #6a6458;
    --text-mute:   #8a7e6a;
    --umber-deep:  #5a4a30;
    --umber-mid:   #6a6458;
    --neon:        #34d399;
    --sage-brown:  #8a7e6a;
    --grid-cell:   60px;
    --margin-left: 15%;
    --max-width:   1280px;

    --font-mono:   "Space Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
    --font-serif:  "Source Serif 4", "Source Serif Pro", Georgia, "Times New Roman", serif;
    --font-code:   "Fira Code", ui-monospace, "SFMono-Regular", Menlo, monospace;
}

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

html, body {
    background: var(--stone-light);
    color: var(--text-ink);
    font-family: var(--font-serif);
    font-size: clamp(16px, 1.6vw, 19px);
    line-height: 1.75;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
}

em { font-style: italic; font-weight: 600; color: var(--text-ink); }
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
ol, ul { list-style: none; }

.mono {
    font-family: var(--font-code);
    font-size: 0.94em;
    letter-spacing: 0.03em;
    color: var(--umber-deep);
}

/* ---------- Swiss grid underlay ---------- */
.grid-underlay {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    opacity: 0;
    transition: opacity 400ms ease;
    background-image:
        linear-gradient(to right, var(--grid-line) 1px, transparent 1px),
        linear-gradient(to bottom, var(--grid-line) 1px, transparent 1px);
    background-size: var(--grid-cell) var(--grid-cell);
    mix-blend-mode: multiply;
}
.grid-underlay.is-visible { opacity: 0.4; }

/* ---------- Common section frame ---------- */
section { position: relative; z-index: 1; }

/* ---------- Opening viewport ---------- */
.opening {
    min-height: 100vh;
    background: var(--stone-light);
    padding: clamp(40px, 6vh, 80px) var(--margin-left);
    display: grid;
    grid-template-rows: auto 1fr auto auto;
    gap: clamp(28px, 4vh, 56px);
    border-bottom: 1px solid rgba(192, 184, 160, 0.6);
}

.opening-mark {
    display: flex;
    align-items: center;
    gap: 24px;
    font-family: var(--font-mono);
    font-size: clamp(11px, 0.9vw, 13px);
    text-transform: uppercase;
    letter-spacing: 0.18em;
    color: var(--text-warm);
}
.opening-mark__rule {
    display: block;
    width: 120px;
    height: 1px;
    background: var(--text-warm);
}

.opening-title {
    font-family: var(--font-mono);
    font-weight: 700;
    font-size: clamp(48px, 9vw, 132px);
    letter-spacing: 0.04em;
    line-height: 1;
    color: var(--text-ink);
    align-self: end;
    user-select: none;
    white-space: nowrap;
    overflow: hidden;
}
.opening-title__char {
    display: inline-block;
    opacity: 0;
    transform: translateY(0.4em);
    transition: opacity 320ms ease, transform 320ms ease;
}
.opening-title__char.is-revealed {
    opacity: 1;
    transform: translateY(0);
}
.opening-title__char--dot { color: var(--text-warm); }

.opening-statement {
    font-family: var(--font-serif);
    font-size: clamp(18px, 2.2vw, 28px);
    line-height: 1.55;
    color: var(--text-ink);
    max-width: 36ch;
    margin-left: auto;
    text-align: left;
    opacity: 0;
    transform: translateX(36px);
    transition: opacity 600ms ease 200ms, transform 600ms ease 200ms;
    border-left: 1px solid var(--text-warm);
    padding-left: 28px;
}
.opening-statement.is-visible {
    opacity: 1;
    transform: translateX(0);
}
.opening-statement em { color: var(--umber-deep); }

.opening-meta {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 24px;
    padding-top: 28px;
    border-top: 1px solid rgba(192, 184, 160, 0.6);
}
.opening-meta__item {
    display: flex;
    flex-direction: column;
    gap: 6px;
    transition: transform 280ms cubic-bezier(0.2, 0.7, 0.2, 1);
    will-change: transform;
}
.opening-meta__key {
    font-family: var(--font-mono);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.18em;
    color: var(--text-warm);
}
.opening-meta__val {
    font-family: var(--font-serif);
    font-size: clamp(15px, 1.4vw, 18px);
    color: var(--text-ink);
    font-weight: 600;
}

.opening-scroll {
    display: flex;
    align-items: center;
    gap: 14px;
    font-family: var(--font-mono);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.2em;
    color: var(--text-warm);
}
.opening-scroll__arrow {
    font-family: var(--font-mono);
    animation: nudge 2.4s ease-in-out infinite;
}
@keyframes nudge {
    0%, 100% { transform: translateY(0); opacity: 0.6; }
    50% { transform: translateY(6px); opacity: 1; }
}

/* ---------- Challenge sections ---------- */
.challenge {
    padding: clamp(40px, 6vh, 80px) var(--margin-left);
    border-bottom: 1px solid rgba(192, 184, 160, 0.6);
}
.challenge--light { background: var(--stone-light); }
.challenge--dark  { background: var(--stone-dark); }

.challenge__inner {
    max-width: 1080px;
    display: grid;
    grid-template-columns: minmax(140px, 1fr) 3fr;
    gap: clamp(24px, 4vw, 64px);
    align-items: start;
}

.challenge__head {
    display: flex;
    flex-direction: column;
    gap: 10px;
    position: sticky;
    top: 24px;
}
.challenge__num {
    font-family: var(--font-mono);
    font-weight: 700;
    font-size: clamp(36px, 6vw, 72px);
    line-height: 1;
    letter-spacing: 0.08em;
    color: var(--umber-deep);
    will-change: transform;
    transition: transform 280ms cubic-bezier(0.2, 0.7, 0.2, 1);
}
.challenge__label {
    font-family: var(--font-mono);
    font-size: clamp(12px, 1vw, 14px);
    text-transform: uppercase;
    letter-spacing: 0.18em;
    color: var(--text-warm);
}

.challenge__body {
    display: flex;
    flex-direction: column;
    gap: 22px;
}
.challenge__statement {
    font-family: var(--font-serif);
    font-size: clamp(18px, 1.7vw, 22px);
    line-height: 1.7;
    color: var(--text-ink);
    max-width: 60ch;
}
.challenge__notation {
    font-family: var(--font-code);
    font-size: 16px;
    letter-spacing: 0.03em;
    color: var(--umber-deep);
    padding: 14px 22px;
    background: rgba(192, 184, 160, 0.18);
    border-left: 2px solid var(--text-warm);
    width: fit-content;
}

.challenge__toggle {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    font-family: var(--font-mono);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.2em;
    color: var(--text-ink);
    padding: 12px 20px;
    border: 1px solid var(--text-warm);
    background: transparent;
    width: fit-content;
    transition: background 220ms ease, color 220ms ease, border-color 220ms ease;
}
.challenge__toggle:hover {
    background: var(--text-ink);
    color: var(--stone-light);
    border-color: var(--text-ink);
}
.challenge__toggle-icon {
    font-family: var(--font-mono);
    font-size: 14px;
    transition: transform 320ms ease;
}
.challenge__toggle[aria-expanded="true"] .challenge__toggle-icon {
    transform: rotate(45deg);
}

.challenge__solution {
    max-height: 0;
    overflow: hidden;
    transition: max-height 400ms ease;
    border-top: 1px solid rgba(192, 184, 160, 0.6);
    padding-top: 0;
}
.challenge__solution.is-open {
    max-height: 600px;
    padding-top: 22px;
}

.challenge__steps {
    display: flex;
    flex-direction: column;
    gap: 10px;
    counter-reset: step;
    margin-bottom: 18px;
}
.challenge__steps li {
    font-family: var(--font-serif);
    font-size: clamp(15px, 1.4vw, 17px);
    line-height: 1.7;
    color: var(--text-ink);
    display: grid;
    grid-template-columns: 32px 1fr;
    gap: 12px;
}
.step-num {
    font-family: var(--font-mono);
    font-size: 13px;
    color: var(--text-warm);
    letter-spacing: 0.1em;
}

.challenge__conclusion {
    font-family: var(--font-serif);
    font-size: clamp(17px, 1.6vw, 20px);
    line-height: 1.6;
    color: var(--text-ink);
    font-weight: 600;
    padding-top: 12px;
    border-top: 1px dashed rgba(106, 100, 88, 0.4);
    transition: text-shadow 600ms ease, color 400ms ease;
}
.challenge__solution.is-open .challenge__conclusion {
    color: var(--text-ink);
    text-shadow:
        0 0 2px rgba(52, 211, 153, 0.85),
        0 0 6px rgba(52, 211, 153, 0.6),
        0 0 12px rgba(52, 211, 153, 0.4);
}

/* ---------- Proof section ---------- */
.proof {
    padding: clamp(60px, 9vh, 120px) var(--margin-left);
    background: var(--stone-light);
    border-bottom: 1px solid rgba(192, 184, 160, 0.6);
    position: relative;
}
.proof::before {
    content: "";
    position: absolute;
    top: 0; left: var(--margin-left);
    width: 60px; height: 1px;
    background: var(--text-ink);
}

.proof__inner {
    max-width: 1080px;
    display: flex;
    flex-direction: column;
    gap: clamp(36px, 5vh, 60px);
}

.proof__head { display: flex; flex-direction: column; gap: 16px; max-width: 64ch; }
.proof__tag {
    font-family: var(--font-mono);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.22em;
    color: var(--text-warm);
}
.proof__title {
    font-family: var(--font-mono);
    font-weight: 700;
    font-size: clamp(32px, 5vw, 56px);
    letter-spacing: 0.04em;
    color: var(--text-ink);
    line-height: 1.1;
}
.proof__subtitle {
    font-family: var(--font-serif);
    font-size: clamp(16px, 1.5vw, 19px);
    line-height: 1.7;
    color: var(--text-warm);
    max-width: 56ch;
}

.proof__premises {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0;
    border: 1px solid rgba(192, 184, 160, 0.7);
}
.proof__premise {
    display: grid;
    grid-template-columns: 64px 1fr;
    gap: 16px;
    padding: 18px 22px;
    align-items: center;
    border-right: 1px solid rgba(192, 184, 160, 0.7);
    border-bottom: 1px solid rgba(192, 184, 160, 0.7);
    background: var(--stone-light);
}
.proof__premise:nth-child(2n) { border-right: none; }
.proof__premise:nth-last-child(-n + 2) { border-bottom: none; }
.proof__premise--goal { background: var(--stone-dark); }
.proof__premise-key {
    font-family: var(--font-mono);
    font-size: 12px;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--text-warm);
}
.proof__premise-val {
    font-family: var(--font-code);
    font-size: 15px;
    color: var(--text-ink);
}

.proof__steps {
    display: flex;
    flex-direction: column;
    gap: 0;
    counter-reset: proof;
    border-top: 1px solid rgba(192, 184, 160, 0.7);
}
.proof__step {
    display: grid;
    grid-template-columns: 80px 1fr 240px;
    gap: 24px;
    align-items: baseline;
    padding: 18px 0;
    border-bottom: 1px solid rgba(192, 184, 160, 0.7);
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 300ms ease, transform 300ms ease;
}
.proof__step.is-visible {
    opacity: 1;
    transform: translateY(0);
}
.proof__step-num {
    font-family: var(--font-mono);
    font-weight: 700;
    font-size: clamp(20px, 2vw, 26px);
    color: var(--umber-deep);
    letter-spacing: 0.08em;
}
.proof__step-body {
    font-family: var(--font-code);
    font-size: clamp(15px, 1.4vw, 18px);
    color: var(--text-ink);
    letter-spacing: 0.03em;
    line-height: 1.5;
}
.proof__step-note {
    font-family: var(--font-mono);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.18em;
    color: var(--text-warm);
    text-align: right;
}
.proof__step--final .proof__step-num,
.proof__step--final .proof__step-body {
    color: var(--text-ink);
}
.proof__step--final.is-glowing .proof__step-body {
    text-shadow:
        0 0 2px rgba(52, 211, 153, 0.95),
        0 0 6px rgba(52, 211, 153, 0.75),
        0 0 12px rgba(52, 211, 153, 0.55),
        0 0 24px rgba(52, 211, 153, 0.3);
}

/* ---------- QED ---------- */
.qed {
    background: var(--stone-light);
    padding: clamp(60px, 10vh, 140px) var(--margin-left) 0;
    position: relative;
    overflow: hidden;
    min-height: 80vh;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}
.qed__grid {
    position: absolute;
    inset: 0;
    pointer-events: none;
    background-image:
        linear-gradient(to right, var(--grid-line) 1px, transparent 1px),
        linear-gradient(to bottom, var(--grid-line) 1px, transparent 1px);
    background-size: var(--grid-cell) var(--grid-cell);
    opacity: 0.25;
    mix-blend-mode: multiply;
}
.qed__content {
    position: relative;
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 18px;
    padding-top: clamp(20px, 4vh, 40px);
}
.qed__label {
    font-family: var(--font-mono);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.28em;
    color: var(--text-warm);
}
.qed__mark {
    font-family: var(--font-mono);
    font-weight: 700;
    font-size: clamp(72px, 14vw, 200px);
    letter-spacing: 0.06em;
    color: var(--text-ink);
    line-height: 1;
}
.qed__mark.is-glowing {
    text-shadow:
        0 0 4px rgba(52, 211, 153, 0.9),
        0 0 14px rgba(52, 211, 153, 0.7),
        0 0 28px rgba(52, 211, 153, 0.4);
}
.qed__caption {
    font-family: var(--font-serif);
    font-size: clamp(15px, 1.4vw, 18px);
    color: var(--text-warm);
    max-width: 42ch;
    line-height: 1.6;
}

.qed__mountain {
    position: relative;
    height: clamp(120px, 22vh, 220px);
    margin-top: clamp(40px, 6vh, 80px);
}
.qed__mountain-range {
    position: absolute;
    left: 0; right: 0; bottom: 0;
    height: 100%;
}
.qed__mountain-range--back {
    background: var(--text-mute);
    opacity: 0.55;
    clip-path: polygon(
        0% 100%,
        0% 75%,
        8% 55%, 16% 70%, 24% 40%, 33% 60%,
        42% 30%, 52% 55%, 60% 35%, 70% 60%,
        80% 38%, 90% 58%, 100% 45%,
        100% 100%
    );
}
.qed__mountain-range--front {
    background: var(--sage-brown);
    clip-path: polygon(
        0% 100%,
        0% 85%,
        6% 70%, 14% 80%, 20% 50%, 28% 72%,
        36% 42%, 45% 65%, 54% 25%, 62% 60%,
        70% 50%, 78% 70%, 86% 45%, 94% 65%, 100% 55%,
        100% 100%
    );
}

.qed__footer {
    position: relative;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 28px 0;
    font-family: var(--font-mono);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.18em;
    color: var(--text-warm);
    border-top: 1px solid rgba(192, 184, 160, 0.6);
}
.qed__footer-rule {
    display: inline-block;
    width: 36px;
    height: 1px;
    background: var(--text-warm);
}

/* ---------- Magnetic ---------- */
.magnetic { will-change: transform; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
    :root { --margin-left: 8%; }
    .opening { padding-left: 8%; padding-right: 8%; }
    .challenge { padding-left: 8%; padding-right: 8%; }
    .challenge__inner { grid-template-columns: 1fr; gap: 18px; }
    .challenge__head { position: static; }
    .opening-meta { grid-template-columns: repeat(2, 1fr); }
    .proof { padding-left: 8%; padding-right: 8%; }
    .proof__premises { grid-template-columns: 1fr; }
    .proof__premise { border-right: none !important; }
    .proof__premise:last-child { border-bottom: none; }
    .proof__step { grid-template-columns: 56px 1fr; }
    .proof__step-note { grid-column: 2; text-align: left; padding-top: 4px; }
    .qed { padding-left: 8%; padding-right: 8%; }
}
@media (max-width: 540px) {
    .opening-title { font-size: 56px; letter-spacing: 0.02em; }
    .opening-meta { grid-template-columns: 1fr; }
    .qed__footer { flex-wrap: wrap; }
}
