:root {
    --bg-color: #121212;
    --card-bg: #1e1e1e;
    --card-hover: #2a2a2a;
    --text-primary: #ffffff;
    --text-secondary: #aaaaaa;
    --accent: #3b82f6;
    --danger: #ef4444;
    --gap: 20px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    /* Prevent selection during tests */
}

body {
    font-family: 'Noto Sans KR', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    overflow-x: hidden;
}

/* Ad Container Styles - Preventing CLS */
.ad-container {
    width: 100%;
    margin: 20px 0;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: #1a1a1a;
    border-radius: 8px;
    overflow: hidden;
}

.ad-top {
    min-height: 100px;
    /* Reserve height for top banner */
}

.ad-bottom {
    min-height: 250px;
    /* Reserve height for display ad */
    margin-top: 40px;
}

.ad-placeholder {
    color: #444;
    font-size: 0.9rem;
    border: 1px dashed #333;
    padding: 10px 20px;
    border-radius: 4px;
}

/* Layout Wrapper */
.layout-wrapper {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100vh;
    padding: 0 10px;
}

/* Side Ads */
.side-ad {
    width: 160px;
    /* Standard Skyscraper width */
    height: 600px;
    position: sticky;
    top: 20px;
    flex-shrink: 0;
    margin-top: 100px;
    /* Align somewhat with content */
    display: none;
    /* Hidden by default on small screens */
}

.ad-left {
    margin-right: 20px;
}

.ad-right {
    margin-left: 20px;
}

@media (min-width: 1400px) {
    .side-ad {
        display: block;
    }
}

.ad-placeholder-tall {
    width: 100%;
    height: 100%;
    border: 1px dashed #333;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #444;
    writing-mode: vertical-rl;
}

/* Dashboard Layout */
.dashboard {
    flex: 1;
    max-width: 1000px;
    /* Reduced from 1200px to fit ads */
    margin: 0;
    padding: 40px 20px;
}

/* Language Switcher */
.lang-switcher {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.lang-btn {
    background: transparent;
    border: 2px solid transparent;
    /* Highlight border */
    border-radius: 50%;
    /* Circle button */
    width: 40px;
    height: 40px;
    cursor: pointer;
    transition: transform 0.2s, border-color 0.2s;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0;
    /* Remove padding for icon centering */
    overflow: hidden;
    /* Clip flat flags to circle if needed */
}

/* Flag Icon adjustments */
.lang-btn .fi {
    width: 30px;
    /* Adjust size inside button */
    height: 30px;
    border-radius: 50%;
    /* Make flag circular */
    background-size: cover;
    background-position: center;
    font-size: 30px;
    /* Some libraries use font-size for raw svg scaling control context */
    line-height: 1em;
}

/* Specific to flag-icons css library: it uses background-image on :before or the element itself with fixed ratio. 
   We need to ensure it fits the circle. The library usually sets width/height/background-size: cover. 
   The library classes are .fi and .fi-xx. They are rectangular 4x3 usually.
   To make them circular: */
.fi {
    width: 30px !important;
    height: 30px !important;
    border-radius: 50%;
    object-fit: cover;
}

.lang-btn:hover {
    transform: scale(1.1);
    background: rgba(255, 255, 255, 0.1);
}

.lang-btn.active {
    border-color: #3b82f6;
    background: rgba(59, 130, 246, 0.1);
}

.main-header {
    text-align: center;
    margin-bottom: 40px;
}

.main-header h1 {
    font-size: 2.5rem;
    margin-bottom: 10px;
    font-weight: 700;
}

.main-header p {
    color: var(--text-secondary);
    margin-bottom: 20px;
}

.header-guide {
    display: inline-flex;
    gap: 15px;
    background: rgba(255, 255, 255, 0.1);
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 0.9rem;
}

.key-badge {
    background: rgba(255, 255, 255, 0.2);
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: bold;
    font-family: monospace;
}

.test-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: var(--gap);
}

@media (max-width: 768px) {
    .main-header h1 {
        font-size: 1.8rem;
    }

    .header-guide {
        display: none;
        /* Hide keyboard shortcuts on mobile */
    }

    .test-grid {
        grid-template-columns: 1fr;
        /* 1 column on mobile for better card readability */
    }

    .test-card {
        padding: 20px;
        /* Slightly compact */
    }

    .lang-switcher .lang-btn {
        width: 35px;
        height: 35px;
    }

    .lang-btn .fi {
        width: 25px !important;
        height: 25px !important;
    }

    /* Adjust test UI for touch */
    /* Adjust test UI for touch */
    .test-ui-overlay {
        top: 10px;
        top: env(safe-area-inset-top, 10px);
        /* iOS Safe Area Support */
        left: 10px;
        left: env(safe-area-inset-left, 10px);
        right: 10px;
        right: env(safe-area-inset-right, 10px);

        /* Force visibility on mobile since there is no hover */
        opacity: 1 !important;
    }

    .ui-btn,
    .test-guide-text {
        padding: 10px 15px;
        /* Larger touch target */
        font-size: 0.9rem;
    }
}

.test-card {
    background: var(--card-bg);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    padding: 25px;
    text-align: left;
    cursor: pointer;
    transition: transform 0.2s, background 0.2s, box-shadow 0.2s;
    display: flex;
    flex-direction: column;
    gap: 10px;
    color: inherit;
    font: inherit;
}

.test-card:hover {
    background: var(--card-hover);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.test-card .icon {
    font-size: 2rem;
    margin-bottom: 5px;
}

.test-card .le {
    font-size: 1.25rem;
    font-weight: 700;
}

.test-card .desc {
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.4;
}

.test-card.danger {
    border-color: rgba(239, 68, 68, 0.3);
}

.test-card.danger:hover {
    background: rgba(239, 68, 68, 0.1);
}

/* Test Container (Overlay) */
.test-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: black;
    z-index: 1000;
}

.hidden {
    display: none !important;
}

#test-content {
    width: 100%;
    height: 100%;
    cursor: auto;
    /* Ensure cursor is visible */
}

/* UI Overlay within Test */
.test-ui-overlay {
    position: absolute;
    top: 20px;
    left: 20px;
    right: 20px;
    display: flex;
    justify-content: space-between;
    pointer-events: none;
    /* Allow clicks to pass through to test */
    opacity: 0;
    transition: opacity 0.3s;
}

.test-container:hover .test-ui-overlay {
    opacity: 1;
}

.ui-btn {
    pointer-events: auto;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 8px 16px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    backdrop-filter: blur(4px);
}

.ui-btn:hover {
    background: rgba(0, 0, 0, 0.8);
}

.test-guide-text {
    background: rgba(0, 0, 0, 0.6);
    padding: 8px 16px;
    border-radius: 8px;
    backdrop-filter: blur(4px);
    color: #eee;
}

/* Common Utilities for Tests */
.full-screen-color {
    width: 100%;
    height: 100%;
}