/* ============================================
   layer2.quest - Retro Arcade Cartography
   Hexagonal Territory Map of L2 Scaling
   ============================================ */

/* --- CSS Custom Properties --- */
:root {
    --bg-charcoal: #1C1A17;
    --hex-surface: #2A2621;
    --amber-glow: #D4873E;
    --burnt-orange: #D46A3E;
    --coral-signal: #D4503E;
    --phosphor-green: #7BC47F;
    --scanline-gray: #3D3A35;
    --text-light: #C9C0B3;
}

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

html {
    scroll-behavior: smooth;
    background: var(--bg-charcoal);
}

body {
    font-family: 'Space Grotesk', sans-serif;
    background: var(--bg-charcoal);
    color: var(--text-light);
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* --- CRT Scan-Line Overlay --- */
#crt-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9999;
    background: repeating-linear-gradient(
        0deg,
        transparent,
        transparent 2px,
        rgba(0, 0, 0, 0.08) 2px,
        rgba(0, 0, 0, 0.08) 4px
    );
    animation: flicker 8s infinite;
    opacity: 0;
    transition: opacity 0.5s ease;
}

#crt-overlay.active {
    opacity: 1;
}

@keyframes flicker {
    0%, 100% { opacity: 0.05; }
    10% { opacity: 0.04; }
    20% { opacity: 0.07; }
    30% { opacity: 0.03; }
    40% { opacity: 0.06; }
    50% { opacity: 0.08; }
    60% { opacity: 0.04; }
    70% { opacity: 0.07; }
    80% { opacity: 0.05; }
    90% { opacity: 0.06; }
}

/* --- Hexagon Base Styles --- */
.hex {
    clip-path: polygon(25% 0%, 75% 0%, 100% 50%, 75% 100%, 25% 100%, 0% 50%);
    position: relative;
    transition: transform 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    opacity: 0;
    transform: scale(0.8);
}

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

.hex-inner {
    clip-path: polygon(25% 0%, 75% 0%, 100% 50%, 75% 100%, 25% 100%, 0% 50%);
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

.hex-pattern {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0.15;
    pointer-events: none;
}

.hex-label {
    font-family: 'Share Tech Mono', monospace;
    font-size: 0.65rem;
    font-weight: 400;
    letter-spacing: 0.1em;
    color: var(--text-light);
    text-transform: uppercase;
    z-index: 2;
    text-align: center;
    line-height: 1.2;
}

/* --- SECTION 1: Command Center (Hero) --- */
#command-center {
    width: 100%;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--bg-charcoal);
    position: relative;
    overflow: hidden;
    padding: 2rem;
}

.hex-grid-hero {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    transform-origin: center;
    transition: transform 0.8s ease, opacity 0.8s ease;
}

.hex-grid-hero.scrolled {
    transform: scale(0.6) translateY(-30%);
    opacity: 0.5;
}

.hex-row {
    display: flex;
    gap: 6px;
    justify-content: center;
}

.hex-row-3 {
    margin: 0;
}

.hex-row-4 {
    margin-top: -18px;
}

.hex-row-5 {
    margin-top: -18px;
}

.hex-row-4 + .hex-row-3,
.hex-row-5 + .hex-row-4 {
    margin-top: -18px;
}

/* Outer hexagons */
.hex-outer {
    width: 120px;
    height: 138px;
    background: var(--hex-surface);
    border: none;
    cursor: pointer;
    box-shadow: inset 0 0 15px rgba(212, 135, 62, 0.15);
    position: relative;
}

.hex-outer::before {
    content: '';
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    clip-path: polygon(25% 0%, 75% 0%, 100% 50%, 75% 100%, 25% 100%, 0% 50%);
    background: var(--amber-glow);
    z-index: -1;
}

.hex-outer .hex-inner {
    background: var(--hex-surface);
}

.hex-outer .hex-pattern {
    color: var(--amber-glow);
}

/* Hex types color variations */
.hex-outer[data-type="rollup"] .hex-pattern {
    color: var(--amber-glow);
}

.hex-outer[data-type="sidechain"] .hex-pattern {
    color: var(--burnt-orange);
}

.hex-outer[data-type="channel"] .hex-pattern {
    color: var(--coral-signal);
}

/* Center hex */
.hex-center {
    width: 180px;
    height: 208px;
    background: var(--hex-surface);
    cursor: default;
    box-shadow: inset 0 0 25px rgba(212, 135, 62, 0.25);
    position: relative;
}

.hex-center::before {
    content: '';
    position: absolute;
    top: -3px;
    left: -3px;
    right: -3px;
    bottom: -3px;
    clip-path: polygon(25% 0%, 75% 0%, 100% 50%, 75% 100%, 25% 100%, 0% 50%);
    background: var(--amber-glow);
    z-index: -1;
}

.hex-center .hex-inner {
    background: var(--hex-surface);
}

.hex-title {
    font-family: 'Press Start 2P', cursive;
    font-size: 0.9rem;
    font-weight: 400;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--amber-glow);
    text-align: center;
    z-index: 2;
    line-height: 1.6;
    min-height: 2.4em;
}

.hex-subtitle {
    font-family: 'Share Tech Mono', monospace;
    font-size: 0.55rem;
    letter-spacing: 0.2em;
    color: var(--phosphor-green);
    margin-top: 6px;
    z-index: 2;
    opacity: 0;
    transition: opacity 0.5s ease 1.5s;
}

.hex-subtitle.visible {
    opacity: 1;
}

/* Hover ripple effect on outer hexes */
.hex-outer:hover {
    transform: scale(1.08);
    z-index: 10;
}

.hex-outer:hover .hex-label {
    color: var(--amber-glow);
}

.hex-outer.ripple {
    animation: hexRipple 0.6s ease-out;
}

@keyframes hexRipple {
    0% {
        box-shadow: inset 0 0 15px rgba(212, 135, 62, 0.15), 0 0 0 0 rgba(212, 135, 62, 0.4);
    }
    100% {
        box-shadow: inset 0 0 15px rgba(212, 135, 62, 0.15), 0 0 0 20px rgba(212, 135, 62, 0);
    }
}

/* Command center status line */
.command-center-status {
    margin-top: 3rem;
    text-align: center;
}

.status-line {
    font-family: 'Share Tech Mono', monospace;
    font-size: 0.8rem;
    color: var(--phosphor-green);
    letter-spacing: 0.1em;
    opacity: 0.7;
}

/* --- SECTION 2: Territory Map --- */
#territory-map {
    width: 100%;
    min-height: 150vh;
    padding: 4rem 2rem;
    background: var(--bg-charcoal);
    position: relative;
}

.section-header {
    font-family: 'Press Start 2P', cursive;
    font-size: clamp(0.8rem, 1.5vw, 1.2rem);
    font-weight: 400;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--amber-glow);
    text-align: center;
    margin-bottom: 3rem;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.6s ease, transform 0.6s ease;
}

.section-header.visible {
    opacity: 1;
    transform: translateY(0);
}

.territory-category {
    margin-bottom: 3rem;
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 0.6s ease, transform 0.6s ease;
}

.territory-category.visible {
    opacity: 1;
    transform: translateY(0);
}

.category-label {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 700;
    font-size: clamp(1.2rem, 2vw, 1.8rem);
    color: var(--text-light);
    margin-bottom: 1.5rem;
    padding-left: 1rem;
    border-left: 3px solid var(--amber-glow);
}

.hex-row-scroll {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    padding: 1rem 0.5rem;
    scrollbar-width: thin;
    scrollbar-color: var(--amber-glow) var(--hex-surface);
}

.hex-row-scroll::-webkit-scrollbar {
    height: 4px;
}

.hex-row-scroll::-webkit-scrollbar-track {
    background: var(--hex-surface);
}

.hex-row-scroll::-webkit-scrollbar-thumb {
    background: var(--amber-glow);
}

/* Territory hexes */
.hex-territory {
    width: 160px;
    height: 184px;
    min-width: 160px;
    cursor: pointer;
    box-shadow: inset 0 0 15px rgba(212, 135, 62, 0.12);
    position: relative;
}

.hex-territory::before {
    content: '';
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    clip-path: polygon(25% 0%, 75% 0%, 100% 50%, 75% 100%, 25% 100%, 0% 50%);
    z-index: -1;
}

.hex-territory .hex-inner {
    gap: 4px;
}

.hex-territory[data-color="amber"] {
    background: var(--hex-surface);
}

.hex-territory[data-color="amber"]::before {
    background: var(--amber-glow);
}

.hex-territory[data-color="amber"] .hex-pattern {
    color: var(--amber-glow);
}

.hex-territory[data-color="orange"] {
    background: var(--hex-surface);
}

.hex-territory[data-color="orange"]::before {
    background: var(--burnt-orange);
}

.hex-territory[data-color="orange"] .hex-pattern {
    color: var(--burnt-orange);
}

.hex-territory[data-color="coral"] {
    background: var(--hex-surface);
}

.hex-territory[data-color="coral"]::before {
    background: var(--coral-signal);
}

.hex-territory[data-color="coral"] .hex-pattern {
    color: var(--coral-signal);
}

.hex-territory .hex-label {
    font-family: 'Press Start 2P', cursive;
    font-size: 0.5rem;
    color: var(--text-light);
    letter-spacing: 0.08em;
}

.hex-data {
    font-family: 'Share Tech Mono', monospace;
    font-size: 0.6rem;
    color: var(--phosphor-green);
    letter-spacing: 0.05em;
    z-index: 2;
    text-align: center;
    opacity: 0.8;
}

.hex-territory:hover {
    transform: scale(1.1);
    z-index: 10;
}

.hex-territory:hover .hex-label {
    color: var(--amber-glow);
}

.hex-territory:hover .hex-data {
    opacity: 1;
}

/* --- SECTION 3: Protocol Dossier --- */
#protocol-dossier {
    width: 100%;
    min-height: 100vh;
    padding: 4rem 2rem;
    background: var(--bg-charcoal);
}

.dossier-container {
    max-width: 800px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.dossier-entry {
    display: flex;
    gap: 0;
    position: relative;
    opacity: 0;
    transform: translateX(-20px);
    transition: opacity 0.5s ease, transform 0.5s ease;
}

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

.dossier-accent {
    width: 3px;
    background: var(--amber-glow);
    flex-shrink: 0;
    transform-origin: top;
    transform: scaleY(0);
    transition: transform 0.4s ease;
    position: relative;
}

.dossier-entry.visible .dossier-accent {
    transform: scaleY(1);
}

.dossier-accent::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 3px;
    height: 100%;
    background: var(--amber-glow);
    opacity: 0;
    animation: none;
}

.dossier-entry.decoded .dossier-accent::after {
    animation: accentPulse 1s ease-out;
}

@keyframes accentPulse {
    0% { opacity: 0.8; box-shadow: 0 0 10px var(--amber-glow); }
    100% { opacity: 0; box-shadow: 0 0 0 var(--amber-glow); }
}

.dossier-content {
    padding: 1.5rem 1.5rem;
    background: rgba(42, 38, 33, 0.6);
    flex-grow: 1;
    position: relative;
    overflow: hidden;
}

/* Scan-line overlay on dossier entries */
.dossier-content::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: repeating-linear-gradient(
        0deg,
        transparent,
        transparent 2px,
        rgba(0, 0, 0, 0.04) 2px,
        rgba(0, 0, 0, 0.04) 4px
    );
    pointer-events: none;
    z-index: 1;
}

.dossier-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.dossier-id {
    font-family: 'Share Tech Mono', monospace;
    font-size: 0.7rem;
    color: var(--burnt-orange);
    letter-spacing: 0.1em;
}

.dossier-status {
    font-family: 'Share Tech Mono', monospace;
    font-size: 0.65rem;
    color: var(--phosphor-green);
    letter-spacing: 0.1em;
}

.dossier-title {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 700;
    font-size: clamp(1.2rem, 2vw, 1.8rem);
    color: var(--amber-glow);
    margin-bottom: 0.75rem;
    letter-spacing: 0.05em;
}

.dossier-text {
    font-family: 'Share Tech Mono', monospace;
    font-size: 0.8rem;
    font-weight: 400;
    color: var(--text-light);
    line-height: 1.75;
    letter-spacing: 0.02em;
    overflow: hidden;
}

.dossier-text .char {
    opacity: 0;
    transition: opacity 0.05s;
}

.dossier-text .char.typed {
    opacity: 1;
}

.dossier-coords {
    display: flex;
    gap: 1.5rem;
    margin-top: 1rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--scanline-gray);
}

.dossier-coords span {
    font-family: 'Share Tech Mono', monospace;
    font-size: 0.65rem;
    color: var(--burnt-orange);
    letter-spacing: 0.1em;
}

/* --- SECTION 4: Signal Footer --- */
#signal-footer {
    width: 100%;
    padding: 2rem 0;
    background: var(--bg-charcoal);
    overflow: hidden;
}

.footer-hex-strip {
    display: flex;
    justify-content: center;
    gap: 3px;
    overflow: hidden;
}

.footer-hex {
    width: 40px;
    height: 46px;
    min-width: 40px;
    clip-path: polygon(25% 0%, 75% 0%, 100% 50%, 75% 100%, 25% 100%, 0% 50%);
    background: var(--bg-charcoal);
}

.footer-hex.alt {
    background: var(--hex-surface);
}

.footer-transmission {
    text-align: center;
    padding: 1.5rem 0;
}

.transmission-text {
    font-family: 'Press Start 2P', cursive;
    font-size: 0.7rem;
    font-weight: 400;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--amber-glow);
    opacity: 0.7;
}

/* --- Responsive --- */
@media (max-width: 768px) {
    .hex-outer {
        width: 80px;
        height: 92px;
    }

    .hex-outer .hex-label {
        font-size: 0.45rem;
    }

    .hex-center {
        width: 120px;
        height: 138px;
    }

    .hex-title {
        font-size: 0.55rem;
    }

    .hex-subtitle {
        font-size: 0.4rem;
    }

    .hex-row {
        gap: 3px;
    }

    .hex-row-4 {
        margin-top: -12px;
    }

    .hex-row-5 {
        margin-top: -12px;
    }

    .hex-row-4 + .hex-row-3,
    .hex-row-5 + .hex-row-4 {
        margin-top: -12px;
    }

    .hex-territory {
        width: 120px;
        height: 138px;
        min-width: 120px;
    }

    .hex-territory .hex-label {
        font-size: 0.4rem;
    }

    .hex-data {
        font-size: 0.5rem;
    }

    .dossier-coords {
        flex-wrap: wrap;
        gap: 0.75rem;
    }

    .footer-hex {
        width: 28px;
        height: 32px;
        min-width: 28px;
    }
}

@media (max-width: 480px) {
    .hex-outer {
        width: 60px;
        height: 69px;
    }

    .hex-outer .hex-label {
        font-size: 0.35rem;
    }

    .hex-center {
        width: 90px;
        height: 104px;
    }

    .hex-title {
        font-size: 0.4rem;
    }

    .hex-row {
        gap: 2px;
    }

    .hex-row-4 {
        margin-top: -8px;
    }

    .hex-row-5 {
        margin-top: -8px;
    }

    .hex-row-4 + .hex-row-3,
    .hex-row-5 + .hex-row-4 {
        margin-top: -8px;
    }

    .section-header {
        font-size: 0.6rem;
    }

    .category-label {
        font-size: 1rem;
    }

    .dossier-text {
        font-size: 0.7rem;
    }
}
