:root {
  --theme: #6b4e31; --bg: #f4ece4; --theme-light: #fdfaf6;
  --color-a: #339af0; --color-b: #e67e22;
  --success: #40c057; --warning: #fcc419; --danger: #e74c3c;
  --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; border: 4px solid var(--theme);}

/* Header & Mission */
header { background: var(--theme); padding: 15px; text-align: center; color: white;}
h1 { margin: 0 0 10px; font-size: 1.6rem; letter-spacing: 2px;}
.notebook-prompt { display: inline-block; background: white; color: var(--theme); padding: 5px 15px; border-radius: 20px; font-weight: bold; }
.mission-bar { background: var(--theme-light); padding: 10px 15px; border-bottom: 2px solid var(--border); display: flex; align-items: center; gap: 10px; flex-wrap: wrap;}
.mission-label { font-weight: bold; color: var(--theme);}

/* 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 var(--theme); color: var(--theme); }
.btn-outline.active-prob { background: var(--theme); color: white; }
.btn-yellow { background: var(--warning); 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: 15px; color: #495057; padding: 10px; background: var(--theme-light); border-radius: 8px; border-left: 5px solid var(--color-b); }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* 共通コントロール */
.data-controls { display: flex; justify-content: center; gap: 15px; margin-bottom: 15px; }
.prob-selector-container { text-align: center; margin-bottom: 15px; }
.prob-select { font-size: 1.2rem; padding: 10px; border-radius: 8px; border: 2px solid var(--color-b); font-family: inherit; font-weight: bold; color: var(--theme); outline: none; cursor: pointer; background: white;}
.practice-stage { display: flex; flex-direction: column; align-items: center; padding: 20px; background: var(--theme-light); border-radius: 12px; border: 2px solid #e9ecef; margin-bottom: 15px; }

/* 文章問題 */
.word-problem-text { background: white; border-left: 6px solid var(--color-b); padding: 15px; font-size: 1.3rem; font-weight: bold; margin-bottom: 15px; border-radius: 0 8px 8px 0; line-height: 1.5; box-shadow: 0 2px 4px rgba(0,0,0,0.05);}
.equation-area { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 10px; font-size: 1.3rem; font-weight: bold; margin-bottom: 20px; background: white; padding: 15px; border-radius: 12px; border: 2px dashed var(--color-b); width: 100%;}
.eq-label { color: var(--theme); }
.num-input-large { width: 60px; height: 40px; font-size: 1.3rem; text-align: center; border: 2px solid #adb5bd; border-radius: 6px; font-weight: bold; color: #495057;}
.num-input-large.correct { border-color: var(--success); background: #ebfbee; color: #2b8a3e; }
.ans-input { width: 80px; border-color: var(--danger); background: #fff0f6; color: var(--danger);}

/* まちがいさがし */
.mistake-stage { display: flex; justify-content: center; gap: 40px; flex-wrap: wrap; }
.mistake-bad, .mistake-good { background: white; padding: 20px; border-radius: 12px; border: 2px solid #dee2e6; display: flex; flex-direction: column; align-items: center; }
.bad-title { color: var(--danger); font-weight: bold; font-size: 1.2rem; margin-bottom: 15px; border-bottom: 2px solid var(--danger); padding-bottom: 5px; }
.good-title { color: var(--success); font-weight: bold; font-size: 1.2rem; margin-bottom: 15px; border-bottom: 2px solid var(--success); padding-bottom: 5px; }
.bad-math { font-size: 2rem; font-family: 'Courier New', monospace; font-weight: bold; color: #c92a2a; letter-spacing: 5px; line-height: 1.2;}
.bad-math hr { border: 2px solid #c92a2a; margin: 5px 0; }

/* --- 筆算グリッド --- */
.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 #ced4da; 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; padding-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: var(--theme); background: white; transition: all 0.2s; padding: 0; }
.num-box:focus { outline: none; border-color: var(--color-b); background: #fff4e6; box-shadow: 0 0 0 3px rgba(230, 126, 34, 0.2); }
.num-box.correct { border-color: var(--success); background: #ebfbee; color: #2b8a3e; }
.num-box:disabled { display: none; }

/* アドバイス機能 */
.advice-controls { display: flex; justify-content: center; margin-top: 10px; }
.advice-msg { text-align: center; font-size: 1.1rem; font-weight: bold; color: var(--theme); background: white; padding: 10px; border-radius: 8px; margin-top: 10px; min-height: 45px; border: 2px solid var(--color-b); 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: 1.1rem; color: var(--color-b); font-weight: bold; margin-bottom: 10px; border-bottom: 2px dashed #ffc078; 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; position: absolute; left: 100%; margin-left: 10px; font-size: 1.1rem; color: var(--color-a); white-space: nowrap; font-family: 'Hiragino Maru Gothic ProN', sans-serif; font-weight: normal;}
.help-zero { display: none; color: #adb5bd; font-size: 1.6rem; }

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

.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; }