:root {
  --theme: #845ef7; --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: #f3f0ff; padding: 15px; text-align: center; border-bottom: 3px solid var(--theme); }
h1 { margin: 0 0 10px; color: #5f3dc4; font-size: 1.5rem; }
.notebook-prompt { display: inline-block; background: white; border: 2px solid #b197fc; color: #5f3dc4; 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: #f3f0ff; color: #5f3dc4; }
.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; margin-bottom: 15px;}
.mt-3 { margin-top: 20px; }
.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; z-index: 2;}
.char-name { font-size: 0.9rem; font-weight: bold; color: #868e96; }
.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; margin-left: 10px;}
.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; }

/* 暗算ステージ */
.anzan-stage { display: flex; gap: 20px; justify-content: center; flex-wrap: wrap; }
.anzan-box { background: white; border: 2px solid #dee2e6; border-radius: 12px; padding: 20px; box-shadow: 0 4px 6px rgba(0,0,0,0.02); min-width: 300px; display: flex; flex-direction: column; }
.bg-light { background: #f8f9fa; }

/* さくらんぼ計算ツリー */
.tree-diagram { display: flex; flex-direction: column; align-items: center; margin-bottom: 15px; font-weight: bold; font-size: 1.4rem; color: #495057; }
.tree-top { margin-bottom: 5px; }
.tree-branches { display: flex; gap: 30px; position: relative; }
.tree-branches::before { content: ''; position: absolute; top: -15px; left: 20px; width: 2px; height: 15px; background: #adb5bd; transform: rotate(30deg); }
.tree-branches::after { content: ''; position: absolute; top: -15px; right: 20px; width: 2px; height: 15px; background: #adb5bd; transform: rotate(-30deg); }
.branch-left { color: var(--color-a); }
.branch-right { color: var(--success); }

/* 数式ブレイクダウン */
.eq-breakdown { display: flex; flex-direction: column; gap: 10px; font-size: 1.3rem; font-weight: bold; }
.eq-row { display: flex; align-items: center; justify-content: flex-start; gap: 10px; }
.eq-num { color: #495057; width: 100px; text-align: right; }
.eq-total { border-top: 2px dashed #ced4da; padding-top: 10px; margin-top: 5px; }
.large-text { font-size: 1.5rem; }
.small-input { width: 45px !important; }

/* 10倍のきまり */
.tens-rule { display: flex; flex-direction: column; align-items: center; gap: 5px; font-size: 1.3rem; font-weight: bold; color: #495057; }
.tr-row { display: flex; align-items: center; gap: 10px; }
.tr-arrows { display: flex; gap: 40px; color: var(--danger); font-size: 1rem; margin: 5px 0; }
.tr-arrow { background: #fff0f6; padding: 2px 8px; border-radius: 4px; border: 1px solid #ffc9c9; }
.tr-note { font-size: 1rem; color: var(--theme); background: #f3f0ff; padding: 10px; border-radius: 8px; text-align: center; border: 1px solid #e5dbff; margin-top: 10px;}
.dashed-line { border: none; border-top: 2px dashed #ced4da; width: 100%; margin: 15px 0; }

/* 共通入力系 */
.num-input { width: 60px; height: 40px; text-align: center; border: 2px solid #adb5bd; border-radius: 8px; font-weight: bold; font-size: 1.4rem; color: #343a40; transition: all 0.2s; }
.num-input:focus { outline: none; border-color: var(--theme); box-shadow: 0 0 0 3px rgba(132, 94, 247, 0.2); }
.num-input.correct { border-color: var(--success); background: #ebfbee; color: #2b8a3e; }
.highlight-ans { border-color: var(--danger); background: #fff0f6; color: #c92a2a; }

/* 板書のまとめ */
.board-summary { background: white; border: 4px solid #63e6be; border-radius: 12px; padding: 15px 20px; margin-top: 20px; font-weight: bold; font-size: 1.2rem; 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: #5f3dc4; outline: none; cursor: pointer; background: white;}
.data-controls { display: flex; justify-content: center; gap: 15px; margin-bottom: 20px; }

.practice-stage { display: flex; flex-direction: column; align-items: center; padding: 30px; background: #f8f9fa; border-radius: 12px; border: 2px solid #e9ecef; margin-bottom: 15px; }
.equation-area-large { display: flex; align-items: center; justify-content: center; gap: 15px; font-size: 2.5rem; font-weight: bold; color: #343a40; background: white; padding: 20px 40px; border-radius: 16px; border: 3px solid #dee2e6; box-shadow: 0 4px 10px rgba(0,0,0,0.05);}
.eq-left-text { letter-spacing: 2px; }
.num-input-huge { width: 120px; height: 60px; font-size: 2.2rem; text-align: center; border: 3px solid #adb5bd; border-radius: 10px; font-weight: bold; color: var(--danger); background: #fff0f6;}
.num-input-huge.correct { border-color: var(--success); background: #ebfbee; color: #2b8a3e; }

/* おたすけモード（ヒント式） */
.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-area { margin-top: 20px; background: #e7f5ff; border: 2px dashed #74c0fc; border-radius: 12px; padding: 15px 30px; width: 100%; max-width: 500px;}
.hint-title { font-weight: bold; color: #1864ab; font-size: 1.1rem; border-bottom: 2px solid #74c0fc; padding-bottom: 5px; margin-bottom: 10px;}
.hint-breakdown { font-size: 1.4rem; font-weight: bold; color: #495057; line-height: 1.8; text-align: center;}
.hint-breakdown span { display: inline-block; background: white; padding: 2px 8px; border-radius: 6px; border: 1px solid #ced4da; margin: 0 5px;}

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

/* 共通パーツ */
.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; }
.hidden { display: none !important; }
.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; }