/* --- Root Variables & Reset --- */
:root {
    --primary: #4F46E5;
    --primary-light: #EEF2FF;
    --primary-dark: #3730A3;
    --accent-input: #0284C7;
    --accent-input-bg: #E0F2FE;
    --accent-process: #DC2626;
    --accent-process-bg: #FEE2E2;
    --accent-output: #16A34A;
    --accent-output-bg: #DCFCE7;
    --accent-storage: #9333EA;
    --accent-storage-bg: #F3E8FF;
    --bg-main: #F8FAFC;
    --bg-surface: #FFFFFF;
    --text-main: #1E293B;
    --text-muted: #64748B;
    --radius-sm: 8px;
    --radius-md: 16px;
    --radius-lg: 24px;
    --shadow-sm: 0 2px 4px rgba(0,0,0,0.05);
    --shadow-md: 0 8px 16px rgba(0,0,0,0.08);
    --shadow-lg: 0 16px 32px rgba(79, 70, 229, 0.12);
    --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Prompt', 'Kanit', 'Sarabun', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

body {
    background-color: var(--bg-main);
    color: var(--text-main);
    line-height: 1.6;
    overflow-x: hidden;
}

/* --- Navigation Header --- */
.main-header {
    background: var(--bg-surface);
    border-bottom: 2px solid #E2E8F0;
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0.8rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-size: 1.25rem;
    color: var(--primary-dark);
}

.logo-icon {
    font-size: 1.8rem;
    animation: float 3s ease-in-out infinite;
}

.nav-links {
    display: flex;
    gap: 0.5rem;
}

.nav-btn {
    border: none;
    background: transparent;
    padding: 0.6rem 1.1rem;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-muted);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition);
}

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

.nav-btn.active {
    background: var(--primary);
    color: #FFFFFF;
    box-shadow: var(--shadow-sm);
}

/* --- Hero Section --- */
.hero-section {
    max-width: 1200px;
    margin: 1.5rem auto;
    padding: 2.5rem 1.5rem;
    display: grid;
    grid-template-columns: 1.2fr 0.8fr;
    gap: 2rem;
    align-items: center;
}

.hero-badge {
    display: inline-block;
    background: var(--primary-light);
    color: var(--primary);
    padding: 0.4rem 1rem;
    border-radius: 99px;
    font-size: 0.85rem;
    font-weight: 700;
    margin-bottom: 1rem;
}

.hero-title {
    font-size: 2.5rem;
    line-height: 1.25;
    margin-bottom: 1rem;
    color: #0F172A;
}

.highlight-text {
    background: linear-gradient(120deg, var(--primary) 0%, #EC4899 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.hero-subtitle {
    font-size: 1.05rem;
    color: var(--text-muted);
    margin-bottom: 1.8rem;
    max-width: 540px;
}

.hero-actions {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

/* --- Mascot Illustration --- */
.hero-visual {
    display: flex;
    justify-content: center;
    align-items: center;
}

.computer-mascot {
    position: relative;
    width: 220px;
    height: 200px;
}

.monitor-frame {
    width: 200px;
    height: 150px;
    background: #334155;
    border-radius: 16px;
    padding: 10px;
    position: relative;
    box-shadow: 0 12px 24px rgba(0,0,0,0.15);
    animation: gentleBounce 4s ease-in-out infinite;
}

.screen {
    width: 100%;
    height: 100%;
    background: #38BDF8;
    border-radius: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    overflow: hidden;
}

.face {
    position: relative;
    width: 100px;
    height: 60px;
}

.eye {
    width: 14px;
    height: 22px;
    background: #0F172A;
    border-radius: 99px;
    position: absolute;
    top: 10px;
    animation: blink 4s infinite;
}

.eye.left { left: 20px; }
.eye.right { right: 20px; }

.mouth {
    width: 32px;
    height: 16px;
    border-bottom: 4px solid #0F172A;
    border-radius: 0 0 16px 16px;
    position: absolute;
    bottom: 8px;
    left: 34px;
}

.stand {
    width: 36px;
    height: 30px;
    background: #64748B;
    margin: 0 auto;
}

.base {
    width: 110px;
    height: 14px;
    background: #475569;
    border-radius: 8px;
    margin: 0 auto;
}

/* --- Buttons --- */
.btn {
    border: none;
    outline: none;
    padding: 0.8rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
    background: var(--primary);
    color: #FFFFFF;
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
}

.btn-primary:hover {
    background: var(--primary-dark);
    box-shadow: 0 6px 16px rgba(79, 70, 229, 0.4);
    transform: translateY(-2px);
}

.btn-secondary {
    background: #E2E8F0;
    color: #334155;
}

.btn-secondary:hover {
    background: #CBD5E1;
    color: #0F172A;
}

.btn-outline {
    background: transparent;
    border: 2px solid #E2E8F0;
    color: var(--text-muted);
}

.btn-outline:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.btn-sm {
    padding: 0.4rem 0.9rem;
    font-size: 0.85rem;
}

.btn-large {
    padding: 1rem 2rem;
    font-size: 1.15rem;
}

/* --- Section Layout --- */
.content-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1rem 1.5rem 4rem 1.5rem;
}

.app-section {
    display: block;
    animation: fadeIn 0.4s ease-out;
}

.hidden-section {
    display: none;
}

.section-header {
    text-align: center;
    margin-bottom: 2rem;
}

.section-header h2 {
    font-size: 1.85rem;
    color: #0F172A;
    margin-bottom: 0.4rem;
}

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

/* --- Category Filters --- */
.category-filters {
    display: flex;
    justify-content: center;
    gap: 0.6rem;
    flex-wrap: wrap;
    margin-bottom: 2.2rem;
}

.filter-btn {
    border: 2px solid transparent;
    background: #FFFFFF;
    padding: 0.6rem 1.2rem;
    border-radius: 99px;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
}

.filter-btn:hover {
    border-color: #CBD5E1;
    color: var(--text-main);
    transform: translateY(-2px);
}

.filter-btn.active {
    background: var(--primary);
    color: #FFFFFF;
    box-shadow: 0 4px 10px rgba(79, 70, 229, 0.25);
}

/* --- Device Cards Grid --- */
.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 1.5rem;
}

.device-card {
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    border: 2px solid #F1F5F9;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    position: relative;
}

.device-card:hover {
    transform: translateY(-6px);
    box-shadow: var(--shadow-lg);
    border-color: #E2E8F0;
}

.device-badge {
    position: absolute;
    top: 1rem;
    right: 1rem;
    font-size: 0.72rem;
    font-weight: 700;
    padding: 0.25rem 0.6rem;
    border-radius: 99px;
    text-transform: uppercase;
}

.badge-input { background: var(--accent-input-bg); color: var(--accent-input); }
.badge-process { background: var(--accent-process-bg); color: var(--accent-process); }
.badge-output { background: var(--accent-output-bg); color: var(--accent-output); }
.badge-storage { background: var(--accent-storage-bg); color: var(--accent-storage); }

.card-svg-wrap {
    width: 80px;
    height: 80px;
    margin: 1.2rem 0 0.8rem 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.device-card h3 {
    font-size: 1.15rem;
    color: #0F172A;
    margin-bottom: 0.2rem;
}

.device-en {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 0.8rem;
}

.card-action-hint {
    margin-top: auto;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--primary);
    background: var(--primary-light);
    padding: 0.35rem 0.8rem;
    border-radius: var(--radius-sm);
}

/* --- Game Section --- */
.game-container {
    max-width: 900px;
    margin: 0 auto;
    background: #FFFFFF;
    border-radius: var(--radius-lg);
    padding: 2rem;
    box-shadow: var(--shadow-md);
    border: 2px solid #E2E8F0;
}

.game-topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.8rem;
    padding-bottom: 1rem;
    border-bottom: 2px dashed #E2E8F0;
}

.game-score {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary-dark);
}

.game-deck {
    display: flex;
    justify-content: center;
    margin-bottom: 2.2rem;
    min-height: 180px;
}

.deck-item-card {
    background: #F8FAFC;
    border: 3px solid var(--primary);
    border-radius: var(--radius-md);
    padding: 1.2rem 2.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    box-shadow: 0 8px 20px rgba(79, 70, 229, 0.15);
    animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.deck-item-card .card-svg-wrap {
    width: 65px;
    height: 65px;
    margin: 0;
}

.deck-item-card h4 {
    font-size: 1.2rem;
    color: #0F172A;
}

.deck-item-card p {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.game-bins {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
}

.bin-card {
    background: #F8FAFC;
    border: 2px dashed #CBD5E1;
    border-radius: var(--radius-md);
    padding: 1.2rem 0.8rem;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
    user-select: none;
}

.bin-card:hover {
    transform: translateY(-4px);
    border-color: var(--primary);
    background: var(--primary-light);
}

.bin-card:active {
    transform: scale(0.96);
}

.bin-icon {
    font-size: 2rem;
    margin-bottom: 0.4rem;
}

.bin-card h3 {
    font-size: 1rem;
    color: #1E293B;
}

.bin-sub {
    font-size: 0.75rem;
    color: var(--text-muted);
    display: block;
    margin-bottom: 0.5rem;
}

.bin-counter {
    display: inline-block;
    background: #E2E8F0;
    padding: 0.2rem 0.6rem;
    border-radius: 99px;
    font-size: 0.75rem;
    font-weight: 700;
}

.game-message {
    margin-top: 1.5rem;
    padding: 1rem;
    border-radius: var(--radius-md);
    text-align: center;
    font-weight: 600;
    display: none;
    animation: fadeIn 0.3s;
}

.game-message.success {
    display: block;
    background: var(--accent-output-bg);
    color: var(--accent-output);
}

.game-message.error {
    display: block;
    background: var(--accent-process-bg);
    color: var(--accent-process);
}

.game-message.finished {
    display: block;
    background: var(--primary-light);
    color: var(--primary-dark);
    font-size: 1.1rem;
}

/* --- Quiz Section --- */
.quiz-wrapper {
    max-width: 720px;
    margin: 0 auto;
}

.quiz-box {
    background: #FFFFFF;
    border-radius: var(--radius-lg);
    padding: 2.2rem;
    box-shadow: var(--shadow-md);
    border: 2px solid #E2E8F0;
}

.quiz-intro-icon {
    font-size: 3.5rem;
    margin-bottom: 1rem;
}

.quiz-progress-bar {
    width: 100%;
    height: 8px;
    background: #E2E8F0;
    border-radius: 99px;
    overflow: hidden;
    margin-bottom: 1.2rem;
}

.quiz-progress-fill {
    width: 20%;
    height: 100%;
    background: var(--primary);
    transition: width 0.3s ease;
}

.quiz-header-status {
    display: flex;
    justify-content: space-between;
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text-muted);
    margin-bottom: 1.5rem;
}

.quiz-question-card h3 {
    font-size: 1.3rem;
    color: #0F172A;
    margin-bottom: 1.5rem;
    line-height: 1.4;
}

.quiz-options {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

.quiz-opt-btn {
    width: 100%;
    text-align: left;
    background: #F8FAFC;
    border: 2px solid #E2E8F0;
    border-radius: var(--radius-md);
    padding: 1rem 1.2rem;
    font-size: 1rem;
    font-weight: 600;
    color: #334155;
    cursor: pointer;
    transition: var(--transition);
}

.quiz-opt-btn:hover:not(:disabled) {
    border-color: var(--primary);
    background: var(--primary-light);
    color: var(--primary-dark);
}

.quiz-opt-btn.correct {
    background: var(--accent-output-bg) !important;
    border-color: var(--accent-output) !important;
    color: var(--accent-output) !important;
}

.quiz-opt-btn.wrong {
    background: var(--accent-process-bg) !important;
    border-color: var(--accent-process) !important;
    color: var(--accent-process) !important;
}

.quiz-feedback {
    margin-top: 1.5rem;
    padding: 1.2rem;
    background: #F8FAFC;
    border-radius: var(--radius-md);
    border-left: 5px solid var(--primary);
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    animation: fadeIn 0.3s;
}

.quiz-feedback.hidden {
    display: none;
}

.trophy-icon {
    font-size: 4rem;
    margin-bottom: 0.8rem;
    animation: gentleBounce 2s infinite;
}

.result-score-text {
    font-size: 1.35rem;
    font-weight: 700;
    margin: 0.8rem 0;
    color: var(--primary-dark);
}

.result-desc {
    color: var(--text-muted);
    margin-bottom: 1.8rem;
}

.result-actions {
    display: flex;
    justify-content: center;
    gap: 1rem;
    flex-wrap: wrap;
}

/* --- Modal Popup --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.modal-card {
    background: #FFFFFF;
    width: 100%;
    max-width: 480px;
    border-radius: var(--radius-lg);
    padding: 2rem;
    box-shadow: var(--shadow-lg);
    position: relative;
    transform: translateY(20px) scale(0.95);
    transition: transform 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.modal-overlay.active .modal-card {
    transform: translateY(0) scale(1);
}

.modal-close {
    position: absolute;
    top: 1rem;
    right: 1.2rem;
    font-size: 1.8rem;
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
}

.modal-header {
    text-align: center;
    margin-bottom: 1.2rem;
}

.modal-badge {
    display: inline-block;
    padding: 0.25rem 0.8rem;
    border-radius: 99px;
    font-size: 0.8rem;
    font-weight: 700;
    margin-bottom: 0.8rem;
}

.modal-svg-wrap {
    width: 90px;
    height: 90px;
    margin: 0 auto 0.8rem auto;
}

.modal-svg-wrap svg {
    width: 100%;
    height: 100%;
}

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

.modal-body {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.modal-section {
    background: #F8FAFC;
    padding: 1rem;
    border-radius: var(--radius-md);
}

.modal-section h4 {
    font-size: 0.95rem;
    color: #1E293B;
    margin-bottom: 0.3rem;
}

.modal-section p {
    font-size: 0.9rem;
    color: #475569;
}

.modal-footer {
    display: flex;
    justify-content: center;
}

/* --- Utilities & Animations --- */
.text-center { text-align: center; }
.hidden { display: none !important; }

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes popIn {
    0% { transform: scale(0.8); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-5px); }
}

@keyframes gentleBounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-8px); }
}

@keyframes blink {
    0%, 90%, 100% { transform: scaleY(1); }
    95% { transform: scaleY(0.1); }
}

/* --- Footer --- */
.main-footer {
    background: #FFFFFF;
    border-top: 1px solid #E2E8F0;
    text-align: center;
    padding: 1.5rem;
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* --- Responsive Adjustments --- */
@media (max-width: 768px) {
    .hero-section {
        grid-template-columns: 1fr;
        text-align: center;
        padding: 1.5rem 1rem;
    }
    .hero-actions {
        justify-content: center;
    }
    .hero-title {
        font-size: 2rem;
    }
    .hero-subtitle {
        margin: 0 auto 1.5rem auto;
    }
    .nav-container {
        justify-content: center;
    }
}