:root {
  --primary: #1565c0;
  --secondary: #f57c00;
  --bg: #e3f2fd;
  --card: #ffffff;
  --text: #333333;
  --c-div: #1976d2; /* 青：わられる数 */
  --c-dsr: #388e3c; /* 緑：わる数 */
  --c-quo: #d32f2f; /* 赤：答え */
  --c-rem: #e65100; /* オレンジ：あまり */
}

body {
  font-family: 'Hiragino Maru Gothic ProN', 'Meiryo', sans-serif;
  background-color: #bbdefb;
  margin: 0;
  padding: 10px;
  display: flex;
  justify-content: center;
  color: var(--text);
}

#app {
  width: 100%;
  max-width: 800px;
  background: var(--bg);
  border-radius: 16px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.2);
  overflow: hidden;
  position: relative;
}

header {
  background: var(--primary);
  color: white;
  padding: 16px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
header h1 { margin: 0; font-size: 20px; }
.step-indicator { background: rgba(255,255,255,0.2); padding: 5px 12px; border-radius: 16px; font-weight: bold; }

/* ---------------- Visualizer ---------------- */
.visualizer { background: #fff; padding: 20px; border-bottom: 4px solid #90caf9; }
.area-label { font-weight: bold; color: #555; display: flex; justify-content: space-between; align-items: center; }
.vis-controls { display: flex; gap: 10px; }
.btn-small { background: #eee; border: none; padding: 8px 12px; border-radius: 6px; cursor: pointer; font-weight: bold; font-family: inherit; transition: 0.2s;}
.btn-small:active { transform: scale(0.95); }
.btn-magic { background: #fff3e0; color: #e65100; border: 1px solid #ffb74d; box-shadow: 0 2px 0 #fb8c00;}

.pool-container { background: #fafafa; border: 2px dashed #ccc; border-radius: 8px; margin-top: 10px; padding: 10px; }
.pool-status { font-weight: bold; margin-bottom: 5px; color: #555; }
.pool-status strong { color: var(--primary); font-size: 1.2em; }
.pool { display: flex; flex-wrap: wrap; gap: 4px; max-height: 80px; overflow-y: auto;}

.groups { display: grid; grid-template-columns: repeat(auto-fit, minmax(70px, 1fr)); gap: 8px; margin-top: 10px; }
.person-box {
  background: #f1f8e9; border: 3px solid #aed581; border-radius: 8px; padding: 5px;
  display: flex; flex-direction: column; align-items: center; min-height: 80px;
}
.person-icon { font-size: 24px; margin-bottom: 5px; }
.items-area { display: flex; flex-wrap: wrap; gap: 3px; justify-content: center; }

.item {
  width: 14px; height: 18px; background: #fff9c4; border: 1px solid #fbc02d; border-radius: 2px;
  box-shadow: 1px 1px 2px rgba(0,0,0,0.1); cursor: pointer; transition: transform 0.1s;
}
.item:hover { transform: scale(1.2); }

/* ---------------- Question Board ---------------- */
.question-board { padding: 20px; }
.question-card { background: var(--card); border-radius: 12px; padding: 25px; box-shadow: 0 4px 10px rgba(0,0,0,0.05); }
.question-card h2 { margin-top: 0; color: var(--primary); font-size: 20px; border-bottom: 2px solid #e3f2fd; padding-bottom: 8px; }
.question-text { font-size: 22px; font-weight: bold; line-height: 1.8; margin-bottom: 15px; }
rt { font-size: 12px; color: #777; }
.sub-text { font-size: 14px; color: #666; font-weight: bold; margin-top: -10px; margin-bottom: 10px;}

.hint-area { background: #fff8e1; border: 2px dashed #ffc107; padding: 12px; border-radius: 8px; margin-bottom: 20px; font-size: 18px; font-weight: bold; color: #555; animation: fadeIn 0.3s;}

.input-section { margin-bottom: 25px; }
.input-section h3 { font-size: 18px; color: #455a64; margin-bottom: 10px; }
.highlight-section { background: #f9fbe7; padding: 15px; border-radius: 12px; border: 2px solid #cddc39; }

.answer-box { background: #f5f5f5; padding: 15px; border-radius: 8px; font-size: 22px; font-weight: bold; display: flex; align-items: center; flex-wrap: wrap; gap: 5px; justify-content: center;}
.answer-box .label { margin-right: 10px; color: #555; }

input[type="text"] {
  width: 50px; height: 40px; font-size: 20px; text-align: center; font-weight: bold; font-family: inherit;
  border: 3px solid #ccc; border-radius: 8px; outline: none; transition: 0.2s; margin: 0 4px;
}
input[type="text"]:focus { background: #fffde7; }
input.input-dividend { border-color: var(--c-div); }
input.input-divisor { border-color: var(--c-dsr); }
input.input-quotient { border-color: var(--c-quo); }
input.input-remainder { border-color: var(--c-rem); }

.action-buttons { display: flex; gap: 15px; margin-top: 20px; }
.btn-hint { flex: 1; background: #ffb74d; color: white; border: none; border-radius: 8px; font-size: 18px; font-weight: bold; cursor: pointer; box-shadow: 0 4px 0 #f57c00;}
.btn-hint:active { transform: translateY(4px); box-shadow: 0 0 0 #f57c00; }
.btn-primary, .btn-next { flex: 2; background: var(--primary); color: white; border: none; padding: 16px; font-size: 20px; font-weight: bold; border-radius: 8px; cursor: pointer; box-shadow: 0 4px 0 #0d47a1; transition: 0.1s; }
.btn-primary:active, .btn-next:active { transform: translateY(4px); box-shadow: 0 0 0 #0d47a1; }
.btn-next { background: #2e7d32; box-shadow: 0 4px 0 #1b5e20; animation: pop 0.4s; }

.msg { margin-top: 20px; padding: 15px; border-radius: 8px; font-weight: bold; font-size: 18px; line-height: 1.5; white-space: pre-wrap; animation: fadeIn 0.3s; }
.msg.error { background: #ffebee; color: #c62828; border-left: 6px solid #f44336; }
.msg.warning { background: #fff3e0; color: #e65100; border-left: 6px solid #ff9800; }
.msg.success { background: #e8f5e9; color: #2e7d32; border-left: 6px solid #4caf50; }

/* Clear Screen */
.clear-screen { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: rgba(255,255,255,0.95); display: flex; justify-content: center; align-items: center; text-align: center; z-index: 100; animation: fadeIn 1s; }
.clear-content { padding: 40px; }
.crown { font-size: 80px; animation: pop 1s infinite alternate; }
.clear-content h2 { color: var(--primary); font-size: 36px; margin: 10px 0; }
.clear-content p { font-size: 20px; font-weight: bold; color: #333; line-height: 1.6; }

.hidden { display: none !important; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { 0% { transform: scale(0.9); } 100% { transform: scale(1); } }