:root {
  --theme: #8b4513; --bg: #fdfbf7; --border: #ced4da;
  --primary: #4dabf7; --danger: #fa5252; --success: #40c057; --warning: #fcc419;
}

* { 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: 950px; width: 100%; border-radius: 12px; box-shadow: 0 8px 24px rgba(0,0,0,0.1); overflow: hidden; }

/* Header */
header { background: #f4ece4; padding: 15px; text-align: center; border-bottom: 3px solid var(--theme); }
h1 { margin: 0 0 5px; color: var(--theme); font-size: 1.6rem; }
.header-desc { font-weight: bold; color: #5c3a21; }

/* Tabs */
.tool-tabs { display: flex; background: #e9ecef; }
.tool-tab { flex: 1; padding: 12px 5px; border: none; background: transparent; font-size: 1.1rem; font-weight: bold; color: #495057; cursor: pointer; border-bottom: 4px solid transparent; transition: all 0.2s; }
.tool-tab.active { background: white; color: var(--theme); border-bottom: 4px solid var(--theme); }

/* Workspace */
.workspace { padding: 20px; min-height: 450px; }
.tab-content { display: none; animation: fadeIn 0.3s; }
.tab-content.active { display: block; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.q-title { font-size: 1.2rem; border-left: 5px solid var(--warning); padding-left: 10px; margin-top: 0; margin-bottom: 20px; line-height: 1.4; }
.q-num { display: inline-block; background: #ffe8cc; color: #d9480f; width: 26px; height: 26px; text-align: center; border-radius: 50%; font-weight: bold; line-height: 26px; margin-right: 8px; border: 1px solid #ffd8a8; }

/* Inputs */
.ans-in { padding: 6px; border: 2px solid #a5d8ff; border-radius: 6px; font-size: 1.2rem; text-align: center; font-weight: bold; width: 80px; transition: all 0.2s; background: #f8f9fa; }
.ans-in:focus { outline: none; border-color: var(--primary); background: white; }
.ans-in.short { width: 60px; }
.ans-in.sign { width: 40px; }
.ans-in.correct { border-color: var(--success); background: #ebfbee; color: #2b8a3e; }
.ans-in.incorrect { border-color: var(--danger); background: #fff5f5; color: #c92a2a; }

/* Measure Stage */
.measure-stage { display: flex; flex-direction: column; gap: 30px; }
.q-panel { background: #f8f9fa; padding: 20px; border-radius: 8px; border: 1px solid var(--border); }
.beaker-container { display: flex; gap: 40px; justify-content: center; margin: 20px 0; }
.beaker { width: 90px; height: 140px; border: 3px solid #343a40; border-top: none; position: relative; background: #fffcf0; border-radius: 0 0 8px 8px; }
.liquid { position: absolute; bottom: 0; left: 0; width: 100%; background: rgba(77, 171, 247, 0.85); border-radius: 0 0 5px 5px; z-index: 1; }
/* ★マス目の線を濃くはっきりと表示★ */
.ticks-overlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: 10; pointer-events: none; }
.tick { position: absolute; left: 0; width: 100%; border-bottom: 2px solid rgba(0, 0, 0, 0.6); }
.tick.half { border-bottom: 3px solid rgba(0, 0, 0, 0.9); }
.label-1l { position: absolute; top: 50%; left: -35px; transform: translateY(-50%); font-weight: bold; }
.ans-row { text-align: center; font-size: 1.2rem; font-weight: bold; }

/* Tape & Ruler */
.tape-container { margin: 20px 0; position: relative; height: 100px; }
.tape-bar { height: 30px; background: var(--danger); position: absolute; top: 10px; left: 10px; border-bottom: 2px dashed #c92a2a; z-index: 2; }
.ruler { height: 40px; background: #ffe066; position: absolute; top: 40px; left: 10px; right: 10px; border: 1px solid #343a40; z-index: 1; }
.r-tick { position: absolute; bottom: 0; width: 1px; background: #343a40; }
.r-tick.major { height: 100%; width: 2px; } .r-tick.half { height: 60%; } .r-tick.minor { height: 30%; }
.r-label { position: absolute; top: 5px; transform: translateX(-50%); font-weight: bold; font-size: 0.9rem; }

/* Number Line */
.line-container { padding: 40px 20px 60px; background: #f8f9fa; border-radius: 8px; border: 1px solid var(--border); margin-bottom: 20px; }
.number-line { position: relative; height: 4px; background: #343a40; width: 100%; }
.nl-tick { position: absolute; bottom: 0; width: 2px; background: #343a40; 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; }
.marker { position: absolute; top: 15px; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; color: var(--danger); font-weight: bold; }
.ans-grid { display: flex; gap: 15px; flex-wrap: wrap; margin-top: 10px; margin-bottom: 10px; padding-left: 30px; }
.q-row { font-size: 1.1rem; font-weight: bold; margin-bottom: 15px; line-height: 2; }

/* Logic & Comparison */
.split-layout { display: flex; gap: 20px; flex-wrap: wrap; }
.left-panel { flex: 1; min-width: 300px; }
.right-panel { flex: 1; min-width: 300px; }
.mt-4 { margin-top: 30px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.helper-box { background: #fff9db; border: 2px solid #fcc419; border-radius: 8px; padding: 15px; height: 100%; }
.helper-header { font-weight: bold; margin-bottom: 10px; color: #d4a017; border-bottom: 1px dashed #fcc419; padding-bottom: 5px; }
.helper-controls { display: flex; gap: 5px; align-items: center; margin-bottom: 15px; }
.val-badge { font-size: 1.2rem; font-weight: bold; margin-left: auto; background: white; padding: 4px 15px; border: 2px solid #fcc419; border-radius: 20px; color: var(--danger); }
.helper-stage { display: flex; flex-wrap: wrap; gap: 4px; align-content: flex-start; min-height: 150px; background: white; border-radius: 6px; padding: 10px; border: 1px solid #f1c40f; }
.b-1 { width: 30px; height: 30px; background: var(--success); border-radius: 4px; border: 1px solid #2b8a3e; display: flex; align-items: center; justify-content: center; color: white; font-weight: bold; font-size: 0.9rem; }
.b-01 { width: 10px; height: 30px; background: var(--primary); border-radius: 2px; border: 1px solid #1864ab; }

/* Buttons */
.btn { padding: 6px 12px; border: none; border-radius: 6px; cursor: pointer; font-weight: bold; transition: transform 0.1s; }
.btn:active { transform: translateY(2px); }
.btn-blue { background: var(--primary); color: white; }
.btn-lightblue { background: #74c0fc; color: white; }
.btn-red { background: var(--danger); color: white; }
.btn-green { background: var(--success); color: white; font-size: 1.2rem; padding: 15px 30px; box-shadow: 0 4px 0 #2b8a3e; border-radius: 30px; }
.btn-green:active { box-shadow: 0 0 0 #2b8a3e; transform: translateY(4px); }

/* Calculations & Hissan */
.calc-grid-horizontal { display: grid; grid-template-columns: repeat(3, 1fr); gap: 15px; margin-bottom: 30px; background: #f8f9fa; padding: 20px; border-radius: 8px; border: 1px solid var(--border); }
.hissan-container { display: flex; gap: 20px; justify-content: space-around; flex-wrap: wrap; }
.hissan-box { background: white; padding: 15px; border-radius: 8px; border: 2px solid var(--border); display: flex; flex-direction: column; align-items: center; position: relative; }
.hissan-box .q-num { position: absolute; top: 10px; left: 10px; }
.h-grid { display: flex; flex-direction: column; gap: 5px; margin-top: 20px; }
.h-row { display: flex; justify-content: flex-end; align-items: center; }
.h-cell { width: 40px; height: 40px; display: flex; align-items: center; justify-content: center; font-size: 1.6rem; font-weight: bold; font-family: monospace; }
.h-cell.empty { width: 20px; }
.h-cell.dot { width: 15px; font-weight: bold; color: var(--danger); }
.h-cell.dot-col { width: 25px; display: flex; justify-content: center; align-items: flex-end; }
.h-cell.sign { justify-content: flex-start; }

/* ★筆算の「＝」を表す太い横線★ */
.h-line { height: 4px; background: #343a40; width: 100%; margin: 8px 0; border-radius: 2px; }

/* ★自分でタップする小数点の枠★ */
.dot-btn { width: 16px; height: 16px; border: 2px dashed #ff8787; background: transparent; border-radius: 4px; cursor: pointer; outline: none; transition: all 0.2s; margin-bottom: 6px; }
.dot-btn.active { background: #e03131; border: 2px solid #e03131; border-radius: 50%; width: 12px; height: 12px; margin-bottom: 8px; }
.dot-btn.correct { border-color: var(--success); background: var(--success); }
.dot-btn.incorrect { border-color: var(--danger); background: #ffe3e3; }

.h-in { width: 40px; height: 45px; font-size: 1.6rem; padding: 0; }
.action-footer { background: #f4ece4; padding: 20px; text-align: center; border-top: 3px solid var(--theme); }