/* ===== Reset ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --purple:       #5B21B6;
  --purple-light: #7C3AED;
  --purple-pale:  #EDE9FE;
  --gold:         #F59E0B;
  --gold-dark:    #D97706;
  --green:        #10B981;
  --red:          #EF4444;
  --gray-100:     #F3F4F6;
  --gray-300:     #D1D5DB;
  --gray-500:     #6B7280;
  --white:        #FFFFFF;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans TC', sans-serif;
  background: linear-gradient(160deg, #EDE9FE 0%, #FEF3C7 100%);
  min-height: 100vh;
  color: #1F2937;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

/* ===== Header ===== */
.app-header {
  background: var(--purple);
  color: var(--white);
  padding: 10px 16px 8px;
  text-align: center;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
}
.app-header h1 { font-size: 1.05rem; font-weight: 700; letter-spacing: 0.02em; }
.player-badge {
  display: inline-block;
  margin-top: 4px;
  font-size: 0.78rem;
  background: var(--gold);
  color: #78350F;
  padding: 2px 12px;
  border-radius: 99px;
  font-weight: 700;
}

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  backdrop-filter: blur(4px);
}
.modal-card {
  background: var(--white);
  border-radius: 20px;
  padding: 28px 22px 22px;
  width: 100%;
  max-width: 340px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.35);
  animation: slideUp 0.3s cubic-bezier(0.34,1.56,0.64,1);
}
@keyframes slideUp {
  from { transform: translateY(50px) scale(0.9); opacity: 0; }
  to   { transform: translateY(0)    scale(1);   opacity: 1; }
}
.modal-icon   { font-size: 2.8rem; margin-bottom: 10px; }
.modal-card h2 { font-size: 1.2rem; color: var(--purple); margin-bottom: 8px; line-height: 1.5; }
.modal-desc   { color: var(--gray-500); font-size: 0.88rem; margin-bottom: 6px; }
.modal-actions { display: flex; gap: 10px; margin-top: 4px; }
.modal-actions .btn-primary,
.modal-actions .btn-secondary { margin-top: 0; flex: 1; }

/* ===== Win card ===== */
.win-card .win-emoji { font-size: 3.5rem; margin-bottom: 6px; }
.win-card { animation: winPop 0.45s cubic-bezier(0.34,1.56,0.64,1); }
@keyframes winPop {
  from { transform: scale(0.4); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}

/* ===== Input ===== */
input[type="text"] {
  width: 100%;
  padding: 11px 14px;
  border: 2px solid var(--gray-300);
  border-radius: 12px;
  font-size: 1rem;
  margin-top: 14px;
  outline: none;
  transition: border-color 0.2s;
  font-family: inherit;
}
input[type="text"]:focus { border-color: var(--purple-light); }

/* ===== Buttons ===== */
.btn-primary {
  display: block;
  width: 100%;
  background: var(--purple);
  color: var(--white);
  border: none;
  padding: 13px 20px;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  margin-top: 14px;
  transition: background 0.15s, transform 0.1s;
  font-family: inherit;
}
.btn-primary:hover  { background: var(--purple-light); }
.btn-primary:active { transform: scale(0.97); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary {
  display: block;
  width: 100%;
  background: var(--gray-100);
  color: var(--gray-500);
  border: none;
  padding: 13px 20px;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  margin-top: 14px;
  font-family: inherit;
}

.btn-confirm {
  max-width: 220px;
  margin: 16px auto 0;
  background: var(--gold-dark);
  font-size: 1.05rem;
}
.btn-confirm:hover { background: var(--gold); }

.error-msg { color: var(--red); font-size: 0.83rem; margin-top: 6px; min-height: 18px; }

/* ===== Sections ===== */
#setup-phase, #game-phase {
  padding: 12px 14px 100px;
  max-width: 420px;
  margin: 0 auto;
}
.hint-text {
  text-align: center;
  color: var(--purple);
  font-weight: 600;
  font-size: 0.88rem;
  margin-bottom: 10px;
}
.progress-text {
  text-align: center;
  color: var(--gray-500);
  font-size: 0.83rem;
  margin: 8px 0 12px;
}
.pool-label {
  text-align: center;
  font-size: 0.8rem;
  color: var(--gray-500);
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  margin-bottom: 6px;
}
#icon-pool-wrap {
  background: rgba(255,255,255,0.55);
  border-radius: 14px;
  padding: 8px;
}

/* ===== Bingo Board ===== */
.bingo-board {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 7px;
  margin: 0 auto 6px;
  max-width: 340px;
}

/* ===== Bingo Cell ===== */
.bingo-cell {
  aspect-ratio: 1;
  border-radius: 50%;
  border: 2.5px dashed var(--gray-300);
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.7);
  position: relative;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
  transition: border-color 0.15s, transform 0.1s, background 0.15s;
}
.bingo-cell.occupied {
  border-style: solid;
  border-color: var(--purple);
  background: var(--white);
}
.bingo-cell.drag-over {
  border-color: var(--gold);
  border-style: solid;
  transform: scale(1.08);
  background: #FEF3C7;
}

/* 已抽出標記 */
.bingo-cell.drawn::after {
  content: '✓';
  position: absolute;
  inset: 0;
  background: rgba(16,185,129,0.82);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  color: var(--white);
  font-weight: 900;
  animation: markIn 0.35s cubic-bezier(0.34,1.56,0.64,1);
  pointer-events: none;
}
@keyframes markIn {
  from { transform: scale(0); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}

/* 連線高亮 */
.bingo-cell.line-complete {
  background: linear-gradient(135deg, #FEF3C7, #FDE68A);
  border-color: var(--gold-dark);
  box-shadow: 0 0 10px rgba(245,158,11,0.55);
}

/* ===== Icon Item ===== */
.icon-item {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: grab;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  font-size: 1.55rem;
  line-height: 1;
}
.icon-item:active  { cursor: grabbing; }
.icon-label {
  font-size: 0.42rem;
  color: rgba(255,255,255,0.92);
  font-weight: 700;
  margin-top: 2px;
  letter-spacing: 0.02em;
  max-width: 90%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Pool 空位（已放到板上的 icon） */
.pool-slot {
  aspect-ratio: 1;
  border-radius: 50%;
  overflow: hidden;
}
.pool-slot.used { visibility: hidden; }

/* ===== 拖曳替身 ===== */
.drag-ghost {
  position: fixed;
  pointer-events: none;
  z-index: 9999;
  border-radius: 50%;
  opacity: 0.88;
  transform: translate(-50%, -50%) scale(1.1);
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
  transition: opacity 0.1s;
}

/* ===== 遊戲階段 ===== */
#drawn-section { margin-top: 18px; }
#drawn-section h3 {
  font-size: 0.88rem;
  color: var(--purple);
  margin-bottom: 8px;
  font-weight: 700;
}
#drawn-icons { display: flex; flex-wrap: wrap; gap: 6px; }
.drawn-badge {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  animation: popIn 0.35s cubic-bezier(0.34,1.56,0.64,1);
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
}
@keyframes popIn {
  from { transform: scale(0); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}

#winner-section {
  margin-top: 16px;
  padding: 12px 14px;
  background: #FEF3C7;
  border-radius: 14px;
  border: 1.5px solid var(--gold);
}
#winner-section h3 { color: var(--gold-dark); font-size: 0.9rem; margin-bottom: 8px; }
.winner-chip {
  display: inline-block;
  background: var(--gold);
  color: #78350F;
  padding: 4px 12px;
  border-radius: 99px;
  font-weight: 700;
  font-size: 0.85rem;
  margin: 3px 3px 0 0;
}

/* ===== Utility ===== */
.hidden { display: none !important; }
