:root {
    --primary-color: #2c3e50;
    --accent-color: #2980b9;
    --bg-color: #f4f7f6;
    --paper-color: #fff;
    --text-color: #333;
    --flash-text-color: #333;
    --flash-negative-color: #e74c3c;
    --main-width: 550px;
}

body {
    font-family: "Helvetica Neue", Arial, sans-serif;
    background-color: var(--bg-color);
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
    margin: 0;
    padding: 20px;
    color: var(--text-color);
    touch-action: manipulation;
    position: relative;
    padding-bottom: 60px;
    box-sizing: border-box;
}

h1 {
    color: var(--primary-color);
    font-size: 1.5rem;
    margin-bottom: 10px;
}

/* --- 共通レイアウト設定 --- */
/* モード選択パネルは個別に幅を設定するためここから除外しました */
.control-panel, 
.problem-card {
    width: 100%;
    max-width: var(--main-width);
    box-sizing: border-box;
    margin-left: auto;
    margin-right: auto;
}

/* --- モード切替スイッチ --- */
.mode-selector {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 5px;
    
    /* ここを変更: 幅をコンテンツに合わせる */
    width: fit-content;
    margin: 0 auto 15px auto; /* 中央揃え */
    
    background: #ddd;
    border-radius: 25px;
    padding: 4px;
    box-sizing: border-box;
}

.mode-selector input[type="radio"] {
    display: none;
}

.mode-selector label {
    padding: 8px 16px;
    border-radius: 20px;
    cursor: pointer;
    font-weight: bold;
    color: #666;
    transition: all 0.2s;
    font-size: 0.9rem;
    white-space: nowrap; /* ボタン内の文字折り返し防止 */
}

.mode-selector input:checked + label {
    background: var(--primary-color);
    color: white;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

/* --- 設定パネル --- */
.control-panel {
    background: var(--paper-color);
    padding: 15px 20px;
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    align-items: center;
    justify-content: center;
    margin-bottom: 20px;
    font-size: 0.9rem;
    min-height: 50px;
}

.setting-group {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
    justify-content: center;
}

/* 速度設定の区切り線 */
#settings-speed {
    margin-top: 10px;
    width: 100%;
    border-top: 1px dashed #ccc;
    padding-top: 10px;
}

.speed-label {
    font-size: 0.8rem;
}

.hidden {
    display: none !important;
}

.input-group {
    display: flex;
    align-items: center;
    gap: 5px;
}

input[type="number"] {
    padding: 6px;
    border: 1px solid #ddd;
    border-radius: 4px;
    width: 50px;
    text-align: center;
    font-size: 1rem;
}

input[type="range"] {
    width: 120px;
    cursor: pointer;
}

/* --- 問題表示カード --- */
.problem-card {
    background: var(--paper-color);
    padding: 40px 20px;
    border-radius: 4px;
    box-shadow: 0 8px 20px rgba(0,0,0,0.1);
    margin-bottom: 30px;
    text-align: center;
    position: relative;
    cursor: pointer;
    min-height: 250px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    transition: border 0.3s;
}

.problem-card.active-run {
    border: 2px solid var(--accent-color);
    background-color: #fcfeff;
}

/* 見取算リスト */
.number-list-mitori {
    font-family: "Courier New", Courier, monospace;
    font-size: 2.2rem;
    font-weight: bold;
    text-align: right;
    line-height: 1.4;
    width: 280px; 
    border-bottom: 4px solid #333;
    padding-bottom: 10px;
    padding-right: 20px;
    margin: 0 auto; 
}

@media (max-width: 400px) {
    .number-list-mitori {
        width: 100%;
        padding-right: 0;
    }
}

/* 掛け算表示 */
.problem-kake {
    font-family: "Courier New", Courier, monospace;
    font-size: 2.5rem;
    font-weight: bold;
    white-space: nowrap;
}

/* フラッシュ暗算 */
.flash-number {
    font-family: "Helvetica Neue", Arial, sans-serif;
    font-size: 5rem;
    font-weight: bold;
    color: var(--flash-text-color);
    line-height: 1;
}

.flash-number.negative {
    color: var(--flash-negative-color);
}

/* インジケータ */
.running-indicator {
    font-size: 1.5rem;
    color: var(--accent-color);
    font-weight: bold;
    animation: blink 1.5s infinite;
}

@keyframes blink {
    0% { opacity: 1; }
    50% { opacity: 0.5; }
    100% { opacity: 1; }
}

/* 答え表示 */
.answer-display {
    font-family: "Courier New", Courier, monospace;
    font-size: 2.5rem;
    font-weight: bold;
    color: var(--accent-color);
    margin-top: 20px;
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.2s ease;
    min-height: 1.2em;
}

.answer-display.visible {
    opacity: 1;
    transform: translateY(0);
}

/* --- ボタン --- */
button#action-btn {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 15px 40px;
    border-radius: 50px;
    font-size: 1.2rem;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 4px 6px rgba(0,0,0,0.2);
    transition: background-color 0.2s;
    width: 80%;
    max-width: 300px;
}

button#action-btn:hover {
    background-color: #34495e;
}

button#action-btn:disabled {
    background-color: #95a5a6;
    cursor: not-allowed;
}

.key-hint {
    margin-top: 15px;
    font-size: 0.8rem;
    color: #999;
}

/* フッター */
footer {
    position: absolute;
    bottom: 10px;
    width: 100%;
    text-align: center;
    font-size: 0.8rem;
    color: #bdc3c7;
}

footer a {
    color: #95a5a6;
    text-decoration: none;
}

footer a:hover {
    color: var(--accent-color);
    text-decoration: underline;
}