/**
 * gTesseract 4D Hypercube Styles
 * GPU-accelerated CSS3 3D transforms for tesseract interface
 *
 * Architecture:
 * - .viewport: 3D perspective container (full screen)
 * - .world: Transform origin for wireframe (centered)
 * - .cell-layer: Content cells positioned at inner cube
 * - .nav-layer: Navigation buttons (fixed sides)
 *
 * @package gTesseract
 * @version 2.0.0
 */

/* --- CSS VARIABLES --- */
:root {
    --bg-inner: #1b1b2f;
    --bg-outer: #050510;
    --neon-cyan: #00f3ff;
    --neon-pink: #ff0055;
    --neon-purple: #9d00ff;
    --glass: rgba(0, 243, 255, 0.05);
    --border: rgba(0, 243, 255, 0.3);
    --color-highlight: #e51022;
    --content-bg: rgba(0, 10, 20, 0.85);

    /* SIZE CONTROLS */
    --tesseract-scale: 35vmin;
    --cell-size: 28vmin;        /* Content cell size (fits inside inner cube) */
    --cell-max-size: 90vmin;    /* Maximum content cell size (0 = no max) */
    --line-width: 2px;
    --node-size: 8px;
    --tesseract-depth-offset: 0; /* Depth axis offset for content positioning */

    /* TYPOGRAPHY - vmin based for consistent scaling */
    --font-size-nav: 2vmin;
    --font-size-title: 4vmin;
    --font-size-body: 2.2vmin;
    --font-size-small: 1.6vmin;
    --font-size-tiny: 1.2vmin;

    /* ANIMATION */
    --transition-speed: 0.4s;
    --rotation-smoothing: 0.08;
}

/* --- RESET & BASE --- */
*, *::before, *::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    overflow: hidden;
    background: radial-gradient(circle at center, var(--bg-inner) 0%, var(--bg-outer) 100%);
    min-height: 100vh;
    font-family: 'Courier New', 'Consolas', monospace;
    color: white;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* --- COPY PROTECTION (disabled for reading mode) --- */
body:not(.cell-expanded-mode) {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

/* Prevent image dragging */
img {
    -webkit-user-drag: none;
    -khtml-user-drag: none;
    -moz-user-drag: none;
    -o-user-drag: none;
    user-drag: none;
    pointer-events: none;
}

/* Allow pointer events on logo for link clicks */
.site-logo img {
    pointer-events: auto;
}

/* --- UI LAYER: NAVIGATION --- */
.nav-layer {
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    z-index: 100;
    display: flex;
    flex-direction: column;
    gap: 15px;
    padding: 20px;
}

.nav-layer.left {
    left: 0;
    align-items: flex-start;
}

.nav-layer.right {
    right: 0;
    align-items: flex-end;
}

.nav-btn {
    background: var(--nav-button-bg-color, rgba(0, 0, 0, 0.5));
    border: var(--nav-button-border-width, 1px) solid var(--nav-button-border-color, var(--border));
    color: var(--nav-button-text-color, var(--neon-cyan));
    padding: var(--nav-button-padding, 12px 24px);
    font-size: var(--nav-button-font-size, var(--font-size-nav));
    font-family: inherit;
    text-transform: uppercase;
    cursor: pointer;
    transition: all var(--transition-speed) ease;
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    min-width: var(--nav-button-min-width, 140px);
    letter-spacing: 2px;
    border-radius: var(--nav-button-border-radius, 0);
}

.nav-btn:hover {
    background: var(--nav-button-hover-bg-color, var(--neon-cyan));
    color: var(--nav-button-hover-text-color, #000);
    box-shadow: 0 0 20px var(--neon-cyan);
}

.nav-btn:focus {
    outline: none;
    box-shadow: 0 0 0 2px var(--neon-pink);
}

.nav-btn.active {
    border-color: var(--neon-pink);
    color: var(--neon-pink);
    box-shadow: 0 0 10px var(--neon-pink) inset;
}

/* --- 3D VIEWPORT (WIREFRAME LAYER) --- */
.viewport {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    pointer-events: none;
    /* NO CSS perspective - all projection done in JavaScript for accurate edge connections */
}

.world {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    will-change: transform;
    /* NO preserve-3d - pure 2D positioning ensures edges always connect at vertices */
}

/* --- TESSERACT GEOMETRY (WIREFRAME) --- */
.edge {
    position: absolute;
    background: linear-gradient(90deg, var(--neon-cyan), rgba(0, 243, 255, 0.6));
    height: var(--line-width);
    transform-origin: 0 50%;
    box-shadow: 0 0 8px var(--neon-cyan), 0 0 2px white;
    will-change: transform, opacity, width;
    opacity: 0.8;
    border-radius: 1px;
    backface-visibility: visible;
}

.node {
    position: absolute;
    width: var(--node-size);
    height: var(--node-size);
    background: radial-gradient(circle, white 30%, var(--neon-cyan) 100%);
    border-radius: 50%;
    /* transform handled by JS - includes centering */
    box-shadow: 0 0 15px white, 0 0 30px var(--neon-cyan);
    will-change: transform, opacity;
}

/* --- CONTENT LAYER (CELLS) --- */
.cell-layer {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    pointer-events: none;
    /* No flexbox - JS positions cells directly */
}

/* Individual cell panel - positioned by JS at inner cube center */
.tesseract-cell {
    position: fixed;
    width: var(--cell-size);
    height: var(--cell-size);
    max-width: var(--cell-max-size, none);
    max-height: var(--cell-max-size, none);
    opacity: 0;
    pointer-events: none;
    /* Default center position before JS kicks in */
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%) scale(0.9);
    transition: opacity var(--transition-speed) ease-out;
    will-change: transform, left, top, opacity;
    /* Prevent iOS double-tap zoom - allows our double-tap handler to work */
    touch-action: manipulation;
}

.tesseract-cell.active {
    opacity: 1;
    pointer-events: auto;
    /* transform is set by JS for positioning and tilt */
}

/* Cell container - glass morphism style */
.cell-container {
    width: 100%;
    height: 100%;
    background: var(--content-bg);
    border: 1px solid var(--border);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* Cell content area */
.cell-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 30px;
    overflow: hidden;
}

.cell-header {
    flex-shrink: 0;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--border);
}

.cell-title {
    font-size: var(--font-size-title);
    margin: 0;
    color: var(--neon-cyan);
    text-shadow: 0 0 20px var(--neon-cyan);
    text-transform: uppercase;
    letter-spacing: 3px;
}

.cell-body {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    font-size: var(--font-size-body);
    line-height: 1.6;
    color: #ddd;
    scrollbar-width: thin;
    scrollbar-color: var(--neon-cyan) transparent;
}

.cell-body::-webkit-scrollbar {
    width: 6px;
}

.cell-body::-webkit-scrollbar-track {
    background: transparent;
}

.cell-body::-webkit-scrollbar-thumb {
    background: var(--neon-cyan);
    border-radius: 3px;
}

.cell-body a {
    color: var(--neon-cyan);
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: border-color var(--transition-speed);
}

.cell-body a:hover {
    border-bottom-color: var(--neon-cyan);
}

.cell-body p {
    margin: 0 0 15px 0;
}

.cell-body p:last-child {
    margin-bottom: 0;
}

/* --- LOADING STATE --- */
.tesseract-loading {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: var(--font-size-title);
    color: var(--neon-cyan);
    text-transform: uppercase;
    letter-spacing: 4px;
    animation: pulse 1.5s ease-in-out infinite;
    z-index: 200;
}

@keyframes pulse {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 1; }
}

/* --- RESPONSIVE --- */
@media (max-width: 768px) {
    :root {
        /* Smaller wireframe on mobile */
        --tesseract-scale: 18vmin;
        --cell-size: 80vw;
        --line-width: 1.5px;
        --node-size: 5px;
        /* Typography using vmin for consistent scaling */
        --font-size-nav: 2.5vmin;
        --font-size-title: 5vmin;
        --font-size-body: 3vmin;
        --font-size-small: 2.2vmin;
        --font-size-tiny: 1.8vmin;
    }

    /* Mobile: 4 buttons on top (2x2), 4 buttons on bottom (2x2) */
    .nav-layer {
        position: fixed;
        left: 0;
        right: 0;
        transform: none;
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
        padding: 1vmin 2vmin;
        background: rgba(0, 0, 0, 0.85);
        gap: 1vmin;
        z-index: 100;
    }

    .nav-layer.left {
        top: 0;
        bottom: auto;
        align-items: center;
    }

    .nav-layer.right {
        top: auto;
        bottom: 0;
        display: flex;
        align-items: center;
    }

    .nav-btn {
        min-width: auto;
        padding: 1.5vmin 2vmin;
        font-size: 2.5vmin;
        flex: 1 1 45%;
        max-width: 48%;
        letter-spacing: 0;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .tesseract-cell {
        max-width: 85vw;
        max-height: 45vh;
        /* Keep centered on tesseract face - no offset margins */
        margin: 0;
    }

    .cell-content {
        padding: 20px;
    }

    .cell-title {
        font-size: var(--font-size-title);
    }

    /* Mobile logo positioning - always centered above nav buttons */
    .site-logo,
    .site-logo.logo-left,
    .site-logo.logo-center,
    .site-logo.logo-right {
        top: 8px;
        bottom: auto;
        left: 50%;
        right: auto;
        transform: translateX(-50%);
        z-index: 200;
    }

    .site-logo img {
        max-width: 40px;
        height: auto;
    }

    /* Adjust top nav to make room for logo */
    .nav-layer.left {
        top: 52px;
    }

    /* Ensure content cell is above wireframe on mobile */
    .cell-layer {
        z-index: 50;
    }

    .tesseract-cell {
        z-index: 60;
    }
}

/* --- ACCESSIBILITY --- */
@media (prefers-reduced-motion: reduce) {
    .edge,
    .node,
    .tesseract-cell,
    .nav-btn {
        transition: none;
    }

    .world {
        animation: none !important;
    }
}

/* --- PRINT --- */
@media print {
    .viewport,
    .nav-layer {
        display: none;
    }

    .cell-layer {
        position: static;
    }

    .tesseract-cell {
        position: static;
        opacity: 1;
        transform: none;
        width: 100%;
        height: auto;
        max-width: none;
        max-height: none;
    }

    .tesseract-cell:not(.active) {
        display: none;
    }

    .cell-container {
        background: white;
        color: black;
        border: 1px solid #ccc;
    }

    .cell-title {
        color: black;
        text-shadow: none;
    }
}

/* --- CELL EXPANSION (Fullscreen Reading Mode) --- */

/* Backdrop overlay - z-index 990, BELOW expanded overlay (995) */
.cell-expand-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease;
    z-index: 990 !important;
}

.cell-expand-backdrop.active {
    opacity: 1;
    pointer-events: auto;
    z-index: 990 !important;
}

/* Expanded overlay - cloned content at body level, outside stacking context */
.cell-expanded-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 995;
    background: var(--bg-color, #0a0a0f);
    overflow-y: auto;
    overflow-x: hidden;
    opacity: 0;
    transform: scale(0.9);
    transition: opacity 0.4s ease, transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.cell-expanded-overlay.active {
    opacity: 1;
    transform: scale(1);
}

/* Style the content inside the overlay */
.cell-expanded-overlay .cell-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 60px 20px 40px;
    min-height: 100vh;
}

/* Re-enable text selection in expanded overlay (reading mode) */
.cell-expanded-overlay,
.cell-expanded-overlay * {
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    user-select: text;
}

/* Close button - must be above overlay (995) */
.cell-expand-close {
    position: fixed;
    top: 20px;
    right: 20px;
    width: 50px;
    height: 50px;
    background: rgba(0, 0, 0, 0.7);
    border: 2px solid var(--neon-cyan);
    color: var(--neon-cyan);
    font-size: var(--font-size-title);
    line-height: 1;
    cursor: pointer;
    border-radius: 50%;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    z-index: 999;
}

.cell-expand-close.active {
    opacity: 1;
    visibility: visible;
}

.cell-expand-close:hover {
    background: var(--neon-cyan);
    color: #000;
    box-shadow: 0 0 20px var(--neon-cyan);
}

/* Expand hint */
.cell-expand-hint {
    position: absolute;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.7);
    color: var(--neon-cyan);
    padding: 5px 15px;
    font-size: var(--font-size-small);
    text-transform: uppercase;
    letter-spacing: 1px;
    border-radius: 20px;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
    white-space: nowrap;
}

.tesseract-cell.active:hover .cell-expand-hint {
    opacity: 0.8;
}

/* Expanded cell state - BASE (applies to all modes) */
/* z-index 1000 ensures content is ABOVE backdrop (50) */
.tesseract-cell.cell-expanded-active {
    position: fixed !important;
    left: 50% !important;
    top: 50% !important;
    width: 90vw !important;
    height: 90vh !important;
    max-width: none !important;
    max-height: none !important;
    transform: translate(-50%, -50%) !important;
    z-index: 1000 !important;
    opacity: 1 !important;
    pointer-events: auto !important;
}

/* Expanded cell state - FOCUS MODE (100% viewport) */
.expand-mode-focus .tesseract-cell.cell-expanded-active {
    width: 90vw !important;
    height: 90vh !important;
}

/* Expanded cell state - CLASSIC MODE (scaled) */
.expand-mode-classic .tesseract-cell.cell-expanded-active {
    width: 70vmin !important;
    height: 70vmin !important;
    max-width: 800px !important;
    max-height: 800px !important;
    transform: translate(-50%, -50%) scale(1.2) !important;
}

/* Hide tesseract when cell is expanded */
.cell-expanded-mode .viewport {
    opacity: 0.3;
    pointer-events: none;
}

/* Hide navigation when expanded */
.cell-expanded-mode .nav-layer {
    opacity: 0;
    pointer-events: none;
}

/* Smooth transitions */
.tesseract-cell {
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.viewport,
.nav-layer {
    transition: opacity 0.4s ease;
}

/* --- LOGO --- */
.site-logo {
    position: fixed;
    top: 15px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 150;
    pointer-events: auto;
}

.site-logo img {
    max-width: var(--logo-width, 10vmin);
    max-height: var(--logo-height, auto);
    height: auto;
    width: auto;
    filter: drop-shadow(0 0 10px rgba(0, 243, 255, 0.3));
    transition: filter var(--transition-speed) ease;
}

.site-logo img:hover {
    filter: drop-shadow(0 0 20px rgba(0, 243, 255, 0.6));
}

/* Logo position variants */
.site-logo.logo-left {
    left: 15px;
    transform: none;
}

.site-logo.logo-center {
    left: 50%;
    transform: translateX(-50%);
}

.site-logo.logo-right {
    left: auto;
    right: 15px;
    transform: none;
}

/* Hide logo when cell is expanded */
.cell-expanded-mode .site-logo {
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-speed) ease;
}

/* --- FOOTER CREDIT --- */
.site-footer {
    position: fixed;
    bottom: 10px;
    right: 15px;
    z-index: 50;
    pointer-events: auto;
}

.geodineum-credit {
    font-size: var(--font-size-tiny);
    color: rgba(0, 243, 255, 0.4);
    text-transform: uppercase;
    letter-spacing: 1px;
    font-family: inherit;
}

.geodineum-credit:hover {
    color: rgba(0, 243, 255, 0.7);
}

/* Hide footer when cell is expanded */
.cell-expanded-mode .site-footer {
    opacity: 0;
    pointer-events: none;
}

/* ==========================================================================
   Posts Container (Scrollable Multi-Post Display)
   ========================================================================== */

/* Posts content wrapper */
.cell-content-posts {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

/* Scrollable posts container */
.cell-posts-container {
    max-height: 70vh;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 1rem;
    scroll-behavior: smooth;
    flex: 1;
}

/* Custom scrollbar styling (cyan neon theme) */
.cell-posts-container::-webkit-scrollbar {
    width: 6px;
}

.cell-posts-container::-webkit-scrollbar-track {
    background: rgba(0, 243, 255, 0.05);
    border-radius: 3px;
}

.cell-posts-container::-webkit-scrollbar-thumb {
    background: rgba(0, 243, 255, 0.3);
    border-radius: 3px;
    transition: background 0.2s ease;
}

.cell-posts-container::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 243, 255, 0.5);
}

/* Firefox scrollbar */
.cell-posts-container {
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 243, 255, 0.3) rgba(0, 243, 255, 0.05);
}

/* Individual post item */
.cell-post-item {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.25rem;
    padding-bottom: 1.25rem;
    border-bottom: 1px solid rgba(0, 243, 255, 0.1);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.cell-post-item:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.cell-post-item:hover {
    transform: translateX(4px);
}

/* Post thumbnail */
.cell-post-thumbnail {
    flex-shrink: 0;
    width: 80px;
    height: 80px;
    border-radius: 6px;
    overflow: hidden;
    border: 1px solid rgba(0, 243, 255, 0.2);
}

.cell-post-thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.cell-post-item:hover .cell-post-thumbnail img {
    transform: scale(1.05);
}

/* Post content area */
.cell-post-content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

/* Post title */
.cell-post-title {
    font-size: 1rem;
    font-weight: 500;
    margin: 0 0 0.4rem 0;
    line-height: 1.3;
}

.cell-post-title a {
    color: rgba(255, 255, 255, 0.9);
    text-decoration: none;
    transition: color 0.2s ease;
}

.cell-post-title a:hover {
    color: var(--neon-primary, #00f3ff);
    text-shadow: 0 0 8px var(--neon-primary, #00f3ff);
}

/* Post excerpt */
.cell-post-excerpt {
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.5);
    line-height: 1.5;
    margin-bottom: 0.4rem;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Post meta (date, category) */
.cell-post-meta {
    font-size: 0.7rem;
    color: rgba(0, 243, 255, 0.5);
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.cell-post-categories {
    background: rgba(0, 243, 255, 0.1);
    padding: 0.15rem 0.5rem;
    border-radius: 3px;
    font-weight: 500;
    border: 1px solid rgba(0, 243, 255, 0.2);
}

/* Empty state */
.cell-posts-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 2rem;
}

.cell-posts-message {
    text-align: center;
    color: rgba(0, 243, 255, 0.4);
    font-size: 1rem;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .cell-post-item {
        flex-direction: column;
        gap: 0.75rem;
    }

    .cell-post-thumbnail {
        width: 100%;
        height: 100px;
    }

    .cell-posts-container {
        max-height: 65vh;
        padding: 0.75rem;
    }
}
