/* ========================================
   lrx.wiki — License & Right eXchange
   Surrealist Bureaucracy + Honeycomb Grid
   ======================================== */

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

:root {
    --parchment-light: #F2EDE3;
    --parchment: #E8DCC2;
    --parchment-mid: #D4C8B0;
    --gold: #C9A84C;
    --gold-dark: #B8923A;
    --earth: #9C8B6E;
    --earth-dark: #6B6259;
    --brown-deep: #5A4E3C;
    --brown-dark: #3A2F20;
    --brown-darkest: #2E2519;
    --ink: #1C1610;
    --seal-red: #8B3A2A;

    --font-display: 'Instrument Serif', serif;
    --font-body: 'Inter', sans-serif;
    --font-mono: 'Space Mono', monospace;
    --font-secondary: 'Lora', serif;

    --hex-clip: polygon(25% 0%, 75% 0%, 100% 50%, 75% 100%, 25% 100%, 0% 50%);
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: var(--font-body);
    background: var(--ink);
    color: var(--parchment);
}

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

/* --- Entry Overlay --- */
#entry-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--ink);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: opacity 0.8s ease, visibility 0.8s ease;
}

#entry-overlay.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.entry-hex-ring {
    position: relative;
    width: 180px;
    height: 180px;
    margin-bottom: 40px;
}

.entry-hex {
    position: absolute;
    width: 50px;
    height: 50px;
    background: var(--gold);
    clip-path: var(--hex-clip);
    opacity: 0;
    animation: entryHexAppear 0.6s ease forwards;
    animation-delay: calc(var(--i) * 0.15s);
}

.entry-hex:nth-child(1) { top: 0; left: 65px; }
.entry-hex:nth-child(2) { top: 35px; left: 115px; }
.entry-hex:nth-child(3) { top: 95px; left: 115px; }
.entry-hex:nth-child(4) { top: 130px; left: 65px; }
.entry-hex:nth-child(5) { top: 95px; left: 15px; }
.entry-hex:nth-child(6) { top: 35px; left: 15px; }

@keyframes entryHexAppear {
    0% { opacity: 0; transform: scale(0) rotate(60deg); }
    60% { opacity: 0.8; transform: scale(1.15) rotate(-5deg); }
    100% { opacity: 0.6; transform: scale(1) rotate(0deg); }
}

.entry-title {
    font-family: var(--font-display);
    font-style: italic;
    font-size: clamp(3rem, 8vw, 6rem);
    letter-spacing: -0.02em;
    line-height: 0.95;
    color: var(--parchment);
}

.entry-char {
    display: inline-block;
    opacity: 0;
    transform: translateY(30px) rotate(10deg);
    animation: charReveal 0.5s ease forwards;
    animation-delay: calc(1s + var(--d) * 0.1s);
}

@keyframes charReveal {
    0% { opacity: 0; transform: translateY(30px) rotate(10deg); }
    100% { opacity: 1; transform: translateY(0) rotate(0deg); }
}

/* --- Main Viewport --- */
#honeycomb-viewport {
    position: relative;
    width: 100%;
    height: 100%;
    background: var(--ink);
    overflow: hidden;
}

/* --- Hex Navigation --- */
#hex-nav {
    position: fixed;
    left: 24px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 100;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.hex-nav-btn {
    width: 48px;
    height: 48px;
    clip-path: var(--hex-clip);
    background: var(--brown-dark);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--earth);
    transition: all 0.4s ease;
    position: relative;
}

.hex-nav-btn:hover {
    background: var(--brown-deep);
    color: var(--gold);
    transform: scale(1.1);
}

.hex-nav-btn.active {
    background: var(--gold-dark);
    color: var(--ink);
}

.nav-icon {
    width: 24px;
    height: 24px;
}

/* --- Hex Sections --- */
.hex-section {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transform: scale(0.85);
    transition: opacity 0.7s ease, transform 0.7s ease, visibility 0.7s ease;
}

.hex-section.active {
    opacity: 1;
    visibility: visible;
    transform: scale(1);
}

.hex-section.zooming-in {
    opacity: 0;
    transform: scale(2.5);
}

.hex-section.zooming-out {
    opacity: 0;
    transform: scale(0.3);
}

/* --- Honeycomb Grid (Home) --- */
.honeycomb-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    width: min(80vw, 720px);
    padding: 20px;
}

.hex-cell {
    aspect-ratio: 1.1547;
    clip-path: var(--hex-clip);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    transition: transform 0.5s cubic-bezier(0.34, 1.56, 0.64, 1), background 0.4s ease;
    opacity: 0;
    animation: hexCellAppear 0.6s ease forwards;
    animation-delay: calc((var(--row, 0) * 3 + var(--col, 0)) * 0.08s);
}

.hex-cell[data-row="0"] { --row: 0; }
.hex-cell[data-row="1"] { --row: 1; }
.hex-cell[data-row="2"] { --row: 2; }
.hex-cell[data-row="3"] { --row: 3; }
.hex-cell[data-col="0"] { --col: 0; }
.hex-cell[data-col="1"] { --col: 1; }
.hex-cell[data-col="2"] { --col: 2; }

/* Offset odd rows */
.hex-cell[data-row="1"],
.hex-cell[data-row="3"] {
    transform: translateX(50%);
}

.hex-cell[data-row="1"].hex-cell,
.hex-cell[data-row="3"].hex-cell {
    animation: hexCellAppearOffset 0.6s ease forwards;
    animation-delay: calc((var(--row, 0) * 3 + var(--col, 0)) * 0.08s);
}

@keyframes hexCellAppear {
    0% { opacity: 0; transform: scale(0.5) rotate(30deg); }
    100% { opacity: 1; transform: scale(1) rotate(0deg); }
}

@keyframes hexCellAppearOffset {
    0% { opacity: 0; transform: translateX(50%) scale(0.5) rotate(30deg); }
    100% { opacity: 1; transform: translateX(50%) scale(1) rotate(0deg); }
}

.hex-inner {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 15%;
    text-align: center;
}

/* Cell types */
.hex-empty {
    background: var(--brown-darkest);
}

.hex-title {
    background: linear-gradient(135deg, var(--brown-dark) 0%, var(--ink) 100%);
}

.hex-content {
    background: var(--brown-dark);
}

.hex-accent {
    background: rgba(201, 168, 76, 0.08);
    border: 1px solid transparent;
}

.hex-nav-cell {
    background: var(--brown-darkest);
    cursor: pointer;
}

.hex-nav-cell:hover {
    background: rgba(201, 168, 76, 0.15);
}

.hex-nav-cell:hover .hex-label {
    color: var(--gold);
}

/* Hex cell content */
.kinetic-title {
    font-family: var(--font-display);
    font-style: italic;
    font-weight: 400;
    font-size: clamp(2rem, 6vw, 5rem);
    letter-spacing: -0.02em;
    line-height: 0.95;
    color: var(--parchment);
}

.kinetic-title .char {
    display: inline-block;
    opacity: 0;
    animation: titleCharIn 0.5s ease forwards;
    animation-delay: calc(0.3s + var(--i) * 0.08s);
}

@keyframes titleCharIn {
    0% {
        opacity: 0;
        transform: translateY(20px) rotate(15deg) scale(0.5);
    }
    70% {
        opacity: 1;
        transform: translateY(-3px) rotate(-2deg) scale(1.05);
    }
    100% {
        opacity: 1;
        transform: translateY(0) rotate(0) scale(1);
    }
}

.hex-subtitle {
    font-family: var(--font-mono);
    font-size: clamp(0.55rem, 1.2vw, 0.85rem);
    color: var(--gold);
    letter-spacing: 0.15em;
    text-transform: uppercase;
    margin-top: 8px;
    opacity: 0.8;
}

.hex-text {
    font-family: var(--font-secondary);
    font-size: clamp(0.65rem, 1.1vw, 0.85rem);
    color: var(--parchment-mid);
    line-height: 1.5;
    font-style: italic;
}

.hex-text.mono-text {
    font-family: var(--font-mono);
    font-style: normal;
    color: var(--gold);
    font-size: clamp(0.7rem, 1.3vw, 1rem);
    letter-spacing: 0.1em;
}

.hex-text.small-text {
    font-size: clamp(0.5rem, 0.9vw, 0.7rem);
    margin-top: 4px;
}

.hex-icon {
    width: 50%;
    height: auto;
    opacity: 0.7;
}

.hex-icon-large {
    width: 70%;
}

.hex-label {
    font-family: var(--font-mono);
    font-size: clamp(0.5rem, 0.9vw, 0.7rem);
    color: var(--earth);
    text-transform: uppercase;
    letter-spacing: 0.15em;
    margin-top: 6px;
    transition: color 0.3s ease;
}

/* --- Ambient Hexagons --- */
.ambient-hexagons {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
}

.ambient-hex {
    position: absolute;
    left: var(--x);
    top: var(--y);
    width: var(--size);
    height: var(--size);
    clip-path: var(--hex-clip);
    background: var(--gold);
    opacity: 0;
    animation: ambientFloat var(--dur) ease-in-out infinite;
    animation-delay: var(--delay);
}

@keyframes ambientFloat {
    0%, 100% {
        opacity: 0;
        transform: translateY(0) rotate(0deg) scale(0.8);
    }
    15% {
        opacity: 0.06;
    }
    50% {
        opacity: 0.04;
        transform: translateY(-30px) rotate(60deg) scale(1);
    }
    85% {
        opacity: 0.06;
    }
}

/* --- Section Content Layouts --- */
.section-content {
    width: min(85vw, 900px);
    padding: 40px 80px;
    max-height: 100vh;
    overflow-y: auto;
    scrollbar-width: none;
}

.section-content::-webkit-scrollbar {
    display: none;
}

.section-header {
    margin-bottom: 50px;
    text-align: center;
}

.section-title {
    font-size: clamp(2.5rem, 7vw, 5rem);
    margin-bottom: 16px;
}

.section-line {
    width: 120px;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--gold), transparent);
    margin: 0 auto;
}

/* --- Licenses Section --- */
.hex-detail-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 24px;
}

.detail-hex {
    clip-path: var(--hex-clip);
    background: var(--brown-dark);
    aspect-ratio: 1.1547;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transform: scale(0.7) rotate(10deg);
    transition: opacity 0.6s ease, transform 0.6s ease, background 0.4s ease;
}

.detail-hex.visible {
    opacity: 1;
    transform: scale(1) rotate(0deg);
}

.detail-hex:hover {
    background: rgba(201, 168, 76, 0.12);
}

.detail-hex-inner {
    text-align: center;
    padding: 20%;
}

.detail-icon {
    width: 50px;
    height: 50px;
    margin-bottom: 12px;
}

.detail-hex-inner h3 {
    font-family: var(--font-display);
    font-style: italic;
    font-size: clamp(1rem, 2vw, 1.4rem);
    color: var(--parchment);
    margin-bottom: 8px;
}

.detail-hex-inner p {
    font-family: var(--font-secondary);
    font-style: italic;
    font-size: clamp(0.6rem, 1vw, 0.8rem);
    color: var(--earth);
    line-height: 1.5;
}

/* --- Rights Section --- */
.rights-honeycomb {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
}

.rights-hex {
    clip-path: var(--hex-clip);
    background: var(--brown-darkest);
    aspect-ratio: 1.1547;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 0.5s ease, transform 0.5s ease, background 0.3s ease;
}

.rights-hex.visible {
    opacity: 1;
    transform: translateY(0);
}

.rights-hex:hover {
    background: rgba(139, 58, 42, 0.15);
}

.rights-hex-inner {
    text-align: center;
    padding: 20%;
}

.rights-number {
    font-family: var(--font-mono);
    font-size: clamp(0.6rem, 1vw, 0.8rem);
    color: var(--gold);
    letter-spacing: 0.2em;
    opacity: 0.6;
    display: block;
    margin-bottom: 8px;
}

.rights-hex-inner h3 {
    font-family: var(--font-display);
    font-style: italic;
    font-size: clamp(0.9rem, 1.8vw, 1.3rem);
    color: var(--parchment);
    margin-bottom: 6px;
}

.rights-hex-inner p {
    font-family: var(--font-secondary);
    font-style: italic;
    font-size: clamp(0.55rem, 0.9vw, 0.75rem);
    color: var(--earth);
    line-height: 1.4;
}

/* --- Exchange Section --- */
.exchange-flow {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    margin-bottom: 60px;
    flex-wrap: wrap;
}

.flow-node {
    text-align: center;
    max-width: 200px;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.6s ease, transform 0.6s ease;
}

.flow-node.visible {
    opacity: 1;
    transform: translateY(0);
}

.flow-hex {
    width: 90px;
    height: 90px;
    clip-path: var(--hex-clip);
    background: var(--brown-dark);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 16px;
    transition: background 0.3s ease;
}

.flow-node:hover .flow-hex {
    background: rgba(201, 168, 76, 0.15);
}

.flow-icon {
    width: 45px;
    height: 45px;
}

.flow-content h3 {
    font-family: var(--font-display);
    font-style: italic;
    font-size: clamp(1rem, 2vw, 1.4rem);
    color: var(--parchment);
    margin-bottom: 8px;
}

.flow-content p {
    font-family: var(--font-secondary);
    font-style: italic;
    font-size: clamp(0.6rem, 0.95vw, 0.8rem);
    color: var(--earth);
    line-height: 1.5;
}

.flow-arrow {
    width: 80px;
    opacity: 0;
    animation: flowArrowPulse 2s ease-in-out infinite;
}

.flow-arrow.visible {
    opacity: 0.6;
}

@keyframes flowArrowPulse {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 0.7; }
}

.exchange-stats {
    display: flex;
    justify-content: center;
    gap: 40px;
    flex-wrap: wrap;
}

.stat-hex {
    text-align: center;
    width: 140px;
    height: 140px;
    clip-path: var(--hex-clip);
    background: var(--brown-darkest);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transform: scale(0.5);
    transition: opacity 0.6s ease, transform 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.stat-hex.visible {
    opacity: 1;
    transform: scale(1);
}

.stat-number {
    font-family: var(--font-display);
    font-style: italic;
    font-size: clamp(1.5rem, 3vw, 2.5rem);
    color: var(--gold);
    line-height: 1;
}

.stat-unit {
    font-family: var(--font-mono);
    font-size: clamp(0.7rem, 1.2vw, 1rem);
    color: var(--gold);
    opacity: 0.7;
}

.stat-label {
    font-family: var(--font-mono);
    font-size: clamp(0.45rem, 0.7vw, 0.6rem);
    color: var(--earth);
    text-transform: uppercase;
    letter-spacing: 0.15em;
    margin-top: 4px;
}

/* --- Archive Section --- */
.archive-timeline {
    position: relative;
    padding-left: 60px;
}

.timeline-line {
    position: absolute;
    left: 19px;
    top: 0;
    bottom: 0;
    width: 2px;
    background: linear-gradient(180deg, transparent, var(--gold-dark), var(--seal-red), transparent);
}

.timeline-entry {
    display: flex;
    align-items: flex-start;
    gap: 24px;
    margin-bottom: 36px;
    opacity: 0;
    transform: translateX(-20px);
    transition: opacity 0.5s ease, transform 0.5s ease;
}

.timeline-entry.visible {
    opacity: 1;
    transform: translateX(0);
}

.timeline-hex {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    margin-left: -40px;
}

.timeline-hex svg {
    width: 100%;
    height: 100%;
}

.timeline-content {
    padding-top: 4px;
}

.timeline-date {
    font-family: var(--font-mono);
    font-size: clamp(0.6rem, 1vw, 0.8rem);
    color: var(--gold);
    letter-spacing: 0.2em;
    display: block;
    margin-bottom: 4px;
}

.timeline-content h3 {
    font-family: var(--font-display);
    font-style: italic;
    font-size: clamp(1rem, 2vw, 1.4rem);
    color: var(--parchment);
    margin-bottom: 4px;
}

.timeline-content p {
    font-family: var(--font-secondary);
    font-style: italic;
    font-size: clamp(0.65rem, 1vw, 0.85rem);
    color: var(--earth);
    line-height: 1.5;
}

/* --- Grain Overlay --- */
#grain-overlay {
    position: fixed;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    pointer-events: none;
    z-index: 999;
    opacity: 0.035;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
    background-repeat: repeat;
    animation: grainShift 0.5s steps(4) infinite;
}

@keyframes grainShift {
    0% { transform: translate(0, 0); }
    25% { transform: translate(-2%, -1%); }
    50% { transform: translate(1%, 2%); }
    75% { transform: translate(-1%, -2%); }
    100% { transform: translate(2%, 1%); }
}

/* --- Responsive --- */
@media (max-width: 768px) {
    #hex-nav {
        left: auto;
        right: auto;
        bottom: 16px;
        top: auto;
        transform: none;
        flex-direction: row;
        justify-content: center;
        width: 100%;
        padding: 0 16px;
    }

    .hex-nav-btn {
        width: 40px;
        height: 40px;
    }

    .honeycomb-grid {
        width: 95vw;
        gap: 4px;
    }

    .section-content {
        padding: 30px 20px;
        width: 95vw;
    }

    .hex-detail-grid {
        grid-template-columns: 1fr;
    }

    .rights-honeycomb {
        grid-template-columns: repeat(2, 1fr);
    }

    .exchange-flow {
        flex-direction: column;
    }

    .flow-arrow {
        transform: rotate(90deg);
        width: 50px;
    }

    .exchange-stats {
        gap: 16px;
    }

    .stat-hex {
        width: 110px;
        height: 110px;
    }
}

@media (max-width: 480px) {
    .honeycomb-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .rights-honeycomb {
        grid-template-columns: 1fr;
    }

    .hex-cell[data-row="1"],
    .hex-cell[data-row="3"] {
        transform: translateX(25%);
    }

    @keyframes hexCellAppearOffset {
        0% { opacity: 0; transform: translateX(25%) scale(0.5) rotate(30deg); }
        100% { opacity: 1; transform: translateX(25%) scale(1) rotate(0deg); }
    }
}
