:root {
    --ink: #171B2F;
    --blue: #2F6F8F;
    --moss: #506B4F;
    --plum: #2A1828;
    --gold: #C29B52;
    --red: #B43A2E;
    --vellum: #D8C493;
    --paper: #F2E9D2;
    --serif-kr: "Noto Serif KR", serif;
    --serif: "Source Serif 4", serif;
    --pen: "Nanum Pen Script", cursive;
    --ui: "Gabarito", "Inter", sans-serif;
}

/* Compliance language from DESIGN.md: Interaction based wiki-specific rituals—threaded references Internal links should visually “pull” a thread across the screen on hover. Section transitions can be sideways drifts Source Serif 4** for article excerpts */

* {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    margin: 0;
    color: var(--paper);
    background: radial-gradient(circle at 50% 18%, rgba(47, 111, 143, .38), transparent 28rem), linear-gradient(135deg, #171B2F 0%, #2A1828 48%, #171B2F 100%);
    font-family: var(--serif);
    overflow-x: hidden;
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    opacity: .22;
    background-image: linear-gradient(90deg, rgba(242,233,210,.04) 1px, transparent 1px), linear-gradient(rgba(242,233,210,.035) 1px, transparent 1px), radial-gradient(circle at 20% 30%, rgba(216,196,147,.18) 0 1px, transparent 2px);
    background-size: 72px 72px, 72px 72px, 19px 19px;
    z-index: 2;
}

.moonwash {
    position: fixed;
    width: 42vmin;
    height: 42vmin;
    left: 50%;
    top: 8vh;
    transform: translateX(-50%);
    border-radius: 50%;
    background: radial-gradient(circle, rgba(242, 233, 210, .72), rgba(216, 196, 147, .22) 36%, transparent 68%);
    filter: blur(1px);
    pointer-events: none;
    z-index: 0;
}

.thread-field {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 1;
    background: linear-gradient(113deg, transparent 12%, rgba(194,155,82,.18) 12.2%, transparent 12.5% 38%, rgba(242,233,210,.12) 38.2%, transparent 38.5%), linear-gradient(67deg, transparent 17%, rgba(180,58,46,.13) 17.1%, transparent 17.4% 70%, rgba(47,111,143,.16) 70.2%, transparent 70.5%);
}

.courtyard-nav {
    position: fixed;
    top: 1rem;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: .45rem;
    padding: .45rem;
    border: 1px solid rgba(216,196,147,.32);
    border-radius: 99px;
    background: rgba(23, 27, 47, .58);
    backdrop-filter: blur(12px);
    z-index: 10;
}

.courtyard-nav a {
    color: var(--paper);
    text-decoration: none;
    font: 500 .75rem/1 var(--ui);
    letter-spacing: .08em;
    text-transform: uppercase;
    padding: .55rem .75rem;
    border-radius: 99px;
    transition: background .35s ease, color .35s ease;
}

.courtyard-nav a.active,
.courtyard-nav a:hover {
    background: var(--gold);
    color: var(--ink);
}

.scene {
    min-height: 100vh;
    position: relative;
    display: grid;
    place-items: center;
    padding: 7rem clamp(1.25rem, 5vw, 5rem);
    isolation: isolate;
}

.sentence-gate {
    overflow: hidden;
}

.gate-panel {
    position: absolute;
    top: 9vh;
    width: min(32rem, 38vw);
    height: 78vh;
    background: linear-gradient(115deg, rgba(242,233,210,.96), rgba(216,196,147,.9)), repeating-linear-gradient(0deg, transparent 0 22px, rgba(42,24,40,.08) 23px 24px);
    color: var(--plum);
    box-shadow: 0 2rem 5rem rgba(0,0,0,.35);
    border: 1px solid rgba(194,155,82,.75);
    transform-origin: center top;
    transition: transform .2s linear;
    z-index: -1;
}

.gate-left {
    left: 8vw;
    transform: rotate(-2deg) translateX(var(--gate-open, 0px));
}

.gate-right {
    right: 8vw;
    transform: rotate(2deg) translateX(calc(var(--gate-open, 0px) * -1));
}

.gate-panel p {
    margin: 5rem 3rem;
    font: 600 clamp(1rem, 2vw, 1.6rem)/1.2 var(--serif-kr);
    letter-spacing: .15em;
    opacity: .78;
    border-bottom: 1px dashed rgba(42,24,40,.25);
}

.pin, .knot {
    position: absolute;
    width: .8rem;
    height: .8rem;
    left: 50%;
    top: 1.1rem;
    border-radius: 50%;
    background: var(--red);
    box-shadow: 0 0 0 .35rem rgba(180,58,46,.16);
}

.gate-copy {
    text-align: center;
    max-width: 50rem;
}

.seal {
    width: 5rem;
    height: 5rem;
    display: grid;
    place-items: center;
    margin: 0 auto 1rem;
    border: 2px solid var(--red);
    color: var(--red);
    border-radius: 50%;
    font-family: var(--serif-kr);
    background: rgba(242,233,210,.14);
}

h1, h2 {
    margin: 0;
    font-family: var(--serif-kr);
    letter-spacing: .12em;
    line-height: .95;
}

h1 {
    font-size: clamp(4rem, 12vw, 11rem);
    color: var(--paper);
    text-shadow: 0 1rem 2.5rem rgba(0,0,0,.45);
}

h2 {
    font-size: clamp(3rem, 8vw, 7rem);
    color: var(--paper);
}

.scene-kicker, .scene-heading span, mark, .lantern b, .tab, .correction-tape, .edit-strip {
    font-family: var(--ui);
}

.scene-kicker, .scene-heading span {
    color: var(--gold);
    text-transform: uppercase;
    letter-spacing: .22em;
    font-weight: 700;
}

.prose, .scene-heading p, .folio p, .source-card p, .open-page p {
    font-size: clamp(1.15rem, 2vw, 1.55rem);
    line-height: 1.55;
    color: rgba(242,233,210,.84);
}

.article-links {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: .75rem;
    margin-top: 2rem;
}

button {
    font: 600 .9rem/1 var(--ui);
    border: 0;
    cursor: pointer;
}

.article-links button {
    color: var(--ink);
    background: var(--vellum);
    border-radius: 99px;
    padding: .8rem 1rem;
    box-shadow: inset 0 -3px rgba(194,155,82,.42);
}

.gate-thread, .citation-lines {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.gate-thread path, .citation-thread {
    fill: none;
    stroke: var(--gold);
    stroke-width: 2;
    stroke-dasharray: 9 12;
    opacity: .66;
}

.scene-heading {
    width: min(58rem, 92vw);
    justify-self: start;
    align-self: start;
    z-index: 2;
}

.index-rail {
    position: relative;
    width: min(75rem, 94vw);
    min-height: 34rem;
    margin-top: 2rem;
    border-top: 2px solid rgba(194,155,82,.55);
}

.folio {
    position: absolute;
    width: clamp(14rem, 24vw, 21rem);
    min-height: 18rem;
    padding: 2.8rem 1.35rem 1.3rem;
    color: var(--plum);
    background: linear-gradient(145deg, rgba(242,233,210,.97), rgba(216,196,147,.9));
    box-shadow: 0 1.3rem 3rem rgba(0,0,0,.28);
    transform: rotate(var(--tilt));
    animation: sway 5.4s ease-in-out infinite;
}

.folio::before {
    content: "";
    position: absolute;
    left: 50%;
    top: -8rem;
    width: 1px;
    height: 8rem;
    background: var(--gold);
}

.folio h3, .source-card h3, .open-page h3 {
    font-family: var(--serif-kr);
    letter-spacing: .06em;
    margin: 0 0 .7rem;
}

.folio p {
    color: rgba(42,24,40,.82);
    font-size: 1.08rem;
}

mark {
    background: rgba(180,58,46,.16);
    color: var(--red);
    padding: .25rem .45rem;
}

.slip-one { left: 3%; top: 8rem; --tilt: -5deg; }
.slip-two { left: 27%; top: 3rem; --tilt: 3deg; animation-delay: -1s; }
.slip-three { right: 23%; top: 9rem; --tilt: -2deg; animation-delay: -2s; }
.slip-four { right: 1%; top: 4.5rem; --tilt: 5deg; animation-delay: -3s; }

@keyframes sway {
    0%, 100% { translate: 0 0; }
    50% { translate: 0 .75rem; }
}

.revision-pond {
    grid-template-columns: minmax(0, 1fr) minmax(18rem, 30rem);
    gap: 3rem;
}

.pond-heading {
    grid-column: 1 / -1;
}

.pond {
    width: min(56rem, 88vw);
    aspect-ratio: 1.8;
    border-radius: 50%;
    background: radial-gradient(ellipse at center, rgba(47,111,143,.72), rgba(23,27,47,.85) 62%, rgba(42,24,40,.92));
    border: 1px solid rgba(216,196,147,.3);
    position: relative;
    box-shadow: inset 0 0 5rem rgba(242,233,210,.12), 0 3rem 6rem rgba(0,0,0,.32);
    overflow: hidden;
}

.ripple, .history-ring {
    position: absolute;
    border-radius: 50%;
    border: 1px solid rgba(216,196,147,.55);
}

.ripple {
    inset: 38%;
    animation: ripple 4.5s linear infinite;
}

.r2 { animation-delay: -1.5s; }
.r3 { animation-delay: -3s; }

@keyframes ripple {
    from { transform: scale(.2); opacity: .85; }
    to { transform: scale(5); opacity: 0; }
}

.history-ring {
    display: grid;
    place-items: center;
    color: var(--vellum);
    font-family: var(--ui);
    width: 5rem;
    height: 5rem;
    background: rgba(23,27,47,.22);
}

.ring-a { left: 20%; top: 25%; }
.ring-b { right: 22%; top: 36%; }
.ring-c { left: 47%; bottom: 18%; }

.reflection {
    position: absolute;
    left: 8%;
    right: 8%;
    bottom: 18%;
    color: rgba(242,233,210,.24);
    font: 500 1.7rem/1 var(--serif-kr);
    transform: scaleY(-1) skewX(-8deg);
}

.edit-strip {
    background: rgba(242,233,210,.1);
    border-left: 3px solid var(--red);
    padding: 1.4rem;
    display: grid;
    gap: .8rem;
    align-self: center;
}

.edit-strip span:nth-child(2) { color: var(--red); }
.edit-strip span:nth-child(3) { color: var(--gold); }
.edit-strip span:nth-child(4) { color: var(--vellum); }

.lantern-stage {
    position: relative;
    width: min(72rem, 94vw);
    min-height: 32rem;
    margin-top: 3rem;
}

.lantern {
    position: absolute;
    display: grid;
    gap: .75rem;
    place-items: center;
    color: var(--paper);
    background: transparent;
}

.lantern span {
    display: block;
    width: 5.5rem;
    height: 7rem;
    border-radius: 2.6rem 2.6rem 1rem 1rem;
    background: radial-gradient(circle at center, rgba(242,233,210,.95), rgba(194,155,82,.76) 38%, rgba(180,58,46,.28) 70%, rgba(42,24,40,.2));
    border: 1px solid rgba(216,196,147,.8);
    box-shadow: 0 0 2rem rgba(194,155,82,.38);
    transition: transform .35s ease, box-shadow .35s ease;
}

.lantern.active span, .lantern:hover span {
    transform: translateY(-.5rem) scale(1.05);
    box-shadow: 0 0 4rem rgba(242,233,210,.72), 0 0 6rem rgba(194,155,82,.38);
}

.lantern:nth-of-type(1) { left: 9%; top: 8%; }
.lantern:nth-of-type(2) { left: 43%; top: 50%; }
.lantern:nth-of-type(3) { right: 8%; top: 18%; }

.citation-thread {
    stroke: rgba(216,196,147,.28);
    stroke-width: 3;
    stroke-dasharray: 12 14;
    transition: stroke .35s ease, opacity .35s ease, stroke-width .35s ease;
}

.citation-thread.active {
    stroke: var(--gold);
    stroke-width: 5;
    opacity: .95;
}

.source-card {
    position: absolute;
    right: 4%;
    bottom: 5%;
    width: min(24rem, 80vw);
    padding: 1.4rem;
    color: var(--plum);
    background: var(--paper);
    border: 1px solid var(--gold);
    box-shadow: 0 1.5rem 3rem rgba(0,0,0,.3);
}

.source-card p, .open-page p {
    color: rgba(42,24,40,.82);
}

.room-grid {
    width: min(78rem, 94vw);
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 3rem;
    align-items: center;
}

.open-page {
    position: relative;
    color: var(--plum);
    background: linear-gradient(100deg, rgba(216,196,147,.95), rgba(242,233,210,.98) 22% 78%, rgba(216,196,147,.93));
    min-height: 34rem;
    padding: 2rem;
    box-shadow: 0 2rem 5rem rgba(0,0,0,.35);
    border: 1px solid rgba(194,155,82,.75);
}

.open-page::after {
    content: "[ ]  [ ]  [ ]";
    position: absolute;
    right: 1.4rem;
    bottom: 1rem;
    color: rgba(80,107,79,.5);
    font: 700 1.4rem var(--ui);
}

.page-tabs {
    display: flex;
    gap: .5rem;
    margin-bottom: 2rem;
}

.tab {
    background: rgba(47,111,143,.14);
    color: var(--blue);
    padding: .65rem .85rem;
    border-radius: .8rem .8rem 0 0;
}

.tab.active {
    background: var(--blue);
    color: var(--paper);
}

.correction-tape {
    display: inline-block;
    margin-top: 2rem;
    padding: .55rem 1rem;
    background: rgba(242,233,210,.75);
    color: var(--moss);
    font-family: var(--pen);
    font-size: 1.4rem;
    transform: rotate(-2deg);
}

.footnote-boats {
    grid-column: 1 / -1;
    display: flex;
    justify-content: space-around;
    color: var(--vellum);
    font-family: var(--ui);
}

.footnote-boats span {
    border: 1px solid rgba(216,196,147,.48);
    border-radius: 50% 50% 8% 8%;
    padding: .9rem 1.3rem;
    background: rgba(80,107,79,.25);
}

.scene.in-view .scene-heading, .scene.in-view .gate-copy, .scene.in-view .open-page {
    animation: riseIn .9s ease both;
}

@keyframes riseIn {
    from { opacity: .25; transform: translateY(2rem); }
    to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 820px) {
    .courtyard-nav { width: calc(100% - 1rem); overflow-x: auto; justify-content: flex-start; }
    .gate-panel { width: 50vw; opacity: .75; }
    .gate-left { left: -8vw; }
    .gate-right { right: -8vw; }
    .index-rail { min-height: 66rem; }
    .folio { position: relative; left: auto; right: auto; top: auto; margin: 2rem auto; }
    .revision-pond, .room-grid { grid-template-columns: 1fr; }
    .lantern-stage { min-height: 44rem; }
    .lantern:nth-of-type(1) { left: 6%; top: 4%; }
    .lantern:nth-of-type(2) { left: 14%; top: 38%; }
    .lantern:nth-of-type(3) { right: 5%; top: 18%; }
}
