/* =============================================
   台灣大富翁 - 完整樣式
   ============================================= */

:root {
  --bg: #f0f4f8;
  --card-bg: #ffffff;
  --border: #e2e8f0;
  --primary: #6c3fc5;
  --primary-dark: #5a31a8;
  --success: #2ecc71;
  --danger: #e74c3c;
  --warning: #f39c12;
  --text: #1a202c;
  --text-muted: #718096;
  --board-bg: #c8e6c9;
  --cell-size: 70px;
  --corner-size: 100px;
  --shadow: 0 4px 20px rgba(0,0,0,0.12);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Segoe UI', 'Noto Sans TC', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ── SCREENS ── */
.screen { display: none; }
.screen.active { display: block; }

/* ── SETUP SCREEN ── */
#setup-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  min-height: 100vh;
  padding: 40px 20px;
}

.setup-card {
  background: var(--card-bg);
  border-radius: 16px;
  padding: 36px 40px;
  width: 100%;
  max-width: 520px;
  box-shadow: var(--shadow);
}

.setup-card h1 {
  text-align: center;
  font-size: 1.8rem;
  margin-bottom: 24px;
  color: var(--primary);
}

.form-group {
  margin-bottom: 18px;
}

.form-group label {
  display: block;
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 6px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-group select,
.form-group input[type="text"],
.form-group input[type="number"] {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 1rem;
  background: #fafafa;
  transition: border-color 0.2s;
}

.form-group select:focus,
.form-group input:focus {
  outline: none;
  border-color: var(--primary);
}

/* Player rows */
#players-config { display: flex; flex-direction: column; gap: 10px; }

.player-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.player-row input[type="text"] {
  flex: 1;
  padding: 8px 12px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 0.95rem;
}

.emoji-btn {
  width: 46px; height: 46px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: #fafafa;
  font-size: 1.4rem;
  cursor: pointer;
  transition: border-color 0.2s;
  display: flex; align-items: center; justify-content: center;
}
.emoji-btn:hover { border-color: var(--primary); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 11px 20px;
  border: none;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); transform: translateY(-1px); }

.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { filter: brightness(1.1); transform: translateY(-1px); }

.btn-danger  { background: var(--danger);  color: #fff; }
.btn-danger:hover  { filter: brightness(1.1); }

.btn-outline {
  background: transparent;
  border: 2px solid var(--primary);
  color: var(--primary);
}
.btn-outline:hover { background: var(--primary); color: #fff; }

.btn-gray {
  background: #6c757d;
  color: #fff;
}

.btn-block { width: 100%; }
.btn-sm { padding: 7px 14px; font-size: 0.85rem; }

.button-group { display: flex; gap: 10px; margin-top: 8px; flex-wrap: wrap; }
.button-group .btn { flex: 1; min-width: 140px; }

.setup-actions { margin-top: 24px; display: flex; flex-direction: column; gap: 10px; }

/* Question bank file area */
.file-area {
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 14px;
  text-align: center;
  font-size: 0.9rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color 0.2s;
}
.file-area:hover { border-color: var(--primary); color: var(--primary); }
.file-area.has-file { border-color: var(--success); color: var(--success); background: #f0fff4; }

/* ── GAME SCREEN ── */
#game-screen {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background: var(--bg);
}

#game-topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

#game-topbar h2 { flex: 1; font-size: 1.2rem; color: var(--primary); }
#timer-display { font-weight: 700; font-size: 1rem; color: var(--text-muted); min-width: 60px; }

#game-body {
  display: flex;
  gap: 16px;
  padding: 16px;
  flex: 1;
  overflow: auto;
}

/* ── BOARD ── */
#board-wrap {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-start;
}

#board {
  display: grid;
  grid-template-columns: var(--corner-size) repeat(9, var(--cell-size)) var(--corner-size);
  grid-template-rows:    var(--corner-size) repeat(9, var(--cell-size)) var(--corner-size);
  border: 3px solid #1a202c;
  background: var(--board-bg);
  box-shadow: var(--shadow);
  border-radius: 4px;
  overflow: hidden;
}

/* Board center logo */
#board-center {
  grid-row: 2 / 11;
  grid-column: 2 / 11;
  background: var(--board-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 8px;
}

#board-center h2 {
  font-size: 1.8rem;
  color: var(--primary);
  text-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

/* ── BOARD CELLS ── */
.cell {
  border: 1px solid rgba(0,0,0,0.15);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  background: #fff;
  font-size: 0.65rem;
  cursor: default;
  transition: background 0.2s;
}

.cell:hover { z-index: 5; }

/* Color banner */
.cell-banner {
  width: 100%;
  height: 14px;
  flex-shrink: 0;
}

/* Cell text */
.cell-name {
  font-weight: 700;
  text-align: center;
  line-height: 1.2;
  padding: 1px 2px;
  word-break: break-all;
}

.cell-price {
  font-size: 0.6rem;
  color: #555;
}

/* Corner cells */
.cell.corner {
  background: #e8f5e9;
}

/* Special cells */
.cell.chance  { background: #fff9c4; }
.cell.community { background: #bbdefb; }
.cell.tax     { background: #ffccbc; }
.cell.go      { background: #f3e5f5; }
.cell.jail    { background: #fce4ec; }
.cell.go-to-jail { background: #ffcdd2; }
.cell.free-parking { background: #e8f5e9; }
.cell.railroad { background: #f5f5f5; }

/* Cell orientations */
.cell.rotate-90  { writing-mode: vertical-lr; text-orientation: mixed; }
.cell.rotate-270 { writing-mode: vertical-rl; transform: rotate(180deg); }
.cell.rotate-180 { transform: rotate(180deg); }

/* Player tokens on board */
.cell-tokens {
  position: absolute;
  bottom: 2px;
  left: 0;
  right: 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 1px;
}

.token {
  font-size: 1rem;
  line-height: 1;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.4));
  transition: transform 0.3s;
}

.token.active-player { animation: bounce 0.6s infinite alternate; }

@keyframes bounce {
  from { transform: translateY(0); }
  to   { transform: translateY(-4px); }
}

/* Ownership dot */
.owner-dot {
  position: absolute;
  top: 2px;
  right: 3px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  border: 1px solid rgba(0,0,0,0.3);
}

/* ── DICE AREA ── */
#dice-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 20px;
  background: var(--card-bg);
  border-radius: 14px;
  min-width: 180px;
}

#turn-label {
  font-weight: 700;
  font-size: 1rem;
  text-align: center;
}

.dice-pair {
  display: flex;
  gap: 14px;
}

.die {
  width: 60px; height: 60px;
  background: #fff;
  border: 3px solid #2d3748;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  font-weight: 900;
  box-shadow: 3px 3px 8px rgba(0,0,0,0.2);
  transition: transform 0.1s;
}

.die.rolling { animation: roll-spin 0.5s ease-in-out; }

@keyframes roll-spin {
  0%   { transform: rotate(0deg) scale(1); }
  25%  { transform: rotate(90deg) scale(1.1); }
  50%  { transform: rotate(180deg) scale(0.9); }
  75%  { transform: rotate(270deg) scale(1.1); }
  100% { transform: rotate(360deg) scale(1); }
}

#roll-btn {
  padding: 12px 28px;
  font-size: 1.1rem;
  border-radius: 12px;
}

#end-turn-btn {
  display: none;
  padding: 10px 24px;
  font-size: 0.95rem;
}

#action-log {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
  max-width: 160px;
  line-height: 1.4;
  min-height: 40px;
}

/* ── PLAYER CARDS ── */
#players-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 200px;
  max-width: 220px;
  flex: 0 0 auto;
}

.player-card {
  background: var(--card-bg);
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.player-card.active {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(108, 63, 197, 0.15);
}

.player-card.bankrupt {
  opacity: 0.5;
  background: #f7f7f7;
}

.player-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.player-card-emoji { font-size: 1.5rem; }
.player-card-name { font-weight: 700; font-size: 0.95rem; flex: 1; }
.player-card-money { font-weight: 800; font-size: 1rem; color: var(--success); }

.player-card-props {
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.prop-dot {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 2px;
  margin-right: 2px;
  vertical-align: middle;
}

/* ── MODALS / DIALOGS ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  backdrop-filter: blur(3px);
}

.modal-overlay.hidden { display: none; }

.modal {
  background: var(--card-bg);
  border-radius: 16px;
  padding: 28px 32px;
  max-width: 480px;
  width: 100%;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  animation: modal-in 0.2s ease;
}

@keyframes modal-in {
  from { opacity: 0; transform: translateY(-20px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.modal h3 { font-size: 1.3rem; margin-bottom: 6px; }
.modal .modal-price { font-size: 1.1rem; color: var(--text-muted); margin-bottom: 16px; }
.modal .modal-desc { margin-bottom: 20px; line-height: 1.5; }

.modal .modal-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* Question modal */
.question-text {
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: 16px;
  line-height: 1.5;
}

.answer-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 20px;
}

.answer-btn {
  padding: 12px;
  border: 2px solid var(--border);
  border-radius: 10px;
  background: #fafafa;
  cursor: pointer;
  font-size: 0.95rem;
  text-align: left;
  transition: all 0.2s;
}
.answer-btn:hover { border-color: var(--primary); background: #f5f0ff; }
.answer-btn.correct { border-color: var(--success); background: #f0fff4; }
.answer-btn.wrong   { border-color: var(--danger);  background: #fff5f5; }
.answer-btn:disabled { cursor: default; }

/* Result banner */
.result-banner {
  text-align: center;
  padding: 10px;
  border-radius: 10px;
  font-weight: 700;
  font-size: 1rem;
  margin-bottom: 12px;
}
.result-banner.correct { background: #f0fff4; color: var(--success); }
.result-banner.wrong   { background: #fff5f5; color: var(--danger); }

/* ── AI MODAL ── */
.ai-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 20px;
  border-bottom: 2px solid var(--border);
}

.ai-tab {
  padding: 8px 18px;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: -2px;
  transition: all 0.2s;
}
.ai-tab.active { border-color: var(--primary); color: var(--primary); }

.ai-tab-panel { display: none; }
.ai-tab-panel.active { display: block; }

.ai-tab-panel textarea {
  width: 100%;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  font-size: 0.95rem;
  resize: vertical;
  min-height: 80px;
  margin-bottom: 10px;
}

/* API key input */
.api-key-row {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}
.api-key-row input {
  flex: 1;
  padding: 8px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  font-family: monospace;
}

/* Loading spinner in button */
.btn.loading::after {
  content: '';
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid rgba(255,255,255,0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin-left: 8px;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── EMOJI PICKER ── */
.emoji-picker {
  background: #fff;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-width: 260px;
  box-shadow: var(--shadow);
  position: absolute;
  z-index: 200;
}

.emoji-picker span {
  font-size: 1.4rem;
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  transition: background 0.15s;
}
.emoji-picker span:hover { background: #f0f4f8; }

/* ── RULES MODAL ── */
.rules-content {
  max-height: 60vh;
  overflow-y: auto;
  line-height: 1.7;
  font-size: 0.95rem;
}
.rules-content h4 { margin: 14px 0 6px; color: var(--primary); }

/* ── GAME OVER SCREEN ── */
#gameover-modal .winner-emoji { font-size: 4rem; display: block; text-align: center; margin: 10px 0; }
#gameover-modal .winner-name { text-align: center; font-size: 1.4rem; font-weight: 800; margin-bottom: 4px; }
#gameover-modal .winner-money { text-align: center; color: var(--success); font-size: 1.1rem; margin-bottom: 20px; }
#gameover-modal .rankings { font-size: 0.9rem; }
#gameover-modal .rankings li { padding: 6px 0; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; }

/* ── RESPONSIVE ── */
@media (max-width: 900px) {
  :root {
    --cell-size: 50px;
    --corner-size: 72px;
  }
  #game-body { flex-direction: column; align-items: center; }
  #players-panel { flex-direction: row; flex-wrap: wrap; max-width: 100%; min-width: 0; }
  .player-card { min-width: 140px; flex: 1; }
}

@media (max-width: 640px) {
  :root {
    --cell-size: 38px;
    --corner-size: 54px;
  }
  .cell-name { font-size: 0.5rem; }
  .cell-price { display: none; }
}

/* ── UTILITY ── */
.hidden { display: none !important; }
.text-center { text-align: center; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 16px; }

/* Tooltip on hover */
.cell[title]:hover::after {
  content: attr(title);
  position: absolute;
  bottom: 105%;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.85);
  color: #fff;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 0.75rem;
  white-space: nowrap;
  pointer-events: none;
  z-index: 100;
}

/* Progress bar for timer */
#timer-bar-wrap {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 4px;
  background: var(--border);
  z-index: 999;
}
#timer-bar {
  height: 100%;
  background: var(--primary);
  transition: width 1s linear;
}

/* Bankrupt overlay */
.bankrupt-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,0,0,0.12);
  font-size: 0.7rem;
  font-weight: 900;
  color: var(--danger);
  letter-spacing: 1px;
}
