* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-dark: #0a0a0f;
    --bg-purple: #1a0a2e;
    --text-primary: #e0e0e0;
    --text-secondary: #a0a0a0;
    --accent-purple: #6b5ce7;
    --accent-blue: #4ea8de;
    --border-white: #ffffff;
    --shadow: rgba(107, 92, 231, 0.3);
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: linear-gradient(135deg, var(--bg-dark) 0%, var(--bg-purple) 100%);
    color: var(--text-primary);
    min-height: 100vh;
    position: relative;
    overflow-x: hidden;
}

.stars {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: 
        radial-gradient(2px 2px at 20% 30%, white, transparent),
        radial-gradient(2px 2px at 60% 70%, white, transparent),
        radial-gradient(1px 1px at 50% 50%, white, transparent),
        radial-gradient(1px 1px at 80% 10%, white, transparent),
        radial-gradient(2px 2px at 90% 60%, white, transparent),
        radial-gradient(1px 1px at 33% 80%, white, transparent);
    background-size: 200% 200%;
    animation: twinkle 60s ease-in-out infinite;
    opacity: 0.4;
    pointer-events: none;
    z-index: 0;
}

@keyframes twinkle {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 0.5; }
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem;
    position: relative;
    z-index: 1;
}

header {
    text-align: center;
    margin-bottom: 3rem;
}

h1 {
    font-family: 'Crimson Text', serif;
    font-size: 3.5rem;
    font-weight: 600;
    background: linear-gradient(135deg, var(--accent-purple), var(--accent-blue));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-shadow: 0 0 30px var(--shadow);
    margin-bottom: 1rem;
}

.subtitle {
    font-size: 1.1rem;
    color: var(--text-secondary);
    font-style: italic;
    max-width: 600px;
    margin: 0 auto;
    line-height: 1.6;
}

.canvas-wrapper {
    position: relative;
    width: 100%;
    max-width: 1280px;
    margin: 0 auto 2rem;
    background: #000;
    border: 3px solid var(--border-white);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5), 0 0 40px var(--shadow);
    border-radius: 4px;
    overflow: hidden;
}

#mainCanvas {
    display: block;
    width: 100%;
    height: auto;
    background: #000;
}

.loading {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(10, 10, 15, 0.95);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}

.loading.active {
    opacity: 1;
    pointer-events: all;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--text-secondary);
    border-top-color: var(--accent-purple);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading p {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.hash-display {
    text-align: center;
    margin-bottom: 2rem;
}

.hash-display label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.hash-input-group {
    display: flex;
    gap: 0.5rem;
    max-width: 800px;
    margin: 0 auto;
    justify-content: center;
    align-items: center;
}

#currentHash {
    font-family: 'Monaco', 'Consolas', 'Courier New', monospace;
    font-size: 0.9rem;
    padding: 0.75rem 1rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--accent-purple);
    border-radius: 4px;
    color: var(--text-primary);
    text-align: center;
    flex: 1;
    max-width: 700px;
}

#copyHash {
    padding: 0.75rem 1.5rem;
    background: var(--accent-purple);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.3s;
    white-space: nowrap;
}

#copyHash:hover {
    background: var(--accent-blue);
    box-shadow: 0 0 20px var(--shadow);
}

.copy-feedback {
    margin-top: 0.5rem;
    color: var(--accent-blue);
    font-size: 0.85rem;
    opacity: 0;
    transition: opacity 0.3s;
}

.copy-feedback.show {
    opacity: 1;
}

.navigation-controls {
    display: flex;
    gap: 1rem;
    justify-content: center;
    margin-bottom: 2rem;
    flex-wrap: wrap;
}

.nav-btn, .random-btn {
    padding: 1rem 2rem;
    font-size: 1rem;
    border: 2px solid var(--accent-purple);
    background: rgba(107, 92, 231, 0.1);
    color: var(--text-primary);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s;
    font-weight: 500;
}

.nav-btn:hover, .random-btn:hover {
    background: var(--accent-purple);
    box-shadow: 0 0 20px var(--shadow);
    transform: translateY(-2px);
}

.nav-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
    transform: none;
}

.random-btn {
    background: linear-gradient(135deg, var(--accent-purple), var(--accent-blue));
    border: none;
    font-size: 1.1rem;
    padding: 1rem 2.5rem;
    font-weight: 600;
}

.stats-box {
    text-align: center;
    margin-bottom: 2rem;
    padding: 1.5rem;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 8px;
    border: 1px solid rgba(107, 92, 231, 0.2);
}

.stats-box p {
    margin: 0.5rem 0;
    font-size: 0.9rem;
}

#viewCount {
    color: var(--accent-blue);
    font-weight: 600;
}

.math-note {
    font-family: 'Monaco', monospace;
    color: var(--text-secondary);
    font-size: 0.85rem !important;
}

.probability {
    font-style: italic;
    color: var(--text-secondary);
    font-size: 0.85rem !important;
}

.panel {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(107, 92, 231, 0.3);
    border-radius: 8px;
    margin-bottom: 1.5rem;
    overflow: hidden;
}

.panel summary {
    padding: 1.25rem;
    cursor: pointer;
    font-weight: 600;
    font-size: 1.1rem;
    user-select: none;
    transition: background 0.3s;
}

.panel summary:hover {
    background: rgba(107, 92, 231, 0.1);
}

.panel-content {
    padding: 1.5rem;
    border-top: 1px solid rgba(107, 92, 231, 0.2);
}

.search-section, .upload-section {
    margin-bottom: 2rem;
}

.search-section h3, .upload-section h3 {
    font-family: 'Crimson Text', serif;
    font-size: 1.3rem;
    margin-bottom: 1rem;
    color: var(--accent-blue);
}

.input-group {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

#hashInput {
    flex: 1;
    padding: 0.75rem 1rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--accent-purple);
    border-radius: 4px;
    color: var(--text-primary);
    font-family: 'Monaco', monospace;
    font-size: 0.9rem;
}

#goBtn {
    padding: 0.75rem 2rem;
    background: var(--accent-purple);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s;
}

#goBtn:hover {
    background: var(--accent-blue);
}

.error-message {
    color: #ff6b6b;
    font-size: 0.85rem;
    min-height: 1.2rem;
}

.drop-zone {
    border: 2px dashed var(--accent-purple);
    border-radius: 8px;
    padding: 3rem 2rem;
    text-align: center;
    transition: all 0.3s;
    cursor: pointer;
}

.drop-zone:hover, .drop-zone.dragover {
    background: rgba(107, 92, 231, 0.1);
    border-color: var(--accent-blue);
}

.drop-zone p {
    margin: 0.5rem 0;
}

.or {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

#browseBtn {
    padding: 0.75rem 2rem;
    background: var(--accent-purple);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s;
    margin-top: 0.5rem;
}

#browseBtn:hover {
    background: var(--accent-blue);
}

.upload-result {
    margin-top: 1rem;
    padding: 1rem;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 4px;
    display: none;
}

.upload-result.show {
    display: block;
}

.neighbors {
    display: none;
    margin-top: 1.5rem;
}

.neighbors.show {
    display: block;
}

.neighbors h4 {
    margin-bottom: 1rem;
    color: var(--accent-blue);
}

.neighbor-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}

.neighbor-item {
    text-align: center;
}

.neighbor-item canvas {
    width: 100%;
    border: 2px solid var(--accent-purple);
    border-radius: 4px;
    margin-bottom: 0.5rem;
}

.neighbor-item p {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.explanation-mode p {
    margin-bottom: 1rem;
    line-height: 1.8;
}

.explanation-mode ul {
    margin: 1rem 0 1rem 2rem;
    line-height: 1.8;
}

.explanation-mode ol {
    margin: 1rem 0 1rem 2rem;
    line-height: 1.8;
}

.explanation-mode em {
    color: var(--accent-blue);
    font-style: normal;
    font-weight: 600;
}

.explanation-mode strong {
    color: var(--accent-purple);
}

.toggle-btn {
    padding: 0.5rem 1.5rem;
    background: rgba(107, 92, 231, 0.2);
    color: var(--text-primary);
    border: 1px solid var(--accent-purple);
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.3s;
    margin-top: 1rem;
}

.toggle-btn:hover {
    background: var(--accent-purple);
}

.quotes {
    text-align: center;
    font-family: 'Crimson Text', serif;
    font-style: italic;
    font-size: 1.1rem;
    color: var(--text-secondary);
    margin: 2rem 0;
    padding: 1.5rem;
    border-top: 1px solid rgba(107, 92, 231, 0.2);
    border-bottom: 1px solid rgba(107, 92, 231, 0.2);
}

footer {
    text-align: center;
    margin-top: 3rem;
    padding: 2rem 0;
    border-top: 1px solid rgba(107, 92, 231, 0.2);
    color: var(--text-secondary);
    font-size: 0.9rem;
}

footer p {
    margin: 0.5rem 0;
}

footer a {
    color: var(--accent-blue);
    text-decoration: none;
    transition: color 0.3s;
}

footer a:hover {
    color: var(--accent-purple);
}

@media (max-width: 768px) {
    h1 {
        font-size: 2.5rem;
    }
    
    .subtitle {
        font-size: 1rem;
    }
    
    .hash-input-group {
        flex-direction: column;
    }
    
    #currentHash {
        font-size: 0.7rem;
        word-break: break-all;
    }
    
    .navigation-controls {
        flex-direction: column;
    }
    
    .nav-btn, .random-btn {
        width: 100%;
    }
    
    .neighbor-grid {
        grid-template-columns: 1fr;
    }
}