:root {
    --primary-color: #005a9e;
    --secondary-color: #f7b801;
    --light-bg: #f8f9fa;
    --dark-text: #212529;
    --light-text: #ffffff;
    --green-positive: #28a745;
    --red-negative: #dc3545;
    --gray-neutral: #6c757d;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    --correct-bg: #d4edda;
    --incorrect-bg: #fff3cd;
    --border-color: #e9ecef;
    --body-bg: linear-gradient(135deg, #7488de 0%, #764ba2 100%);
    --container-bg: var(--light-text);
}

body.dark-mode {
    --primary-color: #58a6ff;
    --secondary-color: #f7b801;
    --light-bg: #4a5360;
    --dark-text: #c9d1d9;
    --light-text: #0d1117;
    --green-positive: #56d364;
    --red-negative: #f85149;
    --gray-neutral: #8b949e;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    --correct-bg: #166f26;
    --incorrect-bg: #b48d16;
    --border-color: #30363d;
    --body-bg: linear-gradient(135deg, #180439 0%, #0f001e 100%);
    --container-bg: #33383f;
}

* { box-sizing: border-box; }

body {
    font-family: 'Kanit', sans-serif;
    background: var(--body-bg);
    color: var(--dark-text);
    margin: 0;
    padding: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    transition: background-color 0.3s, color 0.3s;
}

#game-container {
    width: 100%;
    max-width: 880px;
    background: var(--container-bg);
    border-radius: 16px;
    box-shadow: var(--shadow);
    padding: 1rem;
    display: flex;
    flex-direction: column;
}

/* Registration Styles */
#registration-screen, #goal-screen {
    padding: 2rem;
}

.registration-container, .goal-container {
    max-width: 800px;
    margin: 0 auto;
    background: var(--container-bg);
    padding: 2rem;
    border-radius: 16px;
    box-shadow: var(--shadow);
}

.registration-container h2, .goal-container h2 {
    text-align: center;
    color: var(--primary-color);
    margin-bottom: 2rem;
    font-size: 2rem;
}

.avatar-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin-bottom: 2rem;
}

.avatar-item {
    border: 3px solid var(--border-color);
    border-radius: 12px;
    padding: 1rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    background: var(--light-bg);
}

.avatar-item:hover, .avatar-item.selected {
    border-color: var(--primary-color);
    transform: scale(1.05);
}

.avatar-item.selected { background: var(--primary-color); color: white; }

.avatar-icon { font-size: 2.5rem; margin-bottom: 0.5rem; }

.player-info-section {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 2rem;
}

.form-group { display: flex; flex-direction: column; }
.form-group label { margin-bottom: 0.5rem; font-weight: 500; color: var(--primary-color); }
.form-group input, .form-group select {
    padding: 0.75rem;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-family: 'Kanit', sans-serif;
    font-size: 1rem;
    background: var(--container-bg);
    color: var(--dark-text);
}

.form-group input:focus, .form-group select:focus {
    outline: none;
    border-color: var(--primary-color);
}

/* Goal Selection */
.goal-options {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.goal-card {
    background: var(--light-bg);
    border: 2px solid var(--border-color);
    border-radius: 16px;
    padding: 1.5rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
}

.goal-card:hover, .goal-card.selected {
    transform: translateY(-5px);
    border-color: var(--primary-color);
    box-shadow: 0 8px 25px rgba(0, 90, 158, 0.2);
}

.goal-card.selected { background: var(--primary-color); color: white; }
.goal-card.selected .goal-icon { color: white; }

.goal-icon { font-size: 3rem; margin-bottom: 1rem; color: var(--primary-color); }
.goal-card h3 { margin: 0 0 1rem 0; font-size: 1.2rem; }
.goal-card p { margin: 0; color: var(--gray-neutral); font-size: 0.9rem; line-height: 1.4; }
.goal-card.selected p { color: rgba(255, 255, 255, 0.9); }

/* Buttons */
button {
    font-family: 'Kanit', sans-serif;
    cursor: pointer;
    transition: all 0.3s ease;
}

#register-button, #confirm-goal-button, #start-button, #restart-button, #next-button, #continue-button {
    display: block;
    width: 60%;
    margin: 0 auto;
    padding: 1rem 2rem;
    font-size: 1.2rem;
    font-weight: 500;
    background: linear-gradient(135deg, var(--secondary-color), #ffc933);
    color: #212529;
    border: none;
    border-radius: 25px;
    box-shadow: 0 4px 15px rgba(247, 184, 1, 0.3);
}

#register-button:hover:not(:disabled), #confirm-goal-button:hover, #start-button:hover, 
#restart-button:hover, #next-button:hover, #continue-button:hover {
    background: linear-gradient(135deg, #ffc933, var(--secondary-color));
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(247, 184, 1, 0.4);
}

#register-button:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }

#save-results-button {
    display: block;
    width: 200px;
    margin: 1rem auto;
    padding: 1rem 2rem;
    font-size: 1.1rem;
    font-weight: 500;
    background: linear-gradient(135deg, #28a745, #34ce57);
    color: white;
    border: none;
    border-radius: 25px;
    box-shadow: 0 4px 15px rgba(40, 167, 69, 0.3);
}

#save-results-button:hover {
    background: linear-gradient(135deg, #34ce57, #28a745);
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(40, 167, 69, 0.4);
}

/* Header & Stats */
header .header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
}

header h1 {
    text-align: center;
    color: var(--primary-color);
    margin-bottom: 1.5rem;
    font-size: 2rem;
    flex-grow: 1;
}

#dark-mode-toggle {
    position: absolute;
    top: 0;
    right: 0;
    background: none;
    border: 2px solid var(--border-color);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    font-size: 1.5rem;
    color: var(--dark-text);
}

#dark-mode-toggle:hover {
    background-color: var(--light-bg);
    transform: scale(1.1);
}

#stats-bar {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 1rem;
    text-align: center;
    margin-bottom: 0.5rem;
    padding: 0.2rem;
    background: var(--light-bg);
    border-radius: 12px;
    border: 2px solid var(--border-color);
}

.stat p { margin: 0 0 0.2rem 0; font-weight: 500; color: var(--primary-color); }
.stat span { font-size: 1.4rem; font-weight: 700; }
#cash-value, #assets-value { color: var(--green-positive); }
#debt-value { color: var(--red-negative); }
#bonus-value { color: var(--secondary-color); }

/* Progress Bar */
#progress-container { margin-bottom: 1.5rem; padding: 0 0.5rem; }
#progress-bar {
    position: relative;
    width: 100%;
    height: 8px;
    background-color: var(--primary-color);
    border-radius: 4px;
}

#progress-pin {
    position: absolute;
    top: 50%;
    left: 0%;
    width: 22px;
    height: 22px;
    background-color: white;
    border: 3px solid var(--primary-color);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    transition: left 0.4s ease-in-out;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

body.dark-mode #progress-bar { background-color: white; }
body.dark-mode #progress-pin { border: 3px solid var(--primary-color); }

/* Difficulty Cards */
#difficulty-options {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
    justify-content: space-between;
}

.difficulty-card {
    background: var(--container-bg);
    border: 2px solid var(--border-color);
    border-radius: 16px;
    padding: 1.1rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    flex: 1;
    min-width: 0;
}

.difficulty-card:hover, .difficulty-card.selected {
    transform: translateY(-5px);
    border-color: var(--primary-color);
    box-shadow: 0 8px 25px rgba(0, 90, 158, 0.2);
}

.difficulty-card.selected { border-color: var(--primary-color); background: var(--light-bg); transform: scale(1.02); }

.difficulty-icon { font-size: 2.5rem; margin-bottom: 0.8rem; }
.difficulty-card h3 { color: var(--primary-color); margin: 0 0 0.8rem 0; font-size: 1.2rem; }
.difficulty-card p { color: var(--gray-neutral); margin-bottom: 0.8rem; text-align: center; font-size: 1rem; }
.difficulty-card ul { list-style: none; padding: 0; margin: 0; }
.difficulty-card li { padding: 0.2rem 0; color: var(--dark-text); font-size: 1rem; }
.difficulty-card li:before { content: "✓ "; color: var(--green-positive); font-weight: bold; }

/* Question Screen */
#question-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    color: var(--gray-neutral);
    font-size: 0.9rem;
}

#question-category {
    background: linear-gradient(135deg, var(--secondary-color), #ffc933);
    color: #212529;
    padding: 0.5rem 1rem;
    border-radius: 20px;
    font-weight: 500;
}

#timer {
    background: linear-gradient(135deg, #dc3545, #fd7e8f);
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 20px;
    font-weight: 500;
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0% { opacity: 1; }
    50% { opacity: 0.7; }
    100% { opacity: 1; }
}

.question-content-wrapper {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    width: 100%;
    justify-content: center;
    max-width: 90%;
}

#question-text {
    font-size: 1.5rem;
    margin-bottom: 2rem;
    min-height: 80px;
    text-align: left;
    line-height: 1.6;
    flex-grow: 1;
}

#choices-container {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.choice-btn {
    width: 100%;
    padding: 1.2rem;
    font-family: 'Kanit', sans-serif;
    font-size: 1.1rem;
    border: 2px solid var(--primary-color);
    background: var(--container-bg);
    color: var(--primary-color);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    text-align: left;
    position: relative;
    overflow: hidden;
}

.choice-btn:hover:not(:disabled) {
    background: var(--primary-color);
    color: var(--light-text);
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(88, 166, 255, 0.3);
}

.choice-btn:disabled { cursor: not-allowed; opacity: 0.7; }
.choice-btn.correct { background: var(--green-positive); border-color: var(--green-positive); color: var(--light-text); transform: scale(1.02); }
.choice-btn.incorrect { background: var(--incorrect-bg); border-color: var(--incorrect-bg); color: #212529; }

/* Hint Box */
#hint-box {
    margin-top: 1rem;
    padding: 1rem;
    background: var(--light-bg);
    border-left: 4px solid var(--primary-color);
    border-radius: 8px;
    font-size: 0.95rem;
}

/* Modals */
#modal-overlay, #bonus-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(5px);
}

#modal-overlay.hidden, #bonus-modal-overlay.hidden { display: none !important; }

#explanation-modal, #bonus-modal {
    border-radius: 20px;
    padding: 2rem;
    max-width: 600px;
    width: 90%;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    animation: modalSlideIn 0.4s ease-out;
    position: relative;
    border: 3px solid var(--secondary-color);
    color: var(--dark-text);
    max-height: 85vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

@keyframes modalSlideIn {
    from { opacity: 0; transform: scale(0.7) translateY(-50px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

#explanation-modal.correct-answer { background: var(--correct-bg); border-color: var(--green-positive); }
#explanation-modal.incorrect-answer { background: var(--incorrect-bg); border-color: #f7b801; }
#bonus-modal { background: var(--light-bg); border-color: var(--secondary-color); }

.modal-header, .bonus-header { text-align: center; margin-bottom: 1.5rem; }
.modal-header h3 { color: var(--primary-color); margin: 0; font-size: 1.6rem; }
.bonus-header h3 { color: var(--primary-color); margin: 0; font-size: 1.6rem; }

.modal-icon, .bonus-icon { font-size: 3rem; margin-bottom: 1rem; }
.modal-icon.correct { color: var(--green-positive); }
.modal-icon.incorrect { color: #f7b801; }

#explanation-text {
    font-size: 1.3rem;
    line-height: 1.8;
    margin-bottom: 2rem;
    color: var(--dark-text);
    text-align: center;
    font-weight: 400;
}

/* Bonus Modal */
#bonus-content { text-align: center; }
#bonus-message { font-size: 1.2rem; color: var(--primary-color); margin-bottom: 1rem; font-weight: 500; }
#bonus-stats {
    background: var(--container-bg);
    padding: 1rem;
    border-radius: 12px;
    margin: 1rem 0;
}
#bonus-stats p { margin: 0.5rem 0; font-size: 1.1rem; }
#motivation-text { font-size: 1rem; color: var(--gray-neutral); font-style: italic; margin-top: 1rem; }

/* End Screen */
.profile-section {
    margin: 2rem 0;
    padding: 1rem;
    background: var(--light-bg);
    border-radius: 16px;
    border: 2px solid var(--border-color);
}

.profile-header { text-align: center; margin-bottom: 2rem; }
.profile-header h3 { color: var(--primary-color); font-size: 1.8rem; margin: 0; }

.skill-meter { margin-bottom: 1.5rem; }
.skill-label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.skill-name { font-weight: 500; color: var(--dark-text); }
.skill-score { font-weight: 700; color: var(--primary-color); }

.meter-container {
    background: var(--container-bg);
    border-radius: 10px;
    height: 12px;
    overflow: hidden;
    position: relative;
}

.meter-fill {
    height: 100%;
    border-radius: 10px;
    transition: width 1s ease-out;
    position: relative;
    overflow: hidden;
}

.meter-excellent { background: linear-gradient(135deg, #28a745, #34ce57); }
.meter-good { background: linear-gradient(135deg, #17a2b8, #20c997); }
.meter-average { background: linear-gradient(135deg, #ffc107, #ffdb4d); }
.meter-poor { background: linear-gradient(135deg, #dc3545, #fd7e8f); }

/* Final Stats */
#final-stats {
    text-align: center;
    margin-bottom: 1.5rem;
    font-size: 1.2rem;
    padding: 1rem;
    background: var(--light-bg);
    border-radius: 16px;
    border: 2px solid var(--border-color);
    position: relative;
}

.final-verdict-message {
    font-size: 1.3rem;
    font-weight: 1000;
    text-align: center;
    padding: 1rem;
    margin: -1rem -1rem 1.5rem -1rem;
    border-bottom: 1px solid var(--border-color);
    background-color: var(--light-bg);
    border-top-left-radius: 16px;
    border-top-right-radius: 16px;
}

.nested-stats-container {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.5rem;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}

.nested-stat {
    background: var(--container-bg);
    padding: 0.2rem;
    border-radius: 1px;
    text-align: center;
    border: 1px solid var(--border-color);
}

.nested-stat p { margin: 0 0 0rem 0; font-size: 0.2rem; font-weight: 700; color: var(--primary-color); }
.nested-stat span { font-size: 1rem; font-weight: 700; }

/* Learning Recommendations */
#learning-recommendations {
    margin: 2.5rem 0;
    padding: 1rem;
    background: var(--container-bg);
    border-radius: 16px;
    border: 2px solid var(--border-color);
}

#recommendations-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    text-align: left;
}

.recommendation-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.5rem;
    background-color: var(--light-bg);
    border-radius: 12px;
    border: 2px solid var(--border-color);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    cursor: pointer;
}

.recommendation-item:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow);
}

.recommendation-icon { font-size: 2rem; color: var(--primary-color); flex-shrink: 0; }
.recommendation-details h4 { margin: 0 0 0.25rem 0; font-size: 1rem; color: var(--primary-color); font-weight: 500; }
.recommendation-details p { margin: 0; font-size: 0.7rem; color: var(--gray-neutral); text-align: left; line-height: 1.2; }

/* Utility Classes */
.hidden { display: none !important; }
.center { display: block; margin-left: auto; margin-right: auto; width: 50%; }

/* Responsive Design */
@media (max-width: 768px) {
    .player-info-section { grid-template-columns: 1fr; }
    .avatar-grid { grid-template-columns: repeat(3, 1fr); }
    .goal-options { grid-template-columns: 1fr; }
    #difficulty-options { flex-direction: column; gap: 1rem; }
    .difficulty-card { padding: 1rem; }
    .difficulty-icon { font-size: 2rem; }
    .difficulty-card h3 { font-size: 1rem; }
}

@media (max-width: 480px) {
    .avatar-grid { grid-template-columns: repeat(2, 1fr); }
    .registration-container, .goal-container { padding: 1rem; }
    body { padding: 10px; }
    #game-container { padding: 1rem; }
    header h1 { font-size: 1.5rem; }
    #question-text { font-size: 1.1rem; }
    .choice-btn { padding: 1rem; font-size: 1rem; }
}