:root {
  --primary-color: #4a90e2;
  --secondary-color: #f5f5f5;
  --text-color: #333;
  --accent-color: #ff9800;
  --border-color: #ddd;
}

* {
  box-sizing: border-box;
}

body {
  font-family: "Helvetica Neue", Arial, "Hiragino Kaku Gothic ProN", "Hiragino Sans", Meiryo, sans-serif;
  margin: 0;
  padding: 0;
  background-color: #f9f9f9;
  color: var(--text-color);
}

.app-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

header {
  background-color: white;
  padding: 15px 20px;
  border-radius: 12px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
  margin-bottom: 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 15px;
}

h1 {
  margin: 0;
  font-size: 1.5rem;
  color: var(--primary-color);
}

.controls {
  display: flex;
  align-items: center;
  gap: 15px;
}

.input-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.input-group input {
  font-size: 1.2rem;
  padding: 8px;
  width: 80px;
  text-align: center;
  border: 2px solid var(--border-color);
  border-radius: 6px;
}

.operator {
  font-size: 1.5rem;
  font-weight: bold;
  margin: 0 5px;
}

button#start-btn {
  background-color: var(--primary-color);
  color: white;
  border: none;
  padding: 10px 20px;
  font-size: 1rem;
  border-radius: 6px;
  cursor: pointer;
  transition: background-color 0.2s;
  font-weight: bold;
}

button#start-btn:hover {
  background-color: #357abd;
}

.workspace {
  display: flex;
  flex: 1;
  gap: 20px;
  min-height: 0;
  /* Enable scrolling within flex items */
}

.calc-panel,
.visual-panel {
  background-color: white;
  border-radius: 12px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
  padding: 20px;
  display: flex;
  flex-direction: column;
}

.calc-panel {
  flex: 1;
  max-width: 400px;
}

.visual-panel {
  flex: 2;
  background-color: #fffaf0;
  /* Light cream for differentiation */
}

h2 {
  font-size: 1.2rem;
  margin-top: 0;
  border-bottom: 2px solid var(--secondary-color);
  padding-bottom: 10px;
  margin-bottom: 15px;
}

.calc-container {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  font-family: 'Courier New', Courier, monospace;
  font-size: 2rem;
  padding-top: 20px;
}

.coins-header {
  margin-top: 10px;
}

.coin-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
  background-color: #fff8e1;
  border: 2px solid var(--border-color);
  border-radius: 8px;
  padding: 10px;
  min-height: 200px;
}

.place-col {
  display: flex;
  flex-direction: column;
  border-right: 2px dashed #ccc;
  min-height: 180px;
}

.place-col:last-child {
  border-right: none;
}

.col-label {
  text-align: center;
  font-weight: bold;
  background-color: rgba(0, 0, 0, 0.05);
  margin-bottom: 10px;
  padding: 5px;
  border-radius: 4px;
}

.coin-area {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 5px;
  padding: 5px;
}

/* For Addition: Upper and Lower rows within a column */
.operand-row {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  padding: 5px;
  min-height: 60px;
  border-bottom: 1px dotted #ddd;
}

.operand-row:last-child {
  border-bottom: none;
}

.coin {
  width: 50px;
  height: 50px;
  cursor: grab;
  transition: transform 0.1s;
  user-select: none;
}

.result-zone {
  margin-top: auto;
  /* Push to bottom */
  border: 3px dashed #aaa;
  background-color: rgba(255, 255, 255, 0.6);
  border-radius: 8px;
  min-height: 80px;
  padding: 5px;
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  align-items: center;
  justify-content: center;
  color: #aaa;
  font-size: 0.9rem;
  font-weight: bold;
}

.result-zone.drag-over {
  background-color: #e3f2fd;
  border-color: #2196f3;
  color: #2196f3;
}

.regroup-btn {
  width: 100%;
  margin-top: 5px;
  padding: 5px;
  background-color: #ff9800;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0% {
    transform: scale(1);
  }

  50% {
    transform: scale(1.05);
  }

  100% {
    transform: scale(1);
  }
}

.coin:active {
  cursor: grabbing;
  transform: scale(1.1);
}

.coin img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  /* Let parent handle drag */
}

.groups-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 15px;
  margin-top: 10px;
}

.group-box {
  border: 2px solid var(--border-color);
  border-radius: 8px;
  padding: 10px;
  min-height: 100px;
  background-color: white;
}

.placeholder-text {
  color: #999;
  font-size: 1rem;
}

/* Feedback Overlay */
#feedback-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(255, 255, 255, 0.8);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.5s;
}

#feedback-overlay.show {
  opacity: 1;
  pointer-events: auto;
}

.feedback-text {
  font-size: 5rem;
  color: #ff3366;
  font-weight: bold;
  text-shadow: 2px 2px 0px #fff, 4px 4px 0px rgba(0, 0, 0, 0.1);
  transform: scale(0);
  transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

#feedback-overlay.show .feedback-text {
  transform: scale(1);
  animation: feedbackPulse 1s infinite alternate;
}

@keyframes feedbackPulse {
  from {
    transform: scale(1);
  }

  to {
    transform: scale(1.1);
  }
}

.hidden {
  display: none !important;
}