body {
    font-family: 'M PLUS Rounded 1c', sans-serif;
    background: #fef8e4;
    margin: 0;
    padding: 20px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    max-width: 1200px;
    margin-left: auto;
    margin-right: auto;
}
h2 {
    text-align: center;
    font-family: 'Yusei Magic', cursive;
    font-size: 32px;
    margin-bottom: 30px;
    color: #333;
}
.main-section {
    display: flex;
    width: 100%;
    gap: 40px;
    align-items: flex-start;
}
.left-panel, .right-panel {
    flex: 1;
    max-width: 50%;
}
.blackboard {
    background-color: #2f4f4f;
    color: white;
    padding: 40px 20px;
    border-radius: 12px;
    font-size: 5vw;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 8px solid #8b5a2b;
    max-width: 100%;
    box-sizing: border-box;
    overflow: hidden;
    /* ← ここを修正 */
}
.vertical-question {
    text-align: right;
    font-size: 5vw;
    line-height: 1.2;
}
.vertical-question hr {
    border: none;
    border-top: 4px solid white;
    margin: 10px 0;
}
.blackboard.correct::after {
    content: "◯";
    position: absolute;
    top: 55%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 200px;
    color: #ff7fa8;
    animation: pop 0.4s ease;
}
@keyframes pop {
    0% {
        transform: translate(-50%, -50%) scale(0.5);
        opacity: 0;
    }
    100% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
    }
}
.answer-box {
    display: flex;
    justify-content: flex-end;
    /* ← 中央から右寄せに変更 */
    align-items: end;
    gap: 10px;
    margin-top: 10px;
}
.digit-container {
    display: flex;
    flex-direction: column;
    align-items: center;
}
.digit-input {
    width: 60px;
    height: 80px;
    font-size: 5vw;
    text-align: center;
    background-color: #223838;
    color: white;
    border-radius: 8px;
    border: none;
}
.arrow {
    height: 30px;
    font-size: 24px;
    color: #fff799;
    animation: blink 1s infinite;
    margin-top: 8px;
}
@keyframes blink {
    0%, 100% {
        opacity: 0;
    }
    50% {
        opacity: 1;
    }
}
.keypad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-top: 10px;
}
button {
    font-size: 28px;
    width: 100%;
    height: 70px;
    border: none;
    border-radius: 16px;
    cursor: pointer;
    transition: background-color 0.3s ease;
    color: white;
}
button:nth-child(1) {
    background-color: #f48fb1;
}
button:nth-child(2) {
    background-color: #ce93d8;
}
button:nth-child(3) {
    background-color: #90caf9;
}
button:nth-child(4) {
    background-color: #a5d6a7;
}
button:nth-child(5) {
    background-color: #ff9ca7;
}
button:nth-child(6) {
    background-color: #ff9c62;
}
button:nth-child(7) {
    background-color: #80cbc4;
}
button:nth-child(8) {
    background-color: #bcaaa4;
}
button:nth-child(9) {
    background-color: #ffab91;
}
button:nth-child(10) {
    background-color: #b0bec5;
}
.btn-clear {
    background-color: #ef9a9a !important;
}
.btn-action {
    background-color: #81d4fa !important;
}
.hint-container {
    display: flex;
    align-items: flex-start;
    margin: 20px 0;
    width: 100%;
}
.popochi {
    width: 150px;
    height: auto;
    margin-right: 10px;
    flex-shrink: 0;
    margin-top: -20px;
}
.hint-box {
    background: #ffffff;
    color: #999;
    padding: 16px 24px;
    border-radius: 25px;
    font-size: 20px;
    font-weight: bold;
    width: 100%;
    text-align: left;
    position: relative;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    word-break: break-word;
}
.hint-box::before {
    content: "";
    position: absolute;
    left: -10px;
    top: 50%;
    transform: translateY(-50%);
    width: 0;
    height: 0;
    border-top: 10px solid transparent;
    border-bottom: 10px solid transparent;
    border-right: 10px solid #ffffff;
}
/* ▼ 問題の数式を横並び＆桁そろえに */
.digit-row {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    flex-wrap: nowrap;
}
.digit {
    width: 40px;
    height: 80px;
    font-size: 50px;
    font-family: 'M PLUS Rounded 1c', sans-serif;
    text-align: center;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
/* ▼ 解答欄（ボックス）も同じ基準 */
.digit-input {
    width: 60px;
    height: 80px;
    font-size: 40px;
}
/* ▼ 黒板のサイズ安定（スマホ対策） */
.blackboard {
    max-width: 100%;
    box-sizing: border-box;
    overflow-x: auto;
}
@media (max-width: 768px) {
    .main-section {
        flex-direction: column;
        gap: 20px;
        width: 100%;
    }
    .left-panel,
    .right-panel {
        max-width: 100%;
        width: 100%;
    }
    .blackboard {
        font-size: 16px;
        padding: 20px 10px;
        width: 100%;
        overflow-x: auto;
    }
    .digit {
        width: 40px;
        height: 70px;
        font-size: 50px;
    }
    .digit-input {
        width: 50px;
        height: 70px;
        font-size: 32px;
    }
    .arrow {
        font-size: 20px;
    }
    .keypad {
        width: 100%;
        grid-template-columns: repeat(3, 1fr);
        gap: 8px;
    }
    button {
        font-size: 6vw;
        height: 12vw;
    }
    .hint-box {
        font-size: 18px;
    }
    .popochi {
        width: 120px;
    }
}
.unit-label {
    font-size: 16px;
    color: #fff799;
    margin-top: 4px;
    height: 20px;
}
/* ▼ 進捗表示スタイル（上部） */
#progressDisplay {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-bottom: 20px;
    font-family: "M PLUS Rounded 1c", sans-serif;
}
.progress-item {
    text-align: center;
}
.progress-item .number {
    font-size: 1.2rem;
    color: #555;
}
.progress-item .mark {
    font-size: 2rem;
    color: #333;
}
/* ▼ 最終メッセージ（黒板用） */
.final-result-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    /* ← 中央揃えを強化 */
    gap: 24px;
    padding: 32px 16px;
    text-align: center;
    width: 100%;
}
.final-message-text {
    font-size: 28px;
    font-weight: bold;
    line-height: 1.6;
    text-align: center;
    color: white;
}
.retry-button {
    padding: 14px 20px;
    /* ← 上下のpaddingを少しだけ減らす */
    font-size: 22px;
    font-weight: bold;
    border-radius: 16px;
    background-color: #ff9b6c !important;
    color: white;
    border: none;
    cursor: pointer;
    text-align: center;
    display: inline-block;
    line-height: 1;
    box-sizing: border-box;
    width: auto;
    max-width: 90%;
    vertical-align: middle;
    /* ← 追加：微調整用 */
}
.retry-button:hover {
    background-color: #ff7f47 !important;
}
.blackboard.final::after {
    display: none !important;
}
.blackboard.final hr {
    display: none !important;
}
#progressDisplay {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 40px;
    gap: 0;
}
.step {
    display: flex;
    align-items: center;
    justify-content: center;
}
.circle {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    font-size: 18px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #ccc;
    color: white;
}
.connector {
    width: 40px;
    height: 4px;
    background-color: #ccc;
}
.step.correct .circle {
    background-color: #70e09a;
    /* 緑 */
    color: white;
}
.step.incorrect .circle {
    background-color: #fbc02d;
    /* 黄オレンジ */
    color: white;
}
.step.pending .circle {
    background-color: #e0e0e0;
    /* グレー */
}
.step.pending+.connector {
    background-color: #e0e0e0;
}
#progress {
    font-size: 24px;
    font-weight: bold;
    color: #555;
    background: #fff7dc;
    padding: 10px 20px;
    border-radius: 12px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    margin-bottom: 20px;
}
.unit {
    font-size: 20px;
    color: #fff799;
    margin-top: 6px;
}
.vertical-question #line1,
.vertical-question #line2 {
    font-size: 40px;
}
.ampm-select {
    font-size: 24px;
    padding: 6px 12px;
    border-radius: 8px;
    background-color: #223838;
    color: white;
    border: none;
    margin-bottom: 10px;
}
.answer-row {
    display: flex;
    align-items: flex-end;
    gap: 10px;
}
.ampm-buttons {
    display: flex;
    flex-direction: row;
    /* 横並びに変更 */
    gap: 8px;
    margin-right: 10px;
    /* 少し右にスペース */
}
@media (max-width: 768px) {
    .ampm-buttons {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
    }
    .ampm-btn {
        font-size: 18px;
        padding: 8px 12px;
        min-width: 80px;
    }
}
.ampm-btn {
    padding: 8px 9px;
    font-size: 18px;
    border-radius: 12px;
    border: none;
    background-color: #888 !important;;
    /* ← グレーに変更 */
    color: white;
    cursor: pointer;
    min-width: 80px;
    font-weight: bold;
    transition: all 0.2s ease-in-out;
}
.ampm-btn.selected {
    background-color: #ff9c62 !important;;
    border: 3px solid white;
    box-shadow: 0 0 0 3px #ff9c62aa;
}
.answer-row {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    justify-content: flex-start;
}
.ampm-buttons {
    display: flex;
    flex-direction: column;
    gap: 6px;
    align-items: flex-end;
    /* 右寄せにしない */
    margin-right: 0;
    /* 黒板にピタッとつける */
}

.mode-buttons {
  display: flex !important;
  justify-content: center !important;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 24px;
  text-align: initial !important;
}

.mode-buttons button {
  font-size: 14px;
  padding: 10px 16px;
  border-radius: 12px;
  border: none;
  color: white;
  font-weight: bold;
  cursor: pointer;
  min-width: 120px;
  font-family: "M PLUS Rounded 1c", sans-serif;
  box-shadow: 2px 2px 4px rgba(0,0,0,0.1);
  width:auto !important;
}

.mode-btn {
  font-size: 14px;
  padding: 8px 12px;
  border-radius: 12px;
  border: none;
  color: white;
  font-weight: bold;
  cursor: pointer;
  min-width: 90px;
  transition: all 0.2s ease-in-out;
  font-family: "M PLUS Rounded 1c", sans-serif;
}

.mode-btn.pink {
  background-color: #f48fb1;
}
.mode-btn.purple {
  background-color: #ce93d8;
}
.mode-btn.blue {
  background-color: #90caf9;
}
.mode-btn.green {
  background-color: #a5d6a7;
}

.mode-btn:hover {
  opacity: 0.85;
}
