/* =====================================================================
   p9r.dev  —  Muji-greenhouse / candy-bright on warm earth
   Typography: Cormorant Garamond + EB Garamond + IBM Plex Mono
   ===================================================================== */

:root {
    /* Earth substrate */
    --ground: #F5F0E6;       /* Warm Linen */
    --card:   #FAF7F0;       /* Cream Clay */
    --ink:    #3B2F2F;       /* Fired Umber */
    --mute:   #7A6B5D;       /* Kiln Dust */

    /* Candy accents */
    --rose:       #E8457C;
    --lemon:      #F5C842;
    --pistachio:  #7EC8A0;
    --cornflower: #6B8CCE;
    --peach:      #F4A572;

    /* Geometry */
    --column: 680px;
    --column-wide: 960px;
    --gutter: 48px;

    /* Type */
    --serif:  "Cormorant Garamond", "EB Garamond", Georgia, serif;
    --eb:     "EB Garamond", "Cormorant Garamond", Georgia, serif;
    --mono:   "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;

    /* Active accent (set per-section by JS) */
    --accent: var(--rose);
    --accent-soft: rgba(232, 69, 124, 0.12);
}

* { box-sizing: border-box; }

html {
    scroll-behavior: smooth;
    background-color: var(--ground);
}

body {
    margin: 0;
    padding: 0;
    background-color: var(--ground);
    color: var(--ink);
    font-family: var(--serif);
    font-weight: 300;
    font-size: 19px;
    line-height: 1.72;
    letter-spacing: 0.01em;
    overflow-x: hidden;
    position: relative;
    min-height: 100vh;
}

/* =====================================================================
   GRAIN OVERLAY  —  inline SVG turbulence, blended multiply
   ===================================================================== */
.grain {
    position: relative;
}
.grain::after {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='200' height='200'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.23  0 0 0 0 0.18  0 0 0 0 0.18  0 0 0 0.55 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
    background-repeat: repeat;
    background-size: 200px 200px;
    opacity: 0.04;
    mix-blend-mode: multiply;
    z-index: 1;
}
body.grain::after {
    position: fixed;
    opacity: 0.035;
    z-index: 2;
}

/* =====================================================================
   LEAF INDICATOR (top-right cluster of ginkgo dots)
   ===================================================================== */
.leaf-indicator {
    position: fixed;
    top: 32px;
    right: 32px;
    z-index: 50;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 14px 10px;
    background: rgba(250, 247, 240, 0.78);
    border: 1px solid rgba(122, 107, 93, 0.18);
    border-radius: 28px;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    box-shadow: 0 1px 0 rgba(59, 47, 47, 0.04),
                0 8px 24px -10px rgba(59, 47, 47, 0.18);
}
.leaf-dot {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    color: var(--mute);
    transition: color 360ms ease, transform 360ms ease;
    text-decoration: none;
}
.leaf-dot:hover {
    transform: scale(1.12);
}
.leaf-dot[data-tone="rose"].active        { color: var(--rose); }
.leaf-dot[data-tone="lemon"].active       { color: var(--lemon); }
.leaf-dot[data-tone="pistachio"].active   { color: var(--pistachio); }
.leaf-dot[data-tone="cornflower"].active  { color: var(--cornflower); }
.leaf-dot[data-tone="peach"].active       { color: var(--peach); }
.leaf-dot.active svg path:first-of-type {
    fill: currentColor;
    fill-opacity: 0.18;
}

/* =====================================================================
   MARGIN LEAF DRIFT (ambient set-dressing)
   ===================================================================== */
.margin-leaves {
    position: fixed;
    top: 0;
    height: 100vh;
    width: clamp(60px, 12vw, 180px);
    pointer-events: none;
    z-index: 1;
    overflow: hidden;
}
.margin-leaves.left  { left: 0; }
.margin-leaves.right { right: 0; }

.drift-leaf {
    position: absolute;
    left: var(--drift-x, 30%);
    top:  var(--drift-y, 30%);
    width: 48px;
    height: 48px;
    will-change: transform;
    animation:
        drift-rotate var(--drift-duration, 110s) linear infinite,
        drift-translate var(--drift-duration, 110s) ease-in-out infinite alternate;
    animation-delay: var(--drift-delay, 0s);
    opacity: 0.55;
}
@keyframes drift-rotate {
    from { transform: rotate(0deg) translateY(0); }
    to   { transform: rotate(360deg) translateY(0); }
}
@keyframes drift-translate {
    from { margin-top: 0; }
    to   { margin-top: 32px; }
}

@media (max-width: 900px) {
    .margin-leaves { display: none; }
}

/* =====================================================================
   SPINE  —  centred 680px column
   ===================================================================== */
.spine {
    position: relative;
    width: 100%;
    max-width: var(--column);
    margin: 0 auto;
    padding: 96px 24px 96px;
    z-index: 5;
}

/* =====================================================================
   CHAPTER (full viewport-height section)
   ===================================================================== */
.chapter {
    min-height: 100vh;
    padding: 80px 0 64px;
    position: relative;
    transition: --accent 600ms ease;
}
.chapter[data-tone="rose"]        { --accent: #E8457C; --accent-soft: rgba(232, 69, 124, 0.12); }
.chapter[data-tone="lemon"]       { --accent: #F5C842; --accent-soft: rgba(245, 200, 66, 0.14); }
.chapter[data-tone="pistachio"]   { --accent: #7EC8A0; --accent-soft: rgba(126, 200, 160, 0.14); }
.chapter[data-tone="cornflower"]  { --accent: #6B8CCE; --accent-soft: rgba(107, 140, 206, 0.13); }
.chapter[data-tone="peach"]       { --accent: #F4A572; --accent-soft: rgba(244, 165, 114, 0.14); }

.chapter-head {
    text-align: center;
    margin-top: 40px;
    margin-bottom: 96px;
}
.eyebrow {
    display: inline-block;
    font-family: var(--eb);
    font-variant: small-caps;
    letter-spacing: 0.18em;
    font-size: 13px;
    color: var(--mute);
    margin-bottom: 24px;
}
.eyebrow::before {
    content: "—  ";
    color: var(--accent);
}
.eyebrow::after {
    content: "  —";
    color: var(--accent);
}

.chapter-title {
    font-family: var(--serif);
    font-weight: 600;
    font-size: 36px;
    line-height: 1.2;
    letter-spacing: -0.01em;
    margin: 0 0 32px;
    color: var(--ink);
}

.chapter-lede {
    max-width: 580px;
    margin: 0 auto;
    font-family: var(--serif);
    font-weight: 300;
    font-size: 19px;
    line-height: 1.72;
    color: var(--ink);
}
.chapter-lede em {
    font-style: italic;
    color: var(--accent);
}

/* =====================================================================
   CARD GRID
   ===================================================================== */
.card-grid {
    display: flex;
    flex-direction: column;
    gap: 48px;
    margin: 0 auto;
}

/* =====================================================================
   CARD  —  the flip element
   ===================================================================== */
.card {
    position: relative;
    perspective: 1200px;
    width: 100%;
    height: 380px;
    cursor: pointer;
}
.card.wide { height: 460px; }

.card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
    transition: transform 600ms cubic-bezier(0.4, 0.0, 0.2, 1);
}
@media (hover: hover) {
    .card:hover .card-inner {
        transform: rotateY(180deg) scale(1.02);
        animation: flip-pulse 600ms cubic-bezier(0.4, 0.0, 0.2, 1);
    }
    .card:hover .card-inner { transform: rotateY(180deg); }
}
.card.flipped .card-inner {
    transform: rotateY(180deg);
}
@keyframes flip-pulse {
    0%   { transform: rotateY(0deg)   scale(1); }
    50%  { transform: rotateY(90deg)  scale(1.02); }
    100% { transform: rotateY(180deg) scale(1); }
}

.card-face {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    border-radius: 6px;
    padding: 40px 44px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--card);
    border: 1px solid rgba(122, 107, 93, 0.18);
    box-shadow:
        0 1px 0 rgba(59, 47, 47, 0.04),
        0 2px 4px rgba(59, 47, 47, 0.05),
        0 20px 40px -16px rgba(59, 47, 47, 0.18);
}

/* per-card tone overrides — accent-soft tints the verso face */
.card[data-tone="rose"]        { --c-accent: var(--rose); --c-soft: rgba(232, 69, 124, 0.12); }
.card[data-tone="lemon"]       { --c-accent: var(--lemon); --c-soft: rgba(245, 200, 66, 0.14); }
.card[data-tone="pistachio"]   { --c-accent: var(--pistachio); --c-soft: rgba(126, 200, 160, 0.14); }
.card[data-tone="cornflower"]  { --c-accent: var(--cornflower); --c-soft: rgba(107, 140, 206, 0.13); }
.card[data-tone="peach"]       { --c-accent: var(--peach); --c-soft: rgba(244, 165, 114, 0.14); }

.card-front {
    color: var(--ink);
}
.card-front::before {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(180deg, transparent 70%, var(--c-soft, rgba(232, 69, 124, 0.08)));
    pointer-events: none;
}

.card-back {
    transform: rotateY(180deg);
    background:
        linear-gradient(0deg, var(--c-soft, rgba(232, 69, 124, 0.12)), var(--c-soft, rgba(232, 69, 124, 0.12))),
        var(--card);
    color: var(--ink);
}
.card-back .grain { opacity: 0.05; }
.card-back::after { opacity: 0.05; } /* heavier grain on verso */

/* card content blocks */
.card-motif {
    color: var(--c-accent, var(--rose));
    margin-bottom: 24px;
    line-height: 0;
}
.card-title {
    font-family: var(--serif);
    font-weight: 600;
    font-size: 28px;
    line-height: 1.18;
    letter-spacing: -0.01em;
    color: var(--ink);
    margin: 0 0 14px;
}
.card-summary {
    font-family: var(--serif);
    font-weight: 300;
    font-size: 18px;
    line-height: 1.6;
    color: var(--ink);
    margin: 0;
    flex: 1;
}
.card-summary em {
    color: var(--c-accent, var(--rose));
    font-style: italic;
}
.card-hint {
    margin-top: auto;
    font-family: var(--eb);
    font-variant: small-caps;
    letter-spacing: 0.16em;
    font-size: 12px;
    color: var(--mute);
    align-self: flex-end;
    position: relative;
    padding-right: 22px;
}
.card-hint::after {
    content: "";
    position: absolute;
    right: 0;
    top: 50%;
    width: 14px;
    height: 1px;
    background: var(--c-accent, var(--rose));
    transform: translateY(-50%);
}

.card-back p {
    font-family: var(--serif);
    font-weight: 300;
    font-size: 17px;
    line-height: 1.7;
    margin: 0 0 14px;
    color: var(--ink);
}
.card-back p:last-child { margin-bottom: 0; }
.card-back .quiet {
    color: var(--mute);
    font-style: italic;
    font-size: 16px;
}
.card-back em { color: var(--c-accent, var(--rose)); font-style: italic; }
.card-back code {
    font-family: var(--mono);
    font-size: 14px;
    background: rgba(59, 47, 47, 0.06);
    padding: 1px 5px;
    border-radius: 3px;
    color: var(--ink);
}
.card-back a.link {
    color: var(--c-accent, var(--rose));
    text-decoration: none;
    border-bottom: 1px solid var(--c-accent, var(--rose));
    padding-bottom: 1px;
    transition: opacity 200ms ease;
}
.card-back a.link:hover { opacity: 0.7; }

.meta-label {
    display: inline-block;
    font-family: var(--eb);
    font-variant: small-caps;
    letter-spacing: 0.18em;
    font-size: 12px;
    color: var(--mute);
    margin-bottom: 18px;
}

/* =====================================================================
   CODE BLOCK  —  cards within cards
   ===================================================================== */
.code {
    font-family: var(--mono);
    font-size: 14px;
    line-height: 1.55;
    background: rgba(59, 47, 47, 0.05);
    border: 1px solid rgba(122, 107, 93, 0.16);
    border-radius: 4px;
    padding: 14px 16px;
    margin: 12px 0 6px;
    overflow-x: auto;
    color: var(--ink);
    box-shadow: inset 0 1px 0 rgba(59, 47, 47, 0.04),
                inset 0 -1px 0 rgba(255, 255, 255, 0.6);
    white-space: pre;
}
.code .kw   { color: var(--rose); font-weight: 500; }
.code .fn   { color: var(--cornflower); }
.code .ty   { color: var(--peach); font-style: italic; }
.code .num  { color: var(--lemon); filter: brightness(0.78); }
.code .str  { color: var(--pistachio); filter: brightness(0.78); }
.code .cm   { color: var(--mute); font-style: italic; }
.code .prop { color: var(--cornflower); }

/* =====================================================================
   PRINCIPLES LIST + ENTRY LIST + COLOPHON
   ===================================================================== */
.principles {
    margin: 0;
    padding-left: 0;
    list-style: none;
    counter-reset: pr;
}
.principles li {
    position: relative;
    padding-left: 38px;
    margin-bottom: 12px;
    font-family: var(--serif);
    font-weight: 300;
    font-size: 17px;
    line-height: 1.6;
    counter-increment: pr;
}
.principles li::before {
    content: counter(pr, decimal-leading-zero);
    position: absolute;
    left: 0;
    top: 2px;
    font-family: var(--mono);
    font-size: 12px;
    color: var(--c-accent, var(--rose));
    letter-spacing: 0.05em;
}

.entry-list {
    margin: 0;
    padding: 0;
    list-style: none;
}
.entry-list li {
    padding: 8px 0;
    border-bottom: 1px dashed rgba(122, 107, 93, 0.25);
    font-family: var(--serif);
    font-weight: 300;
    font-size: 16px;
    line-height: 1.5;
    display: flex;
    gap: 12px;
    align-items: baseline;
    flex-wrap: wrap;
}
.entry-list li:last-child { border-bottom: none; }
.entry-list time {
    font-family: var(--mono);
    font-size: 12px;
    color: var(--c-accent, var(--rose));
    flex-shrink: 0;
}

.colophon {
    margin: 0;
    display: grid;
    grid-template-columns: 110px 1fr;
    gap: 8px 18px;
    font-family: var(--serif);
}
.colophon dt {
    font-family: var(--eb);
    font-variant: small-caps;
    letter-spacing: 0.14em;
    font-size: 13px;
    color: var(--c-accent, var(--rose));
}
.colophon dd {
    margin: 0;
    font-weight: 300;
    font-size: 15px;
    line-height: 1.55;
    color: var(--ink);
}
.colophon code {
    font-family: var(--mono);
    font-size: 13px;
    background: rgba(59, 47, 47, 0.06);
    padding: 1px 4px;
    border-radius: 3px;
}

/* =====================================================================
   DIVIDER  —  oversized leaf, breaks the column to 960px
   ===================================================================== */
.divider {
    margin: 64px auto 0;
    width: 100%;
    max-width: var(--column-wide);
    text-align: center;
    color: var(--accent);
    opacity: 0.18;
    pointer-events: none;
}
.divider svg {
    width: 100%;
    max-width: 320px;
    height: auto;
}

/* =====================================================================
   FOOTER
   ===================================================================== */
.page-foot {
    text-align: center;
    margin-top: 96px;
    padding-top: 32px;
    border-top: 1px solid rgba(122, 107, 93, 0.22);
}
.page-foot p { margin: 4px 0; }
.quiet {
    color: var(--mute);
    font-style: italic;
}
.small {
    font-family: var(--eb);
    font-variant: small-caps;
    letter-spacing: 0.18em;
    font-size: 12px;
    font-style: normal;
}

/* =====================================================================
   RESPONSIVE
   ===================================================================== */
@media (max-width: 720px) {
    .spine { padding: 56px 18px; }
    .chapter { padding: 64px 0 48px; min-height: auto; }
    .chapter-head { margin-bottom: 56px; }
    .chapter-title { font-size: 30px; }
    .chapter-lede { font-size: 17px; }
    .card { height: auto; min-height: 360px; cursor: pointer; }
    .card.wide { min-height: 440px; }
    .card-face { padding: 32px 28px; }
    .card-title { font-size: 24px; }
    .leaf-indicator { top: 16px; right: 12px; padding: 10px 6px; gap: 8px; border-radius: 22px; }
    .leaf-dot { width: 24px; height: 24px; }
    .leaf-dot svg { width: 18px; height: 18px; }
    .colophon { grid-template-columns: 90px 1fr; }
    .divider { margin-top: 40px; }
}

@media (max-width: 480px) {
    body { font-size: 17px; }
    .chapter-title { font-size: 26px; }
    .card-face { padding: 24px 20px; }
    .code { font-size: 12px; padding: 10px 12px; }
}
