/* Color variables and basic settings */
:root {
    --bg-primary: #f4f7f9;
    --bg-card: #ffffff;
    --text-main: #2c3e50;
    --text-muted: #7f8c8d;
    --primary-color: #4a90e2;
    --primary-light: #eaf2fc;
    --success-color: #2ecc71;
    --success-light: #eafaf1;
    --warning-color: #f39c12;
    --warning-light: #fef5e7;
    --danger-color: #e74c3c;
    --danger-light: #fdedec;
    --border-radius: 16px;
    --border-radius-sm: 8px;
    --box-shadow: 0 10px 30px rgba(0, 0, 0, 0.04);
    --box-shadow-hover: 0 15px 40px rgba(0, 0, 0, 0.08);
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Global Reset */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Nunito', sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    background: radial-gradient(at 0% 0%, #eef5fc 0px, transparent 50%),
                radial-gradient(at 50% 0%, #f4fdf8 0px, transparent 50%),
                radial-gradient(at 100% 0%, #fefcf3 0px, transparent 50%),
                #f5f7fa;
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Main Container */
.app-container {
    max-width: 1366px;
    width: 100%;
    margin: 0 auto;
    padding: 10px 15px;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Header */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 20px;
    background: var(--bg-card);
    border-radius: var(--border-radius-sm);
    box-shadow: var(--box-shadow);
    margin-bottom: 10px;
}

.header-logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-icon {
    font-size: 2rem;
}

.header-logo h1 {
    font-size: 1.65rem;
    font-weight: 800;
    background: linear-gradient(135deg, #4a90e2, #2ecc71);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.mode-selector {
    display: flex;
    gap: 10px;
}

.mode-btn {
    padding: 10px 20px;
    border: none;
    background: transparent;
    border-radius: 30px;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: var(--transition);
}

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

.mode-btn.active {
    color: #ffffff;
    background: linear-gradient(135deg, #4a90e2, #357abd);
    box-shadow: 0 4px 15px rgba(74, 144, 226, 0.35);
}

/* Main App Layout */
.app-main {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.screen {
    display: none;
    width: 100%;
}

#intro-screen {
    display: none;
    grid-template-columns: 300px 1fr;
    gap: 12px;
    align-items: start;
    width: 100%;
}

#intro-screen.active {
    display: grid;
}

#game-screen.active {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

/* Control Panel */
.control-panel {
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: var(--bg-card);
    padding: 15px;
    border-radius: var(--border-radius-sm);
    box-shadow: var(--box-shadow);
}

.control-panel h3 {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Presets & Option Buttons */
.preset-buttons, .tool-buttons {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.preset-item-wrapper {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
}

.preset-item-wrapper .preset-btn {
    flex: 1;
}

.delete-preset-btn {
    background: #fdedec;
    color: #e74c3c;
    border: 1.5px solid #fadbd8;
    border-radius: var(--border-radius-sm);
    width: 38px;
    height: 38px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    font-size: 1rem;
    transition: var(--transition);
}

.delete-preset-btn:hover {
    background: #e74c3c;
    color: #ffffff;
    border-color: #e74c3c;
    transform: scale(1.05);
}

.preset-btn, .tool-btn {
    padding: 10px 14px;
    background: #ffffff;
    border: 1.5px solid #eef2f6;
    border-radius: var(--border-radius-sm);
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-main);
    cursor: pointer;
    text-align: left;
    transition: var(--transition);
    box-shadow: 0 2px 5px rgba(0,0,0,0.02);
}

.preset-btn:hover, .tool-btn:hover {
    background: var(--primary-light);
    border-color: var(--primary-color);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(74, 144, 226, 0.1);
}

.preset-btn.active, .tool-btn.active {
    background: linear-gradient(135deg, var(--primary-light), #d1e3fa);
    border-color: var(--primary-color);
    color: var(--primary-color);
    font-weight: 700;
    box-shadow: 0 4px 12px rgba(74, 144, 226, 0.15);
}

/* Custom Reaction Form */
.custom-input-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

#custom-eq-input {
    width: 100%;
    padding: 10px 12px;
    border: 2px solid #e2e8f0;
    border-radius: var(--border-radius-sm);
    font-size: 0.95rem;
    color: var(--text-main);
    outline: none;
    transition: var(--transition);
}

#custom-eq-input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.15);
}

.error-msg {
    margin-top: 8px;
    font-size: 0.85rem;
    color: var(--danger-color);
    font-weight: 500;
}

/* Action Buttons */
.action-btn-primary {
    padding: 12px 20px;
    border: none;
    background: var(--primary-color);
    color: #ffffff;
    font-size: 0.95rem;
    font-weight: 600;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(74, 144, 226, 0.2);
    transition: var(--transition);
}

.action-btn-primary:hover {
    background: #357abd;
    transform: translateY(-2px);
    box-shadow: 0 6px 15px rgba(74, 144, 226, 0.3);
}

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

.action-btn-secondary {
    padding: 10px 18px;
    border: 2px solid #e2e8f0;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 600;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    transition: var(--transition);
}

.action-btn-secondary:hover {
    background: var(--bg-primary);
    color: var(--text-main);
    border-color: var(--text-muted);
}

/* Interactive Simulation Area */
.simulation-area {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Visual Tool Display (Scale, Bar Chart) */
.visualization-tool-panel {
    background: var(--bg-card);
    border-radius: var(--border-radius-sm);
    box-shadow: var(--box-shadow);
    padding: 12px;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 120px;
    transition: var(--transition);
}

.visualization-tool-panel.hidden {
    display: none;
}

/* SVG Scale Styling */
.scale-container {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 15px;
    width: 100%;
}

.scale-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: var(--bg-primary);
    border-radius: var(--border-radius-sm);
    padding: 8px 12px;
    min-width: 120px;
}

.scale-title {
    font-size: 0.85rem;
    font-weight: 700;
    margin-bottom: 4px;
    color: var(--text-main);
}

.scale-svg {
    width: 110px;
    height: 75px;
}

/* Bar Chart Styling */
.bar-chart-container {
    display: flex;
    flex-direction: column;
    gap: 15px;
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
}

.bar-row {
    display: grid;
    grid-template-columns: 80px 1fr 1fr;
    align-items: center;
    gap: 20px;
}

.bar-element-name {
    font-size: 1rem;
    font-weight: 700;
    text-align: right;
    color: var(--text-main);
}

.bar-lane {
    height: 32px;
    background: var(--bg-primary);
    border-radius: 6px;
    position: relative;
    overflow: hidden;
    border: 1px solid #e2e8f0;
}

.bar-fill {
    height: 100%;
    transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding-right: 8px;
    font-size: 0.85rem;
    font-weight: 700;
    color: white;
}

.bar-fill.reactants {
    background: linear-gradient(90deg, #ff8a80, #ff5252);
}

.bar-fill.products {
    background: linear-gradient(90deg, #82b1ff, #448aff);
}

.bar-fill.balanced {
    background: linear-gradient(90deg, #a7f3d0, #10b981) !important;
}

.bar-lane::after {
    content: attr(data-value);
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text-muted);
}

/* Molecules Canvas Containers */
.molecules-canvas-container {
    display: grid;
    grid-template-columns: 1fr 50px 1fr;
    gap: 10px;
}

@media (max-width: 768px) {
    .molecules-canvas-container {
        grid-template-columns: 1fr;
    }
    .canvas-divider {
        transform: rotate(90deg);
        margin: 5px 0;
    }
}

.canvas-side {
    background: var(--bg-card);
    border-radius: var(--border-radius-sm);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.02);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0; /* Cho phép co giãn và không tràn */
    border: 1.5px solid #eef2f6;
    transition: var(--transition);
}

.canvas-side:hover {
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.05);
}

.left-side .side-header {
    background: linear-gradient(135deg, #ffebee, #ffcdd2);
    color: #c62828;
    font-weight: 700;
    padding: 8px;
    text-align: center;
    font-size: 0.85rem;
    letter-spacing: 0.5px;
    border-bottom: 1.5px solid #ffccd5;
}

.right-side .side-header {
    background: linear-gradient(135deg, #e3f2fd, #bbdefb);
    color: #1565c0;
    font-weight: 700;
    padding: 8px;
    text-align: center;
    font-size: 0.85rem;
    letter-spacing: 0.5px;
    border-bottom: 1.5px solid #b3d7f5;
}

.canvas-box {
    min-height: 160px;
    padding: 10px;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    gap: 10px;
    background-color: #fafbfc;
}

.canvas-divider {
    display: flex;
    justify-content: center;
    align-items: center;
    min-width: 0;
}

.arrow-indicator {
    font-size: 1.6rem;
    color: var(--primary-color);
    animation: bounceRight 1.5s infinite alternate;
    display: flex;
    justify-content: center;
    align-items: center;
}

@keyframes bounceRight {
    0% { transform: translateX(-5px); }
    100% { transform: translateX(5px); }
}

/* Molecule SVG Display blocks */
.molecule-group-display {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

.molecule-name-lbl {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.molecule-svg-row {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    width: 100%;
}

.molecule-svg-card {
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: var(--border-radius-sm);
    padding: 3px;
    width: 75px;
    height: 75px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.02);
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    transition: var(--transition);
}

.molecule-svg-card svg {
    width: 100%;
    height: 100%;
}

.molecule-svg-card:hover {
    transform: scale(1.05);
    box-shadow: var(--box-shadow);
}

/* Equation Controller Bar */
.equation-controller {
    background: var(--bg-card);
    border-radius: var(--border-radius-sm);
    box-shadow: var(--box-shadow);
    padding: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    font-size: 1.4rem;
    font-weight: 700;
}

.equation-part {
    display: flex;
    align-items: center;
    gap: 10px;
}

.coeff-selector {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: var(--bg-primary);
    padding: 4px 8px;
    border-radius: var(--border-radius-sm);
    border: 1px solid #e2e8f0;
}

.coeff-value {
    font-size: 1.4rem;
    font-weight: 800;
    color: var(--primary-color);
    min-width: 24px;
    text-align: center;
}

.coeff-arrows {
    display: flex;
    gap: 4px;
    margin-top: 2px;
}

.arrow-btn {
    width: 20px;
    height: 20px;
    border: none;
    background: white;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    color: var(--text-main);
}

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

.arrow-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
    background: white;
    color: var(--text-muted);
}

.formula-display {
    font-size: 1.3rem;
    font-weight: 600;
    color: var(--text-main);
}

.formula-display sub {
    font-size: 0.9rem;
    bottom: -0.1em;
    font-weight: 700;
    color: var(--primary-color);
}

.equation-sign {
    color: var(--text-muted);
    font-weight: 500;
    margin: 0 5px;
}

/* Success banner */
.success-banner {
    background: var(--success-light);
    color: var(--success-color);
    border: 2px solid var(--success-color);
    padding: 15px;
    border-radius: var(--border-radius-sm);
    text-align: center;
    font-size: 1.2rem;
    font-weight: 700;
    animation: pulse 1s infinite alternate;
}

@keyframes pulse {
    0% { transform: scale(1); }
    100% { transform: scale(1.02); }
}

/* Game Screen Layouts */
.game-setup {
    background: var(--bg-card);
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
    padding: 40px;
    text-align: center;
    max-width: 700px;
    margin: 40px auto;
}

.game-setup h2 {
    font-size: 1.8rem;
    color: var(--primary-color);
    margin-bottom: 12px;
}

.game-setup p {
    color: var(--text-muted);
    font-size: 1.05rem;
    margin-bottom: 30px;
}

.level-selector {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
}

@media (max-width: 600px) {
    .level-selector {
        grid-template-columns: 1fr;
    }
}

.level-card {
    background: #ffffff;
    border: 2px solid #eef2f6;
    border-radius: var(--border-radius);
    padding: 25px 15px;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    flex-direction: column;
    align-items: center;
    text-decoration: none;
    box-shadow: 0 4px 15px rgba(0,0,0,0.02);
}

.level-card:hover {
    transform: translateY(-8px);
    box-shadow: 0 15px 30px rgba(0,0,0,0.06);
}

.level-num {
    font-size: 2.5rem;
    font-weight: 800;
    margin-bottom: 5px;
}

/* Level 1: Dễ */
.level-card:nth-child(1) .level-num {
    color: var(--success-color);
}
.level-card:nth-child(1):hover {
    border-color: var(--success-color);
    background: var(--success-light);
}

/* Level 2: Trung bình */
.level-card:nth-child(2) .level-num {
    color: var(--warning-color);
}
.level-card:nth-child(2):hover {
    border-color: var(--warning-color);
    background: var(--warning-light);
}

/* Level 3: Khó */
.level-card:nth-child(3) .level-num {
    color: var(--danger-color);
}
.level-card:nth-child(3):hover {
    border-color: var(--danger-color);
    background: var(--danger-light);
}

.level-desc {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 8px;
}

.level-info {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-align: center;
    line-height: 1.4;
}

/* Gameplay panels */
.game-play {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.game-status-bar {
    background: var(--bg-card);
    padding: 15px 25px;
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
}

.status-item {
    font-size: 1.1rem;
    font-weight: 600;
}

.status-label {
    color: var(--text-muted);
    margin-right: 5px;
}

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

.game-canvas .canvas-box {
    min-height: 180px;
}

.game-action-row {
    display: flex;
    justify-content: center;
    gap: 15px;
}

.action-btn-primary.large {
    padding: 15px 40px;
    font-size: 1.1rem;
    border-radius: var(--border-radius);
}

.game-feedback {
    min-height: 60px;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: var(--border-radius-sm);
    font-size: 1.3rem;
    font-weight: 700;
    transition: var(--transition);
}

.feedback-correct {
    background-color: var(--success-light);
    color: var(--success-color);
    border: 2px dashed var(--success-color);
    width: 100%;
    padding: 12px;
    text-align: center;
}

.feedback-incorrect {
    background-color: var(--danger-light);
    color: var(--danger-color);
    border: 2px dashed var(--danger-color);
    width: 100%;
    padding: 12px;
    text-align: center;
}

/* Game Results */
.result-celebration {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.result-trophy {
    font-size: 4.5rem;
    margin-bottom: 15px;
    animation: rotateTrophy 1.5s ease-out;
}

@keyframes rotateTrophy {
    0% { transform: scale(0) rotate(-180deg); }
    80% { transform: scale(1.2) rotate(15deg); }
    100% { transform: scale(1) rotate(0); }
}

.result-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    width: 100%;
    margin: 30px 0;
}

.stat-card {
    background: var(--bg-primary);
    padding: 20px;
    border-radius: var(--border-radius);
    text-align: center;
}

.stat-num {
    font-size: 2.2rem;
    font-weight: 800;
    color: var(--primary-color);
    margin-bottom: 5px;
}

.stat-lbl {
    font-size: 0.9rem;
    color: var(--text-muted);
}

.result-buttons {
    display: flex;
    gap: 15px;
    width: 100%;
    justify-content: center;
}

/* Footer style */
.app-footer-bar {
    text-align: center;
    padding: 20px;
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-top: auto;
}

.hidden {
    display: none !important;
}
