:root {
    --primary: #D4AF37; 
    --primary-hover: #FCD34D;
    --bg: #0F1115; 
    --surface: #1A1C23; 
    --text-main: #F3F4F6; --text-muted: #9CA3AF;
    --success: #10B981; --easy: #059669; --easy-hover: #047857;
    --normal: #D4AF37; --normal-hover: #FCD34D;
    --hard: #991B1B; --hard-hover: #B91C1C; 
    
    --perfect: #FCD34D; --great: #60A5FA; --good: #34D399; --ok: #D4AF37; --late: #991B1B;
}

body { font-family: 'Noto Serif KR', serif; background-color: var(--bg); color: var(--text-main); display: flex; flex-direction: column; align-items: center; min-height: 100vh; margin: 0; padding-top: 2rem; }
.container { background-color: var(--surface); padding: 3rem 2.5rem; border-radius: 0.5rem; border: 1px solid #374151; box-shadow: 0 15px 35px rgba(0, 0, 0, 0.8); text-align: center; width: 100%; max-width: 600px; margin-bottom: 2rem; position: relative;}
h1 { margin-top: 0; color: var(--primary); font-size: 2.4rem; font-weight: 900; letter-spacing: 2px; text-shadow: 0 2px 15px rgba(212, 175, 55, 0.3); border-bottom: 1px solid #374151; padding-bottom: 1rem; margin-bottom: 1.5rem; }
.description { color: var(--text-muted); margin-bottom: 2rem; font-size: 0.95rem; line-height: 1.6; }

.achievement-alert { background: rgba(212, 175, 55, 0.1); border: 1px solid var(--primary); color: #FEF3C7; padding: 1rem; border-radius: 0.3rem; margin-bottom: 1.5rem; animation: slideDown 0.5s ease-out; }

/* UIボタン */
.btn-collection { width: 100%; background: transparent; padding: 1rem; border-radius: 0.3rem; color: var(--primary); margin-bottom: 1.5rem; font-weight: bold; border: 1px solid var(--primary); transition: 0.2s; cursor: pointer; position: relative; font-family: inherit;}
.btn-collection:hover { background: rgba(212, 175, 55, 0.1); box-shadow: 0 0 10px rgba(212, 175, 55, 0.2); }
.btn-danger { background-color: transparent; color: var(--hard); border: 1px solid var(--hard); padding: 0.8rem 1.5rem; border-radius: 0.3rem; font-weight: bold; cursor: pointer; transition: 0.2s; font-family: inherit;}
.btn-danger:hover { background-color: rgba(153, 27, 27, 0.2); }

.mode-toggle { display: flex; gap: 1rem; margin-bottom: 1.5rem; justify-content: center; }
.mode-btn { flex: 1; padding: 1rem; background: #15171C; border: 1px solid #374151; color: var(--text-muted); font-weight: bold; border-radius: 0.3rem; cursor: pointer; transition: 0.2s; font-family: inherit;}
.mode-btn:hover { border-color: var(--primary); color: white; }
.mode-btn.active { background: rgba(212, 175, 55, 0.1); border-color: var(--primary); color: var(--primary); box-shadow: 0 0 15px rgba(212, 175, 55, 0.2); }

/* コレクションタブ */
.collection-tabs { display: flex; gap: 0; margin-bottom: 1.5rem; border-bottom: 2px solid #374151; }
.tab-btn { flex: 1; padding: 1rem; background: transparent; color: var(--text-muted); border: none; font-weight: bold; cursor: pointer; transition: 0.3s; font-size: 1.1rem; position: relative; font-family: inherit;}
.tab-btn::after { content: ''; position: absolute; bottom: -2px; left: 0; width: 100%; height: 2px; background: transparent; transition: 0.3s; }
.tab-btn.active { color: var(--primary); }
.tab-btn.active::after { background: var(--primary); box-shadow: 0 0 10px var(--primary); }
.tab-btn:hover { color: white; }

.collection-content { text-align: left; min-height: 300px; max-height: 500px; overflow-y: auto; padding: 1rem; background: #15171C; border-radius: 0.3rem; border: 1px solid #374151; margin-bottom: 1.5rem;}
.category-header { background: transparent; color: var(--primary); padding: 0.5rem 0; font-weight: bold; border-bottom: 1px dashed #374151; margin: 1.5rem 0 0.5rem 0; font-size: 1.1rem; }
.category-header:first-child { margin-top: 0; }
.new-badge { display: inline-block; background: var(--hard); color: white; font-size: 0.65rem; padding: 0.1rem 0.4rem; border-radius: 1rem; margin-left: 0.5rem; vertical-align: middle; animation: pulse 1s infinite;}
.btn-new-badge { position: absolute; top: -5px; right: -5px; background: var(--hard); color: white; font-size: 0.7rem; padding: 0.2rem 0.5rem; border-radius: 1rem; font-weight: bold; box-shadow: 0 2px 4px rgba(0,0,0,0.5); }

.titles-list { list-style: none; padding: 0; margin: 0; }
.titles-list li { padding: 0.8rem; border-bottom: 1px solid #374151; position: relative;}
.titles-list li.unlocked .title-name { color: #FCD34D; font-weight: bold; font-size: 1.1rem; }
.titles-list li.locked .title-name { color: #6B7280; font-weight: bold; font-size: 1.1rem; }
.title-cond { font-size: 0.8rem; color: var(--text-muted); display: block; margin-top: 0.3rem;}

/* 図鑑 UI */
.progress-box { margin-bottom: 1rem; text-align: center; border-bottom: 1px dashed #374151; padding-bottom: 1rem;}
.tier-header-info { display: flex; justify-content: space-between; align-items: flex-end; margin-top: 1.5rem; margin-bottom: 0.3rem;}
.tier-title { color: var(--primary); font-weight: bold; font-size: 1.1rem;}
.tier-stats { font-size: 0.85rem; color: var(--text-muted); }
.tier-progress-bar { width: 100%; height: 4px; background: #374151; border-radius: 2px; overflow: hidden; margin-bottom: 1rem; }
.tier-progress-fill { height: 100%; background: var(--primary); transition: width 0.5s; }

.hangul-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(45px, 1fr)); gap: 0.5rem; text-align: center; font-size: 1.5rem; }
.hangul-grid div { background: #1A1C23; border: 1px solid #374151; border-radius: 0.2rem; padding: 0.3rem; cursor: pointer; transition: 0.1s; position: relative;}
.hangul-grid div:hover { background: var(--primary); color: #0F1115; border-color: var(--primary); transform: scale(1.15); z-index: 10; }
.hangul-grid div .new-dot { position: absolute; top: 2px; right: 2px; width: 6px; height: 6px; background: var(--hard); border-radius: 50%; }

/* ポップアップモーダル */
.modal-overlay { position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; background: rgba(0, 0, 0, 0.7); z-index: 9999; display: flex; justify-content: center; align-items: center; animation: fadeIn 0.2s; }
.hangul-detail { background: #1A1C23; padding: 2rem 3rem; border-radius: 0.5rem; border: 2px solid var(--primary); text-align: center; font-size: 1.2rem; box-shadow: 0 0 30px rgba(212, 175, 55, 0.3); animation: pop 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275); color: #F3F4F6;}
.hangul-detail strong { font-size: 4rem; color: var(--primary); display: block; margin-bottom: 1rem; text-shadow: 0 0 20px rgba(212, 175, 55, 0.5);}
.hangul-detail button { margin-top: 1.5rem; background: transparent; border: 1px solid var(--text-muted); color: var(--text-muted); padding: 0.5rem 2rem; border-radius: 0.2rem; cursor: pointer; transition: 0.2s; font-family: inherit;}
.hangul-detail button:hover { color: white; border-color: white; }

/* ゲーム画面 */
#game-area, #result-area { display: none; }
.target-char { 
    font-size: 8rem; font-weight: 900; margin: 1rem 0; line-height: 1; color: var(--primary); 
    position: relative; z-index: 10; text-shadow: 0 0 20px rgba(212, 175, 55, 0.2);
    min-height: 8.5rem; /* 文字が空の時も高さを維持 */
    display: flex; align-items: center; justify-content: center;
}
.freq-info { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 1.5rem; height: 1rem;}

.timer-container { width: 100%; height: 8px; background: #15171C; border-radius: 4px; overflow: hidden; margin-bottom: 1rem; border: 1px solid #374151;}
.timer-bar { height: 100%; background: var(--primary); width: 100%; transition: width 0.1s linear;}

.judgment-text { 
    height: 2rem; 
    font-size: 1.8rem; 
    font-weight: 900; 
    letter-spacing: 3px; 
    opacity: 0; 
    font-family: sans-serif;
    margin-bottom: 1.5rem;
    pointer-events: none;
}
.judgment-text.show { animation: popFade 0.8s forwards ease-out; }

.judgment-perfect { color: var(--perfect); text-shadow: 0 0 20px rgba(252, 211, 77, 0.8); }
.judgment-great { color: var(--great); text-shadow: 0 0 15px rgba(96, 165, 250, 0.8); }
.judgment-good { color: var(--good); text-shadow: 0 0 10px rgba(52, 211, 153, 0.8); }
.judgment-ok { color: var(--ok); text-shadow: 0 0 10px rgba(212, 175, 55, 0.5); }
.judgment-late { color: var(--late); text-shadow: 0 0 10px rgba(153, 27, 27, 0.8); }

.combo-text { font-size: 2rem; font-weight: bold; color: #FCD34D; text-shadow: 0 0 10px rgba(252, 211, 77, 0.5); position: absolute; top: 35%; right: 10%; transform: rotate(10deg); animation: pulse 0.3s; }

input[type="text"] { font-size: 2.5rem; text-align: center; width: 150px; padding: 0.5rem; background: #0F1115; color: white; border: 2px solid #374151; border-radius: 0.3rem; outline: none; transition: 0.2s; ime-mode: active; position: relative; z-index: 20; font-family: inherit;}
input[type="text"]:focus { border-color: var(--primary); box-shadow: 0 0 20px rgba(212, 175, 55, 0.2); }

.stats-board { display: flex; justify-content: space-around; margin-top: 2.5rem; padding-top: 1.5rem; border-top: 1px solid #374151; }
.stat-item { display: flex; flex-direction: column; align-items: center; width: 33%; }
.stat-label { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 0.4rem; letter-spacing: 1px;}
.stat-value { font-size: 1.4rem; font-weight: bold; color: var(--primary); }

button { color: var(--bg); border: none; border-radius: 0.3rem; cursor: pointer; transition: 0.2s; font-family: inherit; font-weight: bold;}
.difficulty-btn { width: 100%; padding: 1.2rem; display: flex; flex-direction: column; align-items: center; gap: 0.4rem; margin-bottom: 0.8rem; border: 1px solid transparent; }
.difficulty-btn .title { font-size: 1.2rem; font-weight: 900; letter-spacing: 1px; color: var(--bg);}
.btn-easy { background-color: var(--easy); }
.btn-normal { background-color: var(--normal); }
.btn-hard { background-color: var(--hard); color: white;} .btn-hard .title { color: white; }
.btn-reset { background-color: transparent; color: var(--primary); border: 1px solid var(--primary); padding: 0.8rem 2rem; font-size: 1.1rem; margin-top: 2rem; }
.btn-reset:hover { background-color: rgba(212, 175, 55, 0.1); }
.btn-quit { background-color: transparent; color: var(--text-muted); border: 1px solid #4B5563; padding: 0.3rem 0.8rem; font-size: 0.8rem; }
.btn-quit:hover { background-color: rgba(153, 27, 27, 0.2); color: var(--hard); border-color: var(--hard); }

.form-group { margin-bottom: 1.5rem; background: #15171C; padding: 1rem; border-radius: 0.3rem; display: flex; justify-content: center; align-items: center; gap: 1rem; border: 1px solid #374151;}
select { padding: 0.4rem 1rem; font-size: 1rem; border-radius: 0.2rem; border: 1px solid #4B5563; background: #0F1115; color: white; font-family: inherit;}
.top-info { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem;}
.progress { font-size: 1rem; font-weight: bold; color: var(--text-muted); }
.current-diff { display: inline-block; font-size: 0.8rem; font-weight: bold; padding: 0.3rem 0.8rem; border-radius: 1rem; color: white; text-shadow: 0 1px 2px rgba(0,0,0,0.5);}

.rank-box { padding: 2rem; border-radius: 0.5rem; margin-bottom: 2rem; color: white; background-color: #0F1115; border: 1px solid var(--primary); box-shadow: inset 0 0 30px rgba(212, 175, 55, 0.1);}
.rank-label { font-size: 1rem; opacity: 0.9; margin-bottom: 0.5rem; }
.rank-title { font-size: 2rem; font-weight: 900; margin: 0; text-shadow: 0 0 15px rgba(212, 175, 55, 0.4); line-height: 1.3;}
.total-score-display { font-size: 1.5rem; margin-top: 1rem; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { 0% { transform: scale(0.5); opacity: 0; } 50% { transform: scale(1.3); } 100% { transform: scale(1.2); opacity: 1; } }
@keyframes popFade { 
    0% { transform: scale(0.5); opacity: 0; } 
    15% { transform: scale(1.3); opacity: 1; } 
    25% { transform: scale(1.2); opacity: 1; } 
    80% { transform: scale(1.2); opacity: 1; } 
    100% { transform: scale(1.0); opacity: 0; } 
}
.judgment-text.show { animation: popFade 0.8s forwards ease-out; }
@keyframes countdownPop {
    0% { transform: scale(0.5); opacity: 0; }
    20% { transform: scale(1.2); opacity: 1; }
    80% { transform: scale(1); opacity: 1; }
    100% { transform: scale(0.8); opacity: 0; }
}
@keyframes pulse { 0% { transform: scale(1); } 50% { transform: scale(1.1); } 100% { transform: scale(1); } }
@keyframes slideDown { from { transform: translateY(-20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.loading { padding: 2rem; background: var(--bg); border-radius: 0.5rem; color: var(--primary); font-weight: bold; }
.footer { margin-top: auto; padding: 2rem 1rem; text-align: center; font-size: 0.85rem; color: var(--text-muted); width: 100%; }
.footer a { color: var(--primary); text-decoration: none; }