/* Core Variables and Design Tokens */
:root {
    --bg-dark: #07050d;
    --bg-card: rgba(20, 15, 38, 0.55);
    --border-color: rgba(255, 255, 255, 0.08);
    --border-focus: rgba(168, 85, 247, 0.4);
    
    --text-main: #f3f4f6;
    --text-muted: #9ca3af;
    
    /* Harmonious Neon Gradients */
    --primary: #a855f7;
    --primary-glow: rgba(168, 85, 247, 0.35);
    --accent: #22d3ee;
    --accent-glow: rgba(34, 211, 238, 0.3);
    --success: #10b981;
    --success-glow: rgba(16, 185, 129, 0.25);
    --error: #ef4444;
    
    --font-sans: 'Outfit', sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
    
    --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

html, body {
    height: 100%;
    background-color: var(--bg-dark);
    color: var(--text-main);
    font-family: var(--font-sans);
    overflow-x: hidden;
}

/* Canvas Particle Background */
#bg-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: -1;
    pointer-events: none;
    background: linear-gradient(135deg, #07050d 0%, #110c24 50%, #07050d 100%);
}

/* Main Container */
.app-container {
    max-width: 900px;
    margin: 0 auto;
    padding: 40px 20px;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Header */
.app-header {
    text-align: center;
    margin-bottom: 40px;
}

.logo {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.logo-icon {
    width: 38px;
    height: 38px;
    color: var(--primary);
}

.purple-glow {
    filter: drop-shadow(0 0 10px var(--primary-glow));
}

.logo-text {
    font-size: 32px;
    font-weight: 800;
    letter-spacing: 2px;
}

.logo-text .accent {
    color: var(--accent);
    text-shadow: 0 0 12px var(--accent-glow);
}

.tagline {
    font-size: 16px;
    color: var(--text-muted);
    font-weight: 300;
}

/* Dashboard Card */
.dashboard-card {
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border-color);
    border-radius: 24px;
    padding: 30px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.4);
    position: relative;
    overflow: hidden;
    margin-bottom: 40px;
}

/* Tabs Navigation */
.tabs-nav {
    display: flex;
    gap: 10px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 20px;
    margin-bottom: 30px;
}

.tab-btn {
    flex: 1;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    padding: 14px 20px;
    border-radius: 12px;
    cursor: pointer;
    font-weight: 600;
    font-size: 16px;
    font-family: var(--font-sans);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: var(--transition-smooth);
}

.tab-btn:hover {
    color: var(--text-main);
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.15);
}

.tab-btn.active {
    background: linear-gradient(135deg, rgba(168, 85, 247, 0.15), rgba(34, 211, 238, 0.05));
    border-color: var(--primary);
    color: var(--text-main);
    box-shadow: 0 0 15px rgba(168, 85, 247, 0.15);
}

/* File Drop Zone */
.drop-zone {
    border: 2px dashed rgba(255, 255, 255, 0.15);
    border-radius: 16px;
    padding: 40px 20px;
    text-align: center;
    position: relative;
    background: rgba(255, 255, 255, 0.01);
    transition: var(--transition-smooth);
    cursor: pointer;
    min-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.drop-zone:hover, .drop-zone.dragover {
    border-color: var(--primary);
    background: rgba(168, 85, 247, 0.02);
    box-shadow: 0 0 25px rgba(168, 85, 247, 0.08);
}

.file-input {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
    z-index: 10;
}

.drop-zone-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    pointer-events: none;
}

.icon-wrap {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.03);
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border-color);
    transition: var(--transition-smooth);
}

.drop-zone:hover .icon-wrap {
    transform: translateY(-5px);
    background: rgba(168, 85, 247, 0.1);
    border-color: var(--primary);
}

.upload-icon {
    width: 28px;
    height: 28px;
    color: var(--text-muted);
    transition: var(--transition-smooth);
}

.drop-zone:hover .upload-icon {
    color: var(--primary);
}

.drop-zone-content h3 {
    font-size: 18px;
    font-weight: 600;
}

.drop-zone-content p {
    color: var(--text-muted);
    font-size: 14px;
}

.browse-btn {
    color: var(--primary);
    text-decoration: underline;
    font-weight: 500;
}

.supported-text {
    font-size: 12px !important;
    opacity: 0.6;
}

/* Selected File State */
.selected-file-state {
    display: flex;
    align-items: center;
    gap: 15px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-color);
    padding: 16px 20px;
    border-radius: 12px;
    width: 100%;
    max-width: 500px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    position: relative;
    z-index: 10;
}

.file-icon {
    width: 32px;
    height: 32px;
    color: var(--accent);
}

.file-details {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    overflow: hidden;
    flex: 1;
}

.file-name {
    font-weight: 600;
    font-size: 16px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
    text-align: left;
}

.file-size {
    font-size: 13px;
    color: var(--text-muted);
}

.remove-file-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-smooth);
}

.remove-file-btn:hover {
    color: var(--error);
    background: rgba(239, 68, 68, 0.1);
}

/* Action Bar */
.action-bar {
    margin-top: 24px;
    display: flex;
    justify-content: center;
}

.action-btn {
    background: linear-gradient(135deg, var(--primary), #7c3aed);
    color: white;
    border: none;
    padding: 14px 40px;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    font-family: var(--font-sans);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: var(--transition-smooth);
    box-shadow: 0 4px 20px rgba(168, 85, 247, 0.35);
}

.action-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 25px rgba(168, 85, 247, 0.5);
}

.action-btn:active:not(:disabled) {
    transform: translateY(0);
}

.action-btn:disabled {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-muted);
    border: 1px solid var(--border-color);
    box-shadow: none;
    cursor: not-allowed;
}

/* Loading State Container */
.loading-container {
    padding: 30px 10px;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

.spinner-box {
    position: relative;
    width: 80px;
    height: 80px;
}

.spinner-ring {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 3px solid rgba(168, 85, 247, 0.1);
    border-top-color: var(--primary);
    border-right-color: var(--accent);
    animation: spin 1.2s cubic-bezier(0.5, 0, 0.5, 1) infinite;
}

.loading-center-icon {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 24px;
    height: 24px;
    color: var(--accent);
    animation: pulse 1.8s ease-in-out infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes pulse {
    0%, 100% { opacity: 0.5; transform: translate(-50%, -50%) scale(0.9); }
    50% { opacity: 1; transform: translate(-50%, -50%) scale(1.1); }
}

.loading-container h4 {
    font-size: 18px;
    font-weight: 600;
}

.loading-container p {
    color: var(--text-muted);
    font-size: 14px;
}

/* Results Area */
.results-container {
    animation: slideUp 0.4s ease-out;
}

.section-title {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.success-icon {
    color: var(--success);
}

.comparison-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 20px;
    margin-bottom: 30px;
}

@media (max-width: 768px) {
    .comparison-grid {
        grid-template-columns: 1fr;
    }
}

.metric-card {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.highlight-card {
    border-color: rgba(34, 211, 238, 0.3);
    background: linear-gradient(135deg, rgba(34, 211, 238, 0.03), rgba(168, 85, 247, 0.02));
    box-shadow: 0 0 20px rgba(34, 211, 238, 0.05);
}

.card-header-small {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 600;
}

.metric-val {
    font-size: 20px;
    font-weight: 700;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.metric-desc {
    font-size: 14px;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

.text-success {
    color: var(--success) !important;
}

.text-accent {
    color: var(--accent) !important;
}

.results-actions {
    display: flex;
    gap: 15px;
    justify-content: center;
    align-items: center;
    margin-bottom: 20px;
}

.download-btn {
    background: linear-gradient(135deg, var(--success), #059669);
    color: white;
    text-decoration: none;
    padding: 14px 30px;
    border-radius: 12px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: var(--transition-smooth);
    box-shadow: 0 4px 15px rgba(16, 185, 129, 0.3);
}

.download-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(16, 185, 129, 0.45);
}

.reset-btn {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 14px 24px;
    border-radius: 12px;
    cursor: pointer;
    font-weight: 600;
    font-size: 15px;
    font-family: var(--font-sans);
    display: flex;
    align-items: center;
    gap: 8px;
    transition: var(--transition-smooth);
}

.reset-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.2);
}

.performance-tag {
    font-size: 13px;
    color: var(--text-muted);
    text-align: center;
}

.mono {
    font-family: var(--font-mono);
    color: var(--accent);
}

/* Error Alert */
.error-alert {
    background: rgba(239, 68, 68, 0.08);
    border: 1px solid rgba(239, 68, 68, 0.2);
    border-radius: 12px;
    padding: 15px 20px;
    color: #fca5a5;
    display: flex;
    align-items: flex-start;
    gap: 12px;
    margin-top: 24px;
    animation: slideUp 0.3s ease-out;
}

.error-alert svg {
    color: var(--error);
    flex-shrink: 0;
    margin-top: 2px;
}

.error-content {
    flex: 1;
    text-align: left;
}

.error-content strong {
    display: block;
    font-size: 15px;
    margin-bottom: 3px;
}

.error-content p {
    font-size: 13px;
    opacity: 0.9;
}

.close-error-btn {
    background: none;
    border: none;
    color: #fca5a5;
    cursor: pointer;
    padding: 2px;
    opacity: 0.7;
    transition: var(--transition-smooth);
}

.close-error-btn:hover {
    opacity: 1;
}

/* Info Section */
.info-section {
    margin-top: 10px;
}

.info-section h2 {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 24px;
    text-align: center;
}

.info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 20px;
}

@media (max-width: 768px) {
    .info-grid {
        grid-template-columns: 1fr;
    }
}

.info-card {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 24px;
    text-align: center;
    transition: var(--transition-smooth);
}

.info-card:hover {
    transform: translateY(-4px);
    border-color: rgba(255, 255, 255, 0.15);
    background: rgba(255, 255, 255, 0.03);
}

.info-card svg {
    width: 32px;
    height: 32px;
    color: var(--primary);
    margin-bottom: 16px;
}

.info-card h3 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 10px;
}

.info-card p {
    font-size: 14px;
    color: var(--text-muted);
    line-height: 1.5;
}

/* Footer */
.app-footer {
    text-align: center;
    margin-top: auto;
    padding-top: 40px;
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 300;
}

/* Utility helpers */
.hidden {
    display: none !important;
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(15px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Interactive Sandbox & Tree Visualizer */
.visualizer-container {
    animation: slideUp 0.4s ease-out;
}

.sandbox-input-group {
    margin-bottom: 24px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.sandbox-label {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 8px;
}

.sandbox-input-wrapper {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

#sandbox-input {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 14px 20px;
    color: var(--text-main);
    font-size: 16px;
    font-family: var(--font-sans);
    transition: var(--transition-smooth);
}

#sandbox-input:focus {
    border-color: var(--primary);
    background: rgba(168, 85, 247, 0.05);
    box-shadow: 0 0 15px var(--primary-glow);
    outline: none;
}

.sandbox-quick-presets {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.preset-label {
    font-size: 13px;
    color: var(--text-muted);
    margin-right: 4px;
}

.preset-btn {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 12px;
    cursor: pointer;
    font-family: var(--font-sans);
    font-weight: 500;
    transition: var(--transition-smooth);
}

.preset-btn:hover {
    color: var(--text-main);
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.2);
}

.visualizer-layout {
    display: grid;
    grid-template-columns: 1.5fr 1fr;
    gap: 20px;
    margin-bottom: 24px;
}

@media (max-width: 768px) {
    .visualizer-layout {
        grid-template-columns: 1fr;
    }
}

.tree-panel, .stats-panel {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 20px;
    display: flex;
    flex-direction: column;
}

.tree-panel h3, .stats-panel h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.panel-subtitle {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 16px;
}

.svg-container {
    background: rgba(0, 0, 0, 0.25);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    overflow: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 380px;
}

#tree-svg {
    display: block;
    user-select: none;
}

/* SVG Elements Styling */
.tree-node circle {
    fill: #140f26;
    stroke: var(--primary);
    stroke-width: 2px;
    transition: var(--transition-smooth);
    cursor: pointer;
}

.tree-node.leaf circle {
    stroke: var(--accent);
    fill: #061c2b;
}

.tree-node:hover circle {
    stroke-width: 3px;
    filter: drop-shadow(0 0 8px var(--primary-glow));
}

.tree-node.leaf:hover circle {
    filter: drop-shadow(0 0 8px var(--accent-glow));
}

.tree-node text {
    fill: var(--text-main);
    font-size: 11px;
    font-weight: 500;
    font-family: var(--font-sans);
    text-anchor: middle;
    dominant-baseline: central;
    pointer-events: none;
}

.tree-node.leaf text.char-label {
    fill: var(--accent);
    font-weight: 700;
    font-size: 13px;
}

.tree-node text.freq-label {
    font-size: 9px;
    fill: var(--text-muted);
}

.tree-link {
    fill: none;
    stroke: rgba(255, 255, 255, 0.12);
    stroke-width: 1.5px;
    transition: var(--transition-smooth);
}

.tree-link.active-path {
    stroke: var(--primary);
    stroke-width: 2px;
    filter: drop-shadow(0 0 4px var(--primary-glow));
}

.branch-label {
    font-size: 11px;
    font-family: var(--font-mono);
    fill: var(--text-muted);
    font-weight: bold;
    text-anchor: middle;
    dominant-baseline: central;
}

/* Table styling */
.table-scroll {
    overflow-y: auto;
    max-height: 320px;
}

.codebook-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
    text-align: left;
}

.codebook-table th, .codebook-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border-color);
}

.codebook-table th {
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    font-size: 11px;
    letter-spacing: 0.5px;
    position: sticky;
    top: 0;
    background: #110d26;
    z-index: 1;
}

.codebook-table tbody tr {
    transition: var(--transition-smooth);
}

.codebook-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.02);
}

.codebook-table td.char-cell {
    font-family: var(--font-mono);
    font-weight: 600;
    color: var(--accent);
}

.codebook-table td.code-cell {
    font-family: var(--font-mono);
    font-weight: bold;
    color: var(--success);
}

/* Sandbox Results styling */
.sandbox-results {
    margin-top: 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.bitstream-container {
    background: rgba(0, 0, 0, 0.15);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 16px 20px;
}

.bitstream-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 12px;
}

.bitstream-header span {
    display: flex;
    align-items: center;
    gap: 8px;
}

.bitstream-count {
    color: var(--accent);
    font-family: var(--font-mono);
}

.bitstream-val {
    font-family: var(--font-mono);
    font-size: 13px;
    color: var(--text-muted);
    word-break: break-all;
    line-height: 1.6;
    letter-spacing: 1px;
    max-height: 100px;
    overflow-y: auto;
    background: rgba(0, 0, 0, 0.15);
    padding: 10px;
    border-radius: 8px;
}

