/* ===========================================
   しわけこうじょう - デザイン改善版
   =========================================== */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: 'Zen Maru Gothic', sans-serif;
  touch-action: none;
  user-select: none;
}

body {
  background: linear-gradient(180deg, #87CEEB 0%, #E0F7FA 50%, #B2EBF2 100%);
}

.home-btn {
  position: fixed;
  top: 12px;
  left: 12px;
  width: 48px;
  height: 48px;
  background: white;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 1.4rem;
  text-decoration: none;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 9999;
  border: 3px solid #FFB74D;
}

#game-container {
  max-width: 500px;
  height: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  position: relative;
  background: linear-gradient(180deg, #ECEFF1 0%, #CFD8DC 100%);
}

/* Header */
.header {
  padding: 55px 15px 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: linear-gradient(180deg, #455A64 0%, #37474F 100%);
}

.level-badge {
  background: #FF9800;
  color: white;
  padding: 8px 15px;
  border-radius: 20px;
  font-weight: bold;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  gap: 5px;
  box-shadow: 0 3px 0 #E65100;
}

.level-icon {
  font-size: 1.1rem;
}

.timer-display {
  background: white;
  padding: 8px 15px;
  border-radius: 20px;
  font-weight: bold;
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 1.1rem;
  box-shadow: 0 3px 0 #BDBDBD;
}

.timer-display.warning {
  background: #FFCDD2;
  color: #C62828;
  animation: timerPulse 0.5s ease-in-out infinite alternate;
  box-shadow: 0 3px 0 #EF9A9A;
}

@keyframes timerPulse {
  from {
    transform: scale(1);
  }

  to {
    transform: scale(1.08);
  }
}

.timer-icon {
  font-size: 1.2rem;
}

.timer-unit {
  font-size: 0.7rem;
  color: #666;
}

.score-display {
  background: #4CAF50;
  color: white;
  padding: 8px 15px;
  border-radius: 20px;
  font-weight: bold;
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 1.1rem;
  box-shadow: 0 3px 0 #388E3C;
}

.score-icon {
  font-size: 1.2rem;
}

/* Level Name */
.level-name {
  text-align: center;
  background: rgba(255, 255, 255, 0.9);
  padding: 8px 20px;
  margin: 10px auto;
  border-radius: 20px;
  font-weight: bold;
  color: #37474F;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* Combo Popup */
.combo-popup {
  position: fixed;
  top: 130px;
  left: 50%;
  transform: translateX(-50%);
  background: linear-gradient(135deg, #FFD700 0%, #FFA000 100%);
  color: #5D4037;
  padding: 12px 28px;
  border-radius: 30px;
  font-size: 1.4rem;
  font-weight: bold;
  animation: comboPop 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
  z-index: 100;
  box-shadow: 0 5px 20px rgba(255, 152, 0, 0.4);
}

.combo-popup.hidden {
  display: none;
}

@keyframes comboPop {
  0% {
    transform: translateX(-50%) scale(0);
  }

  100% {
    transform: translateX(-50%) scale(1);
  }
}

/* Conveyor Section */
.conveyor-section {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 0;
  /* 幅いっぱいにするためパディング削除 */
  width: 100%;
}

.conveyor-machine {
  width: 100%;
  /* max-width removed */
  position: relative;
}

.machine-top {
  height: 30px;
  background: linear-gradient(180deg, #78909C 0%, #546E7A 100%);
  border-radius: 15px 15px 0 0;
  margin-bottom: -5px;
}

.conveyor-belt {
  background: #37474F;
  padding: 15px;
  border-radius: 10px;
  position: relative;
}

.belt-rollers {
  display: flex;
  justify-content: space-between;
  position: absolute;
  bottom: 5px;
  left: 15px;
  right: 15px;
}

.roller {
  width: 30px;
  height: 30px;
  background: radial-gradient(circle at 30% 30%, #90A4AE 0%, #546E7A 100%);
  border-radius: 50%;
  animation: rollerSpin 1s linear infinite;
}

@keyframes rollerSpin {
  from {
    transform: rotate(0deg);
  }

  to {
    transform: rotate(360deg);
  }
}

.belt-surface {
  height: 60px;
  background: repeating-linear-gradient(90deg,
      #455A64 0px,
      #455A64 25px,
      #37474F 25px,
      #37474F 50px);
  border-radius: 5px;
  animation: beltMove 0.8s linear infinite;
  border: 3px solid #263238;
}

@keyframes beltMove {
  from {
    background-position-x: 0;
  }

  to {
    background-position-x: 50px;
  }
}

.item-on-belt {
  position: absolute;
  top: 50%;
  left: 0;
  transform: translateY(-50%);
  width: 100%;
  height: 100%;
  pointer-events: none;
  /* クリックはボックスの方で判定する */
}

@keyframes itemBounce {

  0%,
  100% {
    transform: translate(-50%, -50%) translateY(0);
  }

  50% {
    transform: translate(-50%, -50%) translateY(-8px);
  }
}

.game-item {
  font-size: 4.5rem;
  cursor: grab;
  filter: drop-shadow(0 8px 15px rgba(0, 0, 0, 0.3));
  position: absolute;
  /* JSでleftを制御 */
  top: 50%;
  left: 0;
  transform: translate(-50%, -50%);
  /* 中心基準 */
}

.game-item.dragging {
  cursor: grabbing;
  transform: scale(1.3);
  animation: none;
}

.game-item.flying {
  transition: all 0.35s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

/* Boxes Section */
.boxes-section {
  background: linear-gradient(180deg, #ECEFF1 0%, #CFD8DC 100%);
  padding: 15px 20px 25px;
  border-radius: 30px 30px 0 0;
}

.boxes-title {
  text-align: center;
  font-weight: bold;
  color: #455A64;
  margin-bottom: 15px;
  font-size: 1.1rem;
}

.boxes-area {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

.sort-box {
  width: 90px;
  height: 105px;
  border-radius: 20px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  transition: all 0.15s;
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.25);
  border: 4px solid rgba(255, 255, 255, 0.3);
}

.sort-box:active {
  transform: translateY(6px);
  box-shadow: 0 0 0 rgba(0, 0, 0, 0.25);
}

.sort-box.correct {
  animation: boxBounce 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

@keyframes boxBounce {

  0%,
  100% {
    transform: scale(1);
  }

  50% {
    transform: scale(1.2);
  }
}

.sort-box.wrong {
  animation: boxShake 0.4s ease-in-out;
}

@keyframes boxShake {

  0%,
  100% {
    transform: translateX(0);
  }

  20% {
    transform: translateX(-8px);
  }

  40% {
    transform: translateX(8px);
  }

  60% {
    transform: translateX(-4px);
  }

  80% {
    transform: translateX(4px);
  }
}

.sort-box.hint {
  animation: hintGlow 0.8s ease-in-out infinite;
}

@keyframes hintGlow {

  0%,
  100% {
    box-shadow: 0 6px 0 rgba(0, 0, 0, 0.25), 0 0 0 0 rgba(255, 255, 255, 0.8);
  }

  50% {
    box-shadow: 0 6px 0 rgba(0, 0, 0, 0.25), 0 0 0 12px rgba(255, 255, 255, 0);
  }
}

/* Box Colors */
.box-red {
  background: linear-gradient(135deg, #EF5350 0%, #E53935 100%);
}

.box-blue {
  background: linear-gradient(135deg, #42A5F5 0%, #1E88E5 100%);
}

.box-yellow {
  background: linear-gradient(135deg, #FFEE58 0%, #FDD835 100%);
}

.box-green {
  background: linear-gradient(135deg, #66BB6A 0%, #43A047 100%);
}

.box-purple {
  background: linear-gradient(135deg, #AB47BC 0%, #8E24AA 100%);
}

.box-icon {
  font-size: 2.2rem;
  margin-bottom: 5px;
}

.box-label {
  font-size: 0.85rem;
  font-weight: bold;
  color: white;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

/* Particles */
#particles {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 200;
}

.particle {
  position: absolute;
  font-size: 2rem;
  animation: particleFly 1s ease-out forwards;
}

@keyframes particleFly {
  0% {
    transform: translate(0, 0) scale(1);
    opacity: 1;
  }

  100% {
    transform: translate(var(--tx), var(--ty)) scale(0);
    opacity: 0;
  }
}

/* Overlays */
.overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(8px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 2000;
}

.overlay.hidden {
  display: none;
}

.clear-modal,
.gameover-modal {
  background: white;
  border-radius: 30px;
  padding: 25px;
  text-align: center;
  animation: modalPop 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
  max-width: 320px;
  width: 90%;
}

@keyframes modalPop {
  0% {
    transform: scale(0);
  }

  100% {
    transform: scale(1);
  }
}

.clear-banner,
.gameover-banner {
  width: 200px;
  height: auto;
  margin-bottom: 10px;
}

.clear-title {
  font-size: 1.6rem;
  color: #4CAF50;
  margin-bottom: 15px;
}

.gameover-title {
  font-size: 1.6rem;
  color: #FF9800;
  margin-bottom: 10px;
}

.clear-stats {
  display: flex;
  justify-content: center;
  gap: 30px;
  margin-bottom: 15px;
}

.stat {
  text-align: center;
}

.stat-value {
  display: block;
  font-size: 2.2rem;
  font-weight: bold;
  color: #FF9800;
}

.stat-label {
  font-size: 0.8rem;
  color: #666;
}

.clear-msg,
.gameover-msg {
  color: #666;
  margin-bottom: 20px;
  font-size: 1rem;
}

.btn-next,
.btn-retry {
  background: linear-gradient(135deg, #4CAF50 0%, #43A047 100%);
  color: white;
  border: none;
  padding: 15px 30px;
  font-size: 1.2rem;
  font-weight: bold;
  border-radius: 50px;
  cursor: pointer;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 4px 0 #2E7D32;
}

.btn-retry {
  background: linear-gradient(135deg, #FF9800 0%, #F57C00 100%);
  box-shadow: 0 4px 0 #E65100;
}

.btn-next:active,
.btn-retry:active {
  transform: translateY(4px);
  box-shadow: none;
}

.btn-arrow {
  font-size: 1.4rem;
}