* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --secondary: #22c55e;
    --danger: #ef4444;
    --warning: #f59e0b;
    --dark: #1e293b;
    --light: #f8fafc;
    --gray: #64748b;
    --matchstick-head: #ef4444;
    --matchstick-body: #d4a574;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: var(--dark);
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

header {
    text-align: center;
    padding: 30px 0;
    color: white;
    position: relative;
}

/* Language Toggle */
.top-right-btns {
    position: absolute;
    top: 20px;
    right: 20px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.top-btn {
    background: #7c3aed;
    color: white;
    text-decoration: none;
    padding: 8px 16px;
    border-radius: 25px;
    font-size: 0.85rem;
    font-weight: 600;
    transition: background 0.3s;
}

.top-btn:hover {
    background: #6d28d9;
}

.lang-toggle {
    display: flex;
    gap: 5px;
    background: rgba(255,255,255,0.2);
    padding: 5px;
    border-radius: 25px;
}

.lang-btn {
    padding: 8px 16px;
    border: none;
    border-radius: 20px;
    background: transparent;
    color: white;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.lang-btn:hover {
    background: rgba(255,255,255,0.2);
}

.lang-btn.active {
    background: white;
    color: var(--primary);
}

header h1 {
    font-size: 3rem;
    margin-bottom: 10px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}

header .subtitle {
    font-size: 1.2rem;
    opacity: 0.9;
}

/* Navigation */
.main-nav {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 30px;
}

.nav-btn {
    padding: 12px 24px;
    border: none;
    border-radius: 25px;
    background: rgba(255,255,255,0.2);
    color: white;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s ease;
}

.nav-btn:hover {
    background: rgba(255,255,255,0.3);
    transform: translateY(-2px);
}

.nav-btn.active {
    background: white;
    color: var(--primary);
    font-weight: bold;
}

/* Sections */
.section {
    display: none;
    background: white;
    border-radius: 20px;
    padding: 30px;
    margin-bottom: 30px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
}

.section.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.section h2 {
    color: var(--primary);
    margin-bottom: 20px;
    font-size: 1.8rem;
}

/* Home Section */
.welcome-card {
    text-align: center;
}

.welcome-card p {
    font-size: 1.1rem;
    color: var(--gray);
    margin-bottom: 30px;
    max-width: 700px;
    margin-left: auto;
    margin-right: auto;
}

.feature-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.feature-card {
    background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
    border-radius: 15px;
    padding: 25px;
    text-align: center;
    transition: transform 0.3s ease;
}

.feature-card:hover {
    transform: translateY(-5px);
}

.feature-icon {
    width: 60px;
    height: 60px;
    background: var(--primary);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: bold;
    margin: 0 auto 15px;
}

.feature-card h3 {
    color: var(--dark);
    margin-bottom: 10px;
}

.feature-card p {
    color: var(--gray);
    font-size: 0.9rem;
}

.start-btn {
    padding: 15px 40px;
    font-size: 1.2rem;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    border: none;
    border-radius: 30px;
    cursor: pointer;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.start-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 5px 20px rgba(99, 102, 241, 0.4);
}

/* Game Info */
.game-info {
    background: #f0f9ff;
    border-left: 4px solid var(--primary);
    padding: 15px 20px;
    margin-bottom: 20px;
    border-radius: 0 10px 10px 0;
}

/* Settings Panel */
.settings-panel {
    background: #f8fafc;
    border-radius: 15px;
    padding: 20px;
    margin-bottom: 20px;
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    align-items: flex-end;
}

.setting {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.setting label {
    font-size: 0.9rem;
    color: var(--gray);
    font-weight: 500;
}

.setting input, .setting select {
    padding: 10px 15px;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    font-size: 1rem;
    min-width: 100px;
}

.setting input:focus, .setting select:focus {
    outline: none;
    border-color: var(--primary);
}

/* Buttons */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    background: var(--primary);
    color: white;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn:hover {
    background: var(--primary-dark);
    transform: translateY(-2px);
}

.btn.secondary {
    background: #e2e8f0;
    color: var(--dark);
}

.btn.secondary:hover {
    background: #cbd5e1;
}

.btn.danger {
    background: var(--danger);
}

.btn.success {
    background: var(--secondary);
}

/* Game Board */
.game-board {
    margin-top: 20px;
}

.game-board.hidden {
    display: none;
}

.pile-container {
    text-align: center;
    padding: 20px;
    background: #fefce8;
    border-radius: 15px;
    margin-bottom: 15px;
    cursor: pointer;
    transition: all 0.3s ease;
    border: 3px solid transparent;
}

.pile-container:hover {
    border-color: var(--warning);
}

.pile-container.selected {
    border-color: var(--primary);
    background: #eff6ff;
}

.pile-container h4 {
    margin-bottom: 10px;
    color: var(--gray);
}

.pile {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 4px;
    min-height: 60px;
    padding: 10px;
}

.matchstick {
    width: 8px;
    height: 45px;
    background: linear-gradient(to bottom, var(--matchstick-head) 0%, var(--matchstick-head) 20%, var(--matchstick-body) 20%, var(--matchstick-body) 100%);
    border-radius: 4px 4px 2px 2px;
    animation: appear 0.3s ease;
}

@keyframes appear {
    from { transform: scale(0); }
    to { transform: scale(1); }
}

.matchstick.removing {
    animation: remove 0.3s ease forwards;
}

@keyframes remove {
    to { transform: scale(0); opacity: 0; }
}

.pile-count {
    margin-top: 10px;
    font-size: 1.2rem;
    font-weight: bold;
    color: var(--dark);
}

.piles-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 15px;
}

/* Turn Info */
.turn-info {
    text-align: center;
    padding: 20px;
    background: #f8fafc;
    border-radius: 10px;
    margin: 15px 0;
}

.turn-info p {
    margin: 5px 0;
}

#single-turn-text, #two-turn-text, #multi-turn-text {
    font-size: 1.3rem;
    font-weight: bold;
    color: var(--primary);
}

/* Action Buttons */
.action-buttons {
    display: flex;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 15px;
}

.action-buttons .btn {
    min-width: 80px;
}

/* Strategy Panel */
.strategy-panel {
    margin-top: 20px;
    padding: 20px;
    background: #f0fdf4;
    border-radius: 15px;
    border-left: 4px solid var(--secondary);
}

.strategy-panel.hidden {
    display: none;
}

.strategy-panel h3 {
    color: var(--secondary);
    margin-bottom: 15px;
}

/* Hidden class */
.hidden {
    display: none !important;
}

/* Pile select */
#two-pile-select, #multi-pile-select {
    text-align: center;
    padding: 15px;
    background: #eff6ff;
    border-radius: 10px;
    margin-top: 15px;
}

#two-pile-select input, #multi-pile-select input {
    width: 80px;
    padding: 8px;
    margin: 0 10px;
    border: 2px solid var(--primary);
    border-radius: 5px;
    font-size: 1rem;
}

/* Theory Section */
.theory-content {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.theory-card {
    background: #f8fafc;
    border-radius: 15px;
    padding: 25px;
    border-left: 4px solid var(--primary);
}

.theory-card h3 {
    color: var(--primary);
    margin-bottom: 15px;
}

.theory-card p {
    line-height: 1.7;
    margin-bottom: 10px;
}

.theory-card ul, .theory-card ol {
    margin-left: 20px;
    line-height: 1.8;
}

.example-box {
    background: white;
    border-radius: 10px;
    padding: 15px;
    margin: 15px 0;
    border: 1px solid #e2e8f0;
}

.example-box h4 {
    color: var(--secondary);
    margin-bottom: 10px;
}

.example-box pre {
    background: var(--dark);
    color: #22d3ee;
    padding: 15px;
    border-radius: 8px;
    overflow-x: auto;
    font-family: 'Consolas', monospace;
}

.xor-table {
    border-collapse: collapse;
    margin: 10px 0;
}

.xor-table th, .xor-table td {
    border: 1px solid #e2e8f0;
    padding: 10px 20px;
    text-align: center;
}

.xor-table th {
    background: var(--primary);
    color: white;
}

.strategy-rules {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.rule {
    display: flex;
    gap: 15px;
    align-items: flex-start;
}

.rule-num {
    width: 40px;
    height: 40px;
    background: var(--primary);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    flex-shrink: 0;
}

/* Calculator */
.interactive-calculator {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 15px;
    padding: 25px;
    color: white;
}

.interactive-calculator h3 {
    margin-bottom: 15px;
}

.calculator-input {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    margin-bottom: 15px;
}

.calculator-input input {
    flex: 1;
    min-width: 200px;
    padding: 12px 15px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
}

.calc-result {
    background: rgba(255,255,255,0.1);
    border-radius: 10px;
    padding: 15px;
    font-family: 'Consolas', monospace;
    white-space: pre-wrap;
}

/* Practice Section */
.practice-intro {
    color: var(--gray);
    margin-bottom: 20px;
}

.practice-card {
    background: #f8fafc;
    border-radius: 15px;
    padding: 25px;
    margin-bottom: 20px;
}

.problem-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.problem-number {
    font-weight: bold;
    color: var(--primary);
}

.problem-difficulty {
    padding: 5px 15px;
    border-radius: 15px;
    font-size: 0.85rem;
    font-weight: 500;
}

.problem-difficulty.Easy {
    background: #dcfce7;
    color: #166534;
}

.problem-difficulty.Medium {
    background: #fef9c3;
    color: #854d0e;
}

.problem-difficulty.Hard {
    background: #fee2e2;
    color: #991b1b;
}

.problem-text {
    font-size: 1.1rem;
    line-height: 1.7;
    margin-bottom: 20px;
    padding: 15px;
    background: white;
    border-radius: 10px;
}

.answer-section {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
}

.answer-section input {
    padding: 10px 15px;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    font-size: 1rem;
    width: 150px;
}

.feedback {
    margin-top: 15px;
    padding: 15px;
    border-radius: 10px;
}

.feedback.correct {
    background: #dcfce7;
    color: #166534;
}

.feedback.incorrect {
    background: #fee2e2;
    color: #991b1b;
}

.hint-box, .solution-box {
    margin-top: 15px;
    padding: 15px;
    background: #fffbeb;
    border-radius: 10px;
    border-left: 4px solid var(--warning);
}

.solution-box {
    background: #f0fdf4;
    border-left-color: var(--secondary);
}

.practice-nav {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-bottom: 20px;
}

.score-display {
    text-align: center;
    font-size: 1.2rem;
    color: var(--gray);
}

/* Nim Sum Breakdown */
.nim-sum-breakdown {
    font-family: 'Consolas', monospace;
    background: var(--dark);
    color: #22d3ee;
    padding: 15px;
    border-radius: 10px;
    margin: 10px 0;
    text-align: left;
    overflow-x: auto;
}

/* Pile inputs */
.pile-inputs {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    width: 100%;
    margin-bottom: 10px;
}

/* Footer */
footer {
    text-align: center;
    padding: 30px;
    color: rgba(255,255,255,0.8);
}

/* Responsive */
@media (max-width: 768px) {
    header h1 {
        font-size: 2rem;
    }
    
    .nav-btn {
        padding: 10px 15px;
        font-size: 0.9rem;
    }
    
    .section {
        padding: 20px;
    }
    
    .matchstick {
        width: 6px;
        height: 35px;
    }
    
    .settings-panel {
        flex-direction: column;
    }
    
    .setting {
        width: 100%;
    }
    
    .setting input, .setting select {
        width: 100%;
    }
}

/* Win/Loss Animation */
.winner-animation {
    animation: pulse 0.5s ease infinite alternate;
}

@keyframes pulse {
    from { transform: scale(1); }
    to { transform: scale(1.05); }
}

.game-over {
    text-align: center;
    padding: 30px;
    background: linear-gradient(135deg, #f0fdf4 0%, #dcfce7 100%);
    border-radius: 15px;
    margin-top: 20px;
}

.game-over.lost {
    background: linear-gradient(135deg, #fef2f2 0%, #fee2e2 100%);
}

.game-over h3 {
    font-size: 1.8rem;
    margin-bottom: 10px;
}

.game-over .winner {
    color: var(--secondary);
}

.game-over .loser {
    color: var(--danger);
}

/* Binary and Pairing Tables */
.binary-table, .pairing-table {
    border-collapse: collapse;
    margin: 15px 0;
    width: 100%;
    max-width: 600px;
}

.binary-table th, .binary-table td,
.pairing-table th, .pairing-table td {
    border: 1px solid #e2e8f0;
    padding: 10px 15px;
    text-align: center;
}

.binary-table th, .pairing-table th {
    background: var(--primary);
    color: white;
    font-weight: 600;
}

.binary-table td:first-child, .pairing-table td:first-child {
    background: #f8fafc;
    font-weight: 500;
    text-align: left;
}

.pairing-table .count-row td {
    background: #fef3c7;
    font-weight: bold;
}

/* Highlight Card for Important Sections */
.theory-card.highlight-card {
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
    border-left: 4px solid var(--warning);
}

.theory-card.highlight-card h3 {
    color: #92400e;
}

/* XOR Explanation Box */
.xor-explanation {
    background: linear-gradient(135deg, #dbeafe 0%, #bfdbfe 100%);
    padding: 15px 20px;
    border-radius: 10px;
    margin: 15px 0;
    text-align: center;
    font-size: 1.1rem;
}

.xor-explanation p {
    margin: 0;
    color: #1e40af;
}

/* Enhanced XOR Table */
.xor-table th:last-child {
    min-width: 100px;
}

.xor-table td:last-child {
    font-size: 0.85rem;
    color: var(--gray);
}

/* Superscript styling */
sup {
    font-size: 0.7em;
    vertical-align: super;
}

/* Theory card list styling */
.theory-card ul li, .theory-card ol li {
    margin-bottom: 8px;
}

/* Example box paragraph spacing */
.example-box p {
    margin-bottom: 10px;
}

.example-box p:last-child {
    margin-bottom: 0;
}

.example-box ul {
    margin: 10px 0 10px 20px;
}

.example-box ul li {
    margin-bottom: 5px;
}

