/* =============== Base =============== */
:root{
  --bg1:#0b1220;
  --bg2:#111a2e;
  --card: rgba(255,255,255,.08);
  --card2: rgba(255,255,255,.10);
  --stroke: rgba(255,255,255,.14);
  --text: rgba(255,255,255,.92);
  --muted: rgba(255,255,255,.68);
  --muted2: rgba(255,255,255,.50);
  --shadow: 0 18px 60px rgba(0,0,0,.45);
  --shadow2: 0 10px 30px rgba(0,0,0,.30);
  --radius: 22px;
  --radius2: 16px;
  --primary: #7c5cff;
  --primary2:#30d5c8;
  --danger:#ff4d6d;
  --good:#4ade80;
}

*{ box-sizing:border-box; }

html, body{
  /* 修改點：從 height 改為 min-height，並使用 100vh 確保至少填滿視窗 */
  min-height: 100vh;
  /* 確保沒有多餘的捲軸 */
  width: 100%; 
}

body {
  margin: 0;
  font-family: 'Varela Round', system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans TC", Arial, sans-serif;
  color: var(--text);
  
  /* 背景設定維持不變 */
  background:
    radial-gradient(1200px 700px at 10% 10%, rgba(124,92,255,.35), transparent 55%),
    radial-gradient(1000px 600px at 85% 20%, rgba(48,213,200,.25), transparent 55%),
    radial-gradient(900px 700px at 50% 100%, rgba(255,77,109,.14), transparent 55%),
    linear-gradient(180deg, var(--bg1), var(--bg2));
    
  /* ★★★ 關鍵修改：加上這行，讓背景固定不動，像窗外的風景一樣 ★★★ */
  background-attachment: fixed;
  
  /* 確保背景覆蓋整個區域 */
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;

  /* Flex 設定微調：確保內容多時也能正常捲動 */
  display: flex;
  justify-content: center;
  /* 如果內容太長，align-items: center 會導致頂部被切掉，建議改用 padding 控制垂直空間 */
  align-items: center; 
  /* 為了保險起見，可以針對手機版面增加一點 padding-bottom */
  padding-bottom: 20px;
  
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* =============== Ambient blobs =============== */
.bg-blob{
  position:absolute;
  border-radius:50%;
  filter: blur(55px);
  z-index:-1;
  opacity:.55;
  transform: translateZ(0);
}

.b1{
  width:380px;height:380px;
  background: rgba(124,92,255,.55);
  top:-120px;left:-140px;
  animation: float 10s ease-in-out infinite;
}
.b2{
  width:340px;height:340px;
  background: rgba(48,213,200,.45);
  bottom:-140px;right:-120px;
  animation: float 12s ease-in-out infinite reverse;
}
.b3{
  width:220px;height:220px;
  background: rgba(255,77,109,.35);
  top:44%;left:78%;
  animation: float 14s ease-in-out infinite;
}

@keyframes float{
  0%{ transform: translate(0,0) scale(1); }
  50%{ transform: translate(18px,28px) scale(1.04); }
  100%{ transform: translate(-8px,14px) scale(1.01); }
}

/* =============== Layout =============== */
.app-container{
  width:min(520px, 92vw);
  padding: 28px 16px 18px;
  display:flex;
  flex-direction:column;
  gap: 12px; /* 稍微縮小間距，讓畫面更緊湊 */
}

/* =============== Header =============== */
.main-header{
  display:flex;
  justify-content:center;
  align-items:center;
  margin-bottom: 2px;
}
.main-header h1{
  margin:0;
  font-size: clamp(1.6rem, 3.4vw, 2.1rem);
  letter-spacing: .6px;
  font-weight: 800;
  line-height:1.15;
  background: linear-gradient(90deg, rgba(255,255,255,.95), rgba(255,255,255,.65));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 10px 30px rgba(0,0,0,.25);
}

/* =============== Cards =============== */
.glass-card{
  background: linear-gradient(180deg, var(--card2), var(--card));
  border: 1px solid var(--stroke);
  border-radius: var(--radius);
  box-shadow: var(--shadow2);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  padding: 18px;
}

/* main game card */
.main-card{
  padding: 22px 18px 18px;
  text-align:center;
}

/* =============== Stats Bar (NEW) =============== */
.stats-bar {
  display: flex;
  justify-content: space-around;
  align-items: center;
  padding: 12px 16px;
  border-radius: var(--radius2);
  background: rgba(255,255,255,.05); /* 稍微深一點 */
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.stat-label {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.stat-value {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--primary2);
  text-shadow: 0 4px 12px rgba(48,213,200,.25);
}

.divider {
  width: 1px;
  height: 24px;
  background: rgba(255,255,255,.1);
}

/* =============== Score =============== */
.score-board{
  display:flex;
  align-items:baseline;
  justify-content:center;
  gap: 10px;
  margin-top: 6px;
}

#score{
  font-size: clamp(3.2rem, 8vw, 4.3rem);
  font-weight: 900;
  letter-spacing: .5px;
  text-shadow: 0 14px 40px rgba(0,0,0,.35);
}

.unit{
  font-size: 1.05rem;
  color: var(--muted);
  transform: translateY(-6px);
}

/* =============== Sheep button =============== */
.click-zone{ margin: 14px 0 6px; }

.sheep-btn{
  font-size: clamp(5.2rem, 14vw, 6.6rem);
  background: radial-gradient(120px 120px at 50% 40%, rgba(255,255,255,.14), rgba(255,255,255,0));
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 999px;
  padding: 14px 22px;
  cursor:pointer;
  box-shadow: 0 18px 60px rgba(0,0,0,.35);
  transition: transform .12s ease, box-shadow .12s ease, filter .12s ease;
  user-select:none;
  -webkit-tap-highlight-color: transparent;
}

.sheep-btn:hover{
  transform: translateY(-2px);
  box-shadow: 0 22px 70px rgba(0,0,0,.40);
}

.sheep-btn:active{
  transform: translateY(1px) scale(.96);
  filter: brightness(1.05);
}

/* small hint */
.hint{
  margin: 8px 0 0;
  font-size:.92rem;
  color: var(--muted2);
  min-height: 1.2em; /* 防止文字跳動 */
}

/* =============== Leaderboard =============== */
.leaderboard-card{
  padding: 18px;
}

.card-title{
  display:flex;
  align-items:center;
  justify-content:center;
  gap: 10px;
  font-size: 1.1rem;
  font-weight: 800;
  color: rgba(255,255,255,.92);
  margin-bottom: 12px;
}

.card-title i{
  color: rgba(255,255,255,.85);
  filter: drop-shadow(0 8px 16px rgba(0,0,0,.25));
}

/* input row */
.input-area{
  display:flex;
  gap: 10px;
  align-items:center;
  margin-bottom: 8px;
}

input[type="text"]{
  flex:1;
  height: 44px;
  padding: 0 14px;
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,.14);
  background: rgba(0,0,0,.18);
  color: var(--text);
  outline:none;
  transition: border .2s ease, box-shadow .2s ease, background .2s ease;
}

input::placeholder{ color: rgba(255,255,255,.45); }

input:focus{
  border-color: rgba(124,92,255,.55);
  box-shadow: 0 0 0 4px rgba(124,92,255,.18);
  background: rgba(0,0,0,.22);
}

/* buttons */
button{
  border:none;
  border-radius: 14px;
  font-family: inherit;
  font-weight: 800;
  cursor:pointer;
  transition: transform .12s ease, box-shadow .2s ease, filter .2s ease, background .2s ease, opacity .2s ease;
}

#upload-btn{
  height: 44px;
  padding: 0 16px;
  color: rgba(10,10,14,.92);
  background: linear-gradient(135deg, var(--primary), var(--primary2));
  box-shadow: 0 12px 30px rgba(124,92,255,.22);
}

#upload-btn:hover{
  filter: brightness(1.06);
  transform: translateY(-1px);
}

#upload-btn:active{
  transform: translateY(0px) scale(.98);
}

#upload-btn:disabled{
  opacity:.45;
  cursor:not-allowed;
  filter: grayscale(.2);
  box-shadow:none;
}

/* status msg */
.status-msg{
  min-height: 22px;
  font-size: .88rem;
  color: var(--muted);
  margin-bottom: 10px;
}

/* table wrapper */
.list-wrapper{
  border-radius: var(--radius2);
  overflow:hidden;
  border: 1px solid rgba(255,255,255,.12);
  background: rgba(0,0,0,.16);
}

table{
  width:100%;
  border-collapse: collapse;
}

thead th{
  padding: 10px 12px;
  text-align:left;
  font-size: .86rem;
  color: rgba(255,255,255,.70);
  background: rgba(255,255,255,.06);
  border-bottom: 1px solid rgba(255,255,255,.10);
}

tbody td{
  padding: 11px 12px;
  font-size: .98rem;
  color: rgba(255,255,255,.88);
  border-bottom: 1px solid rgba(255,255,255,.06);
}

tbody tr:hover td{
  background: rgba(255,255,255,.04);
}

/* rank medal styles (first col) */
tbody tr:nth-child(1) td:first-child{ color: #ffd166; font-weight: 900; }
tbody tr:nth-child(2) td:first-child{ color: #d0d7de; font-weight: 900; }
tbody tr:nth-child(3) td:first-child{ color: #f4a261; font-weight: 900; }

tbody tr:last-child td{ border-bottom:none; }

/* refresh button */
.refresh-btn{
  margin-top: 12px;
  width:100%;
  height: 44px;
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.14);
  color: rgba(255,255,255,.88);
  box-shadow: 0 14px 40px rgba(0,0,0,.25);
}

.refresh-btn:hover{
  background: rgba(255,255,255,.10);
  transform: translateY(-1px);
}

.refresh-btn:active{
  transform: translateY(0px) scale(.99);
}

/* footer */
.footer{
  text-align:center;
  color: rgba(255,255,255,.55);
  font-size: .82rem;
  margin-top: 6px;
}

/* =============== Message Toast (NEW) =============== */
.message-toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(124, 92, 255, 0.9);
  color: white;
  padding: 12px 24px;
  border-radius: 50px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.3);
  font-weight: bold;
  font-size: 1rem;
  z-index: 1000;
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255,255,255,0.2);
  transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  opacity: 1;
}

.message-toast.hidden {
  transform: translateX(-50%) translateY(50px);
  opacity: 0;
  pointer-events: none;
}

/* small screens */
@media (max-width: 380px){
  .input-area{ flex-direction: column; }
  #upload-btn{ width:100%; }
}

/* =========================================
   新功能：點擊動畫與圖片樣式
   ========================================= */

/* --- 1. 圖片模式按鈕樣式優化 --- */
.sheep-btn.image-mode {
  /* 調整內距，讓圖片在圓圈中更好看 */
  padding: 15px;
  /* 確保圖片超出圓角時被切裁 */
  overflow: hidden; 
  /* 讓按鈕本身成為定位基準點，給 +1 動畫使用 */
  position: relative; 
}

/* 確保這一段存在於你的 style.css 中 */
.sheep-btn.image-mode img {
  width: 100%;
  height: auto;
  display: block;
  pointer-events: none; /* <--- 這一行絕對不能少 */
  transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), filter 0.2s ease;
}

/* 滑鼠懸停時，圖片稍微放大並旋轉一點點，增加動態感 */
.sheep-btn.image-mode:hover img {
  transform: scale(1.08) rotate(3deg);
}

/* 點擊按下時，圖片被壓扁並下沉，模擬Ｑ彈感 */
.sheep-btn.image-mode:active img {
  transform: scale(0.9) translateY(10px) rotate(-3deg);
  filter: brightness(0.9);
}

/* --- 2. "+1" 浮動粒子動畫 --- */
.plus-one-particle {
    position: absolute;
    font-weight: 900;
    font-size: 2rem;
    color: var(--primary2); /* 使用你原本定義的青色 */
    text-shadow: 0 2px 10px rgba(0,0,0,0.5);
    pointer-events: none; /* 確保不擋住滑鼠 */
    user-select: none;
    z-index: 10;
    /* 初始位置在中心，並縮小 */
    transform: translate(-50%, -50%) scale(0.5);
    opacity: 0;
    /* 執行浮動動畫 */
    animation: floatUp 0.8s cubic-bezier(0.23, 1, 0.32, 1) forwards;
}

/* 定義浮動動畫的關鍵影格 */
@keyframes floatUp {
    0% {
        opacity: 0;
        transform: translate(-50%, -20%) scale(0.5);
    }
    20% {
        opacity: 1;
        transform: translate(-50%, -100%) scale(1.2); /* 變大並往上衝 */
    }
    100% {
        opacity: 0;
        transform: translate(-50%, -250%) scale(1); /* 繼續往上並消失 */
    }
}