/* 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, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: white;
    overflow-x: hidden;
}

/* Container */
.container {
    max-width: 900px;
    margin: 0 auto;
    padding: 20px;
}

/* Header */
.header {
    text-align: center;
    margin-bottom: 2rem;
    color: white;
}

.header h1 {
    font-size: 3rem;
    font-weight: bold;
    background: linear-gradient(45deg, #ff6b6b, #4ecdc4, #45b7d1);
    background-size: 200% 200%;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: gradientShift 3s ease-in-out infinite;
    margin-bottom: 1rem;
}

@keyframes gradientShift {
    0%, 100% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
}

.header p {
    font-size: 1.2rem;
    opacity: 0.9;
}

/* Glass Card Design */
.glass-card {
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(15px);
    border-radius: 20px;
    padding: 2rem;
    border: 1px solid rgba(255, 255, 255, 0.2);
    transition: all 0.4s ease;
    position: relative;
    margin-bottom: 1.5rem;
}

/* 컨트롤 카드는 overflow visible로 설정 */
.controls.glass-card {
    overflow: visible;
}

/* 메인 카드는 overflow hidden 유지 */
main.glass-card {
    overflow: hidden;
}

.glass-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.1), transparent);
    transition: left 0.5s ease;
    z-index: -1; /* 가상 요소를 뒤로 보내기 */
}

/* 컨트롤 카드의 shimmer 효과는 드롭다운을 방해하지 않도록 */
.controls.glass-card::before {
    z-index: -1;
}

.glass-card:hover::before {
    left: 100%;
}

.glass-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.2);
}

/* Controls Navigation */
.controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    flex-wrap: wrap;
    gap: 1rem;
    position: relative;
    z-index: 100; /* 높은 z-index 추가 */
}

/* Modern Button Styles */
.btn-modern {
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: 0.7rem 1.2rem;
    border-radius: 15px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    font-weight: 500;
}

.btn-modern:hover,
.btn-modern:focus {
    background: rgba(255, 255, 255, 0.25);
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
    outline: none;
}

/* Language Selector */
.language-selector {
    position: relative;
    z-index: 1001; /* 높은 z-index 설정 */
}

.language-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 12px;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.2);
    min-width: 200px;
    display: none;
    z-index: 1002; /* 매우 높은 z-index */
    border: 1px solid rgba(255, 255, 255, 0.2);
    margin-top: 5px; /* 버튼과의 간격 */
}

.language-dropdown.active {
    display: block;
}

.language-option {
    padding: 0.8rem 1rem;
    cursor: pointer;
    transition: background 0.2s;
    color: #333;
    font-size: 0.9rem;
}

.language-option:hover,
.language-option:focus {
    background: rgba(102, 126, 234, 0.1);
    outline: none;
}

.language-option:first-child {
    border-radius: 12px 12px 0 0;
}

.language-option:last-child {
    border-radius: 0 0 12px 12px;
}

/* Input & Output Sections */
.input-section,
.output-section {
    margin-bottom: 1.5rem;
}

.input-label {
    font-weight: 600;
    margin-bottom: 0.8rem;
    color: white;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.1rem;
}

.input-area,
.output-area {
    width: 100%;
    min-height: 120px;
    padding: 1rem;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 12px;
    font-size: 1rem;
    font-family: 'Consolas', 'Monaco', monospace;
    resize: vertical;
    transition: all 0.3s ease;
    color: white;
}

.input-area:focus {
    outline: none;
    border-color: #4ecdc4;
    box-shadow: 0 0 0 2px rgba(78, 205, 196, 0.3);
    background: rgba(255, 255, 255, 0.12);
}

.input-area::placeholder {
    color: rgba(255, 255, 255, 0.6);
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

.output-area {
    background: rgba(255, 255, 255, 0.05);
}

.output-area::placeholder {
    color: rgba(255, 255, 255, 0.5);
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

/* Detected Language */
.detected-language {
    font-size: 0.9rem;
    color: rgba(255, 255, 255, 0.8);
    margin-top: 0.5rem;
    font-style: italic;
}

/* Audio Controls */
.audio-controls {
    display: flex;
    gap: 1rem;
    align-items: center;
    margin: 1.5rem 0;
    flex-wrap: wrap;
    justify-content: center;
}

.speed-control {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: rgba(255, 255, 255, 0.1);
    padding: 0.5rem 1rem;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.speed-slider {
    width: 100px;
    height: 5px;
    border-radius: 5px;
    background: rgba(255, 255, 255, 0.2);
    outline: none;
    opacity: 0.7;
    transition: opacity 0.2s;
    appearance: none;
}

.speed-slider:hover {
    opacity: 1;
}

.speed-slider::-webkit-slider-thumb {
    appearance: none;
    width: 15px;
    height: 15px;
    border-radius: 50%;
    background: #4ecdc4;
    cursor: pointer;
}

.speed-slider::-moz-range-thumb {
    width: 15px;
    height: 15px;
    border-radius: 50%;
    background: #4ecdc4;
    cursor: pointer;
    border: none;
}

/* Action Buttons */
.action-buttons {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    justify-content: center;
    margin: 2rem 0;
}

.btn {
    padding: 0.8rem 1.5rem;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
}

.btn:focus {
    outline: 2px solid #4ecdc4;
    outline-offset: 2px;
}

.btn-primary {
    background: linear-gradient(45deg, #667eea, #764ba2);
    color: white;
}

.btn-primary:hover,
.btn-primary:focus {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(102, 126, 234, 0.4);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.btn-secondary:hover,
.btn-secondary:focus {
    background: rgba(255, 255, 255, 0.3);
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}

/* Share Section */
.share-section {
    background: rgba(255, 255, 255, 0.08);
    padding: 1.5rem;
    border-radius: 15px;
    margin: 1.5rem 0;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.share-section h3 {
    margin-bottom: 1rem;
    color: white;
}

.share-url {
    width: 100%;
    padding: 0.8rem;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 8px;
    font-family: monospace;
    font-size: 0.9rem;
    color: white;
}

.share-url::placeholder {
    color: rgba(255, 255, 255, 0.6);
}

/* Download Section */
.download-section {
    background: linear-gradient(135deg, #ff6b6b 0%, #ee5a24 100%);
    color: white;
    padding: 2rem;
    border-radius: 20px;
    text-align: center;
    margin: 2rem 0;
    position: relative;
    overflow: hidden;
}

.download-section::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.1), transparent);
    transition: left 0.5s ease;
}

.download-section:hover::before {
    left: 100%;
}

.download-section h3 {
    margin-bottom: 1rem;
    font-size: 1.4rem;
}

.download-section p {
    margin-bottom: 1.5rem;
    opacity: 0.9;
    line-height: 1.6;
}

.download-btn {
    background: white;
    color: #ee5a24;
    padding: 1rem 2rem;
    border: none;
    border-radius: 12px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1rem;
}

.download-btn:hover,
.download-btn:focus {
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.2);
    outline: none;
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(5px);
}

.modal-content {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(15px);
    margin: 3% auto;
    padding: 2rem;
    border-radius: 20px;
    width: 90%;
    max-width: 800px;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
    border: 1px solid rgba(255, 255, 255, 0.3);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.close {
    color: #666;
    float: right;
    font-size: 1.8rem;
    font-weight: bold;
    position: absolute;
    right: 1.5rem;
    top: 1rem;
    cursor: pointer;
    border: none;
    background: none;
    padding: 0;
    line-height: 1;
    transition: color 0.3s ease;
}

.close:hover,
.close:focus {
    color: #333;
    outline: none;
}

/* Codebook Styles */
.codebook-section {
    margin-bottom: 2rem;
}

.codebook-title {
    font-size: 1.3rem;
    margin-bottom: 1rem;
    color: #333;
    border-bottom: 2px solid #667eea;
    padding-bottom: 0.5rem;
}

.codebook-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 0.8rem;
    margin-bottom: 1.5rem;
}

.code-item {
    display: flex;
    justify-content: space-between;
    padding: 0.6rem 0.8rem;
    background: rgba(102, 126, 234, 0.1);
    border-radius: 8px;
    font-family: 'Courier New', monospace;
    border: 1px solid rgba(102, 126, 234, 0.2);
    transition: all 0.3s ease;
}

.code-item:hover {
    background: rgba(102, 126, 234, 0.2);
    transform: translateY(-1px);
}

.code-char {
    font-weight: bold;
    color: #333;
}

.code-morse {
    color: #667eea;
    font-weight: bold;
}

/* Floating particles effect */
.particles {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: -1;
}

.particle {
    position: absolute;
    width: 4px;
    height: 4px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    animation: float 15s infinite linear;
}

@keyframes float {
    0% {
        transform: translateY(100vh) rotate(0deg);
        opacity: 0;
    }
    10% {
        opacity: 1;
    }
    90% {
        opacity: 1;
    }
    100% {
        transform: translateY(-100vh) rotate(360deg);
        opacity: 0;
    }
}

/* Success Animation */
@keyframes success {
    0% { border-color: rgba(76, 175, 80, 0.8); background-color: rgba(76, 175, 80, 0.1); }
    50% { border-color: rgba(76, 175, 80, 1); background-color: rgba(76, 175, 80, 0.2); }
    100% { border-color: rgba(255, 255, 255, 0.25); background-color: rgba(255, 255, 255, 0.08); }
}

.success-animation {
    animation: success 0.6s ease;
}

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

/* Focus Indicators */
button:focus,
input:focus,
textarea:focus,
select:focus {
    outline: 2px solid #4ecdc4;
    outline-offset: 2px;
}

/* High Contrast Mode Support */
@media (prefers-contrast: high) {
    .btn-primary {
        background: #000;
        color: #fff;
        border: 2px solid #fff;
    }
    
    .btn-secondary {
        background: #fff;
        color: #000;
        border: 2px solid #000;
    }
}

/* Reduced Motion Support */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Print Styles */
@media print {
    .controls,
    .audio-controls,
    .action-buttons,
    .download-section,
    .modal {
        display: none;
    }
    
    body {
        background: white;
        color: black;
    }
    
    .glass-card {
        box-shadow: none;
        border: 1px solid #000;
    }
}

/* Responsive Design */
@media (max-width: 768px) {
    .container {
        padding: 1rem;
    }
    
    .header h1 {
        font-size: 2.5rem;
    }
    
    .controls {
        justify-content: center;
        flex-direction: column;
        gap: 1rem;
        z-index: 100; /* 모바일에서도 높은 z-index 유지 */
    }
    
    /* 모바일에서 언어 드롭다운 너비 조정 */
    .language-dropdown {
        min-width: 180px;
        left: 50%;
        transform: translateX(-50%);
    }
    
    .glass-card {
        padding: 1.5rem;
    }
    
    .action-buttons {
        flex-direction: column;
        align-items: stretch;
    }
    
    .audio-controls {
        justify-content: center;
        flex-direction: column;
        align-items: center;
        gap: 1rem;
    }

    .modal-content {
        margin: 5% auto;
        padding: 1.5rem;
        width: 95%;
    }

    .codebook-grid {
        grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
        gap: 0.6rem;
    }
    
    .btn {
        font-size: 0.9rem;
        padding: 0.7rem 1.2rem;
    }
}

@media (max-width: 480px) {
    .header h1 {
        font-size: 2rem;
    }
    
    .input-area,
    .output-area {
        font-size: 0.9rem;
        min-height: 100px;
    }
    
    .speed-control {
        flex-direction: column;
        text-align: center;
        gap: 0.5rem;
    }
    
    .speed-slider {
        width: 120px;
    }
}
