/* ===== CSS RESET & BASE STYLES ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #f5deb3 0%, #d2b48c 100%);
    color: #333;
    overflow-x: hidden;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

/* ===== CONTAINER & LAYOUT ===== */
#app {
    width: 100%;
    height: 450px;
    max-width: 100%;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><circle cx="20" cy="20" r="1" fill="%23d2691e" opacity="0.1"/><circle cx="80" cy="80" r="1" fill="%23d2691e" opacity="0.1"/></svg>') repeat;
}

/* Fullscreen mode detection */
@media (min-height: 600px) {
    #app {
        height: 90vh;
    }
}

/* ===== TITLE BAR (COLLAPSIBLE) ===== */
.title-bar {
    background: linear-gradient(135deg, #8b4513 0%, #a0522d 100%);
    color: white;
    padding: 8px 16px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
    transition: all 0.3s ease;
}

.title-bar.collapsed {
    padding: 4px 16px;
}

.title-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.title-bar h1 {
    font-size: clamp(14px, 3vw, 20px);
    font-weight: 700;
    margin: 0;
    flex: 1;
}

.title-bar.collapsed h1 {
    font-size: clamp(12px, 2.5vw, 16px);
}

.toggle-btn {
    background: rgba(255,255,255,0.2);
    border: 2px solid white;
    color: white;
    width: 44px;
    height: 44px;
    border-radius: 8px;
    font-size: 18px;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}

.toggle-btn:hover,
.toggle-btn:active {
    background: rgba(255,255,255,0.3);
    transform: scale(1.05);
}

/* ===== PROGRESS BAR ===== */
.progress-container {
    background: white;
    padding: 12px 16px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.1);
}

.progress-text {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    font-size: clamp(12px, 2.5vw, 14px);
    font-weight: 600;
    gap: 12px;
    flex-wrap: wrap;
}

#scoreDisplay {
    color: #d2691e;
    font-weight: 700;
}

.progress-bar {
    width: 100%;
    height: 12px;
    background: #e0e0e0;
    border-radius: 6px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #4caf50, #8bc34a);
    width: 0%;
    transition: width 0.5s ease;
    border-radius: 6px;
}

/* ===== GAME AREA ===== */
.game-area {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px;
    position: relative;
}

.section {
    display: none;
    animation: fadeIn 0.4s ease;
}

.section.active {
    display: block;
}

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

/* ===== INSTRUCTION PANEL ===== */
.instruction-panel {
    background: linear-gradient(135deg, #fff8dc 0%, #ffefd5 100%);
    border: 3px solid #d2691e;
    border-radius: 12px;
    padding: 12px 16px;
    margin-bottom: 16px;
    box-shadow: 0 3px 8px rgba(0,0,0,0.15);
}

.instruction-panel p {
    font-size: clamp(13px, 2.8vw, 15px);
    font-weight: 600;
    color: #654321;
    margin: 0;
    line-height: 1.5;
}

/* ===== SECTION 1: MATCHING LAYOUT ===== */
.matching-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 16px;
}

@media (max-width: 768px) {
    .matching-container {
        grid-template-columns: 1fr;
    }
}

.column h3 {
    background: linear-gradient(135deg, #8b4513 0%, #a0522d 100%);
    color: white;
    padding: 10px;
    border-radius: 8px 8px 0 0;
    font-size: clamp(14px, 3vw, 16px);
    text-align: center;
    margin: 0;
}

.item-list {
    background: white;
    border: 2px solid #d2691e;
    border-radius: 0 0 8px 8px;
    padding: 12px;
    min-height: 200px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.match-item {
    background: linear-gradient(135deg, #ffefd5 0%, #ffe4b5 100%);
    border: 2px solid #d2691e;
    border-radius: 8px;
    padding: 12px 16px;
    font-size: clamp(12px, 2.5vw, 14px);
    cursor: pointer;
    transition: all 0.2s;
    min-height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    line-height: 1.4;
    position: relative;
    user-select: none;
}

.match-item:hover,
.match-item:active {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(210, 105, 30, 0.3);
}

.match-item.selected {
    background: linear-gradient(135deg, #ffd700 0%, #ffed4e 100%);
    border-color: #ff8c00;
    box-shadow: 0 0 0 3px rgba(255, 140, 0, 0.3);
    transform: scale(1.03);
}

.match-item.matched {
    background: linear-gradient(135deg, #90ee90 0%, #98fb98 100%);
    border-color: #228b22;
    opacity: 0.7;
    pointer-events: none;
}

.match-item.matched::after {
    content: '✓';
    position: absolute;
    top: 4px;
    right: 8px;
    color: #228b22;
    font-size: 20px;
    font-weight: bold;
}

/* ===== SECTION 2: SITUATION CARDS ===== */
.situation-container {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.situation-card {
    background: white;
    border: 3px solid #d2691e;
    border-radius: 12px;
    padding: 16px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.situation-header {
    background: linear-gradient(135deg, #8b4513 0%, #a0522d 100%);
    color: white;
    padding: 10px 16px;
    border-radius: 8px;
    margin-bottom: 12px;
    font-size: clamp(13px, 2.8vw, 15px);
    font-weight: 600;
    line-height: 1.5;
}

.situation-options {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 10px;
}

.option-btn {
    background: linear-gradient(135deg, #ffefd5 0%, #ffe4b5 100%);
    border: 2px solid #d2691e;
    border-radius: 8px;
    padding: 12px 16px;
    font-size: clamp(12px, 2.5vw, 14px);
    cursor: pointer;
    transition: all 0.2s;
    min-height: 48px;
    text-align: center;
    line-height: 1.4;
    font-weight: 500;
}

.option-btn:hover,
.option-btn:active {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(210, 105, 30, 0.3);
}

.option-btn.correct {
    background: linear-gradient(135deg, #90ee90 0%, #98fb98 100%);
    border-color: #228b22;
    color: #006400;
    font-weight: 700;
    pointer-events: none;
}

.option-btn.wrong {
    background: linear-gradient(135deg, #ffb6c1 0%, #ffc0cb 100%);
    border-color: #dc143c;
    color: #8b0000;
    pointer-events: none;
}

.option-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* ===== ACTION BUTTONS ===== */
.action-buttons {
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
    margin-top: 16px;
}

.btn {
    padding: 12px 24px;
    font-size: clamp(13px, 2.8vw, 15px);
    font-weight: 600;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    min-height: 48px;
    min-width: 120px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-primary {
    background: linear-gradient(135deg, #4caf50 0%, #66bb6a 100%);
    color: white;
    box-shadow: 0 4px 8px rgba(76, 175, 80, 0.3);
}

.btn-primary:hover,
.btn-primary:active {
    background: linear-gradient(135deg, #45a049 0%, #5cb85c 100%);
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(76, 175, 80, 0.4);
}

.btn-primary:disabled {
    background: #cccccc;
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
}

.btn-secondary {
    background: linear-gradient(135deg, #ff9800 0%, #ffa726 100%);
    color: white;
    box-shadow: 0 4px 8px rgba(255, 152, 0, 0.3);
}

.btn-secondary:hover,
.btn-secondary:active {
    background: linear-gradient(135deg, #f57c00 0%, #fb8c00 100%);
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(255, 152, 0, 0.4);
}

.btn-small {
    padding: 6px 12px;
    font-size: 12px;
    min-height: 32px;
    min-width: auto;
}

/* ===== COMPLETION SCREEN ===== */
.completion-content {
    text-align: center;
    padding: 24px;
    background: white;
    border-radius: 16px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.2);
    max-width: 500px;
    margin: 0 auto;
}

.trophy-icon {
    font-size: 80px;
    margin-bottom: 16px;
    animation: bounce 1s infinite;
}

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

.completion-content h2 {
    color: #d2691e;
    font-size: clamp(20px, 4vw, 28px);
    margin-bottom: 12px;
}

.completion-message {
    font-size: clamp(14px, 3vw, 16px);
    margin-bottom: 20px;
    color: #555;
}

.final-score {
    background: linear-gradient(135deg, #fff8dc 0%, #ffefd5 100%);
    border: 2px solid #d2691e;
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 20px;
}

.final-score p {
    font-size: clamp(16px, 3.5vw, 20px);
    font-weight: 700;
    color: #d2691e;
    margin: 8px 0;
}

.score-breakdown {
    font-size: clamp(13px, 2.8vw, 15px) !important;
    color: #654321 !important;
    font-weight: 500 !important;
}

/* ===== FEEDBACK TOOLTIP ===== */
.feedback-tooltip {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    border: 3px solid #d2691e;
    border-radius: 16px;
    padding: 24px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.3);
    z-index: 1000;
    max-width: 400px;
    width: 90%;
    animation: popIn 0.3s ease;
}

@keyframes popIn {
    from { transform: translate(-50%, -50%) scale(0.8); opacity: 0; }
    to { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

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

.feedback-content {
    position: relative;
    text-align: center;
}

.close-tooltip {
    position: absolute;
    top: -12px;
    right: -12px;
    background: #dc143c;
    color: white;
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

.close-tooltip:hover,
.close-tooltip:active {
    background: #b22222;
    transform: scale(1.1);
}

.feedback-icon {
    font-size: 60px;
    margin-bottom: 12px;
}

.feedback-message {
    font-size: clamp(14px, 3vw, 16px);
    line-height: 1.6;
    color: #333;
}

.feedback-tooltip.correct .feedback-icon::before {
    content: '✅';
}

.feedback-tooltip.wrong .feedback-icon::before {
    content: '❌';
}

/* ===== ANALYTICS PANEL ===== */
.analytics-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    border-top: 3px solid #d2691e;
    box-shadow: 0 -4px 12px rgba(0,0,0,0.2);
    transition: transform 0.3s ease;
    z-index: 900;
}

.analytics-panel.collapsed {
    transform: translateY(calc(100% - 48px));
}

.analytics-toggle {
    width: 100%;
    background: linear-gradient(135deg, #8b4513 0%, #a0522d 100%);
    color: white;
    border: none;
    padding: 12px;
    font-size: clamp(13px, 2.8vw, 15px);
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 48px;
}

.analytics-toggle:hover,
.analytics-toggle:active {
    background: linear-gradient(135deg, #a0522d 0%, #8b4513 100%);
}

.analytics-content {
    padding: 16px;
    max-height: 250px;
    overflow-y: auto;
}

.analytics-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    gap: 12px;
}

.analytics-header h3 {
    font-size: clamp(14px, 3vw, 16px);
    color: #d2691e;
    margin: 0;
}

.analytics-log {
    background: #f5f5f5;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 12px;
    font-family: 'Courier New', monospace;
    font-size: clamp(11px, 2.2vw, 13px);
    max-height: 180px;
    overflow-y: auto;
}

.log-entry {
    margin: 4px 0;
    padding: 4px 0;
    border-bottom: 1px solid #e0e0e0;
    line-height: 1.4;
}

.log-entry:last-child {
    border-bottom: none;
}

.log-entry.correct {
    color: #228b22;
}

.log-entry.wrong {
    color: #dc143c;
}

/* ===== TOUCH FEEDBACK ===== */
.match-item:active,
.option-btn:active,
.btn:active {
    opacity: 0.8;
}

/* Touch active state */
[data-touch-active="true"] {
    box-shadow: 0 0 0 4px rgba(255, 140, 0, 0.4);
}

/* ===== RESPONSIVE ADJUSTMENTS ===== */
@media (max-width: 480px) {
    .game-area {
        padding: 12px;
    }
    
    .instruction-panel {
        padding: 10px 12px;
    }
    
    .situation-options {
        grid-template-columns: 1fr;
    }
    
    .action-buttons {
        flex-direction: column;
    }
    
    .btn {
        width: 100%;
    }
}

/* ===== ACCESSIBILITY ===== */
@media (hover: none) and (pointer: coarse) {
    /* Touch device optimizations */
    .match-item,
    .option-btn,
    .btn,
    .toggle-btn,
    .close-tooltip {
        min-height: 48px;
        min-width: 48px;
    }
}

/* High contrast mode */
@media (prefers-contrast: high) {
    .match-item,
    .option-btn {
        border-width: 3px;
    }
}