/* munju.wiki — first principles
   palette: deep-burgundy / parchment / mixed-media blue / highlight gold
   layout: broken-grid + grain texture + scroll-triggered border framing
*/

:root {
  --wine-dark: #4A1028;
  --parchment: #F5EDE0;
  --grid-rule: #6A3048;
  --media-blue: #486898;
  --grain-warm: #C8A888;
  --highlight-gold: #D8B058;
  --entry-cream: #EDE4D4;

  --font-mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --font-serif: "Source Serif 4", "Source Serif Pro", Georgia, "Times New Roman", serif;

  --grain-opacity: 0.14;
  --grid-step: 80px;
}

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

html, body {
  background: var(--wine-dark);
  color: var(--parchment);
  font-family: var(--font-serif);
  font-size: 16px;
  line-height: 1.85;
  overflow-x: hidden;
  scroll-behavior: smooth;
}

body {
  position: relative;
  min-height: 100vh;
  padding-bottom: 0;
}

/* ============================================================
   GRAIN OVERLAY (global film-grain documentary texture)
   ============================================================ */
.grain-defs {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.grain-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9000;
  opacity: var(--grain-opacity);
  mix-blend-mode: overlay;
  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.7' numOctaves='2' seed='7' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.78  0 0 0 0 0.66  0 0 0 0 0.53  0 0 0 0.55 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
  background-size: 220px 220px;
  background-repeat: repeat;
  transition: opacity 600ms ease;
}

/* a second, heavier grain layer for documentary depth */
.grain-overlay::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='180' height='180'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' seed='12' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.85  0 0 0 0 0.69  0 0 0 0 0.35  0 0 0 0.45 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
  background-size: 180px 180px;
  opacity: 0.55;
  mix-blend-mode: soft-light;
}

/* ============================================================
   GRID LINES (drawn structure that content violates)
   ============================================================ */
.grid-lines {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  z-index: 1;
  pointer-events: none;
  opacity: 0.22;
}

.grid-lines line {
  stroke: var(--grid-rule);
  stroke-width: 1;
  stroke-dasharray: 1200;
  stroke-dashoffset: 1200;
}

.grid-lines.drawn line {
  animation: drawLine 1000ms cubic-bezier(.6,.05,.2,1) forwards;
}

.grid-lines.drawn line:nth-child(2n)  { animation-delay: 80ms; }
.grid-lines.drawn line:nth-child(3n)  { animation-delay: 160ms; }
.grid-lines.drawn line:nth-child(5n)  { animation-delay: 240ms; }
.grid-lines.drawn line:nth-child(7n)  { animation-delay: 320ms; }

@keyframes drawLine {
  to { stroke-dashoffset: 0; }
}

/* ============================================================
   TITLE GRID-BREAK (100vh hero with off-center title)
   ============================================================ */
.title-grid-break {
  position: relative;
  width: 100%;
  height: 100vh;
  min-height: 620px;
  z-index: 5;
  overflow: hidden;
}

.title-domain {
  position: absolute;
  left: 30%;
  top: 40%;
  transform: translate(-30%, -50%);
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: clamp(28px, 4.5vw, 64px);
  letter-spacing: -0.02em;
  color: var(--parchment);
  opacity: 0;
  transition: opacity 600ms ease, transform 600ms ease;
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.title-domain.shown {
  opacity: 1;
  transform: translate(-30%, -50%) translateY(0);
}

.title-cursor {
  display: inline-block;
  font-family: var(--font-mono);
  font-weight: 400;
  color: var(--highlight-gold);
  animation: blink 1100ms steps(1, end) infinite;
  margin-left: 2px;
}

@keyframes blink {
  0%, 50% { opacity: 1; }
  50.01%, 100% { opacity: 0; }
}

.title-korean {
  position: absolute;
  left: 60%;
  top: 55%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  opacity: 0;
  transition: opacity 600ms ease 400ms;
}

.title-korean.shown {
  opacity: 1;
}

.korean-glyph {
  font-family: var(--font-serif);
  font-weight: 600;
  font-style: italic;
  font-size: clamp(48px, 9vw, 130px);
  line-height: 1;
  color: var(--highlight-gold);
  letter-spacing: -0.04em;
  text-shadow: 2px 2px 0 var(--grid-rule);
}

.korean-meta {
  font-family: var(--font-mono);
  font-weight: 400;
  font-size: 12px;
  color: var(--grain-warm);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.title-meta {
  position: absolute;
  left: 8%;
  bottom: 8%;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--grain-warm);
  opacity: 0;
  transition: opacity 700ms ease 900ms;
}

.title-meta.shown { opacity: 1; }

.title-meta .meta-line { display: block; letter-spacing: 0.04em; }

.title-diagram {
  position: absolute;
  right: 6%;
  top: 12%;
  width: clamp(140px, 16vw, 220px);
  height: auto;
  color: var(--grain-warm);
  opacity: 0;
  transition: opacity 800ms ease 1200ms;
}

.title-diagram.shown { opacity: 0.85; }

/* ============================================================
   WIKI BODY — broken-grid composition
   ============================================================ */
.wiki-body {
  position: relative;
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  column-gap: 14px;
  row-gap: 0;
  max-width: 1400px;
  margin: 0 auto;
  padding: 96px 4vw 120px;
  z-index: 5;
}

.wiki-entry {
  position: relative;
  background: var(--entry-cream);
  color: #2a0a16;
  font-family: var(--font-serif);
  padding: 36px 38px 40px;
  border: 1px solid transparent;
  transition: border-color 400ms ease, border-width 400ms ease, opacity 500ms ease, transform 500ms ease, background 300ms ease;
  z-index: 2;
  opacity: 0;
  transform: translateY(24px);
}

.wiki-entry.appeared {
  opacity: 1;
  transform: translateY(0);
}

.wiki-entry.dimmed {
  opacity: 0.7;
}

.wiki-entry.in-focus {
  border-color: var(--highlight-gold);
  border-width: 1px;
  box-shadow:
    0 0 0 3px rgba(216, 176, 88, 0.12),
    inset 0 0 0 1px rgba(216, 176, 88, 0.18);
  opacity: 1;
}

.wiki-entry::before {
  /* per-entry grain layer */
  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='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' seed='3' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.42  0 0 0 0 0.18  0 0 0 0 0.16  0 0 0 0.18 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
  background-size: 160px 160px;
  mix-blend-mode: multiply;
  opacity: 0.55;
}

/* broken-grid placement — entries occupy off-standard column starts */
.entry-a { grid-column: 2 / span 6; margin-top: 0;     transform: translateY(24px); }
.entry-b { grid-column: 5 / span 7; margin-top: -28px; margin-right: -3vw; }
.entry-c { grid-column: 1 / span 6; margin-top: 64px;  margin-left: -3vw; }
.entry-d { grid-column: 4 / span 7; margin-top: -16px; }
.entry-e { grid-column: 2 / span 8; margin-top: 80px; }
.entry-f { grid-column: 6 / span 7; margin-top: -40px; margin-right: -2vw; }
.entry-g { grid-column: 1 / span 8; margin-top: 96px;  margin-left: -2vw; }

.wiki-entry.appeared.entry-a { transform: translateY(0); }

/* z-stacking so that overlaps look layered, not just stacked */
.entry-a { z-index: 4; }
.entry-b { z-index: 5; background: rgba(237, 228, 212, 0.93); }
.entry-c { z-index: 6; background: rgba(245, 237, 224, 0.95); }
.entry-d { z-index: 5; background: rgba(237, 228, 212, 0.94); }
.entry-e { z-index: 6; background: rgba(245, 237, 224, 0.96); }
.entry-f { z-index: 5; background: rgba(237, 228, 212, 0.94); }
.entry-g { z-index: 6; background: rgba(245, 237, 224, 0.96); }

.wiki-entry:hover {
  background: var(--parchment);
}

.entry-b:hover, .entry-d:hover, .entry-f:hover {
  background: rgba(245, 237, 224, 0.99);
}

/* shift toward grid alignment on hover */
.wiki-entry { will-change: transform; }
.entry-b:hover { transform: translateY(0) translateX(-4px); }
.entry-c:hover { transform: translateY(0) translateX(4px); }
.entry-d:hover { transform: translateY(0) translateX(-4px); }
.entry-f:hover { transform: translateY(0) translateX(-4px); }
.entry-g:hover { transform: translateY(0) translateX(4px); }

/* ENTRY METADATA */
.entry-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--grid-rule);
  letter-spacing: 0.03em;
  margin-bottom: 18px;
  padding-bottom: 12px;
  border-bottom: 1px dashed var(--grid-rule);
}

.entry-meta .meta-id   { color: var(--wine-dark); font-weight: 700; }
.entry-meta .meta-cat  { color: var(--media-blue); }
.entry-meta .meta-edit { color: var(--grain-warm); margin-left: auto; }

/* ENTRY TITLE */
.entry-title {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: clamp(22px, 2.3vw, 34px);
  letter-spacing: -0.02em;
  line-height: 1.15;
  color: var(--wine-dark);
  margin-bottom: 18px;
}

.entry-title em {
  font-family: var(--font-serif);
  font-style: italic;
  font-weight: 600;
  color: var(--media-blue);
}

/* ENTRY BODY */
.wiki-entry p {
  font-family: var(--font-serif);
  font-size: clamp(15px, 1vw, 17px);
  line-height: 1.85;
  color: #2a0a16;
  margin-bottom: 14px;
  position: relative;
  z-index: 1;
}

.wiki-entry .entry-lead {
  font-size: clamp(16px, 1.1vw, 18px);
  font-weight: 400;
  color: #2a0a16;
}

.wiki-entry em {
  font-style: italic;
  color: var(--wine-dark);
}

.wiki-entry .term {
  font-family: var(--font-mono);
  font-size: 0.9em;
  color: var(--media-blue);
  letter-spacing: 0.02em;
}

.wiki-entry .closing {
  margin-top: 24px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--grid-rule);
}

.wiki-entry .hash {
  color: var(--media-blue);
}

/* WIKI LINKS — animated underline */
.wiki-link {
  position: relative;
  color: var(--media-blue);
  text-decoration: none;
  font-weight: 600;
  background-image: linear-gradient(var(--media-blue), var(--media-blue));
  background-position: 0 100%;
  background-repeat: no-repeat;
  background-size: 0% 1px;
  transition: background-size 350ms cubic-bezier(.6,.1,.2,1), color 200ms ease;
  padding-bottom: 1px;
}

.wiki-link:hover {
  background-size: 100% 1px;
  color: var(--wine-dark);
}

/* PULL QUOTE */
.pull-quote {
  font-family: var(--font-serif);
  font-style: italic;
  font-weight: 600;
  font-size: clamp(18px, 1.6vw, 24px);
  line-height: 1.45;
  color: var(--wine-dark);
  margin: 24px 0 24px 0;
  padding: 14px 20px 14px 22px;
  border-left: 3px solid var(--highlight-gold);
  background: rgba(216, 176, 88, 0.08);
  position: relative;
  z-index: 1;
}

/* ENTRY FRAGMENT (mixed-media sidebar panels) */
.entry-fragment {
  position: absolute;
  width: 38%;
  min-width: 200px;
  max-width: 280px;
  padding: 14px 16px;
  background: rgba(74, 16, 40, 0.92);
  color: var(--parchment);
  font-family: var(--font-serif);
  font-size: 13px;
  line-height: 1.55;
  border: 1px solid var(--grid-rule);
  z-index: 8;
  transition: opacity 400ms ease, transform 400ms ease, background 300ms ease;
}

.entry-fragment::before {
  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='120' height='120'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='1.0' numOctaves='2' seed='9' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.95  0 0 0 0 0.85  0 0 0 0 0.7  0 0 0 0.4 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
  background-size: 120px 120px;
  mix-blend-mode: overlay;
  opacity: 0.6;
}

.entry-fragment:hover {
  background: rgba(74, 16, 40, 0.97);
  transform: translateY(-2px);
}

.entry-fragment .frag-label {
  display: block;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.1em;
  color: var(--highlight-gold);
  margin-bottom: 6px;
  text-transform: uppercase;
}

.entry-fragment p {
  color: var(--parchment);
  font-size: 13px;
  line-height: 1.55;
  margin: 0;
}

.entry-fragment.frag-tr {
  top: -32px;
  right: -4vw;
}

.entry-fragment.frag-bl {
  bottom: -28px;
  left: -3vw;
}

/* DECORATIVE GRAIN-TEXTURED RECTANGLE */
.decorative-rect {
  position: absolute;
  width: 96px;
  height: 96px;
  top: -18px;
  left: -18px;
  background: var(--media-blue);
  z-index: 0;
  opacity: 0.7;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='120' height='120'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' seed='5' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.28  0 0 0 0 0.41  0 0 0 0 0.6  0 0 0 0.55 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
  background-blend-mode: overlay;
}

.decorative-rect.rect-alt {
  background: var(--highlight-gold);
  width: 70px;
  height: 70px;
  top: auto;
  left: auto;
  bottom: -14px;
  right: -14px;
  opacity: 0.65;
}

/* ENTRY DIAGRAMS (CSS-drawn / inline SVG accent) */
.entry-diagram {
  display: block;
  width: 100%;
  max-width: 360px;
  height: auto;
  margin: 18px 0 6px;
  color: var(--grid-rule);
  opacity: 0.85;
}

.entry-diagram.diagram-wide {
  max-width: 520px;
}

/* ============================================================
   FOOTER
   ============================================================ */
.wiki-footer {
  position: relative;
  width: 100%;
  padding: 30px 5vw 36px;
  background: var(--wine-dark);
  border-top: 1px solid var(--grid-rule);
  z-index: 5;
  font-family: var(--font-mono);
}

.footer-line {
  height: 1px;
  background: linear-gradient(to right, transparent 0%, var(--highlight-gold) 50%, transparent 100%);
  margin-bottom: 18px;
}

.footer-content {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  font-size: 12px;
  color: var(--grain-warm);
  letter-spacing: 0.04em;
}

.footer-domain { color: var(--parchment); font-weight: 700; }
.footer-mid    { color: var(--grain-warm); flex: 1; min-width: 250px; }
.footer-rev    { color: var(--media-blue); }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 880px) {
  .title-domain { left: 8%; transform: translate(0, -50%); }
  .title-domain.shown { transform: translate(0, -50%); }
  .title-korean { left: 60%; top: 65%; }
  .title-diagram { right: 4%; top: 8%; opacity: 0.6; }

  .wiki-body { grid-template-columns: 1fr; padding: 60px 4vw 90px; }
  .wiki-entry { padding: 26px 22px 30px; }

  .entry-a, .entry-b, .entry-c, .entry-d, .entry-e, .entry-f, .entry-g {
    grid-column: 1 / -1;
    margin-left: 0;
    margin-right: 0;
  }
  .entry-b { margin-top: -10px; margin-left: 4vw; }
  .entry-c { margin-top: 30px; margin-right: 4vw; }
  .entry-d { margin-top: -8px; margin-left: 3vw; }
  .entry-e { margin-top: 40px; }
  .entry-f { margin-top: -16px; margin-left: 3vw; }
  .entry-g { margin-top: 40px; }

  .entry-fragment.frag-tr { right: -4vw; top: -20px; width: 60%; }
  .entry-fragment.frag-bl { left: -3vw; bottom: -20px; width: 60%; }
}

@media (max-width: 520px) {
  .entry-fragment { position: relative; width: 100%; max-width: none; margin-top: 18px; }
  .entry-fragment.frag-tr, .entry-fragment.frag-bl { top: auto; bottom: auto; left: 0; right: 0; }
  .title-meta { left: 5%; right: 5%; bottom: 5%; }
}
