:root {
    --primary: #06B6D4;
    --primary-hover: #0891B2;
    --secondary: #22D3EE;
    --background: #0A1A1F;
    --surface: rgba(16, 42, 51, 0.65);
    --surface-hover: rgba(22, 60, 72, 0.8);
    --border: rgba(6, 182, 212, 0.25);
    --text-main: #F8FAFC;
    --text-muted: #94A3B8;

    --accent: #F59E0B;
    --success: #10B981;
    --danger: #EF4444;

    --radius: 12px;
    --font-sans: 'Inter', system-ui, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
}

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

body {
    background-color: var(--background);
    color: var(--text-main);
    font-family: var(--font-sans);
    height: 100vh;
    overflow: hidden;
    background-image:
        radial-gradient(circle at 0% 0%, rgba(6, 182, 212, 0.1) 0%, transparent 40%),
        radial-gradient(circle at 100% 100%, rgba(245, 158, 11, 0.05) 0%, transparent 40%);
}

.text-primary {
    color: var(--primary);
}

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

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

/* Layout */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* Glassmorphism */
.glass-header {
    background: rgba(10, 26, 31, 0.7);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    padding: 1rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 10;
}

.card {
    background: var(--surface);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Header */
.brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo-icon {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: var(--background);
    font-weight: 700;
    font-size: 0.85rem;
    padding: 0.4rem 0.6rem;
    border-radius: 8px;
    letter-spacing: 1px;
}

.brand h1 {
    font-size: 1.1rem;
    font-weight: 600;
    letter-spacing: -0.01em;
}

/* Buttons */
.btn {
    padding: 0.6rem 1rem;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    border: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: all 0.2s ease;
    font-family: inherit;
}

.btn-sm {
    padding: 0.4rem 0.75rem;
    font-size: 0.8rem;
}

.btn-primary {
    background: var(--primary);
    color: var(--background);
    font-weight: 600;
}

.btn-primary:hover {
    background: var(--secondary);
    transform: translateY(-1px);
}

.shadow-glow {
    box-shadow: 0 0 15px rgba(6, 182, 212, 0.4);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.15);
}

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

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

/* Main Workspace */
.workspace {
    flex: 1;
    display: grid;
    grid-template-columns: 320px 1fr 320px;
    gap: 1.5rem;
    padding: 1.5rem;
    overflow: hidden;
}

/* Left Panel */
.panel-left {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.controls-card {
    flex: 1;
}

.generator-card {
    flex: 1;
}

.card-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(0, 0, 0, 0.2);
}

.card-header h2 {
    font-size: 0.95rem;
    font-weight: 600;
}

.card-body {
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
    color: var(--text-muted);
}

.help-text {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

/* Toggles */
.toggle-group {
    display: flex;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 8px;
    padding: 2px;
}

.toggle-btn {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 0.5rem;
    font-size: 0.8rem;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s;
}

.toggle-btn.active {
    background: var(--surface-hover);
    color: var(--primary);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

/* Range Slider */
.range-slider {
    display: flex;
    align-items: center;
    gap: 1rem;
}

input[type=range] {
    flex: 1;
    -webkit-appearance: none;
    background: rgba(255, 255, 255, 0.1);
    height: 6px;
    border-radius: 3px;
    outline: none;
}

input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    transition: transform 0.1s;
}

input[type=range]::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

.val-display {
    min-width: 40px;
    text-align: right;
    font-family: var(--font-mono);
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--secondary);
}

/* Code Generator */
.pill-selector {
    display: flex;
    gap: 0.25rem;
}

.pill {
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-muted);
    padding: 0.2rem 0.5rem;
    font-size: 0.75rem;
    border-radius: 4px;
    cursor: pointer;
}

.pill.active {
    background: rgba(6, 182, 212, 0.15);
    color: var(--primary);
    border-color: rgba(6, 182, 212, 0.3);
}

.code-container {
    position: relative;
    flex: 1;
    display: flex;
    flex-direction: column;
}

#codeOutput {
    flex: 1;
    background: rgba(0, 0, 0, 0.4);
    border: none;
    color: #A5B4FC;
    font-family: var(--font-mono);
    font-size: 0.8rem;
    padding: 1rem;
    resize: none;
    outline: none;
    line-height: 1.5;
}

.btn-copy {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: 4px;
    color: var(--text-muted);
    padding: 0.3rem;
    cursor: pointer;
}

.btn-copy:hover {
    color: white;
    background: rgba(255, 255, 255, 0.2);
}


/* Center Panel - Visualization */
.panel-center {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.viz-card {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.legend {
    display: flex;
    gap: 1rem;
    font-size: 0.8rem;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    color: var(--text-muted);
}

.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.dot.accepted {
    background: var(--success);
    box-shadow: 0 0 8px var(--success);
}

.dot.rejected {
    background: var(--danger);
    box-shadow: 0 0 8px var(--danger);
}

.viz-area {
    flex: 1;
    position: relative;
    background: rgba(0, 0, 0, 0.2);
    overflow: hidden;
}

#vizCanvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

.viz-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    display: flex;
    justify-content: center;
    align-items: center;
}

.controls-action {
    padding: 1rem 1.25rem;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    justify-content: center;
    gap: 1rem;
    background: rgba(0, 0, 0, 0.2);
}

/* Custom UI Overlays for Algorithms */
.hidden {
    display: none !important;
}

/* Token Bucket UI */
.bucket-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.bucket {
    width: 120px;
    height: 160px;
    border: 4px solid var(--border);
    border-top: none;
    border-radius: 0 0 20px 20px;
    position: relative;
    overflow: hidden;
    background: rgba(0, 0, 0, 0.3);
}

.water {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(180deg, rgba(6, 182, 212, 0.8), rgba(6, 182, 212, 0.4));
    height: 100%;
    /* controlled by JS */
    transition: height 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.bucket-text {
    position: absolute;
    inset: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: var(--font-mono);
    font-size: 1.2rem;
    font-weight: 700;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.8);
    z-index: 2;
}

.bucket-label {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* Sliding Window UI */
.window-container {
    width: 80%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.timeline {
    width: 100%;
    height: 60px;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    position: relative;
    overflow: hidden;
}

.window-slider {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 20%;
    right: 0;
    /* Moving rect */
    background: rgba(34, 211, 238, 0.1);
    border: 2px solid var(--secondary);
    border-radius: 6px;
    box-shadow: 0 0 15px rgba(34, 211, 238, 0.2);
    z-index: 1;
}

/* Tracks dots handled in canvas mostly, but can do DOM */
.window-label {
    font-family: var(--font-mono);
    font-size: 1rem;
    color: var(--secondary);
}

/* Right Panel */
.panel-right {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.stats-card {
    flex: 0 0 auto;
}

.headers-card {
    flex: 1;
}

.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    padding: 1.25rem;
}

.stat-box {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.stat-box .label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-box .value {
    font-size: 1.5rem;
    font-weight: 700;
    font-family: var(--font-mono);
}

.headers-preview {
    padding: 1.25rem;
    font-family: var(--font-mono);
    font-size: 0.85rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.header-row {
    display: flex;
    gap: 1rem;
    padding: 0.4rem 0;
    border-bottom: 1px dashed rgba(255, 255, 255, 0.1);
}

.h-key {
    color: var(--secondary);
    font-weight: 500;
    min-width: 180px;
}

.h-val {
    color: var(--text-main);
}

.status-val {
    color: var(--success);
    font-weight: 700;
}

.status-val.error {
    color: var(--danger);
}

.error-row {
    background: rgba(239, 68, 68, 0.1);
    padding: 0.4rem;
    border-radius: 4px;
    border: none;
}

/* Toasts */
.toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 100;
}

.toast {
    background: rgba(10, 26, 31, 0.9);
    border: 1px solid var(--border);
    color: white;
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 0.85rem;
    transform: translateX(100%);
    animation: slideIn 0.3s forwards, fadeOut 0.3s forwards 2.5s;
}

@keyframes slideIn {
    to {
        transform: translateX(0);
    }
}

@keyframes fadeOut {
    to {
        opacity: 0;
    }
}