:root {
  --theme: #38d9a9; --bg: #f8f9fa;
  --color-a: #4dabf7; --color-b: #ff922b; --color-c: #ff6b6b;
  --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 */
header { background: #e6fcf5; padding: 15px; text-align: center; border-bottom: 3px solid var(--theme); }
h1 { margin: 0 0 10px; color: #087f5b; font-size: 1.5rem; }
.notebook-prompt { display: inline-block; background: white; border: 2px solid #63e6be; color: #087f5b; 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;}
.mission-label { font-weight: bold; }

/* Word Problem Area */
.word-problem-area { background: white; padding: 20px; border-bottom: 3px dashed var(--border); }
.problem-text-box { background: #f1f3f5; border-left: 6px solid var(--theme); padding: 15px; font-size: 1.3rem; font-weight: bold; margin-bottom: 15px; border-radius: 0 8px 8px 0; }
.problem-text-box p { margin: 5px 0; }
.highlight-num { color: var(--danger); font-size: 1.5rem; padding: 0 2px; }
.word-equation { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 10px; font-weight: bold; margin-bottom: 15px; font-size: 1.1rem; }
.we-box { border: 2px solid #fcc419; background: #fff9db; padding: 5px 15px; border-radius: 6px; }
.we-box.result { border-color: #ff922b; background: #fff4e6; }
.equation-display { text-align: center; font-size: 1.4rem; font-weight: bold; color: #d9480f; }

/* 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: #e6fcf5; color: #087f5b; }
.btn-blue { background: var(--color-a); color: white; padding: 10px 20px; font-size: 1.1rem;}
.btn-blue:disabled { background: #a5d8ff; cursor: not-allowed; }
.btn-gray { background: #dee2e6; color: var(--text); }
.btn-yellow { background: var(--warning); color: var(--text); }

/* Tabs */
.tool-tabs { display: flex; background: #e9ecef; }
.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: #087f5b; border-bottom: 3px solid var(--theme); }
.visual-container { padding: 20px; min-height: 400px; 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; 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; transition: all 0.3s;}
.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. Number Line */
.line-controls { display: flex; justify-content: center; gap: 10px; margin-bottom: 30px; flex-wrap: wrap; }
.btn-step { background: white; border: 2px solid #adb5bd; color: #495057; font-size: 1rem; padding: 8px 15px; border-radius: 30px; }
.btn-step:hover { background: #f1f3f5; }
.btn-step.active-step { background: var(--theme); border-color: var(--theme); color: white; transform: translateY(2px); }

.double-number-line-stage { margin: 20px 0; padding: 0 20px; }
.dnl-container { position: relative; height: 130px; font-weight: bold; font-size: 1.1rem; }
.dnl-row { position: absolute; width: 100%; height: 40px; }
.top-row { top: 0; }
.bottom-row { top: 80px; }
.dnl-line { position: absolute; top: 20px; width: 100%; height: 4px; background: #dee2e6; }
.dnl-fill { position: absolute; top: 20px; height: 4px; background: var(--color-c); width: 0%; transition: width 0.6s cubic-bezier(0.25, 1, 0.5, 1); }
.dnl-tick { position: absolute; top: 12px; width: 2px; height: 20px; background: #495057; transform: translateX(-50%); }
.dnl-label { position: absolute; transform: translateX(-50%); white-space: nowrap; }
.label-top { top: -28px; color: var(--danger); font-size: 1.2rem; }
.label-bottom { top: 25px; color: #495057; }
.dnl-unit { position: absolute; right: -40px; top: -20px; font-size: 1rem; color: #868e96; }
.bottom-row .dnl-unit { top: 20px; }

/* 2. Ami's Blocks */
.array-controls { display: flex; justify-content: center; margin-bottom: 20px; }
.array-stage { background: #f8f9fa; padding: 30px; border-radius: 12px; border: 2px dashed var(--border); display: flex; justify-content: center; min-height: 180px; align-items: center; }
.block-area { width: 100%; max-width: 500px; height: 80px; position: relative; font-size: 1.2rem; font-weight: bold; color: white; text-align: center; line-height: 80px; }
.block-full { width: 100%; height: 100%; background: #adb5bd; border-radius: 8px; border: 2px solid #868e96; transition: opacity 0.3s; }
.block-parts { display: flex; width: 100%; height: 100%; gap: 5px; animation: popIn 0.5s; }
.block-part { height: 100%; border-radius: 8px; box-shadow: 0 4px 6px rgba(0,0,0,0.1); display: flex; justify-content: center; align-items: center; line-height: 1.2;}
.bp-20 { width: 87%; background: var(--color-a); border: 2px solid #339af0; }
.bp-3 { width: 13%; background: var(--color-c); border: 2px solid #fa5252; font-size: 1rem; }

/* 3. Haruto's Formula */
.haruto-stage { background: #f8f9fa; padding: 20px; border-radius: 12px; border: 2px solid var(--border); display: flex; justify-content: center; }
.hc-container { display: flex; align-items: center; gap: 15px; font-size: 1.5rem; font-weight: bold; }
.hc-base { padding: 10px 20px; background: white; border: 2px solid #adb5bd; border-radius: 8px; }
.hc-branch-lines { width: 30px; height: 80px; border-top: 3px solid #adb5bd; border-bottom: 3px solid #adb5bd; border-left: 3px solid #adb5bd; border-radius: 8px 0 0 8px; margin-right: 5px; }
.hc-calcs { display: flex; flex-direction: column; gap: 15px; }
.hc-row { display: flex; align-items: center; gap: 10px; background: white; padding: 10px 15px; border-radius: 8px; border: 2px solid #e9ecef; }
.hc-total-row { background: #fff9db; border-color: #fcc419; margin-top: 5px; justify-content: flex-end; }
.hc-eq { min-width: 90px; text-align: right; }
.hc-note { font-size: 1rem; color: #868e96; font-weight: normal; margin-left: 10px; }

/* Inputs & Summary */
.num-input { width: 80px; height: 40px; text-align: center; border: 2px solid #adb5bd; border-radius: 8px; font-weight: bold; color: var(--text); font-family: inherit; font-size: 1.4rem; transition: all 0.2s; }
.num-input:focus { outline: none; border-color: var(--theme); box-shadow: 0 0 0 3px rgba(56, 217, 169, 0.3); }
.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; }

.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); background: #fff0f6; padding: 0 5px; border-radius: 4px; }
.sub-summary { margin-top: 10px; font-size: 1rem; color: #495057; border-top: 1px dashed #adb5bd; padding-top: 10px; }

/* Notebook & Modals */
.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; }
@keyframes popIn { 0% { transform: scale(0.9); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }