:root {
  --theme: #f59f00; --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: #fff4e6; padding: 15px; text-align: center; border-bottom: 3px solid var(--theme); }
h1 { margin: 0 0 10px; color: #d9480f; font-size: 1.5rem; }
.notebook-prompt { display: inline-block; background: white; border: 2px solid #ffc078; color: #d9480f; 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: #fff4e6; color: #d9480f; }
.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; } }

/* 練習問題 */
.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: #d9480f; outline: none; cursor: pointer; background: white;}
.practice-stage { display: flex; flex-direction: column; align-items: center; padding: 10px; background: #f8f9fa; border-radius: 12px; border: 2px solid #e9ecef; margin-bottom: 15px; transition: opacity 0.3s;}
.data-controls { display: flex; justify-content: center; gap: 15px; margin-bottom: 15px; }

/* Custom Setup */
.custom-setup-area { background: #fff9db; border: 2px dashed #fcc419; padding: 20px; border-radius: 12px; text-align: center; margin-bottom: 15px; font-weight: bold; color: #d4a017; animation: fadeIn 0.3s;}
.custom-inputs { display: flex; justify-content: center; align-items: center; gap: 10px; margin-top: 15px; }
.num-input-large { width: 80px; height: 45px; font-size: 1.5rem; text-align: center; border: 2px solid #adb5bd; border-radius: 8px; font-weight: bold; color: #495057;}
.eq-sign { font-size: 1.5rem; color: #495057; }
.error-msg { color: var(--danger); font-size: 1rem; margin-top: 10px; min-height: 20px; }

/* --- 筆算グリッド (5桁対応) --- */
.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: #d9480f; background: white; transition: all 0.2s; padding: 0; }
.num-box:focus { outline: none; border-color: var(--theme); background: #fff4e6; box-shadow: 0 0 0 3px rgba(245, 159, 0, 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: #d9480f; background: #fff4e6; padding: 10px; border-radius: 8px; margin-top: 10px; min-height: 45px; border: 1px solid #ffc078; 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: #d9480f; font-weight: bold; margin-bottom: 5px; 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: #4dabf7; 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; }
.hidden { display: none !important; }