/* ============================================
   namu.club — Victorian Data Naturalism
   Palette: Terracotta-Warm
   Typography: Eclectic-Hybrid
   ============================================ */

/* --- CSS Custom Properties --- */
:root {
    /* Palette */
    --aged-vellum: #F5EDE0;
    --warm-parchment: #EDE3D0;
    --terracotta-clay: #C1694F;
    --oxidized-copper: #8B6F47;
    --ink-dark: #2C1810;
    --faded-ink: #5C4033;
    --botanical-green: #5B7C5A;
    --pressed-indigo: #4A5568;
    --gilded-amber: #C9A961;
    --gilded-amber-light: #DFC07A;
    --mahogany-shadow: #1A0F0A;

    /* Dynamic warmth */
    --page-warmth: 0%;

    /* Typography scale */
    --hero-size: clamp(3rem, 8vw, 7rem);
    --heading-size: clamp(1.6rem, 3.5vw, 2.8rem);
    --card-title-size: clamp(1.1rem, 2.2vw, 1.6rem);
    --body-size: clamp(0.95rem, 1.8vw, 1.15rem);
    --accent-size: clamp(0.7rem, 1.2vw, 0.85rem);
    --caveat-size: clamp(0.85rem, 1.5vw, 1.1rem);
}

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

html {
    scroll-behavior: smooth;
    overflow-x: hidden;
}

body {
    font-family: 'Lora', Georgia, serif;
    font-size: var(--body-size);
    font-weight: 400;
    line-height: 1.72;
    letter-spacing: 0.01em;
    color: var(--ink-dark);
    background: linear-gradient(180deg, var(--aged-vellum) 0%, var(--warm-parchment) 100%);
    background-color: color-mix(in srgb, var(--aged-vellum), #E8D9C0 var(--page-warmth));
    min-height: 100vh;
    overflow-x: hidden;
}

/* Paper texture overlay */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9998;
    opacity: 0.03;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence baseFrequency='0.65' numOctaves='4' type='fractalNoise'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23n)'/%3E%3C/svg%3E");
}

.svg-defs {
    position: absolute;
    width: 0;
    height: 0;
    overflow: hidden;
}

/* --- Entry Screen --- */
#entry-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: var(--mahogany-shadow);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
}

#entry-line {
    position: absolute;
    width: 60vw;
    height: 0.5px;
    background: var(--gilded-amber);
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scaleX(0);
    transform-origin: center;
    transition: transform 1000ms ease-out;
}

#entry-line.visible {
    transform: translate(-50%, -50%) scaleX(1);
}

#entry-split-top,
#entry-split-bottom {
    position: absolute;
    left: 0;
    width: 100%;
    height: 50%;
    background: var(--mahogany-shadow);
    z-index: 10001;
    transition: transform 1200ms cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

#entry-split-top {
    top: 0;
}

#entry-split-bottom {
    bottom: 0;
}

#entry-split-top.split {
    transform: translateY(-100%);
}

#entry-split-bottom.split {
    transform: translateY(100%);
}

#entry-title {
    position: relative;
    z-index: 10002;
    font-family: 'Cormorant Garamond', 'Georgia', serif;
    font-weight: 700;
    font-size: var(--hero-size);
    letter-spacing: 0.06em;
    color: var(--aged-vellum);
    font-feature-settings: "liga" 1, "onum" 1;
    white-space: nowrap;
}

.entry-letter {
    display: inline-block;
    opacity: 0;
    transform: translateY(12px);
    transition: opacity 400ms ease-out, transform 400ms ease-out;
}

.entry-letter.visible {
    opacity: 1;
    transform: translateY(0);
}

#entry-screen.fade-out {
    opacity: 0;
    pointer-events: none;
    transition: opacity 800ms ease-out;
}

/* --- Main Page --- */
#main-page {
    opacity: 0;
    position: relative;
    min-height: 100vh;
    transition: opacity 800ms ease-out;
}

#main-page.visible {
    opacity: 1;
}

/* --- Herbarium Page Grid --- */
.herbarium-page {
    display: grid;
    grid-template-columns: [margin-left] 80px [content-start] 1fr [content-end] 80px [margin-right];
    grid-template-rows: [top-margin] 60px [plate-area] auto;
    min-height: 100vh;
    max-width: 1200px;
    margin: 0 auto;
    padding-bottom: 60px;
}

.herbarium-page > * {
    grid-column: content-start / content-end;
}

/* --- Ornamental Borders --- */
.ornamental-border {
    position: fixed;
    top: 0;
    height: 100vh;
    width: 80px;
    z-index: 10;
    pointer-events: none;
    opacity: 0;
    transition: opacity 800ms ease-out;
}

.ornamental-border.visible {
    opacity: 1;
}

.ornamental-border--left {
    left: 0;
}

.ornamental-border--right {
    right: 0;
}

.ornamental-border svg {
    width: 100%;
    height: 100%;
}

/* --- Corner Ornaments --- */
.corner-ornament {
    position: fixed;
    width: 80px;
    height: 80px;
    z-index: 11;
    pointer-events: none;
    opacity: 0;
    transition: opacity 800ms ease-out;
}

.corner-ornament.visible {
    opacity: 1;
}

.corner-ornament--tl {
    top: 0;
    left: 0;
}

.corner-ornament--tr {
    top: 0;
    right: 0;
}

/* --- Root Map Toggle --- */
#root-map-toggle {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 1px solid var(--oxidized-copper);
    background: radial-gradient(circle at 40% 35%, var(--gilded-amber), var(--oxidized-copper));
    box-shadow: inset 0 1px 2px rgba(0,0,0,0.4), 0 2px 8px rgba(26,15,10,0.2);
    cursor: pointer;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: transform 300ms ease, box-shadow 300ms ease;
}

#root-map-toggle:hover {
    transform: scale(1.08);
    box-shadow: inset 0 1px 2px rgba(0,0,0,0.4), 0 4px 16px rgba(26,15,10,0.3);
}

/* --- Hero Section --- */
.hero-section {
    grid-row: plate-area;
    text-align: center;
    padding: 80px 20px 60px;
}

.hero-title {
    font-family: 'Cormorant Garamond', 'Georgia', serif;
    font-weight: 700;
    font-size: var(--hero-size);
    letter-spacing: 0.06em;
    color: var(--ink-dark);
    font-feature-settings: "liga" 1, "onum" 1;
    margin-bottom: 16px;
    line-height: 1.1;
}

.hero-subtitle {
    font-size: var(--caveat-size);
    color: var(--faded-ink);
    margin-bottom: 32px;
}

.hero-decoration {
    display: flex;
    justify-content: center;
    gap: 32px;
    align-items: center;
    opacity: 0.5;
}

/* --- Specimen Cards --- */
.specimen-card {
    position: relative;
    margin: 24px 0;
}

.specimen-card[data-row-span="2"] {
    grid-row: span 2;
}

.specimen-card[data-row-span="3"] {
    grid-row: span 3;
}

.specimen-card[data-row-span="4"] {
    grid-row: span 4;
}

.specimen-tab {
    position: absolute;
    top: -1px;
    left: 16px;
    background: var(--warm-parchment);
    border: 2px solid var(--terracotta-clay);
    border-bottom: none;
    padding: 2px 10px;
    z-index: 2;
}

.specimen-number {
    font-family: 'Inconsolata', 'Courier New', monospace;
    font-weight: 400;
    font-size: var(--accent-size);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--faded-ink);
}

.specimen-border-outer {
    border: 2px solid var(--terracotta-clay);
    padding: 3px;
    background: var(--warm-parchment);
    transition: border-color 300ms ease, transform 300ms ease, box-shadow 300ms ease;
    /* Laid lines texture */
    background-image: repeating-linear-gradient(
        0deg,
        transparent,
        transparent 3px,
        rgba(44,24,16,0.02) 3px,
        rgba(44,24,16,0.02) 4px
    );
    background-color: var(--warm-parchment);
}

.specimen-card:hover .specimen-border-outer {
    border-color: var(--terracotta-clay);
    transform: translateY(-3px);
    box-shadow: 0 8px 24px rgba(26,15,10,0.12);
}

.specimen-card:hover .specimen-tab {
    border-color: var(--terracotta-clay);
}

.specimen-card:hover .specimen-number {
    animation: tab-pulse 200ms ease-out;
}

@keyframes tab-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

.specimen-border-inner {
    border: 1px solid var(--oxidized-copper);
    padding: 28px 24px;
    transition: border-color 300ms ease;
}

.specimen-card:hover .specimen-border-inner {
    border-color: var(--terracotta-clay);
}

.specimen-title {
    font-family: 'Cormorant Garamond', 'Georgia', serif;
    font-weight: 600;
    font-size: var(--card-title-size);
    letter-spacing: 0.04em;
    color: var(--ink-dark);
    margin-bottom: 12px;
    font-feature-settings: "liga" 1, "onum" 1;
}

.specimen-body {
    font-family: 'Lora', Georgia, serif;
    font-size: var(--body-size);
    color: var(--ink-dark);
    line-height: 1.72;
    margin-bottom: 16px;
}

.specimen-expanded-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 400ms ease;
}

.specimen-card.expanded .specimen-expanded-content {
    max-height: 600px;
}

.specimen-note {
    color: var(--faded-ink);
    margin-top: 12px;
    font-style: italic;
}

/* --- Caveat text --- */
.caveat-text {
    font-family: 'Caveat', cursive;
    font-weight: 400;
    font-size: var(--caveat-size);
}

/* --- Data Visualizations --- */
.data-viz {
    margin: 20px auto;
    text-align: center;
}

.data-label {
    display: block;
    color: var(--faded-ink);
    margin-top: 8px;
}

/* Tree Ring Chart */
.tree-ring-chart {
    max-width: 260px;
}

.tree-ring-svg {
    width: 100%;
    height: auto;
}

.tree-ring {
    stroke-dasharray: 1000;
    stroke-dashoffset: 1000;
    transition: stroke-dashoffset 2000ms ease-out;
}

.tree-ring.animated {
    stroke-dashoffset: 0;
}

/* Dendrogram */
.dendrogram-chart {
    max-width: 320px;
}

.dendrogram-svg {
    width: 100%;
    height: auto;
}

.dendro-branch {
    stroke-dasharray: 500;
    stroke-dashoffset: 500;
    transition: stroke-dashoffset 1500ms ease-out;
}

.dendro-branch.animated {
    stroke-dashoffset: 0;
}

.dendro-leaf {
    opacity: 0;
    transform-origin: center;
    transition: opacity 500ms ease-out;
}

.dendro-leaf.animated {
    opacity: 0.8;
}

/* Root Network */
.root-network-chart {
    max-width: 300px;
}

.root-network-svg {
    width: 100%;
    height: auto;
}

.root-path {
    stroke-dasharray: 500;
    stroke-dashoffset: 500;
    transition: stroke-dashoffset 2500ms ease-out;
}

.root-path.animated {
    stroke-dashoffset: 0;
}

/* Season Chart */
.season-chart {
    max-width: 280px;
}

.season-svg {
    width: 100%;
    height: auto;
}

.chart-label {
    font-family: 'Inconsolata', 'Courier New', monospace;
    font-size: 9px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    fill: var(--faded-ink);
}

.season-bar {
    transform-origin: bottom;
    transform: scaleY(0);
    transition: transform 800ms ease-out;
}

.season-bar.animated {
    transform: scaleY(1);
}

/* --- Organic Blobs --- */
.organic-blobs-container {
    position: relative;
    width: 200px;
    height: 160px;
    margin: 20px auto;
}

.organic-blob {
    position: absolute;
    width: 100px;
    height: 100px;
    animation: blob-morph 12s ease-in-out infinite;
}

.blob-green {
    background: rgba(91, 124, 90, 0.12);
    border-radius: 40% 60% 55% 45% / 55% 40% 60% 50%;
    top: 10px;
    left: 10px;
    animation-delay: 0s;
}

.blob-terracotta {
    background: rgba(193, 105, 79, 0.08);
    border-radius: 55% 45% 40% 60% / 45% 55% 50% 40%;
    top: 30px;
    left: 50px;
    animation-delay: -4s;
}

.blob-amber {
    background: rgba(201, 169, 97, 0.06);
    border-radius: 50% 50% 45% 55% / 60% 40% 55% 45%;
    top: 20px;
    left: 80px;
    animation-delay: -8s;
}

@keyframes blob-morph {
    0% {
        border-radius: 40% 60% 55% 45% / 55% 40% 60% 50%;
        transform: translate(0, 0) scale(1);
    }
    25% {
        border-radius: 55% 45% 60% 40% / 40% 60% 45% 55%;
        transform: translate(5px, -5px) scale(1.05);
    }
    50% {
        border-radius: 45% 55% 40% 60% / 60% 45% 55% 40%;
        transform: translate(-3px, 3px) scale(0.98);
    }
    75% {
        border-radius: 60% 40% 50% 50% / 50% 55% 40% 60%;
        transform: translate(2px, -2px) scale(1.02);
    }
    100% {
        border-radius: 40% 60% 55% 45% / 55% 40% 60% 50%;
        transform: translate(0, 0) scale(1);
    }
}

/* --- Brass Drawer Pulls --- */
.brass-pull {
    position: absolute;
    bottom: 16px;
    right: 16px;
    display: flex;
    align-items: center;
    gap: 0;
    cursor: pointer;
    z-index: 5;
}

.brass-pull-knob {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: radial-gradient(circle at 40% 35%, var(--gilded-amber), var(--oxidized-copper));
    box-shadow: inset 0 1px 2px rgba(0,0,0,0.4);
    transition: background 200ms ease, transform 300ms ease;
    flex-shrink: 0;
}

.brass-pull:hover .brass-pull-knob {
    background: radial-gradient(circle at 40% 35%, var(--gilded-amber-light), var(--oxidized-copper));
    transform: rotate(15deg);
}

.brass-pull-label {
    font-family: 'Inconsolata', 'Courier New', monospace;
    font-weight: 400;
    font-size: var(--accent-size);
    color: var(--faded-ink);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    max-width: 0;
    overflow: hidden;
    white-space: nowrap;
    transition: max-width 250ms ease-out, padding 250ms ease-out;
    padding-left: 0;
}

.brass-pull:hover .brass-pull-label {
    max-width: 120px;
    padding-left: 8px;
}

/* --- Herbarium Index --- */
.herbarium-index {
    margin: 16px 0;
}

.index-entry {
    display: flex;
    align-items: baseline;
    gap: 12px;
    padding: 6px 0;
    border-bottom: 1px solid rgba(139,111,71,0.15);
}

.index-number {
    font-family: 'Inconsolata', 'Courier New', monospace;
    font-weight: 700;
    font-size: var(--accent-size);
    letter-spacing: 0.08em;
    color: var(--faded-ink);
    min-width: 28px;
}

.index-name {
    font-family: 'Lora', Georgia, serif;
    font-style: italic;
    color: var(--ink-dark);
    flex: 1;
}

.index-date {
    font-family: 'Inconsolata', 'Courier New', monospace;
    font-weight: 400;
    font-size: var(--accent-size);
    letter-spacing: 0.08em;
    color: var(--oxidized-copper);
}

/* --- Marginal Decorations --- */
.marginal-decoration {
    opacity: 0.25;
    grid-column: content-start / content-end;
    display: flex;
    justify-content: flex-end;
    padding: 10px 0;
}

/* --- Marginal Index --- */
.marginal-index {
    position: fixed;
    left: 20px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    gap: 16px;
    z-index: 100;
}

.marginal-index-link {
    font-family: 'Cormorant Garamond', 'Georgia', serif;
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--oxidized-copper);
    text-decoration: none;
    font-variant: small-caps;
    letter-spacing: 0.05em;
    transition: color 200ms ease;
    line-height: 1;
}

.marginal-index-link:hover {
    color: var(--terracotta-clay);
}

/* --- Annotation Strip --- */
.annotation-strip-section {
    grid-column: margin-left / margin-right;
    margin-top: 40px;
    padding: 20px 0;
    background: linear-gradient(180deg, rgba(237,227,208,0.4) 0%, rgba(245,237,224,0.6) 100%);
    border-top: 1px solid rgba(139,111,71,0.2);
    border-bottom: 1px solid rgba(139,111,71,0.2);
    min-height: 120px;
}

.annotation-strip-inner {
    display: flex;
    gap: 40px;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    padding: 10px 40px;
    -webkit-overflow-scrolling: touch;
}

.annotation-strip-inner::-webkit-scrollbar {
    height: 4px;
}

.annotation-strip-inner::-webkit-scrollbar-track {
    background: rgba(139,111,71,0.08);
}

.annotation-strip-inner::-webkit-scrollbar-thumb {
    background: rgba(139,111,71,0.2);
    border-radius: 2px;
}

.annotation-item {
    scroll-snap-align: start;
    flex-shrink: 0;
    min-width: 160px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.annotation-item .caveat-text {
    color: var(--faded-ink);
    max-width: 200px;
}

.annotation-bob {
    animation: annotation-bob 4s ease-in-out infinite;
}

.annotation-bob:nth-child(2) { animation-delay: -0.5s; }
.annotation-bob:nth-child(3) { animation-delay: -1s; }
.annotation-bob:nth-child(4) { animation-delay: -1.5s; }
.annotation-bob:nth-child(5) { animation-delay: -2s; }
.annotation-bob:nth-child(6) { animation-delay: -2.5s; }
.annotation-bob:nth-child(7) { animation-delay: -3s; }
.annotation-bob:nth-child(8) { animation-delay: -3.5s; }

@keyframes annotation-bob {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-2px); }
}

.annotation-strip-section:hover .annotation-bob {
    animation-play-state: paused;
}

.mini-chart {
    width: 80px;
    height: 50px;
}

.mini-chart svg {
    width: 100%;
    height: 100%;
}

/* --- Fade Reveal Animation --- */
.fade-reveal {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 700ms ease-out, transform 700ms ease-out;
}

.fade-reveal.revealed {
    opacity: 1;
    transform: translateY(0);
}

/* --- Root Map Overlay --- */
#root-map-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 20000;
    pointer-events: none;
    opacity: 0;
    transition: opacity 400ms ease;
}

#root-map-overlay.visible {
    pointer-events: auto;
    opacity: 1;
}

.root-map-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(26,15,10,0.92);
    /* Noise texture */
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence baseFrequency='0.65' numOctaves='4' type='fractalNoise'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23n)' opacity='0.08'/%3E%3C/svg%3E");
}

.root-map-content {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.root-map-svg {
    width: 80%;
    max-width: 600px;
    height: auto;
}

.root-map-branch {
    stroke-dasharray: 1000;
    stroke-dashoffset: 1000;
    transition: stroke-dashoffset 800ms ease-out;
}

.root-map-branch.animated {
    stroke-dashoffset: 0;
}

.root-map-node {
    cursor: pointer;
    opacity: 0;
    transition: opacity 400ms ease-out;
}

.root-map-node.animated {
    opacity: 1;
}

.root-map-node circle {
    transition: stroke 300ms ease, fill 300ms ease;
}

.root-map-node:hover circle {
    stroke: var(--terracotta-clay);
    fill: rgba(193,105,79,0.2);
}

.root-map-label {
    font-family: 'Inconsolata', 'Courier New', monospace;
    font-weight: 700;
    font-size: 12px;
    fill: var(--aged-vellum);
    letter-spacing: 0.05em;
}

.root-map-node:hover .root-map-label {
    fill: var(--terracotta-clay);
}

#root-map-close {
    position: absolute;
    top: 24px;
    right: 32px;
    width: 40px;
    height: 40px;
    border: 1px solid var(--gilded-amber);
    background: transparent;
    color: var(--aged-vellum);
    font-size: 24px;
    cursor: pointer;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 200ms ease, color 200ms ease;
}

#root-map-close:hover {
    background: rgba(201,169,97,0.2);
    color: var(--gilded-amber);
}

/* --- Responsive --- */
@media (max-width: 768px) {
    .herbarium-page {
        grid-template-columns: [margin-left] 20px [content-start] 1fr [content-end] 20px [margin-right];
    }

    .ornamental-border {
        display: none;
    }

    .corner-ornament {
        display: none;
    }

    .marginal-index {
        left: 4px;
        gap: 10px;
    }

    .marginal-index-link {
        font-size: 0.7rem;
    }

    .specimen-border-inner {
        padding: 20px 16px;
    }

    .hero-section {
        padding: 60px 16px 40px;
    }

    #root-map-toggle {
        bottom: 16px;
        right: 16px;
        width: 40px;
        height: 40px;
    }

    .annotation-strip-inner {
        padding: 10px 20px;
        gap: 24px;
    }
}

@media (max-width: 480px) {
    .herbarium-page {
        grid-template-columns: [margin-left] 10px [content-start] 1fr [content-end] 10px [margin-right];
    }

    .marginal-index {
        display: none;
    }

    .brass-pull {
        bottom: 10px;
        right: 10px;
    }
}
