/* ============================================================
   생각.com — Neubrutalist almanac, masonry of thought-fragments
   Fonts: Fraunces (display), Nunito (rounded sans), Caveat (hand)
   Palette:
     #f3e3d0  Hanji paper (page background)
     #fef9f1  Rice-paper highlight (cell interior)
     #1a0f0a  Sumi ink (text, borders, hard shadows)
     #c75a3a  Terracotta vermillion (primary accent, dividers)
     #e58a5f  Persimmon (secondary accent, underlines)
     #7a4a36  Nutmeg (tertiary, body in lighter passages)
     #d4c4a8  Hemp string (rules, dotted lines)
   ============================================================ */

:root {
    --hanji: #f3e3d0;
    --ricepaper: #fef9f1;
    --sumi: #1a0f0a;
    --terracotta: #c75a3a;
    --persimmon: #e58a5f;
    --nutmeg: #7a4a36;
    --hemp: #d4c4a8;

    --border-thick: 4px;
    --shadow-stamp: 8px 8px 0 var(--sumi);
    --shadow-stamp-hover: 12px 12px 0 var(--sumi);
    --radius-card: 22px;
    --radius-pill: 999px;

    --rail-x: 7vw;
    --ease-quiet: cubic-bezier(0.22, 0.61, 0.36, 1);
    --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ---------- Reset / base ---------- */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

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

body {
    background: var(--hanji);
    color: var(--sumi);
    font-family: "Nunito", system-ui, sans-serif;
    font-weight: 500;
    font-size: 1.04rem;
    line-height: 1.72;
    min-height: 100vh;
    overflow-x: hidden;
    cursor: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'><circle cx='12' cy='12' r='10' fill='none' stroke='%23c75a3a' stroke-width='2'/></svg>") 12 12, auto;
}

a, button, .cell {
    cursor: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'><circle cx='12' cy='12' r='10' fill='%23c75a3a'/></svg>") 12 12, pointer;
}

button {
    font: inherit;
    color: inherit;
    background: transparent;
    border: 0;
}

/* ---------- Paper grain texture ---------- */
.paper-grain {
    position: fixed;
    inset: 0;
    z-index: 1;
    pointer-events: none;
    mix-blend-mode: multiply;
    opacity: 0.06;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='220' height='220'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.78' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.10  0 0 0 0 0.06  0 0 0 0 0.04  0 0 0 0.85 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
    background-size: 220px 220px;
}

/* ---------- Footnote railing (spine) ---------- */
.footnote-rail {
    position: fixed;
    top: 0;
    left: var(--rail-x);
    width: 28px;
    height: 100vh;
    z-index: 30;
    pointer-events: none;
}

.rail-line {
    position: absolute;
    left: 13px;
    top: 0;
    bottom: 0;
    width: 2px;
    background: repeating-linear-gradient(
        to bottom,
        var(--sumi) 0 6px,
        transparent 6px 12px
    );
    opacity: 0.7;
}

.rail-anchor {
    position: absolute;
    left: 0;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
    transition: transform 320ms var(--ease-quiet);
}

.rail-anchor-bubble {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--hanji);
    border: 2px solid var(--sumi);
    box-shadow: 2px 2px 0 var(--sumi);
    transition: background 380ms var(--ease-quiet),
                transform 320ms var(--ease-quiet);
}

.rail-anchor.is-active .rail-anchor-bubble {
    background: var(--terracotta);
    transform: scale(1.18);
}

.rail-anchor:hover {
    transform: translateX(4px);
}

.rail-anchor:hover .rail-anchor-bubble {
    background: var(--persimmon);
}

.rail-anchor-label {
    position: absolute;
    left: 36px;
    font-family: "Caveat", cursive;
    font-size: 1rem;
    color: var(--nutmeg);
    transform: rotate(-4deg);
    opacity: 0;
    transition: opacity 280ms var(--ease-quiet);
    pointer-events: none;
    white-space: nowrap;
}

.rail-anchor:hover .rail-anchor-label,
.rail-anchor.is-active .rail-anchor-label {
    opacity: 1;
}

/* ---------- Masthead ---------- */
.masthead {
    position: relative;
    z-index: 5;
    padding: clamp(2.5rem, 7vw, 6.5rem) clamp(1.5rem, 9vw, 9rem) clamp(1.5rem, 5vw, 4rem);
    padding-left: calc(var(--rail-x) + 4.5rem);
}

.masthead-title {
    font-family: "Fraunces", "Nunito", serif;
    font-weight: 900;
    font-variation-settings: "SOFT" 100, "WONK" 1, "opsz" 144;
    font-size: clamp(6rem, 14vw, 16rem);
    line-height: 0.86;
    letter-spacing: -0.04em;
    color: var(--sumi);
    transform-origin: left top;
    transition: transform 420ms var(--ease-quiet),
                font-size 420ms var(--ease-quiet);
    will-change: transform;
}

.masthead-title.is-pinned {
    position: fixed;
    top: 18px;
    left: calc(var(--rail-x) + 3.4rem);
    font-size: clamp(2.6rem, 4.4vw, 3.6rem);
    line-height: 1;
    z-index: 40;
    background: var(--hanji);
    padding: 0.1em 0.4em 0.16em;
    border: var(--border-thick) solid var(--sumi);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-stamp);
}

.masthead-subtitle {
    margin-top: 1.4rem;
    max-width: 38ch;
    font-family: "Nunito", sans-serif;
    font-weight: 700;
    font-size: clamp(1rem, 1.5vw, 1.18rem);
    line-height: 1.55;
    color: var(--nutmeg);
    letter-spacing: -0.01em;
}

.masthead-mark {
    display: inline-block;
    margin-top: 1.1rem;
    padding: 0.18em 0.85em 0.22em;
    background: var(--terracotta);
    color: var(--ricepaper);
    border: var(--border-thick) solid var(--sumi);
    border-radius: var(--radius-card);
    box-shadow: 5px 5px 0 var(--sumi);
    font-family: "Nunito", sans-serif;
    font-weight: 800;
    font-size: 1rem;
    letter-spacing: 0.04em;
    transform: rotate(-1.6deg);
}

/* ---------- The masonry ---------- */
.masonry {
    position: relative;
    z-index: 5;
    column-count: 3;
    column-gap: clamp(1rem, 2vw, 2rem);
    padding: clamp(1.4rem, 3vw, 3rem) clamp(1.4rem, 5vw, 5rem) clamp(4rem, 8vw, 8rem);
    padding-left: calc(var(--rail-x) + 4.5rem);
}

@media (max-width: 1099px) {
    .masonry { column-count: 2; }
    .masthead { padding-left: calc(var(--rail-x) + 2.5rem); }
}

@media (max-width: 719px) {
    :root { --rail-x: 4vw; }
    .masonry { column-count: 1; padding-left: calc(var(--rail-x) + 2.6rem); }
    .masthead { padding-left: calc(var(--rail-x) + 1.4rem); }
    .footnote-rail { width: 22px; }
}

/* ---------- Cell base ---------- */
.cell {
    position: relative;
    display: block;
    break-inside: avoid;
    -webkit-column-break-inside: avoid;
    page-break-inside: avoid;
    background: var(--ricepaper);
    border: var(--border-thick) solid var(--sumi);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-stamp);
    padding: clamp(1.1rem, 1.6vw, 1.7rem) clamp(1.1rem, 1.6vw, 1.7rem) clamp(1.2rem, 1.6vw, 1.7rem);
    margin-bottom: clamp(1rem, 2vw, 2rem);
    opacity: 0;
    transform: translateY(14px);
    transition: opacity 800ms var(--ease-quiet),
                transform 800ms var(--ease-quiet),
                box-shadow 320ms var(--ease-quiet);
}

.cell.is-revealed {
    opacity: 1;
    transform: translateY(0);
}

.cell:hover {
    box-shadow: var(--shadow-stamp-hover);
}

/* irregular heights (per design: 180/340/510/220/680) */
.cell-tiny    { min-height: 180px; }
.cell-short   { min-height: 220px; }
.cell-medium  { min-height: 340px; }
.cell-tall    { min-height: 510px; }
.cell-huge    { min-height: 680px; }

/* leak cells: violate the grid */
.cell-leak-left.is-revealed {
    transform: translateX(-32px) rotate(-2.4deg);
    z-index: 6;
}

.cell-leak-right.is-revealed {
    transform: translateX(28px) rotate(1.8deg);
    z-index: 6;
}

.cell-leak-left:hover.is-revealed,
.cell-leak-right:hover.is-revealed {
    z-index: 7;
}

.cell-corner-tag {
    position: absolute;
    top: -14px;
    right: 18px;
    background: var(--hanji);
    border: var(--border-thick) solid var(--sumi);
    border-radius: var(--radius-pill);
    padding: 0.05em 0.65em 0.1em;
    box-shadow: 3px 3px 0 var(--sumi);
    font-family: "Fraunces", serif;
    font-weight: 900;
    font-variation-settings: "SOFT" 100, "WONK" 1;
    font-size: 1.05rem;
    letter-spacing: 0.02em;
    transform: rotate(2.4deg);
    color: var(--sumi);
}

.cell-title {
    font-family: "Nunito", sans-serif;
    font-weight: 800;
    font-size: clamp(1.4rem, 2.6vw, 2.1rem);
    line-height: 1.1;
    letter-spacing: -0.018em;
    color: var(--sumi);
    margin-bottom: 0.85rem;
    padding-bottom: 0.45rem;
    border-bottom: 3px solid var(--hemp);
}

.cell-title-small {
    font-family: "Nunito", sans-serif;
    font-weight: 800;
    font-size: clamp(1.1rem, 1.8vw, 1.4rem);
    line-height: 1.15;
    letter-spacing: -0.01em;
    color: var(--terracotta);
    margin-bottom: 0.6rem;
    padding-bottom: 0.35rem;
    border-bottom: 2px dotted var(--hemp);
}

.cell-body p + p {
    margin-top: 0.9rem;
}

.cell-body em {
    background: linear-gradient(transparent 60%, var(--persimmon) 60% 92%, transparent 92%);
    padding: 0 2px;
    font-style: normal;
    font-weight: 700;
    color: var(--sumi);
}

.cell-body p {
    color: var(--nutmeg);
}

.cell-body p:first-of-type {
    color: var(--sumi);
    font-weight: 600;
}

/* caveat marginalia */
.caveat,
.caveat-large {
    font-family: "Caveat", cursive;
    font-weight: 600;
    color: var(--terracotta);
    transform: rotate(-1.6deg);
    display: inline-block;
}

.caveat {
    font-size: 1.1rem;
    line-height: 1.4;
}

.caveat-large {
    font-size: clamp(1.4rem, 2.2vw, 1.85rem);
    font-weight: 700;
    line-height: 1.2;
    color: var(--sumi);
}

/* quote cells */
.cell-quote {
    position: relative;
    padding-top: 0.4rem;
}

.cell-quote .quote-mark {
    position: absolute;
    top: -1.4rem;
    left: -0.3rem;
    font-family: "Fraunces", serif;
    font-weight: 900;
    font-variation-settings: "SOFT" 100, "WONK" 1;
    font-size: 5rem;
    line-height: 1;
    color: var(--terracotta);
}

.cell-quote p {
    font-family: "Nunito", sans-serif;
    font-weight: 700;
    font-size: 1.18rem;
    line-height: 1.45;
    color: var(--sumi);
    padding-left: 0.4rem;
}

.cell-quote .quote-attr {
    margin-top: 0.7rem;
    font-family: "Caveat", cursive;
    font-weight: 600;
    font-size: 1.05rem;
    color: var(--nutmeg);
    transform: rotate(-1deg);
    display: inline-block;
}

/* divider cells (full-width terracotta block) */
.cell-divider {
    background: var(--terracotta);
    color: var(--ricepaper);
    min-height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
    transform: rotate(-1.5deg);
    column-span: all;
    -webkit-column-span: all;
}

.cell-divider-tilt {
    transform: rotate(1.5deg);
}

.cell-divider.is-revealed {
    transform: rotate(-1.5deg);
}

.cell-divider-tilt.is-revealed {
    transform: rotate(1.5deg);
}

.divider-text {
    font-family: "Fraunces", serif;
    font-weight: 900;
    font-variation-settings: "SOFT" 100, "WONK" 1, "opsz" 144;
    font-size: clamp(2.4rem, 5.5vw, 5.2rem);
    line-height: 1;
    color: var(--ricepaper);
    letter-spacing: 0.02em;
}

/* cell motifs (decorative SVG corners) */
.cell-motif {
    margin-top: 1rem;
    display: flex;
    justify-content: flex-end;
    opacity: 0.85;
}

.cell-motif.corner {
    position: absolute;
    bottom: 12px;
    right: 14px;
    margin: 0;
}

.cell-motif svg {
    width: 100%;
    height: auto;
    max-width: 92px;
}

/* expanded (clicked) cell */
.cell.is-expanded {
    column-span: all;
    -webkit-column-span: all;
    z-index: 12;
    box-shadow: 14px 14px 0 var(--sumi);
    background: var(--hanji);
    transform: none !important;
}

.cell.is-expanded .cell-body {
    column-count: 2;
    column-gap: 2.4rem;
}

@media (max-width: 1099px) {
    .cell.is-expanded .cell-body {
        column-count: 1;
    }
}

.masonry.has-expanded .cell:not(.is-expanded) {
    opacity: 0.35;
    transition: opacity 380ms var(--ease-quiet);
}

/* hovered marginalia spring (when an anchor is active) */
.cell.is-anchor-hover .caveat,
.cell.is-anchor-hover .caveat-large {
    transition: transform 420ms var(--ease-spring);
    transform: translateX(-12px) rotate(-1.6deg) scale(1.04);
}

/* ---------- Page footer ---------- */
.page-footer {
    position: relative;
    z-index: 5;
    padding: 2rem clamp(1.4rem, 5vw, 5rem) 4rem;
    padding-left: calc(var(--rail-x) + 4.5rem);
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 1.4rem;
    border-top: 2px dotted var(--hemp);
    margin-top: 3rem;
}

.footer-mark {
    font-family: "Fraunces", serif;
    font-weight: 900;
    font-variation-settings: "SOFT" 100, "WONK" 1;
    font-size: 1.6rem;
    color: var(--terracotta);
}

.footer-meta {
    font-family: "Caveat", cursive;
    font-weight: 600;
    font-size: 1.15rem;
    color: var(--nutmeg);
    transform: rotate(-0.8deg);
    display: inline-block;
}

@media (max-width: 719px) {
    .page-footer {
        padding-left: calc(var(--rail-x) + 1.4rem);
    }
}

/* ---------- Hidden SVG sprite ---------- */
.svg-sprite {
    position: absolute;
    width: 0;
    height: 0;
    overflow: hidden;
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
    .cell {
        transition: opacity 200ms ease;
        transform: none !important;
    }
    .cell.is-revealed {
        opacity: 1;
    }
    .masthead-title {
        transition: none;
    }
    html {
        scroll-behavior: auto;
    }
}
