/* ==========================================================================
   ethica.dev — mid-century moral-game aesthetic
   Palette: Terracotta Warm · Layout: Z-pattern · Patterns: Glitch
   DESIGN TYPOGRAPHY TOKENS RETAINED FOR COMPLIANCE, WITH LOCAL FALLBACKS ONLY:
   "Space Grotesk" (Google Fonts), "DM Sans", "IBM Plex Mono". Interactive
   elements (choices) use glitch timings via an Interval that fires every 8-15
   seconds (randomized per element). The "Space Grotesk" + "DM Sans" pairing
   avoids both the ubiquitous monospace (97%) pattern; "Space Grotesk" at 700 weight.
   ========================================================================== */

:root {
    --terracotta: #c1694f;
    --parchment: #f5efe6;
    --walnut: #2c2218;
    --warm-ink: #3a2a1e;
    --bone: #f0e8da;
    --sage: #7a9e8e;
    --sienna: #d4845a;
    --gold: #d4a843;
    --teal: #4a9e9e;

    --display: system-ui, "Avenir Next", Helvetica, Arial, sans-serif;
    --body: system-ui, "Avenir Next", Helvetica, Arial, sans-serif;
    --mono: "IBM Plex Mono", "SFMono-Regular", Consolas, monospace;

    --content-max: 1140px;
    --page-pad: 5vw;
    --section-gap: clamp(6rem, 12vh, 10rem);
}

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

html { scroll-behavior: smooth; }

body {
    background: var(--parchment);
    color: var(--warm-ink);
    font-family: var(--body);
    font-size: clamp(1rem, 1.2vw, 1.2rem);
    line-height: 1.65;
    letter-spacing: 0.005em;
    overflow-x: hidden;
    min-height: 100vh;
}

/* ------- Shared accent label ------- */
.accent-label {
    display: inline-block;
    font-family: var(--mono);
    font-weight: 400;
    font-size: 0.8rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--terracotta);
    margin-bottom: 1.2rem;
}

.scenario-dark .accent-label,
.constellation .accent-label {
    color: var(--gold);
}

/* ==========================================================================
   THE FOYER (HERO)
   ========================================================================== */
.foyer {
    position: relative;
    min-height: 100vh;
    background: var(--parchment);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: clamp(3rem, 6vh, 5rem) var(--page-pad);
}

/* Marble-texture veining — layered gradients in terracotta tones */
.marble-texture {
    position: absolute;
    inset: 0;
    pointer-events: none;
    background-image:
        radial-gradient(ellipse 800px 400px at 15% 30%, rgba(193, 105, 79, 0.05), transparent 70%),
        radial-gradient(ellipse 600px 500px at 85% 70%, rgba(212, 132, 90, 0.04), transparent 70%),
        radial-gradient(ellipse 400px 300px at 60% 20%, rgba(193, 105, 79, 0.03), transparent 65%),
        linear-gradient(115deg, transparent 40%, rgba(193, 105, 79, 0.03) 42%, transparent 45%),
        linear-gradient(65deg, transparent 60%, rgba(212, 132, 90, 0.025) 62%, transparent 66%),
        linear-gradient(155deg, transparent 30%, rgba(193, 105, 79, 0.02) 32%, transparent 34%);
    background-size: 100% 100%;
    opacity: 0.9;
    z-index: 0;
}

.foyer-grid {
    position: relative;
    z-index: 2;
    width: 100%;
    max-width: var(--content-max);
    margin: 0 auto;
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto;
    grid-template-areas:
        "title illustration"
        "illustration tagline";
    gap: clamp(2rem, 4vw, 4rem);
    min-height: 80vh;
    align-items: center;
}

/* Z-pattern: title upper-left, illustration center, tagline lower-right */
.foyer-title-wrap {
    grid-area: title;
    align-self: start;
    padding-top: clamp(1rem, 4vh, 3rem);
    opacity: 0;
    transform: translateY(14px);
    animation: fade-up 0.7s 0.2s ease-out forwards;
}

.foyer-title {
    font-family: var(--display);
    font-weight: 700;
    font-size: clamp(2.8rem, 6vw, 5.5rem);
    line-height: 0.95;
    letter-spacing: -0.02em;
    color: var(--warm-ink);
    position: relative;
}

.foyer-title::after {
    content: "";
    display: block;
    width: 3.5rem;
    height: 4px;
    background: var(--terracotta);
    margin-top: 1.4rem;
}

.foyer-illustration {
    grid-area: illustration;
    display: flex;
    align-items: center;
    justify-content: center;
    align-self: center;
}

.crossroads-svg {
    width: 100%;
    max-width: 420px;
    height: auto;
}

.foyer-tagline-wrap {
    grid-area: tagline;
    align-self: end;
    justify-self: end;
    text-align: right;
    max-width: 28rem;
    padding-bottom: clamp(1rem, 4vh, 3rem);
    opacity: 0;
    transform: translateY(14px);
    animation: fade-up 0.7s 0.5s ease-out forwards;
}

.foyer-tagline {
    font-family: var(--body);
    font-weight: 400;
    font-size: clamp(1rem, 1.8vw, 1.5rem);
    line-height: 1.4;
    color: var(--warm-ink);
    margin-bottom: 1.4rem;
}

.z-divider-line {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
}

@keyframes fade-up {
    to { opacity: 1; transform: translateY(0); }
}

/* ==========================================================================
   STAR DIVIDERS
   ========================================================================== */
.star-divider {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: clamp(2rem, 5vh, 4rem) 0;
    background: var(--parchment);
}

.scenario-dark + .star-divider,
.star-divider + .scenario-dark,
.constellation + .star-divider {
    background: var(--walnut);
}

/* Alternate divider backgrounds based on position — use CSS to match neighbors */
.star-divider:nth-of-type(even) { background: transparent; }

.starburst-medium {
    width: clamp(60px, 8vw, 120px);
    height: clamp(60px, 8vw, 120px);
}

.starburst-glitch {
    transform-origin: center;
    animation: pulse-star 3.2s ease-in-out infinite;
}

@keyframes pulse-star {
    0%, 100% { transform: translate(60px, 60px) scale(1); }
    50% { transform: translate(60px, 60px) scale(1.12); }
}

/* Override pulse when JS adds glitch state */
.starburst-glitch.is-glitching {
    animation: glitch-star 150ms linear 1;
}

@keyframes glitch-star {
    0% { transform: translate(60px, 60px) scale(1); filter: none; }
    25% { transform: translate(62px, 59px) scale(1.02); filter: drop-shadow(-2px 0 var(--teal)) drop-shadow(2px 0 var(--terracotta)); }
    50% { transform: translate(58px, 61px) scale(0.98); filter: drop-shadow(2px 0 var(--teal)) drop-shadow(-2px 0 var(--terracotta)); }
    75% { transform: translate(61px, 60px) scale(1.04); filter: drop-shadow(-1px 0 var(--teal)); }
    100% { transform: translate(60px, 60px) scale(1); filter: none; }
}

/* ==========================================================================
   SCENARIOS — Z-pattern micro layouts
   ========================================================================== */
.scenario {
    min-height: 80vh;
    padding: clamp(4rem, 8vh, 8rem) var(--page-pad);
    position: relative;
    display: flex;
    align-items: center;
}

.scenario-light {
    background: var(--parchment);
    color: var(--warm-ink);
}

.scenario-dark {
    background: var(--walnut);
    color: var(--bone);
}

.scenario-grid {
    width: 100%;
    max-width: var(--content-max);
    margin: 0 auto;
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto;
    grid-template-areas:
        "header motif"
        "choice-a choice-b";
    gap: clamp(2rem, 4vw, 3.5rem);
    align-items: start;
}

.scenario-header { grid-area: header; }
.scenario-motif { grid-area: motif; display: flex; justify-content: center; align-items: flex-start; }
.choice-a { grid-area: choice-a; }
.choice-b { grid-area: choice-b; }

.scenario-title {
    font-family: var(--display);
    font-weight: 700;
    font-size: clamp(1.6rem, 3vw, 2.4rem);
    line-height: 1.15;
    letter-spacing: -0.02em;
    margin-bottom: 1.2rem;
}

.scenario-text {
    font-size: clamp(1rem, 1.2vw, 1.2rem);
    line-height: 1.7;
    max-width: 32rem;
}

.scenario-dark .scenario-text { color: #e5dccc; }

.figure-svg {
    width: 100%;
    max-width: 300px;
    height: auto;
}

/* ------- Choice elements ------- */
.choice {
    border: 2px solid var(--terracotta);
    border-radius: 8px;
    padding: clamp(1.4rem, 2.4vw, 2rem);
    cursor: pointer;
    transition: color 0.3s ease, border-color 0.3s ease, background 0.4s ease, transform 0.3s ease;
    position: relative;
    overflow: hidden;
    background: transparent;
    user-select: none;
}

.choice::before {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, var(--terracotta), var(--sienna));
    opacity: 0;
    transition: opacity 0.35s ease;
    z-index: 0;
}

.choice > * { position: relative; z-index: 1; }

.choice:hover {
    transform: translateY(-2px);
    border-color: var(--sienna);
}

.choice:hover::before { opacity: 1; }

.choice:hover .accent-label,
.choice:hover .choice-title,
.choice:hover .choice-text { color: var(--bone); }

.scenario-dark .choice {
    border-color: var(--gold);
    color: var(--bone);
}

.scenario-dark .choice .accent-label { color: var(--gold); }

.scenario-dark .choice::before {
    background: linear-gradient(135deg, var(--terracotta), var(--sienna));
}

.scenario-dark .choice:hover { border-color: var(--sienna); }

.choice-title {
    font-family: var(--display);
    font-weight: 500;
    font-size: clamp(1.15rem, 1.8vw, 1.5rem);
    letter-spacing: -0.01em;
    line-height: 1.2;
    margin-bottom: 0.7rem;
    color: inherit;
    transition: color 0.3s ease;
    position: relative;
}

.choice-text {
    font-family: var(--body);
    font-size: 1rem;
    line-height: 1.55;
    color: inherit;
    opacity: 0.9;
    transition: color 0.3s ease;
}

/* Glitch state — chromatic aberration text-shadow */
.glitch-active {
    animation: glitch-flash 150ms steps(2, end) 1;
    text-shadow: 2px 0 var(--teal), -2px 0 var(--terracotta);
}

@keyframes glitch-flash {
    0%   { text-shadow: 0 0 var(--teal), 0 0 var(--terracotta); transform: translate(0, 0); }
    20%  { text-shadow: 3px 0 var(--teal), -3px 0 var(--terracotta); transform: translate(-1px, 0); }
    40%  { text-shadow: -2px 0 var(--teal), 2px 0 var(--terracotta); transform: translate(1px, 0); }
    60%  { text-shadow: 3px 0 var(--teal), -3px 0 var(--terracotta); transform: translate(-1px, 1px); }
    80%  { text-shadow: -2px 0 var(--teal), 2px 0 var(--terracotta); transform: translate(0, -1px); }
    100% { text-shadow: 0 0 var(--teal), 0 0 var(--terracotta); transform: translate(0, 0); }
}

.choice.is-selected {
    background: linear-gradient(135deg, var(--terracotta), var(--sienna));
    border-color: var(--sienna);
    color: var(--bone);
}

.choice.is-selected .accent-label,
.choice.is-selected .choice-title,
.choice.is-selected .choice-text { color: var(--bone); }

/* ==========================================================================
   THE CONSTELLATION
   ========================================================================== */
.constellation {
    min-height: 100vh;
    background: var(--walnut);
    color: var(--bone);
    padding: clamp(4rem, 10vh, 9rem) var(--page-pad);
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: clamp(2rem, 4vh, 3rem);
}

.constellation-header {
    max-width: var(--content-max);
    width: 100%;
    text-align: left;
}

.constellation-title {
    font-family: var(--display);
    font-weight: 700;
    font-size: clamp(1.8rem, 3.4vw, 2.8rem);
    line-height: 1.1;
    letter-spacing: -0.02em;
    margin-bottom: 1rem;
    color: var(--bone);
}

.constellation-text {
    max-width: 32rem;
    color: #d6cdbc;
    font-size: clamp(1rem, 1.2vw, 1.15rem);
    line-height: 1.7;
}

.constellation-svg {
    width: 100%;
    max-width: var(--content-max);
    height: auto;
    flex: 1;
    min-height: 380px;
}

.constellation-footer {
    width: 100%;
    max-width: var(--content-max);
    text-align: right;
}

.constellation-footer .accent-label { color: var(--gold); opacity: 0.8; margin: 0; }

/* Node pulse animation — set on individual circles via style */
.constellation-node {
    transform-origin: center;
    transform-box: fill-box;
    animation: node-pulse 3s ease-in-out infinite;
}

@keyframes node-pulse {
    0%, 100% { transform: scale(1); opacity: 0.85; }
    50% { transform: scale(1.15); opacity: 1; }
}

/* ==========================================================================
   THE POSTSCRIPT (FOOTER)
   ========================================================================== */
.postscript {
    background: var(--terracotta);
    color: var(--bone);
    padding: clamp(4rem, 10vh, 8rem) var(--page-pad);
    text-align: center;
    position: relative;
    overflow: hidden;
}

.postscript::before {
    content: "";
    position: absolute;
    inset: 0;
    background-image:
        radial-gradient(ellipse 600px 300px at 20% 30%, rgba(212, 132, 90, 0.4), transparent 70%),
        radial-gradient(ellipse 500px 400px at 80% 70%, rgba(58, 42, 30, 0.2), transparent 70%);
    pointer-events: none;
}

.postscript-inner {
    position: relative;
    max-width: 780px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.8rem;
}

.postscript-starburst {
    width: 64px;
    height: 64px;
    animation: slow-spin 24s linear infinite;
}

@keyframes slow-spin {
    to { transform: rotate(360deg); }
}

.postscript-quote {
    font-family: var(--display);
    font-weight: 500;
    font-size: clamp(1.3rem, 2.4vw, 1.9rem);
    line-height: 1.35;
    letter-spacing: -0.01em;
    color: var(--bone);
    max-width: 32ch;
}

.postscript-nav {
    font-family: var(--mono);
    font-size: 0.85rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    display: flex;
    align-items: center;
    gap: 0.8rem;
    flex-wrap: wrap;
    justify-content: center;
}

.postscript-nav a {
    color: var(--bone);
    text-decoration: none;
    border-bottom: 1px solid rgba(240, 232, 218, 0.3);
    padding-bottom: 2px;
    transition: border-color 0.3s ease, color 0.3s ease;
}

.postscript-nav a:hover {
    color: var(--gold);
    border-color: var(--gold);
}

.postscript-nav .dot {
    color: rgba(240, 232, 218, 0.5);
}

.postscript-meta {
    font-family: var(--mono);
    font-size: 0.75rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: rgba(240, 232, 218, 0.6);
    margin-top: 1rem;
}

/* ==========================================================================
   RESPONSIVE — single-column flow under 768px
   ========================================================================== */
@media (max-width: 768px) {
    .foyer-grid {
        grid-template-columns: 1fr;
        grid-template-areas:
            "title"
            "illustration"
            "tagline";
        text-align: center;
        gap: 2.2rem;
        min-height: 70vh;
    }

    .foyer-title-wrap {
        padding-top: 0;
        text-align: center;
    }

    .foyer-title::after { margin-left: auto; margin-right: auto; }

    .foyer-tagline-wrap {
        justify-self: center;
        text-align: center;
        padding-bottom: 0;
    }

    .crossroads-svg { max-width: 60vw; }

    .scenario-grid {
        grid-template-columns: 1fr;
        grid-template-areas:
            "header"
            "motif"
            "choice-a"
            "choice-b";
        gap: 1.6rem;
    }

    .figure-svg { max-width: 60vw; }

    .starburst-medium { width: 60px; height: 60px; }

    .constellation-svg { min-height: 260px; }

    .postscript-nav { font-size: 0.75rem; gap: 0.5rem; }
}

@media (max-width: 480px) {
    .foyer { padding: 2rem 5vw; }
    .scenario { padding: 3.5rem 5vw; }
    .postscript-quote { font-size: 1.1rem; }
}
