:root {
  --theme: #3bc9db; --bg: #f8f9fa;
  --color-a: #4dabf7; --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: #e3fafc; padding: 15px; text-align: center; border-bottom: 3px solid var(--theme); }
h1 { margin: 0 0 10px; color: #0b7285; font-size: 1.5rem; }
.notebook-prompt { display: inline-block; background: white; border: 2px solid #66d9e8; color: #0b7285; 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: #e3fafc; color: #0b7285; }
.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; }
.char-icon { font-size: 2.2rem; background: #e9ecef; border-radius: 50%; width: 50px; height: 50px; 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::after { content: ''; position: absolute; top: 17px; left: -9px; border-width: 8px 10px 8px 0; border-style: solid; border-color: transparent #ebfbee transparent transparent; }

/* --- 筆算グリッド共通デザイン --- */
.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; border-radius: 8px; }
.clean-grid .mg-cell { border-left: 1px solid #e9ecef; border-right: 1px solid #e9ecef; }
.clean-grid .mg-cell:first-child { border-left: none; }
.clean-grid .mg-cell:last-child { border-right: none; }

.mg-row { display: flex; height: 45px; align-items: center; position: relative; }
.border-bottom { border-bottom: 3px solid #343a40; margin-bottom: 2px; }
.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: #0b7285; background: white; transition: all 0.2s; padding: 0; }
.num-box:focus { outline: none; border-color: var(--theme); background: #e3fafc; }
.num-box.correct { border-color: var(--success); background: #ebfbee; color: #2b8a3e; }
.num-box:disabled { background: transparent; border: none; }
.side-note { position: absolute; left: 100%; margin-left: 10px; font-size: 1.1rem; color: #868e96; white-space: nowrap; font-family: 'Hiragino Maru Gothic ProN', sans-serif; font-weight: normal; background: rgba(255,255,255,0.8); padding: 0 5px; border-radius: 4px;}
.zero-hint { color: #ff922b; font-size: 1.4rem; }

/* 1. ひっ算のしかた (比較) */
.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: #0b7285; 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; }
.comp-note { background: #f1f3f5; padding: 5px 10px; border-radius: 20px; margin-top: 10px; font-size: 0.9rem; font-weight: bold; color: #495057; border: 1px solid #ced4da; }

/* 板書のまとめ */
.board-summary { background: white; border: 4px solid #fcc419; border-radius: 12px; padding: 20px; margin-top: 20px; display: none; }
.board-summary.visible { display: block; animation: fadeIn 0.5s; }
.board-question { background: #fff9db; border: 2px solid #fcc419; padding: 8px 15px; border-radius: 8px; font-weight: bold; color: #d4a017; display: inline-block; margin-bottom: 15px; font-size: 1.2rem; }
.board-answers { display: flex; gap: 20px; justify-content: center; margin-bottom: 20px; }
.ans-box { border: 2px solid #ffc078; padding: 10px 15px; border-radius: 8px; font-weight: bold; color: #d9480f; background: white; text-align: center; }

/* 2. 練習問題 */
.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: #0b7285; outline: none; cursor: pointer; }
.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: #1864ab; background: #e7f5ff; padding: 10px; border-radius: 8px; margin-top: 10px; min-height: 45px; border: 1px solid #74c0fc; 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; }

.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-zero { display: none; }
.help-text { display: none; }

.support-on .memo-row { display: flex; }
.support-on .help-zero { display: flex; color: #adb5bd; font-size: 1.6rem; }
.support-on .help-text { display: inline; color: #4dabf7; }

/* 共通パーツ */
.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; }
.notebook-guide { background: #fff9db; padding: 20px; border-top: 3px dashed #fcc419; text-align: center; margin-top: 20px;}
.notebook-guide h3 { margin: 0 0 10px; color: #d4a017; }