/* ============================================
   npc.quest — Memphis Group × RPG Arcade UI
   ============================================ */

/* CSS Custom Properties */
:root {
    --quest-magenta: #f72585;
    --npc-cyan: #4cc9f0;
    --loot-gold: #f9c74f;
    --dialogue-orange: #f77f00;
    --midnight-void: #1a1a2e;
    --twilight-slate: #16213e;
    --fog-layer: #e2e8f0;

    --font-headline: 'Space Grotesk', sans-serif;
    --font-body: 'Source Sans 3', sans-serif;
    --font-mono: 'Share Tech Mono', monospace;

    --sidebar-width: 280px;
}

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

html {
    scroll-behavior: smooth;
    font-size: 16px;
}

body {
    font-family: var(--font-body);
    font-weight: 400;
    color: var(--fog-layer);
    background-color: var(--twilight-slate);
    line-height: 1.72;
    overflow-x: hidden;
}

/* ============================================
   SIDEBAR — NPC Dialogue Menu
   ============================================ */
#sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background-color: var(--midnight-void);
    z-index: 100;
    display: flex;
    flex-direction: column;
    padding: 2rem 0;
    overflow: hidden;
}

.terrazzo-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    opacity: 0.06;
    background-image:
        radial-gradient(circle 6px at 20% 15%, var(--quest-magenta) 50%, transparent 50%),
        radial-gradient(circle 4px at 60% 25%, var(--npc-cyan) 50%, transparent 50%),
        radial-gradient(circle 5px at 35% 45%, var(--loot-gold) 50%, transparent 50%),
        radial-gradient(circle 3px at 75% 55%, var(--quest-magenta) 50%, transparent 50%),
        radial-gradient(circle 7px at 15% 70%, var(--npc-cyan) 50%, transparent 50%),
        radial-gradient(circle 4px at 50% 80%, var(--dialogue-orange) 50%, transparent 50%),
        radial-gradient(circle 5px at 80% 90%, var(--loot-gold) 50%, transparent 50%),
        radial-gradient(circle 3px at 40% 10%, var(--fog-layer) 50%, transparent 50%),
        radial-gradient(circle 6px at 70% 40%, var(--quest-magenta) 50%, transparent 50%),
        radial-gradient(circle 4px at 25% 60%, var(--npc-cyan) 50%, transparent 50%),
        radial-gradient(circle 5px at 55% 95%, var(--loot-gold) 50%, transparent 50%),
        radial-gradient(circle 3px at 85% 75%, var(--dialogue-orange) 50%, transparent 50%);
}

.sidebar-header {
    padding: 0 1.5rem 2rem;
    border-bottom: 1px solid rgba(76, 201, 240, 0.2);
    margin-bottom: 1.5rem;
}

.sidebar-logo {
    font-family: var(--font-headline);
    font-weight: 700;
    font-size: 2rem;
    color: var(--quest-magenta);
    letter-spacing: 0.05em;
}

.sidebar-nav {
    list-style: none;
    flex: 1;
    padding: 0 1rem;
}

.sidebar-nav li {
    margin-bottom: 0.25rem;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.65rem 0.75rem;
    text-decoration: none;
    color: var(--fog-layer);
    font-family: var(--font-mono);
    font-size: 0.85rem;
    position: relative;
    transition: color 0.3s ease;
    border-radius: 4px;
}

.nav-link:hover {
    color: var(--npc-cyan);
    background: rgba(76, 201, 240, 0.05);
}

.nav-link:hover .triangle-pointer {
    border-left-color: var(--npc-cyan);
}

.nav-link::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0.75rem;
    right: 0.75rem;
    height: 1px;
    background: var(--quest-magenta);
    transform: scaleX(0);
    transform-origin: left;
    transition: transform 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.nav-link:hover::after {
    transform: scaleX(1);
}

.nav-link.active {
    color: var(--quest-magenta);
}

.nav-link.active .triangle-pointer {
    border-left-color: var(--quest-magenta);
}

.triangle-pointer {
    display: inline-block;
    width: 0;
    height: 0;
    border-top: 6px solid transparent;
    border-bottom: 6px solid transparent;
    border-left: 10px solid var(--loot-gold);
    flex-shrink: 0;
    transition: border-left-color 0.3s ease;
}

.sidebar-footer {
    padding: 1.5rem;
    border-top: 1px solid rgba(76, 201, 240, 0.2);
    margin-top: auto;
}

.sidebar-version {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: rgba(226, 232, 240, 0.4);
}

/* Mobile hamburger */
#mobile-menu-toggle {
    display: none;
    position: fixed;
    top: 1rem;
    left: 1rem;
    z-index: 200;
    width: 44px;
    height: 44px;
    background: var(--midnight-void);
    border: 2px solid var(--quest-magenta);
    border-radius: 4px;
    cursor: pointer;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 5px;
    padding: 10px;
}

.hamburger-line {
    display: block;
    width: 22px;
    height: 2px;
    background: var(--quest-magenta);
    transition: transform 0.3s ease, opacity 0.3s ease;
}

#mobile-menu-toggle.active .hamburger-line:nth-child(1) {
    transform: translateY(7px) rotate(45deg);
}

#mobile-menu-toggle.active .hamburger-line:nth-child(2) {
    opacity: 0;
}

#mobile-menu-toggle.active .hamburger-line:nth-child(3) {
    transform: translateY(-7px) rotate(-45deg);
}

/* ============================================
   MAIN CONTENT
   ============================================ */
#main-content {
    margin-left: var(--sidebar-width);
}

/* Chapter sections */
.chapter {
    min-height: 90vh;
    position: relative;
    overflow: hidden;
    padding: 4rem 3rem;
    display: flex;
    align-items: center;
}

.chapter-1 {
    min-height: 100vh;
    background-color: var(--midnight-void);
}

.chapter-2 {
    background-color: var(--twilight-slate);
}

.chapter-3 {
    background-color: var(--midnight-void);
}

.chapter-4 {
    background-color: var(--twilight-slate);
}

.chapter-5 {
    background-color: var(--midnight-void);
    min-height: 60vh;
}

.chapter-inner {
    display: grid;
    grid-template-columns: 1.5fr 1fr;
    gap: 3rem;
    max-width: 960px;
    margin: 0 auto;
    width: 100%;
    align-items: start;
    position: relative;
    z-index: 2;
}

.col-text {
    position: relative;
}

.col-visual {
    position: relative;
    padding-top: 80px;
}

.col-full {
    grid-column: 1 / -1;
}

/* Gradient washes */
.gradient-wash {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    z-index: 1;
}

.wash-warm {
    background: linear-gradient(135deg, #f72585 0%, #4cc9f0 100%);
    opacity: 0.08;
}

.wash-neutral {
    background: linear-gradient(135deg, #f72585 0%, #4cc9f0 100%);
    opacity: 0.04;
}

.wash-cool {
    background: linear-gradient(135deg, #4cc9f0 0%, #f72585 100%);
    opacity: 0.06;
}

/* ============================================
   SCENE TRANSITION BARS
   ============================================ */
.scene-transition {
    height: 48px;
    background: repeating-linear-gradient(
        45deg,
        var(--quest-magenta),
        var(--quest-magenta) 4px,
        var(--npc-cyan) 4px,
        var(--npc-cyan) 8px
    );
    opacity: 0.7;
    margin-left: var(--sidebar-width);
}

/* ============================================
   CHAPTER 1 — THE TAVERN (Hero)
   ============================================ */
.hero-title {
    font-family: var(--font-headline);
    font-weight: 700;
    font-size: clamp(3.5rem, 8vw, 7rem);
    letter-spacing: -0.02em;
    color: var(--fog-layer);
    text-transform: lowercase;
    line-height: 1.05;
    margin-bottom: 1.5rem;
}

.hero-tagline {
    font-family: var(--font-body);
    font-weight: 400;
    font-style: italic;
    font-size: clamp(1rem, 1.8vw, 1.15rem);
    color: var(--fog-layer);
    opacity: 0.85;
    max-width: 480px;
    margin-bottom: 0.75rem;
}

.hero-underline {
    width: min(100%, 400px);
    height: 4px;
    display: block;
}

.underline-draw line {
    stroke-dasharray: 400;
    stroke-dashoffset: 400;
}

.underline-draw.is-drawn line {
    animation: drawLine 1.2s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
}

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

/* Portrait styles */
.duotone-portrait {
    position: relative;
}

.portrait-hero {
    width: 320px;
    height: 320px;
}

.portrait-hero .portrait-svg {
    width: 100%;
    height: 100%;
    border: 4px solid var(--loot-gold);
    border-radius: 50%;
}

.portrait-quest {
    width: 200px;
    height: 240px;
}

.portrait-quest .portrait-svg {
    width: 100%;
    height: 100%;
}

.portrait-credits {
    width: 200px;
    height: 200px;
    margin: 2rem auto;
}

.portrait-credits .portrait-svg {
    width: 100%;
    height: 100%;
    border: 4px solid var(--loot-gold);
    border-radius: 50%;
}

/* ============================================
   CHAPTER 2 — QUEST BOARD / Stat Cards
   ============================================ */
.section-title {
    font-family: var(--font-headline);
    font-weight: 700;
    font-size: clamp(2.4rem, 5.5vw, 4.8rem);
    letter-spacing: -0.02em;
    text-transform: uppercase;
    color: var(--fog-layer);
    margin-bottom: 2.5rem;
    position: relative;
    display: inline-block;
}

.title-underline {
    width: 100%;
    height: 4px;
    display: block;
    margin-top: 0.25rem;
}

.title-underline line {
    stroke-dasharray: 300;
    stroke-dashoffset: 300;
}

.stat-card {
    background: var(--twilight-slate);
    border: 1px solid rgba(76, 201, 240, 0.3);
    border-radius: 6px;
    padding: 1.5rem;
    margin-bottom: 48px;
    max-width: 360px;
    position: relative;
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.5s ease, transform 0.5s ease;
}

.stat-card.is-visible {
    opacity: 1;
    transform: translateY(0);
}

.card-border-trace {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.card-border-trace rect {
    stroke-dasharray: 400;
    stroke-dashoffset: 400;
    transition: stroke-dashoffset 0.8s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.stat-card.is-visible .card-border-trace rect {
    stroke-dashoffset: 0;
}

.stat-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.stat-card-title {
    font-family: var(--font-headline);
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--fog-layer);
}

.level-badge {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--loot-gold);
    color: var(--midnight-void);
    font-family: var(--font-mono);
    font-size: 0.7rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.stat-card-desc {
    font-family: var(--font-body);
    font-size: 0.9rem;
    color: var(--fog-layer);
    opacity: 0.8;
    margin-bottom: 1.25rem;
    line-height: 1.6;
}

.stat-bar-group {
    margin-bottom: 0.6rem;
}

.stat-bar-label {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--fog-layer);
    opacity: 0.6;
    margin-bottom: 0.25rem;
}

.stat-bar-track {
    width: 100%;
    height: 8px;
    background: rgba(226, 232, 240, 0.1);
    border-radius: 4px;
    overflow: hidden;
}

.stat-bar-fill {
    width: 0%;
    height: 100%;
    background: linear-gradient(90deg, var(--quest-magenta), var(--npc-cyan));
    border-radius: 4px;
    transition: width 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.stat-card.is-visible .stat-bar-fill {
    /* Width set via JS */
}

/* ============================================
   CHAPTER 3 — DIALOGUE TREE
   ============================================ */
.dialogue-line {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 2rem;
    opacity: 0;
    transform: translateY(15px);
    transition: opacity 0.4s ease, transform 0.4s ease;
}

.dialogue-line.is-visible {
    opacity: 1;
    transform: translateY(0);
}

.dialogue-triangle {
    display: inline-block;
    width: 0;
    height: 0;
    border-top: 8px solid transparent;
    border-bottom: 8px solid transparent;
    border-left: 12px solid var(--loot-gold);
    flex-shrink: 0;
    margin-top: 0.5rem;
}

.dialogue-content {
    flex: 1;
}

.dialogue-content p {
    font-family: var(--font-body);
    font-size: clamp(1rem, 1.8vw, 1.15rem);
    color: var(--fog-layer);
    line-height: 1.72;
    margin-bottom: 0.5rem;
}

.dialogue-underline {
    width: 100%;
    height: 4px;
    display: block;
}

.dialogue-underline line {
    stroke-dasharray: 400;
    stroke-dashoffset: 400;
}

.dialogue-line.is-visible .dialogue-underline line {
    animation: drawLine 0.8s cubic-bezier(0.25, 0.46, 0.45, 0.94) 0.3s forwards;
}

.dialogue-portrait-thumb {
    width: 48px;
    height: 48px;
    flex-shrink: 0;
    border-radius: 50%;
    overflow: hidden;
    border: 2px solid var(--loot-gold);
}

.dialogue-portrait-thumb svg {
    width: 100%;
    height: 100%;
}

/* Diagonal stripe block decoration */
.diagonal-stripe-block {
    width: 120px;
    height: 80px;
    background: repeating-linear-gradient(
        45deg,
        var(--quest-magenta),
        var(--quest-magenta) 4px,
        var(--npc-cyan) 4px,
        var(--npc-cyan) 8px
    );
    opacity: 0.3;
    border-radius: 4px;
    margin-bottom: 2rem;
}

/* ============================================
   CHAPTER 4 — INVENTORY
   ============================================ */
.inventory-grid {
    display: grid;
    grid-template-columns: repeat(3, 200px);
    gap: 1.5rem;
    margin-top: 2rem;
    justify-content: start;
}

.item-card {
    width: 200px;
    height: 240px;
    background: var(--twilight-slate);
    border: 2px solid transparent;
    border-image: linear-gradient(135deg, var(--quest-magenta), var(--npc-cyan)) 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 1.25rem;
    text-align: center;
    position: relative;
    transition: transform 0.2s ease;
    opacity: 0;
    transform: translateY(20px) perspective(800px);
}

.item-card.is-visible {
    opacity: 1;
    transform: translateY(0) perspective(800px);
}

.card-squiggle {
    position: relative;
}

.card-squiggle::before {
    content: '';
    position: absolute;
    top: -4px;
    left: -4px;
    right: -4px;
    bottom: -4px;
    border: 3px solid transparent;
    border-image: none;
    background:
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='6'%3E%3Cpath d='M0 3 Q5 0 10 3 T20 3 T30 3 T40 3' stroke='%23f72585' fill='none' stroke-width='1.5'/%3E%3C/svg%3E") repeat-x top left,
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='6'%3E%3Cpath d='M0 3 Q5 0 10 3 T20 3 T30 3 T40 3' stroke='%23f72585' fill='none' stroke-width='1.5'/%3E%3C/svg%3E") repeat-x bottom left;
    background-size: 40px 6px;
    pointer-events: none;
    z-index: 1;
}

.card-stripes {
    background:
        repeating-linear-gradient(
            45deg,
            transparent,
            transparent 6px,
            rgba(76, 201, 240, 0.05) 6px,
            rgba(76, 201, 240, 0.05) 12px
        ),
        var(--twilight-slate);
}

.card-terrazzo {
    background:
        radial-gradient(circle 4px at 25% 20%, rgba(247, 37, 133, 0.15) 50%, transparent 50%),
        radial-gradient(circle 3px at 70% 35%, rgba(76, 201, 240, 0.15) 50%, transparent 50%),
        radial-gradient(circle 5px at 45% 75%, rgba(249, 199, 79, 0.12) 50%, transparent 50%),
        radial-gradient(circle 3px at 80% 80%, rgba(247, 37, 133, 0.1) 50%, transparent 50%),
        var(--twilight-slate);
}

.item-icon {
    width: 64px;
    height: 64px;
    margin-bottom: 1rem;
}

.item-icon svg {
    width: 100%;
    height: 100%;
}

.item-name {
    font-family: var(--font-headline);
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--fog-layer);
    margin-bottom: 0.3rem;
}

.item-desc {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    color: var(--fog-layer);
    opacity: 0.6;
}

/* ============================================
   CHAPTER 5 — CREDITS
   ============================================ */
.credits-content {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.credits-domain {
    font-family: var(--font-mono);
    font-size: 0.85rem;
    color: var(--fog-layer);
    opacity: 0.6;
    letter-spacing: 0.1em;
    margin-bottom: 2rem;
}

.credits-portrait-wrap {
    display: flex;
    justify-content: center;
}

.credits-tagline {
    font-family: var(--font-body);
    font-size: clamp(1rem, 1.8vw, 1.15rem);
    font-style: italic;
    color: var(--fog-layer);
    opacity: 0.7;
    max-width: 400px;
    margin: 1.5rem auto;
}

.credits-mono {
    font-family: var(--font-mono);
    font-size: 0.85rem;
    color: var(--fog-layer);
    opacity: 0.4;
}

/* ============================================
   SQUIGGLE DECORATIONS
   ============================================ */
.squiggle-deco {
    width: 200px;
    height: 30px;
    display: block;
    margin: 1.5rem 0;
}

.squiggle-deco path {
    stroke-dasharray: 300;
    stroke-dashoffset: 300;
}

.squiggle-deco.is-drawn path {
    animation: drawLine 1.5s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
}

.squiggle-credits,
.squiggle-credits-2 {
    width: 300px;
    margin: 1rem auto;
}

/* ============================================
   SCROLL ANIMATIONS
   ============================================ */
.animate-on-scroll {
    /* Initial state managed by JS */
}

/* ============================================
   RESPONSIVE — MOBILE
   ============================================ */
@media (max-width: 768px) {
    :root {
        --sidebar-width: 0px;
    }

    #sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        width: 280px;
    }

    #sidebar.is-open {
        transform: translateX(0);
    }

    #mobile-menu-toggle {
        display: flex;
    }

    #main-content {
        margin-left: 0;
    }

    .scene-transition {
        margin-left: 0;
    }

    .chapter {
        padding: 3rem 1.5rem;
    }

    .chapter-inner {
        grid-template-columns: 1fr;
        gap: 2rem;
    }

    .col-visual {
        padding-top: 0;
        order: -1;
    }

    .portrait-hero {
        width: 200px;
        height: 200px;
        margin: 0 auto;
    }

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

    .item-card {
        width: 100%;
    }

    .hero-title {
        text-align: center;
    }

    .hero-tagline {
        text-align: center;
        margin-left: auto;
        margin-right: auto;
    }

    .hero-underline {
        margin: 0 auto;
    }

    .stat-card {
        max-width: 100%;
    }
}

@media (max-width: 480px) {
    .inventory-grid {
        grid-template-columns: 1fr;
        justify-items: center;
    }

    .item-card {
        width: 200px;
    }
}
