:root {
  --theme: #20c997; --bg: #f8f9fa;
  --color-a: #339af0; --color-b: #ff922b;
  --success: #40c057; --warning: #fcc419; --danger: #fa5252;
  --text: #343a40; --border: #ced4da;
}

* { box-sizing: border-box; }
body { font-family: 'Hiragino Maru Gothic ProN', 'Rounded M+ 1c', sans-serif; background-color: var(--bg); margin: 0; padding: 10px; display: flex; justify-content: center; color: var(--text); }
.app-container { background: white; max-width: 900px; width: 100%; border-radius: 12px; box-shadow: 0 8px 24px rgba(0,0,0,0.1); overflow: hidden; }

/* Header & Mission */
header { background: #e6fcf5; padding: 15px; text-align: center; border-bottom: 3px solid var(--theme); }
h1 { margin: 0 0 10px; color: #087f5b; font-size: 1.5rem; }
.notebook-prompt { display: inline-block; background: white; border: 2px solid #63e6be; color: #087f5b; padding: 5px 15px; border-radius: 20px; font-weight: bold; }
.mission-bar { background: #f1f3f5; padding: 10px 15px; border-bottom: 2px dashed var(--border); display: flex; align-items: center; gap: 10px; flex-wrap: wrap;}
.mission-label { font-weight: bold; }

/* Buttons */
.btn { padding: 8px 12px; border: none; border-radius: 6px; cursor: pointer; font-weight: bold; font-size: 0.95rem; transition: all 0.1s; }
.btn:active { transform: translateY(2px); }
.btn-outline { background: white; border: 2px solid #adb5bd; color: var(--text); }
.btn-outline.active-prob { border-color: var(--theme); background: #e6fcf5; color: #087f5b; }
.btn-yellow { background: var(--warning); color: var(--text); }
.btn-gray { background: #dee2e6; color: var(--text); }
.btn-green { background: #40c057; color: white; border: 2px solid #2b8a3e; }
.btn-blue { background: #339af0; color: white; border: 2px solid #1864ab; }

/* Tabs & Container */
.visual-container { padding: 20px; min-height: 480px; background: white; }
.visual-content { display: none; animation: fadeIn 0.3s; }
.visual-content.active { display: block; }
.vis-header { display: flex; justify-content: space-between; align-items: center; font-weight: bold; margin-bottom: 20px; color: #495057; padding: 10px; background: #f8f9fa; border-radius: 8px; border-left: 5px solid var(--warning); }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* Character */
.char-container { display: flex; align-items: center; gap: 10px; position: relative; }
.mt-2 { margin-top: 15px; }
.char-icon { font-size: 2rem; background: #e9ecef; border-radius: 50%; width: 45px; height: 45px; display: flex; justify-content: center; align-items: center; border: 2px solid #adb5bd; }
.char-name { position: absolute; bottom: -18px; left: 10px; font-size: 0.8rem; font-weight: bold; color: #868e96; }
.speech-bubble { position: relative; background: #ebfbee; border: 2px solid #8ce99a; border-radius: 12px; padding: 10px 15px; font-weight: bold; color: #2b8a3e; flex: 1; }
.speech-bubble::before { content: ''; position: absolute; top: 15px; left: -12px; border-width: 10px 12px 10px 0; border-style: solid; border-color: transparent #8ce99a transparent transparent; }
.speech-bubble-small { position: relative; background: white; border: 2px solid #ced4da; border-radius: 8px; padding: 8px 12px; font-weight: bold; color: #495057; font-size: 0.9rem; }
.speech-bubble-small::before { content: ''; position: absolute; top: 10px; left: -10px; border-width: 8px 10px 8px 0; border-style: solid; border-color: transparent #ced4da transparent transparent; }
.speech-bubble-small strong { color: var(--danger); }

/* --- 筆算グリッド --- */
.math-grid { display: flex; flex-direction: column; font-size: 1.8rem; font-weight: bold; font-family: 'Courier New', monospace; width: max-content; margin: 0 auto; }
.clean-grid { background-color: white; padding: 10px 20px; border-radius: 8px; border: 2px solid #e9ecef; box-shadow: 0 4px 6px rgba(0,0,0,0.02);}
.mg-row { display: flex; height: 45px; align-items: center; position: relative; justify-content: flex-end;}
.border-bottom { border-bottom: 3px solid #343a40; margin-bottom: 5px; }
.mg-cell { width: 42px; height: 40px; display: flex; justify-content: center; align-items: center; position: relative; }
.mg-cell.val { color: #343a40; }
.num-box { width: 36px; height: 38px; text-align: center; border: 2px solid #adb5bd; border-radius: 6px; font-weight: bold; font-size: 1.6rem; color: #087f5b; background: white; transition: all 0.2s; padding: 0; }
.num-box:focus { outline: none; border-color: var(--theme); background: #e6fcf5; box-shadow: 0 0 0 3px rgba(32, 201, 151, 0.2); }
.num-box.correct { border-color: var(--success); background: #ebfbee; color: #2b8a3e; }
.num-box:disabled { display: none; }

/* 比較ステージ */
.comparison-stage { display: flex; justify-content: center; gap: 40px; background: #f8f9fa; padding: 20px; border-radius: 12px; border: 2px dashed var(--border); flex-wrap: wrap; }
.comp-past, .comp-current { display: flex; flex-direction: column; align-items: center; }
.past-title { font-weight: bold; color: #868e96; margin-bottom: 10px; }
.current-title { font-weight: bold; color: #087f5b; margin-bottom: 10px; font-size: 1.2rem;}
.readonly-grid { background: white; border: 1px solid #dee2e6; padding: 10px; border-radius: 8px; color: #868e96; opacity: 0.8; }

/* 板書のまとめ */
.board-summary { background: white; border: 4px solid #63e6be; border-radius: 12px; padding: 15px 20px; margin-top: 20px; font-weight: bold; font-size: 1.1rem; line-height: 1.6; color: #087f5b; box-shadow: inset 0 0 0 3px #e6fcf5; display: none; }
.board-summary.visible { display: block; animation: fadeIn 0.5s; }
.board-summary strong { color: var(--danger); background: #fff0f6; padding: 0 5px; border-radius: 4px; }

/* 練習問題 */
.prob-selector-container { text-align: center; margin-bottom: 15px; }
.prob-select { font-size: 1.2rem; padding: 10px; border-radius: 8px; border: 2px solid var(--theme); font-family: inherit; font-weight: bold; color: #087f5b; outline: none; cursor: pointer; background: white;}
.practice-stage { display: flex; justify-content: center; padding: 10px; background: #f8f9fa; border-radius: 12px; border: 2px solid #e9ecef; margin-bottom: 15px; }
.data-controls { display: flex; justify-content: center; gap: 15px; margin-bottom: 15px; }

/* アドバイス機能 */
.advice-controls { display: flex; justify-content: center; margin-top: 10px; }
.advice-msg { text-align: center; font-size: 1.1rem; font-weight: bold; color: #087f5b; background: #e6fcf5; padding: 10px; border-radius: 8px; margin-top: 10px; min-height: 45px; border: 1px solid #63e6be; display: none; }

/* おたすけモード */
.support-toggle { background: #fff3cd; border: 2px solid #ffeeba; padding: 5px 15px; border-radius: 20px; color: #856404; cursor: pointer; display: flex; align-items: center; gap: 5px; }
.support-toggle input { width: 18px; height: 18px; cursor: pointer; }

.prac-hint-msg { text-align: center; font-size: 1rem; color: #087f5b; font-weight: bold; margin-bottom: 5px; border-bottom: 2px dashed #63e6be; padding-bottom: 5px;}
.memo-row { display: none; height: 25px; margin-bottom: 5px; border-bottom: none !important; }
.memo-box { width: 25px; height: 25px; border: 1px solid #ffc9c9; background: #fff0f6; border-radius: 50%; text-align: center; font-size: 0.9rem; color: #c92a2a; font-weight: bold; margin-left: 7px; }
.help-text { display: none; }

.support-on .memo-row { display: flex; }
.support-on .help-text { display: block; animation: fadeIn 0.3s; }

/* 共通パーツ */
.feedback-msg { text-align: center; font-size: 1.3rem; font-weight: bold; color: var(--danger); min-height: 35px; margin-top: 10px; animation: fadeIn 0.3s; }
.modal { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); display: flex; align-items: center; justify-content: center; z-index: 1000; }
.modal-content { background: white; padding: 30px; border-radius: 12px; max-width: 450px; width: 90%; text-align: center; border-top: 8px solid var(--warning); line-height: 1.5; font-weight: bold; }
.hidden { display: none !important; }