/* public/style.css */
:root {
    --bg: #f4f7fb;
    --bg-soft: #eef2f7;
    --card: rgba(255, 255, 255, 0.88);
    --text: #1f2937;
    --muted: #6b7280;
    --border: rgba(148, 163, 184, 0.25);
    --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --success: #16a34a;
    --success-hover: #15803d;
    --danger: #dc2626;
    --danger-hover: #b91c1c;
    --secondary: #475569;
    --secondary-hover: #334155;
    --warning: #f59e0b;
    --warning-hover: #d97706;
    --darkbtn: #0f172a;
    --darkbtn-hover: #020617;
    --grid-bg: #d9e1ea;
}

body.dark {
    --bg: #0f172a;
    --bg-soft: #111827;
    --card: rgba(17, 24, 39, 0.88);
    --text: #e5e7eb;
    --muted: #94a3b8;
    --border: rgba(148, 163, 184, 0.18);
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.30);
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --success: #22c55e;
    --success-hover: #16a34a;
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --secondary: #64748b;
    --secondary-hover: #475569;
    --warning: #f59e0b;
    --warning-hover: #d97706;
    --darkbtn: #e5e7eb;
    --darkbtn-hover: #cbd5e1;
    --grid-bg: #334155;
}

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

body {
    font-family: "Segoe UI", Arial, sans-serif;
    background:
        radial-gradient(circle at top left, rgba(37, 99, 235, 0.08), transparent 30%),
        radial-gradient(circle at bottom right, rgba(16, 185, 129, 0.08), transparent 25%),
        var(--bg);
    color: var(--text);
    min-height: 100vh;
    transition: background .3s ease, color .3s ease;
}

a {
    color: inherit;
    text-decoration: none;
}

.app-shell {
    max-width: 1440px;
    margin: 0 auto;
    padding: 24px;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-bottom: 24px;
}

.topbar h1 {
    font-size: clamp(1.5rem, 2.5vw, 2rem);
    margin-bottom: 6px;
}

.topbar h1 i {
    color: var(--primary);
    margin-right: 8px;
}

.subtitle {
    color: var(--muted);
    font-size: 0.98rem;
}

.card {
    background: var(--card);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    border-radius: 20px;
    backdrop-filter: blur(10px);
}

.panel {
    padding: 20px;
    margin-bottom: 20px;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 18px;
}

.group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.group label {
    font-weight: 600;
    color: var(--text);
    font-size: 0.95rem;
}

.group label i {
    color: var(--primary);
    margin-right: 6px;
}

.group input,
.group select {
    background: var(--bg-soft);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px 14px;
    outline: none;
    transition: .2s;
    width: 100%;
}

.group input:focus,
.group select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.btn,
.theme-btn {
    border: none;
    border-radius: 12px;
    padding: 12px 18px;
    font-weight: 600;
    cursor: pointer;
    transition: .2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.theme-btn {
    background: var(--card);
    color: var(--text);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}

.theme-btn:hover,
.btn:hover {
    transform: translateY(-1px);
}

.btn.primary {
    background: var(--primary);
    color: white;
}

.btn.primary:hover {
    background: var(--primary-hover);
}

.btn.success {
    background: var(--success);
    color: white;
}

.btn.success:hover {
    background: var(--success-hover);
}

.btn.danger {
    background: var(--danger);
    color: white;
}

.btn.danger:hover {
    background: var(--danger-hover);
}

.btn.secondary {
    background: var(--secondary);
    color: white;
}

.btn.secondary:hover {
    background: var(--secondary-hover);
}

.btn.warning {
    background: var(--warning);
    color: white;
}

.btn.warning:hover {
    background: var(--warning-hover);
}

.btn.dark {
    background: var(--darkbtn);
    color: white;
}

body.dark .btn.dark {
    color: #111827;
}

.btn.dark:hover {
    background: var(--darkbtn-hover);
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}

.stat {
    padding: 18px;
    display: flex;
    align-items: center;
    gap: 14px;
}

.stat-icon {
    width: 54px;
    height: 54px;
    border-radius: 16px;
    display: grid;
    place-items: center;
    font-size: 1.3rem;
    color: white;
    flex-shrink: 0;
}

.stat-icon.blue {
    background: linear-gradient(135deg, #2563eb, #60a5fa);
}

.stat-icon.purple {
    background: linear-gradient(135deg, #7c3aed, #a78bfa);
}

.stat-icon.green {
    background: linear-gradient(135deg, #059669, #34d399);
}

.stat-label {
    color: var(--muted);
    font-size: 0.9rem;
    margin-bottom: 4px;
}

.stat h2 {
    font-size: clamp(1rem, 2vw, 1.25rem);
    word-break: break-word;
}

.main-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.8fr) minmax(300px, 0.8fr);
    gap: 20px;
    align-items: start;
}

.simulation-area {
    padding: 20px;
    min-width: 0;
}

.side-panel {
    display: flex;
    flex-direction: column;
    gap: 20px;
    min-width: 0;
}

.legend-card,
.help-card,
.counters-card,
.chart-card {
    padding: 20px;
}

.section-header {
    margin-bottom: 14px;
}

.section-header h3 {
    margin-bottom: 4px;
    font-size: 1.1rem;
}

.section-header h3 i {
    color: var(--primary);
    margin-right: 8px;
}

.section-header p {
    color: var(--muted);
    font-size: 0.95rem;
}

.grid-wrapper {
    background: var(--bg-soft);
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 16px;
    overflow: auto;
    max-width: 100%;
}

.grid {
    display: grid;
    gap: 1px;
    background: var(--grid-bg);
    padding: 6px;
    border-radius: 14px;
    width: fit-content;
    margin: 0 auto;
}

.cell {
    background: white;
    cursor: pointer;
    transition: transform .08s ease, opacity .2s ease, box-shadow .2s ease;
}

.cell:hover {
    transform: scale(1.08);
    opacity: 0.94;
    box-shadow: 0 0 0 1px rgba(255,255,255,0.25);
}

.legend-item,
.counter-item {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
    padding: 10px 12px;
    border-radius: 12px;
    background: var(--bg-soft);
}

.legend-color,
.counter-color {
    width: 18px;
    height: 18px;
    border-radius: 6px;
    border: 1px solid rgba(0,0,0,0.15);
    flex-shrink: 0;
}

.counter-item {
    justify-content: space-between;
}

.counter-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.counter-value {
    font-weight: 700;
}

.state-counters {
    display: flex;
    flex-direction: column;
}

.chart-wrap {
    position: relative;
    width: 100%;
    height: 260px;
}

.chart-wrap canvas {
    width: 100% !important;
    height: 100% !important;
}

.help-card ul {
    padding-left: 20px;
    color: var(--muted);
    line-height: 1.7;
}

.footer {
    margin-top: 24px;
    padding: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    flex-wrap: wrap;
}

.footer-brand {
    display: inline-flex;
    align-items: center;
}

.logo-shine {
    position: relative;
    display: inline-block;
    overflow: hidden;
    border-radius: 14px;
}

.logo-shine img {
    display: block;
    max-height: 40px;
    width: auto;
    object-fit: contain;
    filter: drop-shadow(0 4px 18px rgba(37, 99, 235, 0.22));
}

.logo-shine::after {
    content: "";
    position: absolute;
    top: -20%;
    left: -60%;
    width: 35%;
    height: 140%;
    transform: skewX(-22deg);
    background: linear-gradient(
        90deg,
        rgba(255,255,255,0) 0%,
        rgba(255,255,255,0.15) 35%,
        rgba(255,255,255,0.75) 50%,
        rgba(255,255,255,0.15) 65%,
        rgba(255,255,255,0) 100%
    );
    animation: shine 3s ease-in-out infinite;
    pointer-events: none;
}

.footer-text {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.footer-text p {
    font-weight: 700;
}

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

.footer-text small {
    color: var(--muted);
}

@keyframes shine {
    0% {
        left: -60%;
    }
    100% {
        left: 130%;
    }
}

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

@media (max-width: 768px) {
    .app-shell {
        padding: 16px;
    }

    .topbar {
        flex-direction: column;
        align-items: stretch;
    }

    .theme-btn {
        width: 100%;
    }

    .buttons {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
    }

    .btn {
        width: 100%;
    }

    .footer {
        flex-direction: column;
        align-items: center;
        text-align: center;
    }

    .logo-shine img {
        max-height: 40px;
    }
}

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

    .form-grid {
        grid-template-columns: 1fr;
    }

    .chart-wrap {
        height: 220px;
    }
}