:root {
  --theme: #339af0; --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: #e7f5ff; padding: 15px; text-align: center; border-bottom: 3px solid var(--theme); }
h1 { margin: 0 0 10px; color: #1864ab; font-size: 1.5rem; }
.notebook-prompt { display: inline-block; background: white; border: 2px solid #74c0fc; color: #1864ab; padding: 5px 15px; border-radius: 20px; font-weight: bold; }
.mission-bar { background: #f1f3f5; padding: 15px; border-bottom: 2px dashed var(--border); }
.mission-label { font-weight: bold; display: block; margin-bottom: 10px; }
.prob-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 10px; }
.problem-display { text-align: right; font-size: 1.4rem; font-weight: bold; color: #d9480f; background: white; padding: 5px 15px; border-radius: 8px; border: 2px solid #adb5bd; display: inline-block; float: right; }

/* 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:hover { background: #e7f5ff; border-color: var(--theme); }
.btn-outline.active-prob { border-color: var(--theme); background: var(--theme); color: white; }
.btn-blue { background: var(--color-a); color: white; padding: 10px 20px; font-size: 1.1rem;}
.btn-blue:disabled { background: #a5d8ff; cursor: not-allowed; }
.btn-orange { background: var(--color-b); color: white; padding: 10px 20px; font-size: 1.1rem;}
.btn-orange:disabled { background: #ffd8a8; cursor: not-allowed; }
.btn-gray { background: #dee2e6; color: var(--text); }
.btn-yellow { background: var(--warning); color: var(--text); }

/* Visual Tabs */
.tool-tabs { display: flex; background: #e9ecef; clear: both; }
.tool-tab { flex: 1; padding: 12px; border: none; background: transparent; font-size: 1.1rem; font-weight: bold; color: #495057; cursor: pointer; border-bottom: 3px solid transparent; }
.tool-tab.active { background: white; color: #1864ab; border-bottom: 3px solid var(--theme); }
.visual-container { padding: 20px; min-height: 450px; 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; } }

/* キャラクター */
.char-container { display: flex; align-items: center; gap: 10px; margin-bottom: 25px; 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: #fff4e6; border: 2px solid #ffa94d; border-radius: 12px; padding: 10px 15px; font-weight: bold; color: #d9480f; flex: 1; }
.speech-bubble::before { content: ''; position: absolute; top: 15px; left: -12px; border-width: 10px 12px 10px 0; border-style: solid; border-color: transparent #ffa94d transparent transparent; }
.speech-bubble::after { content: ''; position: absolute; top: 17px; left: -9px; border-width: 8px 10px 8px 0; border-style: solid; border-color: transparent #fff4e6 transparent transparent; }

/* 1. 10倍のくらべっこ */
.compare-stage { display: flex; flex-direction: column; align-items: center; gap: 5px; margin-top: 10px; background: #f8f9fa; padding: 30px; border-radius: 12px; border: 2px dashed var(--border); }
.eq-row { display: grid; grid-template-columns: 80px 40px 80px 40px 120px; align-items: center; justify-items: center; font-size: 1.8rem; font-weight: bold; }
.highlight-blue { color: #1864ab; background: #d0ebff; padding: 0 10px; border-radius: 6px; }
.highlight-red { color: #c92a2a; background: #ffc9c9; padding: 0 10px; border-radius: 6px; }
.arrow-row { display: grid; grid-template-columns: 80px 40px 80px 40px 120px; align-items: center; justify-items: center; width: 100%; height: 50px; }
.arrow-box { position: relative; width: 100%; height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.down-arrow { width: 4px; height: 30px; background: #ff922b; position: relative; }
.down-arrow::after { content: ''; position: absolute; bottom: -5px; left: -6px; border-top: 8px solid #ff922b; border-left: 8px solid transparent; border-right: 8px solid transparent; }
.arrow-text { color: #d9480f; font-size: 0.9rem; font-weight: bold; background: #fff4e6; padding: 2px 5px; border-radius: 4px; position: absolute; left: 60%; white-space: nowrap;}
.ans-arrow { background: #dee2e6; transition: background 0.3s; }
.ans-arrow::after { border-top-color: #dee2e6; transition: border-top-color 0.3s; }
.ans-text { color: #adb5bd; background: white; transition: all 0.3s; }
.ans-arrow.revealed { background: #ff922b; }
.ans-arrow.revealed::after { border-top-color: #ff922b; }
.ans-text.revealed { color: #d9480f; background: #fff4e6; }

/* まとめ枠 */
.summary-box { background: white; border: 3px 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; }
.summary-box.visible { display: block; animation: fadeIn 0.5s; }
.summary-box strong { color: var(--danger); font-size: 1.4rem; padding: 0 4px; background: #fff0f6; border-radius: 4px; }
.sub-summary { margin-top: 10px; font-size: 1rem; color: #495057; border-top: 1px dashed #adb5bd; padding-top: 10px; }

/* 2. 式のへんけい */
.formula-stage { background: #f8f9fa; padding: 20px; border-radius: 12px; border: 2px solid var(--border); display: flex; flex-direction: column; gap: 15px; font-size: 1.5rem; font-weight: bold; width: fit-content; margin: 0 auto; }
.f-row { display: flex; align-items: center; gap: 10px; }
.f-base-eq { width: 120px; text-align: right; }
.f-equal { color: #868e96; }
.f-part .num-input { width: 80px; font-size: 1.4rem; }
.hidden-text { visibility: hidden; }

/* 3. 位取り表（スライド） */
.pv-controls { display: flex; justify-content: center; gap: 15px; margin-bottom: 30px; }
.pv-stage { position: relative; margin: 0 auto; width: fit-content; padding-bottom: 20px; }
.pv-table { display: grid; grid-template-columns: repeat(4, 90px); border: 3px solid #495057; background: white; border-radius: 8px; overflow: hidden; box-shadow: 0 4px 6px rgba(0,0,0,0.05); }
.pv-header { background: #f1f3f5; text-align: center; font-weight: bold; padding: 10px 0; border-bottom: 2px solid #495057; border-right: 1px solid #dee2e6; color: #495057; }
.pv-header:last-child { border-right: none; }
.pv-cell { height: 80px; border-right: 1px solid #dee2e6; position: relative; background: white; }
.pv-cell:last-child { border-right: none; }
.digit { position: absolute; top: 15%; left: 50%; transform: translateX(-50%); font-size: 2.5rem; font-weight: bold; color: var(--danger); transition: transform 0.6s cubic-bezier(0.34, 1.56, 0.64, 1); z-index: 10; }
.digit.shift-left { transform: translateX(calc(-50% - 90px)); /* 左のセルへ移動 */ }
.zero-drop { position: absolute; top: 58px; right: 28px; font-size: 2.5rem; font-weight: bold; color: var(--theme); animation: dropIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275); z-index: 5; }
.pv-msg { text-align: center; font-weight: bold; font-size: 1.2rem; color: #1864ab; margin-top: 10px; min-height: 30px; }

@keyframes dropIn { 0% { transform: translateY(-50px) scale(0.5); opacity: 0; } 100% { transform: translateY(0) scale(1); opacity: 1; } }

/* 共通入力系 */
.num-input { height: 45px; text-align: center; border: 2px solid #adb5bd; border-radius: 8px; font-weight: bold; color: var(--text); font-family: inherit; font-size: 1.5rem; transition: all 0.2s; }
.num-input:focus { outline: none; border-color: var(--theme); box-shadow: 0 0 0 3px rgba(51, 154, 240, 0.2); }
.num-input.correct { border-color: var(--success); background: #ebfbee; color: #2b8a3e; }
.feedback-msg { text-align: center; font-size: 1.2rem; font-weight: bold; color: var(--success); min-height: 30px; margin-top: 15px; }

/* ノート誘導 */
.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; }
.notebook-keywords { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; margin-top: 10px;}
.notebook-keywords span { background: white; padding: 8px 15px; border-radius: 20px; border: 2px solid #ffe066; font-weight: bold; }
.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; visibility: hidden; }