/* ============================================
   Farkle — Game-Specific Styles
   ============================================ */

/* ---------- Scoreboard ---------- */
#scoreboard {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.score-cell {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 6px 16px 8px;
  text-align: center;
  min-width: 100px;
  transition: all 0.2s ease;
}

.score-cell.active-turn {
  border-color: var(--accent);
  box-shadow: 0 0 10px rgba(77, 166, 255, 0.35);
}

.score-name {
  display: block;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 2px;
  font-weight: 700;
}

.score-value {
  display: block;
  font-size: 22px;
  font-weight: 700;
  color: var(--text-heading);
  font-family: 'Oswald', sans-serif;
}

.score-turn-pts {
  display: block;
  font-size: 12px;
  font-weight: 700;
  margin-top: 3px;
  color: #4caf50;
  font-family: 'Oswald', sans-serif;
  min-height: 16px;
}

/* ---------- Table / Play Area ---------- */
#table {
  position: relative;
  width: 100%;
  max-width: 600px;
  height: 320px;
  margin: 0 auto 12px;
  background: radial-gradient(ellipse at center, #1a3d1a 0%, #0e2a14 60%, #0a1f0e 100%);
  border-radius: var(--radius-lg);
  border: 3px solid #0d2f14;
  box-shadow: inset 0 0 60px rgba(0, 0, 0, 0.4), 0 4px 24px rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

/* ---------- Turn Info ---------- */
#turn-info {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
  z-index: 5;
}

#turn-info.hidden { display: none; }

#turn-label {
  display: block;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: rgba(255, 255, 255, 0.45);
  font-weight: 700;
}

#turn-score {
  display: block;
  font-size: 32px;
  font-weight: 700;
  font-family: 'Oswald', sans-serif;
  color: #ffd740;
  text-shadow: 0 2px 8px rgba(255, 215, 64, 0.4);
}

/* ---------- Dice Tray ---------- */
#dice-tray {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  padding: 10px;
  z-index: 2;
}

/* ---------- Die ---------- */
.die {
  width: 64px;
  height: 64px;
  background: linear-gradient(145deg, #ffffff 0%, #e8e8e0 100%);
  border-radius: 10px;
  border: 2px solid #bbb;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.6);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  padding: 8px;
  cursor: default;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
  user-select: none;
  position: relative;
}

.die.empty {
  background: rgba(255, 255, 255, 0.06);
  border: 2px dashed rgba(255, 255, 255, 0.12);
  box-shadow: none;
}

.die.empty .pip { display: none; }

/* Pip dots */
.pip {
  width: 12px;
  height: 12px;
  background: #222;
  border-radius: 50%;
  align-self: center;
  justify-self: center;
}

/* Pip placement grid positions */
.pip.tl { grid-column: 1; grid-row: 1; }
.pip.tc { grid-column: 2; grid-row: 1; }
.pip.tr { grid-column: 3; grid-row: 1; }
.pip.ml { grid-column: 1; grid-row: 2; }
.pip.mc { grid-column: 2; grid-row: 2; }
.pip.mr { grid-column: 3; grid-row: 2; }
.pip.bl { grid-column: 1; grid-row: 3; }
.pip.bc { grid-column: 2; grid-row: 3; }
.pip.br { grid-column: 3; grid-row: 3; }

/* Die states */
.die.selectable {
  cursor: pointer;
  animation: dieSelectable 1.5s ease-in-out infinite;
}

@keyframes dieSelectable {
  0%, 100% { box-shadow: 0 3px 8px rgba(0, 0, 0, 0.35), 0 0 6px rgba(77, 166, 255, 0.3); }
  50% { box-shadow: 0 3px 8px rgba(0, 0, 0, 0.35), 0 0 14px rgba(77, 166, 255, 0.6); }
}

.die.selectable:hover {
  transform: translateY(-4px) scale(1.05);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4), 0 0 12px rgba(77, 166, 255, 0.5);
}

.die.selected {
  background: linear-gradient(145deg, #e8ffe8 0%, #c8f0c8 100%);
  border-color: #4caf50;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.3), 0 0 12px rgba(76, 175, 80, 0.5);
  transform: translateY(-6px);
  animation: none;
}

.die.kept {
  background: linear-gradient(145deg, #e0e0e0 0%, #c8c8c0 100%);
  border-color: #888;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  opacity: 0.7;
  transform: scale(0.92);
}

.die.not-scorable {
  opacity: 0.5;
}

.die.farkle-shake {
  animation: farkleShake 0.5s ease-in-out;
  border-color: #f44336;
}

@keyframes farkleShake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px) rotate(-3deg); }
  40% { transform: translateX(6px) rotate(3deg); }
  60% { transform: translateX(-4px) rotate(-2deg); }
  80% { transform: translateX(4px) rotate(2deg); }
}

.die.rolling {
  animation: dieRoll 0.4s ease-in-out;
}

@keyframes dieRoll {
  0% { transform: scale(0.8) rotateZ(0deg); opacity: 0.5; }
  50% { transform: scale(1.1) rotateZ(180deg); opacity: 0.8; }
  100% { transform: scale(1) rotateZ(360deg); opacity: 1; }
}

.die.ai-highlight {
  border-color: #ffd740;
  box-shadow: 0 0 16px rgba(255, 215, 64, 0.6);
}

/* ---------- Table Status ---------- */
#table-status {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 13px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.6);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
  z-index: 5;
}

#table-status.hidden { display: none; }

/* ---------- Farkle Flash ---------- */
#farkle-flash {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 52px;
  font-weight: 900;
  color: #f44336;
  text-shadow: 0 0 20px rgba(244, 67, 54, 0.8), 0 0 40px rgba(244, 67, 54, 0.4), 2px 2px 4px rgba(0, 0, 0, 0.6);
  font-family: 'Oswald', sans-serif;
  text-transform: uppercase;
  letter-spacing: 4px;
  z-index: 100;
  pointer-events: none;
  animation: farkleFlash 1.8s ease-out forwards;
}

#farkle-flash.hidden { display: none; }

@keyframes farkleFlash {
  0%   { opacity: 0; transform: translate(-50%, -50%) scale(0.5); }
  15%  { opacity: 1; transform: translate(-50%, -50%) scale(1.3); }
  40%  { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1.1) translateY(-20px); }
}

/* ---------- Hot Dice Flash ---------- */
#hot-dice-flash {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 44px;
  font-weight: 900;
  color: #ff9800;
  text-shadow: 0 0 20px rgba(255, 152, 0, 0.8), 0 0 40px rgba(255, 152, 0, 0.4), 2px 2px 4px rgba(0, 0, 0, 0.6);
  font-family: 'Oswald', sans-serif;
  text-transform: uppercase;
  letter-spacing: 4px;
  z-index: 100;
  pointer-events: none;
  animation: hotDiceFlash 1.8s ease-out forwards;
}

#hot-dice-flash.hidden { display: none; }

@keyframes hotDiceFlash {
  0%   { opacity: 0; transform: translate(-50%, -50%) scale(0.5); }
  15%  { opacity: 1; transform: translate(-50%, -50%) scale(1.2); }
  40%  { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1.1) translateY(-20px); }
}

/* ---------- Game Controls ---------- */
#game-controls {
  margin-bottom: 12px;
}

#btn-roll { min-width: 140px; }
#btn-bank { min-width: 140px; }

#btn-bank:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ---------- Meld Reference ---------- */
.meld-reference {
  max-width: 340px;
  margin: 0 auto 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.meld-ref-header {
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: color 0.2s;
}

.meld-ref-header:hover { color: var(--text-primary); }

.meld-arrow {
  font-size: 10px;
  transition: transform 0.2s;
}

.meld-ref-header.open .meld-arrow {
  transform: rotate(180deg);
}

.meld-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  display: none;
}

.meld-table.show { display: table; }

.meld-table th {
  padding: 6px 14px;
  text-align: left;
  font-weight: 700;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-subtle);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.meld-table td {
  padding: 5px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  color: var(--text-primary);
}

.meld-table td:last-child {
  text-align: right;
  font-weight: 700;
  font-family: 'Oswald', sans-serif;
  color: #ffd740;
}

.meld-table tbody tr:last-child td { border-bottom: none; }

/* ---------- Settings ---------- */
.settings-content { text-align: center; }
.settings-content h2 { margin-bottom: 20px; }
.setting { margin-bottom: 16px; }
.setting label { display: block; font-size: 14px; color: var(--text-secondary); margin-bottom: 8px; font-weight: 600; }
.button-group { display: flex; justify-content: center; gap: 8px; }

.option-btn {
  background: var(--bg-surface); border: 2px solid var(--border-subtle);
  color: var(--text-primary); padding: 8px 20px;
  border-radius: var(--radius-sm); font-family: inherit;
  font-size: 15px; font-weight: 600; cursor: pointer;
  transition: all var(--transition);
}
.option-btn:hover { border-color: var(--accent); }
.option-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

#start-game { margin-top: 20px; width: 100%; }

/* ---------- Game Over ---------- */
.final-scores { margin: 16px 0; }

.final-score-row {
  display: flex; justify-content: space-between;
  padding: 8px 12px; border-bottom: 1px solid var(--border-subtle);
  font-size: 16px;
}
.final-score-row:last-child { border-bottom: none; }
.final-score-row.winner { background: rgba(76, 175, 80, 0.1); border-radius: var(--radius-sm); }
.final-score-row.winner .final-pts::after { content: ' \2605'; }
.final-name { font-weight: 600; }
.final-pts { font-weight: 700; color: var(--text-heading); }

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
  #table { height: 280px; max-width: 100%; }
  .die { width: 52px; height: 52px; padding: 6px; border-radius: 8px; }
  .pip { width: 10px; height: 10px; }
  #dice-tray { gap: 8px; }
  #turn-score { font-size: 26px; }
  #farkle-flash { font-size: 40px; }
  #hot-dice-flash { font-size: 34px; }
  .score-cell { min-width: 80px; padding: 5px 10px 6px; }
  .score-value { font-size: 18px; }
}

@media (max-width: 480px) {
  #table { height: 240px; }
  .die { width: 44px; height: 44px; padding: 5px; border-radius: 7px; }
  .pip { width: 8px; height: 8px; }
  #dice-tray { gap: 6px; }
  #turn-score { font-size: 22px; }
  #farkle-flash { font-size: 30px; letter-spacing: 2px; }
  #hot-dice-flash { font-size: 26px; letter-spacing: 2px; }
  .score-cell { min-width: 68px; padding: 4px 8px 5px; }
  .score-value { font-size: 16px; }
  .score-name { font-size: 10px; }
  .meld-reference { max-width: 100%; }
}
