:root {
    --bg: #f8fafc;
    --panel: #ffffff;
    --text: #1e293b;
    --muted: #64748b;
    --accent: #3b82f6;
    --border: #e2e8f0;
    --success: #10b981;
    --error: #ef4444;
    --warning: #f59e0b;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --accent-light: #dbeafe;
    --success-light: #d1fae5;
    --error-light: #fee2e2;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

body {
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    padding: 20px;
    line-height: 1.5;
}

.container {
    max-width: 1000px;
    margin: 0 auto;
}

header {
    text-align: center;
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border);
}

h1 {
    font-size: 32px;
    font-weight: 800;
    margin-bottom: 8px;
    color: var(--accent);
}

.subtitle {
    font-size: 16px;
    color: var(--muted);
    font-weight: 400;
}

.main-content {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.panel {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px;
    box-shadow: var(--shadow);
}

.mode-selector h3 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--text);
}

.mode-buttons {
    display: flex;
    gap: 12px;
}

.mode-btn {
    flex: 1;
    padding: 14px;
    background: var(--bg);
    border: 2px solid var(--border);
    border-radius: 10px;
    color: var(--muted);
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.mode-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-light);
}

.mode-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

.training-area {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.target-section {
    text-align: center;
}

.label {
    font-size: 14px;
    color: var(--muted);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 600;
}

.target-char {
    font-size: 72px;
    font-weight: 800;
    color: var(--accent);
    margin: 10px 0;
    line-height: 1;
    text-shadow: 0 0 10px rgba(59, 130, 246, 0.2);
}

.hint {
    font-size: 14px;
    color: var(--muted);
    margin-top: 8px;
    font-weight: 500;
}

.input-section {
    background: var(--bg);
    border: 2px solid var(--border);
    border-radius: 12px;
    padding: 20px;
}

.input-status {
    text-align: center;
    margin-bottom: 16px;
}

.status-label {
    font-size: 14px;
    color: var(--muted);
    margin-bottom: 8px;
    font-weight: 600;
}

.typed-char {
    font-size: 48px;
    font-weight: 600;
    color: var(--text);
    min-height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.keyboard-hint {
    text-align: center;
    padding: 16px;
    background: var(--accent-light);
    border-radius: 8px;
    color: var(--accent);
    font-size: 15px;
    border: 1px solid var(--accent);
    font-weight: 500;
}

#morse-text {
    width: 100%;
    padding: 16px;
    font-size: 24px;
    font-family: monospace;
    background: var(--bg);
    border: 2px solid var(--border);
    border-radius: 10px;
    color: var(--text);
    text-align: center;
    margin-bottom: 16px;
    outline: none;
    transition: border-color 0.2s;
}

#morse-text:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.morse-buttons {
    display: flex;
    gap: 12px;
}

.btn {
    flex: 1;
    padding: 16px;
    font-size: 20px;
    font-weight: 600;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s;
    background: var(--bg);
    color: var(--text);
    border: 2px solid var(--border);
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.btn.dot {
    background: var(--success-light);
    border-color: var(--success);
    color: var(--success);
}

.btn.dash {
    background: var(--accent-light);
    border-color: var(--accent);
    color: var(--accent);
}

.btn.clear {
    background: var(--error-light);
    border-color: var(--error);
    color: var(--error);
}

.feedback {
    background: var(--bg);
    border: 2px solid var(--border);
    border-radius: 12px;
    padding: 20px;
    text-align: center;
    font-size: 16px;
    color: var(--muted);
    min-height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 500;
}

.feedback.correct {
    background: var(--success-light);
    border-color: var(--success);
    color: var(--success);
}

.feedback.error {
    background: var(--error-light);
    border-color: var(--error);
    color: var(--error);
}

.progress-section {
    margin-top: 8px;
}

.progress-label {
    font-size: 14px;
    color: var(--muted);
    margin-bottom: 12px;
    display: flex;
    justify-content: space-between;
    font-weight: 600;
}

.progress-bar {
    height: 8px;
    background: var(--bg);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 12px;
    border: 1px solid var(--border);
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), #60a5fa);
    border-radius: 4px;
    width: 0%;
    transition: width 0.5s ease;
}

.progress-text {
    font-size: 14px;
    color: var(--muted);
    text-align: center;
    font-weight: 600;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
}

.stat-card {
    background: var(--bg);
    border: 2px solid var(--border);
    border-radius: 10px;
    padding: 20px;
    text-align: center;
    transition: transform 0.2s;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.stat-value {
    font-size: 32px;
    font-weight: 800;
    color: var(--accent);
    margin-bottom: 4px;
    line-height: 1;
}

.stat-label {
    font-size: 12px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 600;
}

.controls {
    display: flex;
    gap: 20px;
    align-items: flex-end;
    flex-wrap: wrap;
}

.control-group {
    flex: 1;
    min-width: 150px;
}

.control-group label {
    display: block;
    font-size: 14px;
    color: var(--muted);
    margin-bottom: 8px;
    font-weight: 600;
}

select {
    width: 100%;
    padding: 12px;
    background: var(--bg);
    border: 2px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 14px;
    outline: none;
    cursor: pointer;
    font-weight: 500;
    transition: border-color 0.2s;
}

select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.start-btn {
    padding: 14px 32px;
    background: var(--accent);
    border: none;
    border-radius: 10px;
    color: white;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    min-width: 140px;
    box-shadow: 0 4px 6px rgba(59, 130, 246, 0.2);
}

.start-btn:hover {
    background: #2563eb;
    transform: translateY(-2px);
    box-shadow: 0 6px 8px rgba(59, 130, 246, 0.3);
}

.ref-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.ref-header h3 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text);
}

.ref-btn {
    padding: 8px 16px;
    background: var(--bg);
    border: 2px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
}

.ref-btn:hover {
    border-color: var(--accent);
    background: var(--accent-light);
}

.ref-content {
    background: var(--bg);
    border: 2px solid var(--border);
    border-radius: 10px;
    padding: 20px;
    max-height: 300px;
    overflow-y: auto;
    display: none;
}

.ref-content.visible {
    display: block;
}

.ref-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
    gap: 12px;
}

.ref-item {
    background: var(--accent-light);
    border: 2px solid var(--border);
    border-radius: 8px;
    padding: 12px 8px;
    text-align: center;
    transition: all 0.2s;
}

.ref-item:hover {
    border-color: var(--accent);
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.ref-char {
    font-size: 18px;
    font-weight: 600;
    color: var(--accent);
    margin-bottom: 4px;
}

.ref-code {
    font-family: monospace;
    font-size: 12px;
    color: var(--muted);
    font-weight: 500;
}

.records-section {
    margin-top: 10px;
}

.records-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.records-header h3 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 8px;
}

.clear-btn {
    padding: 8px 16px;
    background: var(--error-light);
    border: 2px solid var(--error);
    border-radius: 8px;
    color: var(--error);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
}

.clear-btn:hover {
    background: var(--error);
    color: white;
}

.records-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.record-tab {
    flex: 1;
    padding: 12px;
    background: var(--bg);
    border: 2px solid var(--border);
    border-radius: 8px;
    color: var(--muted);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
    text-align: center;
}

.record-tab:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.record-tab.active {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

.records-list {
    max-height: 300px;
    overflow-y: auto;
    padding-right: 8px;
}

.record-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: var(--bg);
    border: 2px solid var(--border);
    border-radius: 8px;
    margin-bottom: 8px;
    transition: all 0.2s;
}

.record-item:hover {
    border-color: var(--accent);
    box-shadow: var(--shadow);
}

.record-item.current {
    background: var(--accent-light);
    border-color: var(--accent);
}

.record-rank {
    font-size: 20px;
    font-weight: 800;
    color: var(--accent);
    min-width: 40px;
}

.record-rank.gold {
    color: #fbbf24;
}

.record-rank.silver {
    color: #94a3b8;
}

.record-rank.bronze {
    color: #f59e0b;
}

.record-info {
    flex: 1;
    padding: 0 16px;
}

.record-date {
    font-size: 12px;
    color: var(--muted);
    font-weight: 500;
}

.record-score {
    display: flex;
    gap: 16px;
    align-items: center;
}

.record-accuracy {
    font-size: 14px;
    color: var(--success);
    font-weight: 600;
    padding: 4px 12px;
    background: var(--success-light);
    border-radius: 20px;
}

.record-details {
    font-size: 14px;
    color: var(--muted);
    font-weight: 500;
}

.record-details span {
    color: var(--accent);
    font-weight: 600;
}

.no-records {
    text-align: center;
    padding: 40px 20px;
    color: var(--muted);
    font-size: 16px;
}

.no-records svg {
    margin-bottom: 16px;
    opacity: 0.5;
}

@media (max-width: 768px) {
    body {
        padding: 16px;
    }
    
    .container {
        max-width: 100%;
    }
    
    h1 {
        font-size: 24px;
    }
    
    .panel {
        padding: 20px;
    }
    
    .target-char {
        font-size: 56px;
    }
    
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .controls {
        flex-direction: column;
    }
    
    .control-group {
        width: 100%;
    }
    
    .start-btn {
        width: 100%;
    }
    
    .mode-buttons {
        flex-direction: column;
    }
    
    .records-tabs {
        flex-direction: column;
    }
}