@import url('https://fonts.googleapis.com/css2?family=Kosugi+Maru&display=swap');

:root {
  --primary: #008080;
  --primary-light: #e0f2f1;
  --bg-color: #f8fcfb;
  --frame-color: #d4a373;
  --beam-color: #8b5a2b;
  --rod-color: #e0c097;
  --bead-blue: #0077b6;
  --bead-green: #55a630;
  --text-main: #333;
  --warning: #e63946;
}

body {
  font-family: 'Kosugi Maru', sans-serif;
  background-color: var(--bg-color);
  color: var(--text-main);
  margin: 0;
  padding: 10px;
  display: flex;
  justify-content: center;
}

.app-container {
  max-width: 950px;
  width: 100%;
  background: white;
  border-radius: 12px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.08);
  padding: 20px;
  box-sizing: border-box;
}

header {
  border-bottom: 2px solid var(--primary-light);
  padding-bottom: 15px;
  margin-bottom: 15px;
}

.title-area {
  display: flex;
  align-items: center;
  gap: 10px;
}

.title-area h1 {
  color: var(--primary);
  margin: 0;
  font-size: 22px;
}

.mode-selectors {
  display: flex;
  gap: 10px;
  margin-top: 15px;
}

.mode-btn {
  font-family: inherit;
  font-size: 15px;
  background-color: #f1f3f5;
  border: 2px solid #dee2e6;
  color: #495057;
  padding: 8px 16px;
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.2s;
  font-weight: bold;
}

.mode-btn.active, .mode-btn:hover {
  background-color: var(--primary);
  border-color: var(--primary);
  color: white;
}

main {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 20px;
}

.problem-area {
  background-color: var(--primary-light);
  border-radius: 8px;
  padding: 15px;
  height: fit-content;
}

.question-header h2 {
  margin: 0 0 10px 0;
  font-size: 16px;
  color: var(--primary);
  border-bottom: 2px dashed var(--primary);
  padding-bottom: 5px;
}

.problem-content {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.problem-item {
  background-color: white;
  border: 1px solid #ced4da;
  border-radius: 6px;
  padding: 10px;
  cursor: pointer;
  font-size: 15px;
  font-weight: bold;
  transition: all 0.1s;
}

.problem-item:hover {
  border-color: var(--primary);
  transform: translateY(-1px);
}

.problem-item.active {
  background-color: var(--primary);
  color: white;
  border-color: var(--primary);
}

/* そろばん本体のデザイン（前回の正確な構造を維持） */
.soroban-section {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.soroban-wrapper {
  overflow-x: auto;
  padding: 10px 0;
  width: 100%;
}

.soroban {
  position: relative;
  height: 200px;
  background: var(--frame-color);
  border: 8px solid #8b5a2b;
  border-radius: 4px;
  box-shadow: inset 0 0 10px rgba(0,0,0,0.5);
  min-width: max-content;
  padding: 0 6px;
}

.beam {
  position: absolute;
  top: 55px;
  left: 0;
  right: 0;
  height: 8px;
  background: var(--beam-color);
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
  z-index: 5;
}

/* 梁の上の定位点 */
.teiiten {
  position: absolute;
  width: 6px;
  height: 6px;
  background: #fff;
  border-radius: 50%;
  top: 56px;
  left: 50%;
  transform: translateX(-50%);
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.5);
  z-index: 20;
}

.rods-container {
  display: flex;
  height: 100%;
}

.rod-col {
  position: relative;
  width: 38px;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.rod-col::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--rod-color);
  box-shadow: inset -1px 0 2px rgba(0,0,0,0.3);
  z-index: 1;
}

.bead {
  position: absolute;
  width: 32px;
  height: 18px;
  background: var(--bead-blue);
  clip-path: polygon(10% 0%, 90% 0%, 100% 50%, 90% 100%, 10% 100%, 0% 50%);
  z-index: 10;
  cursor: pointer;
  transition: transform 0.1s cubic-bezier(0.2, 0.8, 0.2, 1);
  box-shadow: inset 0 -2px 4px rgba(0,0,0,0.4), inset 0 1px 1px rgba(255,255,255,0.4);
}

.bead.go-bead { background: var(--bead-green); }

/* 珠の初期位置と移動定義 */
.go-bead { top: 6px; }
.go-bead.active { transform: translateY(28px); }

.ichi-bead-1 { top: 108px; }
.ichi-bead-2 { top: 128px; }
.ichi-bead-3 { top: 148px; }
.ichi-bead-4 { top: 168px; }

.ichi-bead-1.active { transform: translateY(-44px); }
.ichi-bead-2.active { transform: translateY(-44px); }
.ichi-bead-3.active { transform: translateY(-44px); }
.ichi-bead-4.active { transform: translateY(-44px); }

.display-box {
  background-color: white;
  border: 2px solid #dee2e6;
  border-radius: 8px;
  padding: 10px 20px;
  margin-top: 15px;
  text-align: center;
}

.display-label {
  font-size: 16px;
  color: #6c757d;
}

.current-number {
  font-size: 26px;
  font-weight: bold;
  color: var(--primary);
  letter-spacing: 2px;
}

/* アクション・指示エリア */
.action-area {
  grid-column: 1 / -1;
  background-color: #fff9db;
  border: 2px solid #fcc419;
  border-radius: 8px;
  padding: 15px;
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.instruction-box h3 {
  margin: 0 0 5px 0;
  color: #d9480f;
  font-size: 18px;
}

.hint-text {
  margin: 0;
  color: #495057;
  font-size: 15px;
}

.input-form-area {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.input-group {
  display: flex;
  gap: 10px;
}

input[type="text"] {
  font-family: inherit;
  font-size: 16px;
  padding: 8px 12px;
  border: 2px solid #ced4da;
  border-radius: 6px;
  width: 200px;
}

.action-btn {
  font-family: inherit;
  font-size: 16px;
  background-color: #fcc419;
  border: none;
  color: #343a40;
  padding: 8px 24px;
  border-radius: 20px;
  cursor: pointer;
  font-weight: bold;
  transition: transform 0.1s;
}

.action-btn:hover {
  transform: scale(1.05);
}

.check-btn {
  align-self: flex-start;
  background-color: var(--primary);
  color: white;
}

.success-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.success-box {
  background: white;
  padding: 30px 50px;
  border-radius: 16px;
  text-align: center;
  animation: popIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.success-box h3 {
  font-size: 32px;
  color: var(--warning);
  margin: 0 0 15px 0;
}

.hidden { display: none !important; }

@keyframes popIn {
  from { transform: scale(0.5); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}