body {
    font-family: 'Yu Gothic', sans-serif;
    margin: 0;
    display: flex;
    height: 100vh;
    background-color: #f0f4f8;
    color: #333;
}

.main-content {
    flex: 1; display: flex; flex-direction: column;
    position: relative; padding: 20px; box-sizing: border-box;
    overflow-y: auto;
}

/* ----- トップバー（ボタンの重なりを防ぐエリア） ----- */
.top-bar {
    display: flex; justify-content: space-between; align-items: center;
    width: 100%; max-width: 800px; margin: 0 auto 20px;
    min-height: 40px;
}

#en-link {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 2000;
    margin-right: 0;

    text-decoration: none; color: white; font-weight: bold;
    background: #3498db; padding: 10px 20px; border-radius: 8px;
    box-shadow: 0 4px 0 #2980b9; font-size: 14px;
    transition: all 0.1s;
}
#en-link:active { transform: translateY(4px); box-shadow: none; }

#abort-btn {
    position: fixed;
    top: 20px;
    left: 20px;
    z-index: 2000;

    padding: 10px 16px; font-size: 14px; background-color: #e74c3c;
    color: white; border: none; border-radius: 8px; cursor: pointer;
    font-weight: bold; display: none; margin-left: 0;
}
#abort-btn:hover { background-color: #c0392b; }

.top-bar-spacer { flex-grow: 1; }

/* ----- コンテンツエリア ----- */
.screen-container {
    flex: 1; 
    display: flex; 
    flex-direction: column; 
    align-items: center; 
    padding: 20px 15px; /* 左右に最低限の余白を確保 */
}


/* 1100pxから800pxに縮小し、スタート画面や結果画面の広がりすぎを防止 */
.screen { width: 800px; max-width: 100%; display: none; margin: auto; }
.active { display: block; }

.card {
    background: white; padding: 35px 60px;
    border-radius: 12px; box-shadow: 0 4px 15px rgba(0,0,0,0.05);
    width: 100%; box-sizing: border-box;
}

@media (max-width: 768px) {
    .card { padding: 20px 25px; }
}

/* ----- スタート画面 ----- */
#start-screen { 
    text-align: center; 
    max-width: 1500px;
    margin: 0 auto;
}
#start-screen h1 { margin-top: 0; margin-bottom: 20px; font-size: 24px; color: #333; }

.settings-group {
    margin: 15px 0; padding: 15px; background: #f9f9f9;
    border-radius: 8px; text-align: left;
}
.settings-group h3 {
    margin-top: 0; margin-bottom: 15px; font-size: 14px; color: #555;
}

.settings-row {
    display: grid; grid-template-columns: 1fr 1fr; gap: 15px; margin: 15px 0;
}
.settings-row .settings-group { margin: 0; }

.cond-row { margin-bottom: 10px; display: flex; align-items: center; flex-wrap: wrap; }
.cond-label { display: inline-block; width: 80px; font-weight: bold; color: #555; font-size: 14px; }

.radio-group input[type="radio"] { display: none; }
.radio-btn {
    display: inline-block; padding: 8px 12px; margin: 0 10px 5px 0;
    border: 2px solid #cbd5e1; border-radius: 8px;
    background-color: white; color: #64748b; cursor: pointer;
    transition: all 0.2s; font-size: 14px; font-weight: bold;
}
.radio-btn:hover { border-color: #94a3b8; }
.radio-group input[type="radio"]:checked + .radio-btn {
    background-color: #3498db; color: white; border-color: #3498db;
}
.radio-group input[type="radio"]#diff_hard:checked + .radio-btn {
    background-color: #e74c3c; border-color: #e74c3c;
}
.radio-group input[type="radio"]#diff_demon:checked + .radio-btn {
    background-color: #9b59b6; border-color: #9b59b6;
}

/* 腱鞘炎級のボタン色設定 */
.radio-group input[type="radio"]#diff_kenshouen:checked + .radio-btn {
    background-color: #1a1a1a; /* 視認性の良いダークグレー */
    color: #ff4d4d; /* 読みやすい明るめの赤 */
    border-color: #1a1a1a;
    box-shadow: 0 2px 8px rgba(255, 77, 77, 0.4); /* ほんのり赤く光らせる */
    text-shadow: 0 0 2px rgba(255, 77, 77, 0.3);
}

.desc-text {
    margin-top: 12px; font-size: 15px; color: #64748b;
    background-color: #f8fafc; padding: 12px 15px 12px 22px; 
    border-radius: 8px; font-weight: bold; position: relative;
    --bar-color: #3498db;
}
.desc-text::before {
    content: ""; position: absolute; top: 10px; bottom: 10px; left: 8px;
    width: 5px; background-color: var(--bar-color); border-radius: 10px;
    transition: background-color 0.2s;
}

.custom-input {
    width: 60px; font-size: 14px; padding: 0 5px; margin: 0 5px;
    border: 2px solid #cbd5e1; border-radius: 6px; text-align: center; 
    color: #64748b; font-family: inherit; font-weight: bold; outline: none;
    box-sizing: border-box; height: 24px;
}
.custom-input:focus { border-color: #3498db; }

.start-btn {
    margin-top: 15px; padding: 12px 40px; font-size: 18px;
    cursor: pointer; border: none; border-radius: 8px;
    background: #2ecc71; color: white; font-weight: bold;
    box-shadow: 0 4px 0 #27ae60; transition: all 0.1s;
}
.start-btn:active { transform: translateY(4px); box-shadow: none; }

/* ----- プレイ画面 ----- */
#play-board { text-align: center; position: relative; }

.top-controls {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    width: 500px;
    max-width: 90%;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

#progress-container {
    display: flex;
    align-items: center;
    width: 100%;
}

#progress-bar-wrap {
    flex: 1; background: #ddd; border-radius: 10px;
    height: 20px; overflow: hidden; margin-right: 20px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
#progress-bar { height: 100%; background: #2ecc71; width: 100%; }
#progress-text { font-size: 20px; font-weight: bold; color: #555; min-width: 70px; text-align: left; text-shadow: 1px 1px 2px rgba(255,255,255,0.8); }

#countdown-display { font-size: 120px; font-weight: bold; color: #3498db; text-align: center; margin-top: 50px; }

#finish-overlay {
    position: absolute; inset: 0; background: rgba(255,255,255,0.85);
    display: none; justify-content: center; align-items: center;
    z-index: 1000; border-radius: 12px; backdrop-filter: blur(3px);
}
.finish-text {
    font-size: 100px; font-weight: bold; color: #e74c3c;
    animation: popIn 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}
@keyframes popIn { 0% { transform: scale(0.3); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }

#ruby-display { font-size: 20px; color: #666; margin-bottom: 5px; font-weight: bold; min-height: 30px; word-wrap: break-word; line-height: 1.4; }
#word-display { font-size: 44px; font-weight: bold; margin: 0 0 15px 0; word-wrap: break-word; line-height: 1.4; }
#target-display { font-size: 32px; font-weight: bold; letter-spacing: 2px; color: #777; margin-bottom: 30px; transition: color 0.1s; word-wrap: break-word; line-height: 1.4; word-break: break-all; }

.typed { color: #3498db; }
.next-char { color: #e67e22; border-bottom: 3px solid #e67e22; padding-bottom: 2px; transition: color 0.1s; }
.miss-flash { color: #e74c3c !important; border-color: #e74c3c !important; }

#keyboard-area {
    background: #e2e8f0; padding: 20px; border-radius: 8px;
    font-size: 16px; color: #666; text-align: center; font-weight: bold;
}
.ime-warning { color: #e74c3c; font-size: 13px; margin-top: 10px; display: block; }

/* ----- 結果画面 ----- */
#result-screen { width: 100%; max-width: 1500px; } /* ← 1100px から 100%、max-width:800px に変更 */
#result-screen h1 { text-align: center; margin-top: 0; margin-bottom: 20px; font-size: 24px; color: #333; }

.dashboard { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; align-items: stretch; }

@media (max-width: 768px) {
    .dashboard { grid-template-columns: 1fr; }
}

.dash-left { display: flex; flex-direction: column; gap: 15px; }
.stats-main { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat-box { background: #f8fafc; padding: 15px; border-radius: 10px; text-align: center; border: 1px solid #e2e8f0; }
.stat-title { font-size: 14px; color: #64748b; font-weight: bold; margin-bottom: 5px; }
.stat-value { font-size: 28px; font-weight: bold; color: #3498db; }
.stat-sub { font-size: 12px; color: #94a3b8; }

.graph-box { background: #fff; padding: 15px; border-radius: 10px; border: 1px solid #e2e8f0; flex-grow: 1; position: relative; min-height: 200px; }

.dash-right { display: flex; flex-direction: column; gap: 15px; }
.details-box, .ranking-box { background: #f8fafc; padding: 20px; border-radius: 10px; border: 1px solid #e2e8f0; font-size: 14px; }
.ranking-box { flex-grow: 1; display: flex; flex-direction: column; }
.details-box ul { list-style: none; padding: 0; margin: 0; }
.details-box li { display: flex; justify-content: space-between; padding: 10px 0; border-bottom: 1px dashed #cbd5e1; }
.details-box li:last-child { border-bottom: none; }
.highlight { color: #e74c3c; font-weight: bold; }
.setting-val { color: #3498db; font-weight: bold; }

.history-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px; }
.history-header h3 { margin: 0; font-size: 16px; text-align: left; }
.clear-btn { background: #e74c3c; color: white; border: none; padding: 6px 12px; border-radius: 6px; cursor: pointer; font-size: 12px; font-weight: bold; transition: background 0.2s; }
.clear-btn:hover { background: #c0392b; }
.rank-item { display: flex; justify-content: space-between; padding: 10px 5px; border-bottom: 1px solid #ddd; font-size: 14px; align-items: center; }
.rank-item:last-child { border-bottom: none; }
.hist-date { font-size: 12px; color: #666; width: 80px; }
.hist-speed { font-weight: bold; color: #333; }
.hist-acc { color: #888; font-size: 12px; }

.action-buttons { display: flex; justify-content: center; gap: 20px; margin-top: 25px; }
.retry-btn, .share-btn {
    padding: 12px 30px; font-size: 16px; cursor: pointer; border: none; border-radius: 8px;
    font-weight: bold; color: white; transition: all 0.1s;
}
.retry-btn { background: #3498db; box-shadow: 0 4px 0 #2980b9; }
.share-btn { background: #1abc9c; box-shadow: 0 4px 0 #16a085; }
.retry-btn:active, .share-btn:active { transform: translateY(4px); box-shadow: none; }

/* ----- トップに戻るボタン ----- */
.top-back-link {
    position: fixed;
    top: 20px;
    left: 20px;
    z-index: 2000;
    margin-left: 0;

    text-decoration: none;
    color: #64748b;
    font-weight: bold;
    padding: 8px 12px;
    border-radius: 8px;
    background: #ffffff;
    border: 2px solid #cbd5e1;
    font-size: 14px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
}
.top-back-link:hover {
    background: #f8fafc;
    border-color: #94a3b8;
}


#abort-btn {
    margin-left: 15px;
}

/* ----- フッター ----- */
.site-footer {
    margin-top: auto;
    padding: 20px 0; text-align: center;
    font-size: 13px; color: #64748b; border-top: 1px dashed #cbd5e1;
    width: 100%; max-width: 800px; margin-left: auto; margin-right: auto;
}
.site-footer a {
    color: #3498db; text-decoration: none; margin: 0 15px; font-weight: bold;
}
.site-footer a:hover { text-decoration: underline; }
