:root {
    --primary-color: #4A90E2;
    --secondary-color: #7FBA00;
    --error-color: #E74C3C;
    --success-color: #27AE60;
    --warning-color: #F39C12;
    --bg-light: #F5F5F5;
    --bg-dark: #1E1E1E;
    --text-light: #333333;
    --text-dark: #FFFFFF;
    --card-bg-light: #FFFFFF;
    --card-bg-dark: #2D2D2D;
    --border-light: #E0E0E0;
    --border-dark: #404040;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    --transition: 0.3s ease;
}

[data-theme="dark"] {
    --bg-light: #1E1E1E;
    --bg-dark: #121212;
    --text-light: #FFFFFF;
    --text-dark: #333333;
    --card-bg-light: #2D2D2D;
    --card-bg-dark: #1E1E1E;
    --border-light: #404040;
    --border-dark: #E0E0E0;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', 'Noto Sans JP', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-light);
    color: var(--text-light);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color var(--transition), color var(--transition);
}

.container {
    width: 100%;
    max-width: 900px;
    padding: 20px;
}

.screen {
    display: none;
    animation: fadeIn 0.5s ease;
}

.screen.active {
    display: block;
}

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

/* スタート画面 */
.game-title {
    font-size: 3rem;
    text-align: center;
    margin-bottom: 2rem;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
}

.settings-card {
    background: var(--card-bg-light);
    border-radius: 15px;
    padding: 30px;
    box-shadow: var(--shadow);
    margin-bottom: 30px;
}

.setting-group {
    margin-bottom: 25px;
}

.setting-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 10px;
    color: var(--primary-color);
}

#playerName {
    width: 100%;
    padding: 12px;
    border: 2px solid var(--border-light);
    border-radius: 8px;
    font-size: 1rem;
    transition: border-color var(--transition);
    background: var(--card-bg-light);
    color: var(--text-light);
}

#playerName:focus {
    outline: none;
    border-color: var(--primary-color);
}

.radio-group {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 10px;
}

.radio-label {
    display: flex;
    align-items: center;
    padding: 10px 15px;
    background: var(--bg-light);
    border: 2px solid var(--border-light);
    border-radius: 8px;
    cursor: pointer;
    transition: all var(--transition);
}

.radio-label:hover {
    border-color: var(--primary-color);
    transform: translateY(-2px);
}

.radio-label input[type="radio"] {
    margin-right: 8px;
    cursor: pointer;
}

.radio-label input[type="radio"]:checked + span {
    color: var(--primary-color);
    font-weight: 600;
}

.radio-label:has(input[type="radio"]:checked) {
    background: linear-gradient(135deg, rgba(74, 144, 226, 0.1), rgba(127, 186, 0, 0.1));
    border-color: var(--primary-color);
}

.button-group {
    display: flex;
    gap: 15px;
    justify-content: center;
}

.btn {
    padding: 15px 40px;
    border: none;
    border-radius: 8px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    box-shadow: 0 4px 15px rgba(74, 144, 226, 0.3);
}

.btn-primary:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 20px rgba(74, 144, 226, 0.4);
}

.btn-secondary {
    background: var(--card-bg-light);
    color: var(--primary-color);
    border: 2px solid var(--primary-color);
}

.btn-secondary:hover {
    background: var(--primary-color);
    color: white;
    transform: translateY(-3px);
}

.theme-toggle {
    position: fixed;
    top: 20px;
    right: 20px;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: var(--card-bg-light);
    border: 2px solid var(--border-light);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    transition: all var(--transition);
    box-shadow: var(--shadow);
}

.theme-toggle:hover {
    transform: rotate(20deg) scale(1.1);
}

/* ゲーム画面 */
.game-header {
    margin-bottom: 30px;
}

.game-info {
    display: flex;
    justify-content: space-around;
    background: var(--card-bg-light);
    border-radius: 15px;
    padding: 20px;
    box-shadow: var(--shadow);
}

.info-item {
    text-align: center;
}

.info-label {
    display: block;
    font-size: 0.9rem;
    color: var(--text-light);
    opacity: 0.7;
    margin-bottom: 5px;
}

.info-value {
    display: block;
    font-size: 1.8rem;
    font-weight: bold;
    color: var(--primary-color);
}

.game-main {
    background: var(--card-bg-light);
    border-radius: 15px;
    padding: 40px;
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}

.word-container {
    text-align: center;
    margin-bottom: 30px;
    min-height: 100px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.current-word {
    font-size: 3rem;
    font-weight: bold;
    letter-spacing: 3px;
    margin-bottom: 20px;
    color: var(--text-light);
    transition: all var(--transition);
}

.word-display {
    font-size: 1.5rem;
    min-height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.word-display .char {
    display: inline-block;
    margin: 0 2px;
    transition: all 0.2s;
}

.word-display .char.correct {
    color: var(--success-color);
    transform: scale(1.2);
}

.word-display .char.incorrect {
    color: var(--error-color);
    animation: shake 0.3s;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

.word-input {
    width: 100%;
    padding: 15px;
    font-size: 1.3rem;
    border: 3px solid var(--border-light);
    border-radius: 10px;
    text-align: center;
    transition: all var(--transition);
    background: var(--bg-light);
    color: var(--text-light);
}

.word-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.1);
}

.word-input.correct {
    border-color: var(--success-color);
    animation: correctPulse 0.5s;
}

.word-input.incorrect {
    border-color: var(--error-color);
    animation: shake 0.3s;
}

@keyframes correctPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

.input-feedback {
    text-align: center;
    margin-top: 10px;
    min-height: 25px;
    font-weight: 600;
}

.progress-bar {
    width: 100%;
    height: 10px;
    background: var(--border-light);
    border-radius: 5px;
    overflow: hidden;
    margin-bottom: 20px;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
    width: 0%;
    transition: width var(--transition);
}

.combo-display {
    text-align: center;
    font-size: 1.2rem;
    color: var(--warning-color);
    font-weight: 600;
    opacity: 0;
    transition: opacity var(--transition);
}

.combo-display.active {
    opacity: 1;
    animation: bounce 0.5s;
}

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

/* 結果画面 */
.result-title {
    text-align: center;
    font-size: 2.5rem;
    margin-bottom: 30px;
    color: var(--primary-color);
}

.result-card {
    background: var(--card-bg-light);
    border-radius: 15px;
    padding: 40px;
    box-shadow: var(--shadow);
}

.result-stats {
    margin-bottom: 30px;
}

.stat-item {
    margin-bottom: 20px;
    text-align: center;
}

.stat-label {
    display: block;
    font-size: 1rem;
    color: var(--text-light);
    opacity: 0.7;
    margin-bottom: 8px;
}

.stat-value {
    display: block;
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--primary-color);
}

.stat-value.large {
    font-size: 3rem;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

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

/* 保存ステータス */
.save-status {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 15px;
    margin: 20px 0;
    background: var(--bg-light);
    border-radius: 8px;
    font-size: 1rem;
    transition: all var(--transition);
}

.save-status.saved {
    background: linear-gradient(135deg, rgba(39, 174, 96, 0.1), rgba(127, 186, 0, 0.1));
    color: var(--success-color);
}

.save-status.error {
    background: rgba(231, 76, 60, 0.1);
    color: var(--error-color);
}

.save-icon {
    font-size: 1.2rem;
    animation: pulse 1s infinite;
}

.save-status.saved .save-icon {
    animation: none;
}

/* ランキング画面 */
.ranking-title {
    text-align: center;
    font-size: 2.5rem;
    margin-bottom: 30px;
    color: var(--primary-color);
}

.ranking-tabs {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-bottom: 30px;
}

.tab-btn {
    padding: 10px 20px;
    background: var(--card-bg-light);
    border: 2px solid var(--border-light);
    border-radius: 8px;
    cursor: pointer;
    transition: all var(--transition);
    font-weight: 600;
}

.tab-btn:hover {
    border-color: var(--primary-color);
}

.tab-btn.active {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.ranking-content {
    background: var(--card-bg-light);
    border-radius: 15px;
    padding: 30px;
    box-shadow: var(--shadow);
    margin-bottom: 30px;
    min-height: 400px;
}

.ranking-list {
    max-height: 500px;
    overflow-y: auto;
}

.ranking-item {
    display: flex;
    align-items: center;
    padding: 15px;
    border-bottom: 1px solid var(--border-light);
    transition: all var(--transition);
}

.ranking-item:hover {
    background: var(--bg-light);
    transform: translateX(5px);
}

.ranking-position {
    font-size: 1.5rem;
    font-weight: bold;
    width: 50px;
    text-align: center;
    color: var(--primary-color);
}

.ranking-position.gold {
    color: #FFD700;
}

.ranking-position.silver {
    color: #C0C0C0;
}

.ranking-position.bronze {
    color: #CD7F32;
}

.ranking-details {
    flex: 1;
    margin-left: 20px;
}

.ranking-name {
    font-size: 1.2rem;
    font-weight: 600;
    margin-bottom: 5px;
}

.ranking-stats {
    display: flex;
    gap: 20px;
    font-size: 0.9rem;
    color: var(--text-light);
    opacity: 0.7;
}

.ranking-score {
    font-size: 1.3rem;
    font-weight: bold;
    color: var(--secondary-color);
}

/* モーダル */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
    animation: fadeIn 0.3s;
}

.modal-content {
    background: var(--card-bg-light);
    border-radius: 15px;
    padding: 40px;
    max-width: 500px;
    width: 90%;
    text-align: center;
    animation: slideUp 0.3s;
}

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

.modal-content h3 {
    font-size: 2rem;
    color: var(--primary-color);
    margin-bottom: 20px;
}

.modal-content p {
    font-size: 1.2rem;
    margin-bottom: 30px;
    color: var(--text-light);
}

/* ローディング */
.loading {
    text-align: center;
    padding: 50px;
    font-size: 1.2rem;
    color: var(--text-light);
    opacity: 0.7;
}

.loading::after {
    content: '';
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid var(--border-light);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-left: 10px;
    vertical-align: middle;
}

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

/* ユーティリティ */
.hidden {
    display: none !important;
}

/* レスポンシブ */
@media (max-width: 768px) {
    .game-title {
        font-size: 2rem;
    }
    
    .settings-card {
        padding: 20px;
    }
    
    .radio-group {
        grid-template-columns: 1fr;
    }
    
    .button-group {
        flex-direction: column;
    }
    
    .btn {
        width: 100%;
    }
    
    .game-info {
        flex-wrap: wrap;
        gap: 15px;
    }
    
    .info-item {
        flex: 1 1 45%;
    }
    
    .current-word {
        font-size: 2rem;
    }
    
    .stat-row {
        grid-template-columns: 1fr;
    }
    
    .ranking-tabs {
        flex-wrap: wrap;
    }
    
    .tab-btn {
        flex: 1 1 45%;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 10px;
    }
    
    .game-title {
        font-size: 1.5rem;
    }
    
    .current-word {
        font-size: 1.5rem;
    }
    
    .info-value {
        font-size: 1.3rem;
    }
    
    .word-input {
        font-size: 1rem;
    }
}