/* 타이핑 속도 테스트 - 2026 UI 트렌드 */
:root {
    --primary: #4CAF50;
    --primary-dark: #388E3C;
    --primary-light: #81C784;
    --bg-dark: #1a1a1a;
    --bg-card: #2a2a2a;
    --text-primary: #ffffff;
    --text-secondary: #b0b0b0;
    --success: #66BB6A;
    --error: #EF5350;
    --warning: #FFA726;
    --border-color: #3a3a3a;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}

/* 터치 최적화 */
button, a, input, [role="button"], [role="link"] {
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
}

input[type="text"], textarea {
    -webkit-user-select: text;
    user-select: text;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', sans-serif;
    background: linear-gradient(135deg, #1a1a1a 0%, #242424 100%);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
    overflow-x: hidden;
}

.app-loader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(26, 26, 26, 0.95);
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    transition: opacity 0.3s ease;
}

.app-loader.hidden {
    opacity: 0;
    pointer-events: none;
}

.loader-content {
    text-align: center;
}

.loader-emoji {
    font-size: 3rem;
    margin-bottom: 20px;
    animation: bounce 1s infinite;
}

.loader-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top-color: var(--primary);
    border-radius: 50%;
    margin: 0 auto 20px;
    animation: spin 1s linear infinite;
}

.loader-text {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

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

.app-container {
    max-width: 520px;
    margin: 0 auto;
    padding: 10px;
    min-height: 100vh;
}

/* 광고 배너 */
.ad-banner {
    height: 50px;
    background: var(--bg-card);
    border: 1px dashed var(--border-color);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    font-size: 0.75rem;
    margin-bottom: 10px;
}

.ad-banner::before {
    content: '/* 광고 영역 */';
}

.bottom-ad {
    margin-top: 10px;
    margin-bottom: 0;
}

/* 언어 선택기 */
.language-selector {
    position: fixed;
    top: 15px;
    right: 15px;
    z-index: 1000;
}

.lang-btn {
    background: rgba(76, 175, 80, 0.15);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(76, 175, 80, 0.3);
    color: var(--text-primary);
    font-size: 20px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.lang-btn:hover {
    background: rgba(76, 175, 80, 0.3);
    transform: scale(1.05);
}

.lang-menu {
    position: absolute;
    top: 52px;
    right: 0;
    background: rgba(26, 26, 26, 0.95);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(76, 175, 80, 0.2);
    border-radius: 12px;
    padding: 8px;
    min-width: 160px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.lang-menu.hidden {
    display: none;
}

.lang-option {
    width: 100%;
    padding: 10px 14px;
    background: transparent;
    border: none;
    text-align: left;
    cursor: pointer;
    border-radius: 8px;
    font-size: 14px;
    color: var(--text-secondary);
    transition: all 0.2s;
}

.lang-option:hover {
    background: rgba(76, 175, 80, 0.15);
    color: var(--text-primary);
}

.lang-option.active {
    background: rgba(76, 175, 80, 0.25);
    color: var(--primary);
    font-weight: 600;
}

/* 헤더 */
.header {
    text-align: center;
    padding: 20px 0;
    margin-bottom: 20px;
}

.app-title {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 5px;
}

.app-emoji {
    font-size: 2rem;
    margin-right: 10px;
}

.app-subtitle {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-top: 8px;
}

/* 메인 콘텐츠 */
.main-content {
    animation: fadeIn 0.4s ease;
}

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

/* 시작 화면 */
.start-screen {
    text-align: center;
}

.mode-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 20px;
}

.mode-card {
    background: rgba(76, 175, 80, 0.05);
    border: 2px solid var(--border-color);
    border-radius: 12px;
    padding: 20px;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.mode-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, rgba(76, 175, 80, 0.1) 0%, transparent 100%);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.mode-card:hover {
    border-color: var(--primary);
    transform: translateY(-4px);
    box-shadow: 0 12px 24px rgba(76, 175, 80, 0.15);
}

.mode-card:hover::before {
    opacity: 1;
}

.mode-emoji {
    font-size: 2rem;
    margin-bottom: 10px;
}

.mode-title {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 5px;
    color: var(--text-primary);
}

.mode-desc {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.stats-summary {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 20px;
    border: 1px solid var(--border-color);
}

.stat-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid var(--border-color);
}

.stat-row:last-child {
    border-bottom: none;
}

.stat-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.stat-value {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--primary);
    font-family: 'Courier New', monospace;
}

/* 게임 화면 */
.game-screen {
    display: none;
}

.game-screen.active {
    display: block;
    animation: fadeIn 0.4s ease;
}

.timer-display {
    text-align: center;
    font-size: 1.2rem;
    font-weight: 700;
    margin-bottom: 20px;
    color: var(--text-primary);
    font-family: 'Courier New', monospace;
}

.timer-display.warning {
    color: var(--warning);
}

.timer-display.danger {
    color: var(--error);
}

/* 타이핑 영역 */
.typing-area {
    background: var(--bg-card);
    border: 2px solid var(--border-color);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 20px;
    transition: border-color 0.2s ease;
}

.typing-area.active {
    border-color: var(--primary);
    box-shadow: 0 0 12px rgba(76, 175, 80, 0.2);
}

.typing-display {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 16px;
    font-family: 'Courier New', monospace;
    font-size: 1.1rem;
    line-height: 1.8;
    min-height: 60px;
    position: relative;
}

.typing-word {
    display: inline;
    padding: 2px 4px;
    margin-right: 4px;
    border-radius: 4px;
    transition: all 0.1s ease;
}

.typing-word.correct {
    background: rgba(102, 187, 106, 0.3);
    color: var(--success);
}

.typing-word.incorrect {
    background: rgba(239, 83, 80, 0.3);
    color: var(--error);
}

.typing-word.current {
    background: rgba(76, 175, 80, 0.3);
    border: 1px solid var(--primary);
}

.typing-word.pending {
    color: var(--text-secondary);
}

.typing-input {
    width: 100%;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 1rem;
    font-family: inherit;
    outline: none;
    caret-color: var(--primary);
}

.typing-input::placeholder {
    color: var(--text-secondary);
}

/* 결과 화면 */
.result-screen {
    display: none;
    text-align: center;
    animation: slideUp 0.5s ease;
}

.result-screen.active {
    display: block;
}

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

.result-emoji {
    font-size: 3rem;
    margin-bottom: 15px;
}

.result-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 10px;
    color: var(--primary);
}

.result-grade {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 20px;
    font-family: 'Courier New', monospace;
    text-shadow: 0 0 20px rgba(76, 175, 80, 0.3);
}

.result-percentile {
    background: rgba(76, 175, 80, 0.1);
    border: 1px solid var(--primary);
    border-radius: 8px;
    padding: 12px 16px;
    margin-bottom: 20px;
    color: var(--primary);
    font-weight: 600;
}

.result-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 20px;
}

.result-stat {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 16px;
}

.result-stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
    font-family: 'Courier New', monospace;
}

.result-stat-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 4px;
}

.share-button {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    border: none;
    border-radius: 8px;
    padding: 12px 24px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-bottom: 12px;
}

.share-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 16px rgba(76, 175, 80, 0.3);
}

.share-button:active {
    transform: translateY(0);
}

/* 버튼 */
.btn {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    border: none;
    border-radius: 8px;
    padding: 12px 24px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 16px rgba(76, 175, 80, 0.3);
}

.btn:active {
    transform: translateY(0);
}

.btn-secondary {
    background: transparent;
    border: 2px solid var(--border-color);
    color: var(--text-primary);
}

.btn-secondary:hover {
    border-color: var(--primary);
    background: rgba(76, 175, 80, 0.05);
}

.btn-block {
    width: 100%;
    margin-bottom: 10px;
}

.button-group {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}

.button-group .btn {
    flex: 1;
}

/* 진행 표시기 */
.progress-bar {
    height: 4px;
    background: var(--border-color);
    border-radius: 2px;
    margin-bottom: 20px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary) 0%, var(--primary-light) 100%);
    border-radius: 2px;
    transition: width 0.2s ease;
}

/* 정보 박스 */
.info-box {
    background: rgba(76, 175, 80, 0.05);
    border-left: 3px solid var(--primary);
    border-radius: 6px;
    padding: 12px 16px;
    margin-bottom: 16px;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

/* 반응형 디자인 */
@media (max-width: 480px) {
    .app-title {
        font-size: 1.5rem;
    }

    .mode-grid {
        grid-template-columns: 1fr;
    }

    .result-stats {
        grid-template-columns: 1fr;
    }

    .button-group {
        flex-direction: column;
    }

    .button-group .btn {
        width: 100%;
    }
}

/* 접근성 */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* 터치 타겟 */
button {
    min-height: 44px;
    min-width: 44px;
}

/* Light Theme Override */
[data-theme="light"] {
    --bg-dark: #f5f5fa;
    --bg-card: #ffffff;
    --text-primary: #1a1a2e;
    --text-secondary: #5a5a70;
    --border-color: #e0e0e5;
}

[data-theme="light"] body {
    background: linear-gradient(135deg, #f5f5fa 0%, #ffffff 100%);
}

[data-theme="light"] .app-loader {
    background: rgba(245, 245, 250, 0.95);
}

[data-theme="light"] .ad-banner {
    background: rgba(76, 175, 80, 0.05);
    border-color: rgba(76, 175, 80, 0.15);
}

[data-theme="light"] .mode-card {
    background: rgba(255, 255, 255, 0.9);
    border-color: rgba(76, 175, 80, 0.2);
}

[data-theme="light"] .mode-card:hover {
    border-color: rgba(76, 175, 80, 0.4);
    box-shadow: 0 12px 24px rgba(76, 175, 80, 0.15);
}

[data-theme="light"] .stats-summary {
    background: #ffffff;
    border-color: rgba(76, 175, 80, 0.2);
}

[data-theme="light"] .stat-row {
    border-color: rgba(76, 175, 80, 0.1);
}

[data-theme="light"] .typing-area {
    background: #ffffff;
    border-color: rgba(76, 175, 80, 0.2);
}

[data-theme="light"] .typing-area.active {
    border-color: rgba(76, 175, 80, 0.4);
    box-shadow: 0 0 12px rgba(76, 175, 80, 0.2);
}

[data-theme="light"] .typing-display {
    background: rgba(76, 175, 80, 0.05);
}

[data-theme="light"] .result-stat {
    background: #ffffff;
    border-color: rgba(76, 175, 80, 0.2);
}

[data-theme="light"] .result-percentile {
    background: rgba(76, 175, 80, 0.1);
    border-color: rgba(76, 175, 80, 0.3);
}

[data-theme="light"] .info-box {
    background: rgba(76, 175, 80, 0.05);
    border-left-color: var(--primary);
}

[data-theme="light"] .btn-secondary {
    background: rgba(255, 255, 255, 0.9);
    border-color: rgba(76, 175, 80, 0.2);
}

[data-theme="light"] .btn-secondary:hover {
    background: rgba(76, 175, 80, 0.1);
    border-color: rgba(76, 175, 80, 0.4);
}

/* Theme Toggle Button */
.theme-toggle {
    position: fixed;
    top: 12px;
    right: 56px;
    z-index: 1000;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    font-size: 18px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.theme-toggle:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}

[data-theme="light"] .theme-toggle {
    background: rgba(76, 175, 80, 0.1);
    border-color: rgba(76, 175, 80, 0.2);
}

[data-theme="light"] .theme-toggle:hover {
    background: rgba(76, 175, 80, 0.2);
}

/* 다크 모드 (기본값) */
@media (prefers-color-scheme: light) {
    :root:not([data-theme]) {
        --bg-dark: #f5f5f5;
        --bg-card: #ffffff;
        --text-primary: #1a1a1a;
        --text-secondary: #666666;
        --border-color: #e0e0e0;
    }

    body:not([data-theme]) {
        background: linear-gradient(135deg, #f5f5f5 0%, #eeeeee 100%);
    }

    .typing-display:not([data-theme]) {
        background: rgba(76, 175, 80, 0.05);
    }
}

/* === Keyboard Focus Accessibility === */
button:focus-visible,
a:focus-visible,
input:focus-visible,
[role="button"]:focus-visible,
[role="link"]:focus-visible {
    outline: 3px solid currentColor;
    outline-offset: 2px;
}

/* Remove default outline only if custom one provided */
button:focus-visible,
a:focus-visible,
input:focus-visible {
    outline: 3px solid #9b59b6;
    outline-offset: 2px;
}

/* Tab key only focus style */
button:focus:not(:focus-visible),
a:focus:not(:focus-visible),
input:focus:not(:focus-visible) {
    outline: none;
}

/* Respect user motion preferences */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* High contrast mode support */
@media (prefers-contrast: more) {
    button, input, a[href], [role="button"] {
        border: 2px solid currentColor;
    }
}

/* Enhanced button accessibility */
button:focus-visible,
input[type="button"]:focus-visible,
input[type="submit"]:focus-visible,
[role="button"]:focus-visible {
    outline: 3px solid currentColor;
    outline-offset: 2px;
}

button:active,
input[type="button"]:active,
input[type="submit"]:active,
[role="button"]:active {
    transform: scale(0.98);
}

/* High contrast mode */
@media (prefers-contrast: more) {
    button,
    input[type="button"],
    input[type="submit"],
    [role="button"] {
        border: 2px solid currentColor;
        font-weight: bold;
    }
}

/* Enhanced form accessibility */
label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
textarea,
select {
    font-size: 16px;
    min-height: 44px;
    padding: 10px 12px;
}

input[type="text"]:focus-visible,
input[type="email"]:focus-visible,
input[type="password"]:focus-visible,
input[type="number"]:focus-visible,
textarea:focus-visible,
select:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: 1px;
}

/* Error handling accessibility */
.error-message,
[aria-invalid="true"] {
    color: #dc2626;
    font-size: 0.875rem;
    margin-top: 0.25rem;
}

[aria-invalid="true"] {
    border-color: #dc2626;
}

/* Non-color focus indicators */
:focus-visible {
    outline-width: 3px;
}

/* Icon patterns for colorblind users */
.error::before {
    content: "x ";
}

.success::before {
    content: "✓ ";
}

.warning::before {
    content: "! ";
}

.info::before {
    content: "i ";
}

/* High contrast scrollbar */
::-webkit-scrollbar {
    width: 12px;
    height: 12px;
}

::-webkit-scrollbar-track {
    background: var(--bg-dark, #f1f5f9);
}

::-webkit-scrollbar-thumb {
    background: var(--primary-color, #3b82f6);
    border-radius: 6px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--primary-dark, #1e40af);
}

/* Firefox scrollbar */
* {
    scrollbar-color: var(--primary-color, #3b82f6) var(--bg-dark, #f1f5f9);
    scrollbar-width: thin;
}

/* Selection Color */
::selection {
    background: #4CAF50;
    color: white;
}

::-moz-selection {
    background: #4CAF50;
    color: white;
}
