:root {
  --color-a: #4dabf7; --bg-a: #e7f5ff;
  --color-b: #ff922b; --bg-b: #fff4e6;
  --success: #40c057; --warning: #fcc419; --danger: #fa5252;
  --bg: #f4f6f8; --border: #ced4da; --theme: #2b8a3e;
}

* { 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: #343a40; }
.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: #ebfbee; padding: 15px; text-align: center; border-bottom: 3px solid var(--theme); }
h1 { margin: 0 0 10px; color: var(--theme); font-size: 1.5rem; }
.notebook-prompt { display: inline-block; background: white; border: 2px solid #8ce99a; color: var(--theme); padding: 5px 15px; border-radius: 20px; font-weight: bold; }

/* Mission Bar */
.mission-bar { background: #f8f9fa; padding: 10px 15px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; border-bottom: 1px solid var(--border); }
.mission-label { font-weight: bold; color: #495057; }
.problem-display { margin-left: auto; font-size: 1.4rem; font-weight: bold; background: white; padding: 4px 15px; border: 2px solid #adb5bd; border-radius: 8px; color: #495057; }

/* Global Controls */
.global-controls { display: flex; gap: 15px; padding: 15px; background: white; border-bottom: 3px dashed var(--border); flex-wrap: wrap; justify-content: center; align-items: center; }
.control-group { padding: 10px 15px; border-radius: 8px; display: flex; flex-direction: column; gap: 8px; border: 2px solid transparent; }
.blue-group { background: var(--bg-a); border-color: #a5d8ff; }
.orange-group { background: var(--bg-b); border-color: #ffd8a8; }
.reset-group { flex-direction: row; align-items: center; gap: 15px; background: #f8f9fa; border-color: var(--border); }
.group-title { font-weight: bold; font-size: 1rem; text-align: center; }
.btn-row { display: flex; gap: 5px; }

/* Buttons */
.btn { padding: 8px 12px; border: none; border-radius: 6px; cursor: pointer; font-weight: bold; font-size: 0.95rem; transition: transform 0.1s; }
.btn:active { transform: translateY(2px); }
.btn-outline { background: white; border: 2px solid var(--theme); color: var(--theme); }
.btn-outline:hover { background: #ebfbee; }
.btn-blue { background: var(--color-a); color: white; }
.btn-orange { background: var(--color-b); color: white; }
.btn-gray { background: #dee2e6; color: #495057; }
.btn-red.outline { background: white; border: 2px solid var(--danger); color: var(--danger); }
.btn-green { background: var(--success); color: white; padding: 10px 20px; font-size: 1.1rem; }
.btn-yellow { background: var(--warning); color: #343a40; }

.val-badge { font-size: 1.1rem; font-weight: bold; }
.val-badge span { color: var(--danger); font-size: 1.5rem; }

/* Visual 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: var(--theme); border-bottom: 3px solid var(--theme); }
.visual-container { padding: 20px; min-height: 380px; 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; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* 1. Beaker (絶対配置によるズレなし設計) */
.beaker-stage { display: flex; justify-content: center; gap: 80px; align-items: flex-end; height: 260px; margin-top: 20px; }
.beaker { width: 110px; height: 200px; border: 3px solid #343a40; border-top: none; position: relative; background: #fffcf0; border-radius: 0 0 10px 10px; }
.beaker-inner { position: absolute; top: 0; left: 0; width: 100%; height: 100%; border-radius: 0 0 6px 6px; overflow: hidden; }
.ticks-overlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: 5; pointer-events: none; }
.tick { position: absolute; left: 0; width: 100%; border-bottom: 1px dashed #adb5bd; }
.tick.half { border-bottom: 2px solid #868e96; }
.top-line { position: absolute; top: -3px; left: -20px; width: 144px; border-top: 4px solid var(--danger); z-index: 10; }
.one-liter-label { position: absolute; top: -28px; left: -35px; color: var(--danger); font-weight: bold; font-size: 1.3rem; }
.liquid { position: absolute; bottom: 0; left: 0; width: 100%; transition: all 0.3s ease; z-index: 1; }
.liquid-a { background: rgba(77, 171, 247, 0.85); }
.liquid-b { background: rgba(255, 146, 43, 0.85); }

/* 2. Number Line */
.line-stage { padding: 80px 20px 40px; }
.number-line { position: relative; height: 4px; background: #495057; width: 100%; }
.nl-tick { position: absolute; bottom: 0; width: 2px; background: #495057; transform: translateX(-50%); }
.nl-tick.major { height: 20px; } .nl-tick.minor { height: 10px; }
.nl-label { position: absolute; top: 15px; transform: translateX(-50%); font-weight: bold; font-size: 1.1rem; }
.nl-range { position: absolute; bottom: 4px; height: 12px; transition: all 0.3s ease; opacity: 0.6; }
.range-a { background: var(--color-a); left: 0; border-radius: 6px 0 0 6px; }
.range-b { background: var(--color-b); border-radius: 0 6px 6px 0; }
.jump-arrow { position: absolute; top: -35px; transform: translateX(-50%); color: var(--danger); font-size: 2rem; transition: left 0.3s ease; }

/* 3. Blocks */
.block-stage { display: flex; justify-content: center; margin-top: 10px; }
.block-area { width: 100%; max-width: 550px; min-height: 180px; background: #f1f3f5; border-radius: 12px; padding: 20px; display: flex; flex-wrap: wrap; gap: 6px; align-content: flex-start; border: 2px dashed var(--border); }
.placeholder { color: #adb5bd; width: 100%; text-align: center; margin-top: 50px; font-weight: bold; }
.b-01 { width: 22px; height: 50px; border-radius: 4px; border: 1px solid rgba(0,0,0,0.15); animation: popIn 0.2s; }
.b-01.a-color { background: var(--color-a); }
.b-01.b-color { background: var(--color-b); }
.b-1 { width: 60px; height: 60px; background: var(--danger); border-radius: 8px; display: flex; align-items: center; justify-content: center; color: white; font-weight: bold; font-size: 1.5rem; animation: merge 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275); }
.merge-action { text-align: center; background: #fff3cd; color: #856404; padding: 10px; border-radius: 8px; margin-bottom: 15px; font-weight: bold; border: 1px solid #ffeeba; animation: fadeIn 0.3s; }
.hidden { display: none !important; }
@keyframes popIn { 0% { transform: scale(0.5); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
@keyframes merge { 0% { transform: scale(0.8) rotate(-5deg); } 50% { transform: scale(1.1) rotate(5deg); } 100% { transform: scale(1) rotate(0); } }

/* Notebook Guide */
.notebook-guide { background: #fff9db; padding: 20px; border-top: 3px dashed #fcc419; text-align: center; }
.notebook-guide h3 { margin: 0 0 10px; color: #d4a017; }
.notebook-guide p { margin: 0 0 15px; font-weight: bold; }
.notebook-keywords { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; }
.notebook-keywords span { background: white; padding: 8px 15px; border-radius: 20px; border: 2px solid #ffe066; font-weight: bold; color: #495057; }

/* Modal */
.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: 400px; width: 90%; text-align: center; border-top: 8px solid var(--warning); }
.mt-3 { margin-top: 15px; }