@import url("https://fonts.googleapis.com/css2?family=Bungee&family=Chiron+GoRound+TC:wght@400;900&display=swap");

* {
  box-sizing: border-box;
  font-family: "Chiron GoRound TC", sans-serif;
  font-weight: 900;
  touch-action: manipulation;
}

body {
  margin: 0;
  overflow: hidden;
  background-color: #f6f3eb;
  user-select: none;
}

/* --- 遮罩：中間透明，上下實色 --- */
.gradient-mask {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 5;
  /* 這裡調整了漸層比例，讓圓柱體看起來更像埋在裡面 */
  background: linear-gradient(
    to bottom,
    #f6f3eb 0%,
    #f6f3eb 20%,
    rgba(246, 243, 235, 0) 40%,
    rgba(246, 243, 235, 0) 60%,
    #f6f3eb 80%,
    #f6f3eb 100%
  );

  @media (max-aspect-ratio: 1/1) {
    top: 50% !important;
    left: 0 !important;
    transform: translate(0, -50%);
    height: 53% !important;
  }
}

#ui-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 10;
}

/*  狀態板  */
.status-board {
  position: absolute;
  top: 8%; /* 稍微往下移 */
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
  #awards-text {
    font-family: "Bungee", serif;
    font-size: 46px;
    text-transform: uppercase;
    color: #725349;
    text-shadow: 4px 4px 0 #f6f3eb, -4px -4px 0 #f6f3eb, 4px -4px 0 #f6f3eb,
      -4px 4px 0 #f6f3eb, 0px 4px 0 #f6f3eb, 4px 0px 0 #f6f3eb,
      0px -4px 0 #f6f3eb, -4px 0px 0 #f6f3eb;
    white-space: nowrap;

    @media (max-width: 600px) {
      font-size: 38px;
    }
  }
  #status-text {
    text-transform: uppercase;
    color: #a78276;
    font-size: 24px;
    text-shadow: 4px 4px 0 #f6f3eb, -4px -4px 0 #f6f3eb, 4px -4px 0 #f6f3eb,
      -4px 4px 0 #f6f3eb, 0px 4px 0 #f6f3eb, 4px 0px 0 #f6f3eb,
      0px -4px 0 #f6f3eb, -4px 0px 0 #f6f3eb;
  }
  @media (max-aspect-ratio: 1/1) {
    top: 13%;
  }
}

/* 機器暫停按鈕 */
.reel-controls {
  position: absolute;
  bottom: 15%;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 20px;
  pointer-events: auto;
  justify-content: center;
  .control-group {
    flex: 1;
    display: flex;
    justify-content: center;
  }
  .stop-btn {
    width: 100%;
    max-width: 100px;
    width: 120px;
    height: 60px;
    background: #e05a47;
    border: 7px solid #725349;
    border-radius: 20px;
    color: white;
    font-size: 18px;
    line-height: 18px;
    cursor: pointer;
    box-shadow: 0 4px 0 #72534935;
    transition: transform 0.1s, background 0.2s;
    font-family: "Bungee", serif;
    &:active {
      transform: translateY(4px);
      box-shadow: none;
    }
    &:disabled {
      background: #d6cec0;
      color: #a89f91;
      border-color: #a89f91;
      cursor: default;
      transform: translateY(4px);
      box-shadow: none;
    }
    @media (max-aspect-ratio: 1/1) {
      border: 5px solid #725349;
    }
  }
  @media (max-aspect-ratio: 1/1) {
    bottom: 20%;
  }
}

/* 左上角控制區 */
.top-left-controls {
  position: absolute;
  top: 20px;
  left: 20px;
  pointer-events: auto;
  z-index: 100;
  .back-btn {
    display: block;
    width: 100%;
    padding: 12px 16px;
    text-align: center;
    background: #e6be9154;
    border-radius: 100px;
    color: #752f11;
    font-size: 16px;
    text-decoration: none;
    transition: transform 0.1s, box-shadow 0.1s;
    &:hover {
      background: #e6be917a;
    }
    i {
      margin-right: 8px;
    }
  }
}

/* 右下角控制區 */
.bottom-right-controls {
  position: absolute;
  bottom: 20px;
  right: 20px;
  display: flex;
  gap: 8px;
  pointer-events: auto;
  align-items: flex-end;
}

/* 右上角分數區 */
.top-right-controls {
  position: absolute;
  top: 20px;
  right: 20px;
  pointer-events: auto;
  z-index: 100;
}

.score-board {
  padding: 12px;
  text-align: right;

  @media (max-aspect-ratio: 1/1) {
    padding: 0;
  }

  #score-value {
    font-family: "Bungee", serif;
    font-size: 48px;
    color: #725349; /* 改為棕色 */
    line-height: 1;
    text-shadow: 2px 2px 0 #f6f3eb;
    transition: color 0.2s;
    display: inline-block;
    @media (max-aspect-ratio: 1/1) {
      font-size: 40px;
    }
  }

  #spin-count-value {
    font-family: "Bungee", serif;
    font-size: 28px;
    color: #a78276;
    @media (max-aspect-ratio: 1/1) {
      font-size: 20px;
    }
  }

  .score-update {
    animation: score-pulse 0.3s ease-in-out;
    color: #e05a47 !important; /* 閃爍紅色 */
  }

  .score-deduct {
    animation: score-pulse 0.3s ease-in-out;
    color: #a78276 !important; /* 閃爍淺棕色 */
  }
}

@keyframes score-pulse {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.3);
  }
  100% {
    transform: scale(1);
  }
}

/* 左下角控制區 (RESET) */
.bottom-left-controls {
  position: absolute;
  bottom: 20px;
  left: 20px;
  pointer-events: auto;
}

.circle-btn {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  border: 5px solid #725349;
  background: #f2c94c;
  color: #725349;
  font-size: 16px;
  cursor: pointer;
  box-shadow: 0 4px 0 #72534935;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  transition: transform 0.1s, box-shadow 0.1s;
  line-height: 1.2;
  &:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 rgba(0, 0, 0, 0.2);
  }
  &.mix {
    background: #4d9bea;
    color: white;
  }
  &.restart {
    background: #fff;
    color: #725349;
  }
  &.pick {
    background: #e05a47;
    color: white;
    width: 80px;
    height: 80px;
    z-index: 10;
  }
  &:disabled {
    filter: grayscale(0.8);
    cursor: default;
  }
}

/* --- Modal 通用淡入淡出設定 --- */
.modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(114, 83, 73, 0.6);
  /* 重複斜線 */
  background: linear-gradient(
    45deg,
    rgba(114, 83, 73, 0.5) 25%,
    rgba(130, 97, 87, 0.5) 0,
    rgba(130, 97, 87, 0.5) 50%,
    rgba(114, 83, 73, 0.5) 0,
    rgba(114, 83, 73, 0.5) 75%,
    rgba(130, 97, 87, 0.5) 0
  );
  background-size: 120px 120px;
  backdrop-filter: blur(3px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100;

  /* 預設狀態 (隱藏) */
  opacity: 0;
  visibility: hidden;

  /* 
  淡出邏輯: 
  opacity 花 0.2s 變透明
  visibility 延遲 0.2s 後才變 hidden (確保淡出動畫播完)
  */
  transition: opacity 0.2s ease, visibility 0s linear 0.2s;
}

.modal-overlay.show {
  /* 顯示狀態 */
  opacity: 1;
  visibility: visible;

  /* 
  淡入邏輯:
  opacity 花 0.2s 變不透明
  visibility 不需要延遲，馬上變 visible
  */
  transition: opacity 0.2s ease, visibility 0s linear 0s;
}

.modal-content {
  background: #f6f3eb;
  border: 5px solid #725349;
  border-radius: 20px;
  width: 380px;
  box-shadow: 0 8px 0 rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-content.small {
  width: 320px;
  padding: 20px;
  text-align: center;
}
.modal-content.small h3 {
  color: #725349;
  font-size: 20px;
  margin: 10px 0 20px 0;
}

.modal-footer {
  padding: 16px 20px;
  border-top: 5px solid #725349;
  display: flex;
  gap: 12px;
}

.action-btn {
  flex: 1;
  padding: 12px;
  border-radius: 10px;
  font-size: 16px;
  cursor: pointer;
  border: 5px solid #725349;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.1);
}
.action-btn:active {
  transform: translateY(1px);
  box-shadow: none;
}

.btn-yes {
  background: #e05a47;
  color: white;
}
.btn-no {
  background: #fff;
  color: #725349;
}

/* --- 文字動畫 --- */
@keyframes pulse-text {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.1);
  }
  100% {
    transform: scale(1);
  }
}

.animate-win {
  display: inline-block; /* 必須是 block 或 inline-block 才能 transform */
  animation: pulse-text 0.8s infinite ease-in-out;
}

.animate-win.fast {
  animation: pulse-text 0.4s infinite ease-in-out;
}

#confetti-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 200;
}
