:root {
    --primary: #2c3e50;
    --primary-hover: #34495e;
    --accent: #3498db;
    --accent-hover: #2980b9;
    --error: #ff4757;
    --bg: #f8f9fa;
    --key-border: #dcdde1;
    --gold: #f1c40f;
}

* { box-sizing: border-box; }

body { margin: 0; padding: 0; font-family: 'Noto Sans JP', sans-serif; background-color: var(--bg); color: var(--primary); line-height: 1.6; min-height: 100vh; width: 100vw; display: flex; flex-direction: column; overflow-x: hidden; }

/* ポータル：通常スクロール / ゲーム：完全固定 */
body.portal-page { overflow-y: auto; height: auto; background-color: var(--bg); }
body.game-body { overflow: hidden; height: 100vh; background-color: #d1d5db; position: relative; }

.hidden { display: none !important; }

/* #appを縦に広げてフッター押し下げの土台にする */
#app { width: 1100px; margin: 0 auto; padding: 10px; display: flex; flex-direction: column; box-sizing: border-box; min-height: 100vh; }

header { flex-shrink: 0; text-align: center; margin-bottom: 30px; z-index: 100; width: 100%; }
.logo { font-size: 2rem; font-weight: bold; margin-bottom: 5px; }
.logo span { color: var(--accent); font-size: 1.2rem; }
.nav-menu { margin-bottom: 5px; display: flex; gap: 15px; justify-content: center; flex-wrap: wrap; }
.nav-menu a { color: var(--primary); text-decoration: none; font-size: 0.9rem; font-weight: bold; padding: 5px 8px; border-bottom: 2px solid transparent; transition: all 0.2s; }
.nav-menu a:hover { color: var(--accent); border-bottom: 2px solid var(--accent); }

.ad-container-top { margin-bottom: 5px; min-height: 65px; flex-shrink: 0; }
.ad-placeholder { width: 100%; max-width: 728px; height: 60px; background: #ddd; margin: 0 auto; display: flex; align-items: center; justify-content: center; font-size: 0.75rem; border-radius: 8px; color: #999; border: 1px solid #ccc; }

/* メインエリア：flex: 1 でフッターを最下部へ押し出す */
main { flex: 1; width: 100%; display: flex; flex-direction: column; min-height: 0; align-items: center; justify-content: flex-start; }
body.game-body main { justify-content: flex-start; padding-top: 10px; }
body.portal-page main { justify-content: flex-start; padding-top: 20px; }

/* --- プレイ画面 --- */
.screen { width: 100%; display: flex; flex-direction: column; align-items: center; }

.typing-display { 
    background: white; padding: 15px 50px; border-radius: 25px; 
    box-shadow: 0 10px 30px rgba(0,0,0,0.05); margin-bottom: 15px; 
    height: 170px; display: flex; flex-direction: column; justify-content: center; 
    overflow: hidden; width: 900px; position: relative;
}

.typing-display::before {
    content: ""; position: absolute; left: 40px; top: 50%; transform: translateY(-50%);
    width: 2px; height: 90px; background-color: rgba(52, 152, 219, 0.3); z-index: 10; pointer-events: none;
}

#display-kanji { font-size: 2rem; margin-bottom: 2px; font-weight: bold; text-align: left; width: 100%; }
#display-kana { font-size: 1.1rem; color: #888; margin-bottom: 5px; text-align: left; width: 100%; }

.romaji-scroll-window { 
    width: 100%; overflow: hidden; position: relative; height: 4.2rem; 
    display: flex; justify-content: flex-start; align-items: center; 
    background: #fafafa; border-radius: 12px; padding: 0;
}
.romaji-content { 
    font-family: 'Roboto Mono', monospace; font-size: 2.5rem; font-weight: 700; 
    letter-spacing: 0.1em; color: #333; white-space: nowrap; text-transform: uppercase; 
    transition: transform 0.1s ease-out; margin: 0;
}
.typed { color: #d1d5db !important; }
.current { color: var(--accent) !important; border-bottom: 6px solid var(--accent); }

/* キーボード：横位置中央 */
#keyboard-container { width: 900px; padding: 15px; background: #f1f2f6; border-radius: 15px; flex-shrink: 0; display: flex; flex-direction: column; align-items: center; }
.keyboard-row { display: flex; justify-content: flex-start; gap: 5px; width: 100%; margin-bottom: 5px; max-width: 650px; }
.row-1 { padding-left: 20px; } 
.row-2 { padding-left: 38px; }
.key { width: 44px; height: 44px; background: white; border-radius: 8px; border: 1px solid var(--key-border); border-bottom-width: 3px; display: flex; align-items: center; justify-content: center; font-size: 0.9rem; font-weight: bold; color: #57606f; }
.key.wide-shift { width: 60px; }
.key.space { width: 280px; margin-left: 120px; background: #f9ca24; border-color: #f0932b; color: white; }
.key.highlight { background: var(--accent); color: white; border-color: #2980b9; transform: translateY(1px); border-bottom-width: 1px; }

/* 結果画面 */
.result-container { display: flex; gap: 15px; width: 1000px; margin: 0 auto; height: 420px; padding-bottom: 10px; align-items: stretch; }
.result-side, .result-main { background: white; border-radius: 20px; box-shadow: 0 5px 20px rgba(0,0,0,0.05); padding: 15px 20px; display: flex; flex-direction: column; overflow: hidden; }
.result-side { flex: 1.1; }
.result-main { flex: 2; text-align: center; justify-content: space-around; }
.scroll-list { flex: 1; overflow-y: auto; padding-right: 10px; }
.miss-item { display: flex; justify-content: space-between; padding: 8px 15px; border-bottom: 1px solid #f1f1f1; font-family: 'Roboto Mono', monospace; font-size: 1.1rem; }
.miss-key { font-weight: bold; color: var(--error); }
#result-rank { font-size: 6rem; font-weight: bold; color: var(--accent); margin: 0; line-height: 1; }
.result-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 25px; max-width: 420px; margin: 10px auto; text-align: left; }
.res-item { font-size: 1.1rem; border-bottom: 1px solid #f1f1f1; padding-bottom: 2px; white-space: nowrap; }
.result-btns { margin-top: 10px; display: flex; gap: 10px; justify-content: center; }
.btn-share { background: #1da1f2; color: white; border: none; padding: 10px 20px; border-radius: 30px; cursor: pointer; font-weight: bold; }

.portal-page .hero-section { text-align: center; padding: 60px 20px; background: linear-gradient(135deg, #1a365d 0%, #2980b9 100%); color: white; border-radius: 25px; margin-bottom: 80px; width: 100%; }
.portal-page .section-container { max-width: 1050px; margin: 0 auto 100px auto; width: 100%; }

/* カテゴリグリッド 3列 */
.portal-page .category-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; width: 100%; }
.portal-page .category-card { background: white; padding: 35px 20px; border-radius: 20px; text-align: center; box-shadow: 0 5px 15px rgba(0,0,0,0.05); text-decoration: none; color: inherit; border: 1px solid #eee; display: flex; flex-direction: column; align-items: center; transition: all 0.3s ease; }
.portal-page .category-card:hover { border-color: var(--accent); transform: translateY(-8px); box-shadow: 0 15px 30px rgba(0,0,0,0.1); }
.portal-page .cat-icon { font-size: 4.5rem; margin-bottom: 15px; }

.card { background: white; padding: 30px 40px; border-radius: 20px; box-shadow: 0 10px 30px rgba(0,0,0,0.05); text-align: center; width: 900px; }
.btn-category { padding: 8px 18px; border: 2px solid #ddd; background: white; border-radius: 30px; cursor: pointer; font-weight: bold; transition: all 0.2s; }
.btn-category:hover { border-color: var(--accent); color: var(--accent); }
.btn-category.active { background: var(--accent); color: white; border-color: var(--accent); }

#best-score-display { margin-top: 15px; margin-bottom: 25px; font-size: 1.1rem; color: #7f8c8d; font-weight: bold; }
.settings-area { margin-bottom: 45px; border-top: 1px solid #eee; border-bottom: 1px solid #eee; padding: 25px 0; width: 100%; }

.btn-toggle { background: #ecf0f1; border: 1px solid #bdc3c7; padding: 8px 24px; border-radius: 25px; cursor: pointer; font-weight: bold; transition: background 0.2s; }
.btn-toggle:hover { background: #dfe6e9; }
.btn-main { background: var(--primary); color: white; border: none; padding: 15px 60px; font-size: 1.3rem; border-radius: 40px; cursor: pointer; font-weight: bold; box-shadow: 0 5px 0 #1a252f; text-decoration: none; transition: all 0.2s ease; }
.btn-main:hover { background: var(--accent); transform: translateY(-2px); box-shadow: 0 7px 0 #2980b9; }
.btn-main:active { transform: translateY(3px); box-shadow: 0 2px 0 #2980b9; }

/* 改善：フッターの極小スリム化 ＆ 最下部吸着 */
footer { 
    margin-top: auto; /* mainコンテンツの flex:1 によって最下部へ押し下げられる */
    padding: 10px 0; 
    border-top: 1px solid #eee; 
    text-align: center; 
    background: white; 
    flex-shrink: 0; 
    width: 100%; 
    display: flex; 
    flex-direction: column; 
    align-items: center; 
    justify-content: center; 
}
.footer-links { display: flex; justify-content: center; gap: 20px; margin-bottom: 3px; width: 100%; }
.footer-links a { color: var(--primary); text-decoration: none; font-size: 0.85rem; }
footer p { font-size: 0.75rem; color: #7f8c8d; margin: 3px 0 0 0; }

/* 読み物ページ用のスタイル */
.static-page {
    text-align: left;
    max-width: 900px;
    width: 100%;
    margin: 20px auto 40px auto; 
    background: white;
    padding: 40px 60px; 
    border-radius: 20px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.05);
    line-height: 1.8;
}
.static-page h1 { font-size: 1.8rem; border-bottom: 3px solid var(--accent); padding-bottom: 8px; margin-bottom: 25px; }
.static-page h2 { font-size: 1.4rem; margin-top: 35px; color: var(--primary); border-left: 5px solid var(--accent); padding-left: 15px; margin-bottom: 15px; }
.glossary-list dt { font-weight: bold; font-size: 1.2rem; color: var(--accent); margin-top: 20px; }
.glossary-list dd { margin-left: 0; margin-bottom: 10px; color: #444; border-bottom: 1px solid #eee; padding-bottom: 10px; }
.point-box { background: #fef9e7; border: 2px solid var(--gold); padding: 20px; border-radius: 12px; margin: 25px 0; }
.point-title { font-weight: bold; color: #b7950b; font-size: 1.1rem; display: block; margin-bottom: 10px; }

.countdown-overlay { position: absolute; font-size: 7rem; color: var(--accent); font-weight: bold; z-index: 100; top: 50%; left: 50%; transform: translate(-50%, -50%); }
.ready-text { font-size: 2.2rem; color: var(--primary); font-weight: bold; animation: pulse 1.5s infinite; }
.esc-guide-card { color: #95a5a6; font-size: 0.9rem; margin-top: 15px; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }
.damage-effect { animation: shake 0.05s linear 1; border-color: var(--error) !important; }
@keyframes shake { 0%, 100% { transform: translateX(0); } 50% { transform: translateX(1px); } }
.sparkle { color: var(--gold) !important; text-shadow: 0 0 20px rgba(241, 196, 15, 0.8); animation: glow 1.5s infinite alternate; }
@keyframes glow { from { transform: scale(1); } to { transform: scale(1.08); } }