/* ============================================
   POLYDEX — GEOMETRIC ENCYCLOPEDIA
   Futuristic Glassmorphism Design System
   ============================================ */

/* --- CSS Variables / Design Tokens --- */
:root {
    /* Core Palette */
    --bg-deep: #03060d;
    --bg-primary: #060c1a;
    --bg-secondary: #0a1628;
    --bg-tertiary: #0e1f3d;
    --bg-card: rgba(10, 22, 48, 0.65);
    --bg-card-hover: rgba(15, 32, 65, 0.8);
    --bg-glass: rgba(6, 20, 50, 0.45);
    --bg-glass-border: rgba(0, 240, 255, 0.08);

    /* Accent Colors */
    --cyan: #00f0ff;
    --cyan-dim: #00a8b3;
    --cyan-glow: rgba(0, 240, 255, 0.25);
    --cyan-ultra-glow: rgba(0, 240, 255, 0.5);
    --blue: #2d7bff;
    --blue-glow: rgba(45, 123, 255, 0.2);
    --purple: #7b2fff;
    --purple-glow: rgba(123, 47, 255, 0.2);
    --pink: #ff006e;
    --green: #00ff88;
    --amber: #ffaa00;

    /* Text */
    --text-primary: #e8f0ff;
    --text-secondary: #8a9cc0;
    --text-tertiary: #4a5f8a;
    --text-accent: #00f0ff;

    /* Borders */
    --border-subtle: rgba(0, 240, 255, 0.06);
    --border-dim: rgba(0, 240, 255, 0.12);
    --border-active: rgba(0, 240, 255, 0.3);

    /* Shadows */
    --shadow-card: 0 4px 24px rgba(0, 0, 0, 0.4), 0 0 1px rgba(0, 240, 255, 0.1);
    --shadow-glow-sm: 0 0 15px rgba(0, 240, 255, 0.15);
    --shadow-glow-md: 0 0 30px rgba(0, 240, 255, 0.2);
    --shadow-glow-lg: 0 0 60px rgba(0, 240, 255, 0.15), 0 0 120px rgba(0, 240, 255, 0.05);

    /* Transitions */
    --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
    --ease-out-quart: cubic-bezier(0.25, 1, 0.5, 1);
    --transition-fast: 150ms var(--ease-out-quart);
    --transition-normal: 300ms var(--ease-out-expo);
    --transition-slow: 500ms var(--ease-out-expo);

    /* Spacing */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;

    /* Fonts */
    --font-display: 'Orbitron', sans-serif;
    --font-body: 'Inter', -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
}

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

html {
    font-size: 16px;
    scroll-behavior: smooth;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-body);
    background: var(--bg-deep);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    position: relative;
}

/* --- Background Particles --- */
.bg-particles {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    overflow: hidden;
}

.bg-particle {
    position: absolute;
    border-radius: 50%;
    background: var(--cyan);
    opacity: 0;
    animation: particleFloat linear infinite;
}

@keyframes particleFloat {
    0% {
        opacity: 0;
        transform: translateY(100vh) scale(0);
    }
    10% {
        opacity: 1;
    }
    90% {
        opacity: 1;
    }
    100% {
        opacity: 0;
        transform: translateY(-10vh) scale(1);
    }
}

/* --- Scanlines Overlay --- */
.scanlines {
    position: fixed;
    inset: 0;
    z-index: 9999;
    pointer-events: none;
    background: repeating-linear-gradient(
        0deg,
        transparent,
        transparent 2px,
        rgba(0, 240, 255, 0.008) 2px,
        rgba(0, 240, 255, 0.008) 4px
    );
}

/* --- App Container --- */
.app-container {
    position: relative;
    z-index: 1;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* --- Header --- */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 32px;
    background: var(--bg-glass);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border-dim);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.logo-mark {
    width: 42px;
    height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: logoSpin 12s linear infinite;
}

@keyframes logoSpin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.logo-svg {
    width: 100%;
    height: 100%;
    filter: drop-shadow(0 0 8px rgba(0, 240, 255, 0.4));
}

.logo-text h1 {
    font-family: var(--font-display);
    font-size: 1.5rem;
    font-weight: 800;
    letter-spacing: 6px;
    background: linear-gradient(135deg, var(--cyan) 0%, var(--blue) 50%, var(--purple) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    line-height: 1.2;
}

.logo-subtitle {
    font-family: var(--font-mono);
    font-size: 0.6rem;
    color: var(--text-tertiary);
    letter-spacing: 3px;
    text-transform: uppercase;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 20px;
}

.header-stat {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
}

.header-stat-label {
    font-family: var(--font-mono);
    font-size: 0.55rem;
    color: var(--text-tertiary);
    letter-spacing: 2px;
}

.header-stat-value {
    font-family: var(--font-display);
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text-primary);
}

.status-online {
    color: var(--green) !important;
    text-shadow: 0 0 8px rgba(0, 255, 136, 0.4);
}

.header-divider {
    width: 1px;
    height: 32px;
    background: var(--border-dim);
}

/* --- Main Content — Split Screen --- */
.main-content {
    display: flex;
    flex: 1;
    min-height: calc(100vh - 75px);
}

/* --- LEFT PANEL --- */
.left-panel {
    flex: 0 0 50%;
    max-width: 50%;
    padding: 32px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 24px;
    border-right: 1px solid var(--border-subtle);
    overflow-y: auto;
    position: relative;
}

.left-panel::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 300px;
    background: radial-gradient(ellipse at 50% 0%, rgba(0, 240, 255, 0.04) 0%, transparent 70%);
    pointer-events: none;
}

/* Shape Display Area */
.shape-display-area {
    position: relative;
    width: 320px;
    height: 320px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.shape-display-ring {
    position: absolute;
    border-radius: 50%;
    border: 1px solid var(--border-dim);
}

.ring-outer {
    width: 310px;
    height: 310px;
    animation: ringRotate 30s linear infinite;
    border-style: dashed;
    border-color: rgba(0, 240, 255, 0.08);
}

.ring-inner {
    width: 260px;
    height: 260px;
    animation: ringRotate 20s linear infinite reverse;
    border-color: rgba(123, 47, 255, 0.1);
}

@keyframes ringRotate {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.shape-glow {
    position: absolute;
    width: 200px;
    height: 200px;
    border-radius: 50%;
    background: radial-gradient(circle, var(--cyan-glow) 0%, transparent 70%);
    filter: blur(30px);
    animation: glowPulse 3s ease-in-out infinite;
    pointer-events: none;
    transition: background var(--transition-slow);
}

@keyframes glowPulse {
    0%, 100% {
        opacity: 0.6;
        transform: scale(1);
    }
    50% {
        opacity: 1;
        transform: scale(1.15);
    }
}

#shapeCanvas {
    position: relative;
    z-index: 2;
    width: 300px;
    height: 300px;
    animation: shapeFloat 4s ease-in-out infinite;
    opacity: 0.35;
}

@keyframes shapeFloat {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-12px);
    }
}

/* Pokemon Display Image */
.pokemon-display {
    position: absolute;
    z-index: 5;
    width: 260px;
    height: 260px;
    object-fit: contain;
    animation: pokemonFloat 3.5s ease-in-out infinite;
    filter: drop-shadow(0 8px 24px rgba(0, 0, 0, 0.5))
            drop-shadow(0 0 30px rgba(0, 240, 255, 0.15));
    transition: opacity 300ms ease, transform 300ms ease;
    pointer-events: none;
}

@keyframes pokemonFloat {
    0%, 100% {
        transform: translateY(0) scale(1);
    }
    25% {
        transform: translateY(-10px) scale(1.02);
    }
    50% {
        transform: translateY(-16px) scale(1.01);
    }
    75% {
        transform: translateY(-8px) scale(1.015);
    }
}

.pokemon-fade-out {
    opacity: 0 !important;
    transform: scale(0.9) translateY(10px) !important;
    animation: none !important;
}

.pokemon-fade-in {
    animation: pokemonAppear 500ms var(--ease-out-expo) forwards, pokemonFloat 3.5s ease-in-out 500ms infinite !important;
}

@keyframes pokemonAppear {
    from {
        opacity: 0;
        transform: scale(0.85) translateY(20px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.shape-label-floating {
    position: absolute;
    bottom: -5px;
    font-family: var(--font-mono);
    font-size: 0.65rem;
    color: var(--text-tertiary);
    letter-spacing: 4px;
    text-transform: uppercase;
    z-index: 3;
}

/* Shape Identity */
.shape-identity {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    opacity: 1;
    transition: opacity var(--transition-normal);
}

.shape-identity.fade-out {
    opacity: 0;
}

.shape-id-badge {
    font-family: var(--font-mono);
    font-size: 0.65rem;
    color: var(--cyan-dim);
    background: rgba(0, 240, 255, 0.06);
    padding: 3px 14px;
    border-radius: 20px;
    border: 1px solid var(--border-dim);
    letter-spacing: 2px;
}

.shape-name-bm {
    font-family: var(--font-display);
    font-size: 1.8rem;
    font-weight: 800;
    letter-spacing: 3px;
    background: linear-gradient(135deg, #fff 0%, var(--cyan) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.shape-name-en {
    font-family: var(--font-body);
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 400;
    letter-spacing: 1px;
}

.shape-classification {
    display: flex;
    gap: 8px;
    margin-top: 4px;
}

.class-tag {
    font-family: var(--font-mono);
    font-size: 0.6rem;
    padding: 3px 12px;
    border-radius: 4px;
    background: rgba(123, 47, 255, 0.1);
    border: 1px solid rgba(123, 47, 255, 0.2);
    color: var(--purple);
    letter-spacing: 1px;
    text-transform: uppercase;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    width: 100%;
    max-width: 420px;
}

.stat-card {
    background: var(--bg-card);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-dim);
    border-radius: var(--radius-md);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    transition: all var(--transition-normal);
    position: relative;
    overflow: hidden;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, var(--cyan) 0%, transparent 100%);
    opacity: 0;
    transition: opacity var(--transition-normal);
}

.stat-card:hover {
    border-color: var(--border-active);
    background: var(--bg-card-hover);
    transform: translateY(-2px);
    box-shadow: var(--shadow-glow-sm);
}

.stat-card:hover::before {
    opacity: 1;
}

.stat-card-wide {
    grid-column: 1 / -1;
}

.stat-icon {
    width: 28px;
    height: 28px;
    color: var(--cyan);
    opacity: 0.7;
}

.stat-info {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
}

.stat-label {
    font-family: var(--font-mono);
    font-size: 0.6rem;
    color: var(--text-tertiary);
    letter-spacing: 2px;
}

.stat-value {
    font-family: var(--font-display);
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    transition: all var(--transition-normal);
}

.stat-bar {
    width: 100%;
    height: 3px;
    background: rgba(0, 240, 255, 0.06);
    border-radius: 2px;
    overflow: hidden;
}

.stat-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--cyan), var(--blue));
    border-radius: 2px;
    transition: width 600ms var(--ease-out-expo);
    box-shadow: 0 0 8px var(--cyan-glow);
}

/* Formula Display */
.formula-display {
    width: 100%;
    max-width: 420px;
    background: var(--bg-card);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-dim);
    border-radius: var(--radius-md);
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.formula-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.formula-label {
    font-family: var(--font-mono);
    font-size: 0.6rem;
    color: var(--text-tertiary);
    letter-spacing: 1px;
    text-transform: uppercase;
    flex-shrink: 0;
}

.formula-expr {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--cyan);
    text-align: right;
    transition: all var(--transition-normal);
}

/* --- RIGHT PANEL --- */
.right-panel {
    flex: 0 0 50%;
    max-width: 50%;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    overflow-y: auto;
    position: relative;
}

/* Search */
.search-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.search-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--bg-card);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-dim);
    border-radius: var(--radius-lg);
    padding: 14px 20px;
    transition: all var(--transition-normal);
}

.search-bar:focus-within {
    border-color: var(--cyan);
    box-shadow: var(--shadow-glow-sm), inset 0 0 20px rgba(0, 240, 255, 0.03);
}

.search-icon {
    width: 20px;
    height: 20px;
    color: var(--text-tertiary);
    flex-shrink: 0;
    transition: color var(--transition-normal);
}

.search-bar:focus-within .search-icon {
    color: var(--cyan);
}

#searchInput {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    font-family: var(--font-body);
    font-size: 0.9rem;
    color: var(--text-primary);
    letter-spacing: 0.5px;
}

#searchInput::placeholder {
    color: var(--text-tertiary);
}

.search-shortcut {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.search-shortcut kbd {
    font-family: var(--font-mono);
    font-size: 0.6rem;
    padding: 2px 6px;
    background: rgba(0, 240, 255, 0.05);
    border: 1px solid var(--border-dim);
    border-radius: 4px;
    color: var(--text-tertiary);
}

.search-results-count {
    font-family: var(--font-mono);
    font-size: 0.65rem;
    color: var(--text-tertiary);
    letter-spacing: 1px;
    padding-left: 8px;
}

/* Shape Grid */
.shape-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 14px;
    flex: 1;
}

.grid-card {
    background: var(--bg-card);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-dim);
    border-radius: var(--radius-lg);
    padding: 20px;
    cursor: pointer;
    transition: all var(--transition-normal);
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    animation: cardAppear 400ms var(--ease-out-expo) both;
}

.grid-card::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(0, 240, 255, 0.03) 0%, transparent 50%);
    opacity: 0;
    transition: opacity var(--transition-normal);
}

.grid-card::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--cyan), transparent);
    opacity: 0;
    transition: opacity var(--transition-normal);
}

.grid-card:hover {
    border-color: var(--border-active);
    transform: translateY(-4px);
    box-shadow: var(--shadow-glow-md);
}

.grid-card:hover::before,
.grid-card:hover::after {
    opacity: 1;
}

.grid-card.active {
    border-color: var(--cyan);
    background: rgba(0, 240, 255, 0.06);
    box-shadow: var(--shadow-glow-sm);
}

.grid-card.active::after {
    opacity: 1;
}

.grid-card.hidden {
    display: none;
}

@keyframes cardAppear {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Pokemon Thumbnail in Grid Cards */
.grid-card-pokemon {
    width: 90px;
    height: 90px;
    object-fit: contain;
    filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.3));
    transition: all var(--transition-normal);
    animation: gridPokemonFloat 3s ease-in-out infinite;
    animation-delay: var(--float-delay, 0s);
}

.grid-card:hover .grid-card-pokemon {
    transform: scale(1.1);
    filter: drop-shadow(0 6px 16px rgba(0, 240, 255, 0.2))
            drop-shadow(0 4px 8px rgba(0, 0, 0, 0.3));
}

.grid-card.active .grid-card-pokemon {
    filter: drop-shadow(0 4px 12px rgba(0, 240, 255, 0.3))
            drop-shadow(0 2px 6px rgba(0, 0, 0, 0.4));
}

@keyframes gridPokemonFloat {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-4px);
    }
}

.grid-card-info {
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.grid-card-name {
    font-family: var(--font-display);
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: 1.5px;
}

.grid-card-en {
    font-family: var(--font-body);
    font-size: 0.7rem;
    color: var(--text-secondary);
    font-weight: 400;
}

.grid-card-sides {
    font-family: var(--font-mono);
    font-size: 0.6rem;
    color: var(--text-tertiary);
    margin-top: 4px;
    letter-spacing: 1px;
}

/* No Results State */
.no-results {
    grid-column: 1 / -1;
    text-align: center;
    padding: 40px 20px;
    color: var(--text-tertiary);
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.no-results.visible {
    display: flex;
}

.no-results svg {
    width: 48px;
    height: 48px;
    opacity: 0.3;
}

.no-results p {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    letter-spacing: 1px;
}

/* Right Panel Footer */
.right-panel-footer {
    text-align: center;
    padding: 16px 0 8px;
    border-top: 1px solid var(--border-subtle);
    margin-top: auto;
}

.right-panel-footer p {
    font-family: var(--font-mono);
    font-size: 0.6rem;
    color: var(--text-tertiary);
    letter-spacing: 1px;
}

.footer-formula {
    margin-top: 4px;
    color: var(--cyan-dim) !important;
    opacity: 0.5;
}

/* --- Shape Transition Overlay --- */
.shape-transition-overlay {
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at center, rgba(0, 240, 255, 0.08) 0%, transparent 70%);
    opacity: 0;
    pointer-events: none;
    z-index: 10;
    transition: opacity 400ms ease;
}

.shape-transition-overlay.flash {
    opacity: 1;
}

/* --- Stat Value Animate --- */
.stat-value.counting {
    color: var(--cyan);
    text-shadow: 0 0 12px var(--cyan-glow);
}

/* --- Responsive --- */
@media (max-width: 1024px) {
    .main-content {
        flex-direction: column;
    }
    .left-panel,
    .right-panel {
        flex: none;
        max-width: 100%;
        width: 100%;
    }
    .left-panel {
        border-right: none;
        border-bottom: 1px solid var(--border-subtle);
        padding: 24px 20px;
    }
    .shape-display-area {
        width: 250px;
        height: 250px;
    }
    #shapeCanvas {
        width: 240px;
        height: 240px;
    }
    .ring-outer {
        width: 245px;
        height: 245px;
    }
    .ring-inner {
        width: 210px;
        height: 210px;
    }
    .stats-grid {
        max-width: 100%;
    }
    .formula-display {
        max-width: 100%;
    }
    .right-panel {
        padding: 20px;
    }
}

@media (max-width: 640px) {
    .app-header {
        padding: 12px 16px;
    }
    .logo-text h1 {
        font-size: 1.1rem;
        letter-spacing: 4px;
    }
    .header-right {
        display: none;
    }
    .shape-grid {
        grid-template-columns: 1fr;
    }
    .stats-grid {
        grid-template-columns: 1fr;
    }
    .stat-card-wide {
        grid-column: auto;
    }
    .search-shortcut {
        display: none;
    }
    .shape-name-bm {
        font-size: 1.3rem;
    }
}

/* --- Scrollbar --- */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(0, 240, 255, 0.15);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 240, 255, 0.3);
}

/* --- Selection --- */
::selection {
    background: rgba(0, 240, 255, 0.2);
    color: #fff;
}
