@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@600;700&family=Inter:wght@400;500;600;700&display=swap');

:root {
  --bg-dark: #1A1A2E;
  --bg-card: #16213E;
  --bg-cell: #1E2A4A;
  --bg-cell-hover: #2d4a63;
  --bg-lake: #1B4F72;
  --border: #2d4a63;
  --border-light: rgba(255,255,255,0.08);
  --text-primary: #EAEAEA;
  --text-secondary: #A0A0B0;
  --accent-red: #E74C3C;
  --accent-red-dark: #c0392b;
  --accent-blue: #3498DB;
  --accent-blue-dark: #2980b9;
  --accent-gold: #F5C542;
  --accent-green: #2ECC71;
  --accent-purple: #6C5CE7;
  --cell-size: min(6.5vw, 56px);
  --board-gap: 2px;
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.2);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.3);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.4);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s ease;
}

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

body {
  background: var(--bg-dark);
  background-image:
    radial-gradient(ellipse at 20% 50%, rgba(108,92,231,0.06) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 20%, rgba(52,152,219,0.06) 0%, transparent 50%),
    radial-gradient(ellipse at 50% 80%, rgba(231,76,60,0.04) 0%, transparent 50%);
  color: var(--text-primary);
  font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  min-height: 100vh;
  overflow-x: hidden;
  line-height: 1.5;
}

.screen {
  display: none;
  min-height: 100vh;
  justify-content: center;
  align-items: center;
  padding: 20px;
  animation: screenFadeIn 0.4s ease;
}
.screen.active {
  display: flex;
}
@keyframes screenFadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ====== LOBBY ====== */
.lobby-family {
  margin-top: 28px;
  font-size: 0.82rem;
  line-height: 1.7;
  color: var(--text-secondary);
}
.lobby-family a {
  color: var(--accent-gold);
  font-weight: 600;
  text-decoration: none;
}
.lobby-family a:hover { text-decoration: underline; }
.lobby-container {
  text-align: center;
  max-width: 480px;
  width: 100%;
  background: rgba(22,33,62,0.5);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 36px 32px;
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(8px);
}
.logo-section { margin-bottom: 36px; }
.logo {
  font-family: 'Cinzel', 'Georgia', serif;
  font-size: 3.2rem;
  font-weight: 700;
  letter-spacing: 10px;
  background: linear-gradient(135deg, var(--accent-gold), #E6A817, var(--accent-red));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 6px;
  filter: drop-shadow(0 0 40px rgba(245, 197, 66, 0.25));
  animation: logoShimmer 3s ease-in-out infinite;
}
@keyframes logoShimmer {
  0%, 100% { filter: drop-shadow(0 0 30px rgba(245, 197, 66, 0.2)); }
  50% { filter: drop-shadow(0 0 50px rgba(245, 197, 66, 0.4)); }
}
.subtitle {
  color: var(--text-secondary);
  margin-bottom: 0;
  font-size: 1rem;
  letter-spacing: 2px;
  text-transform: uppercase;
  font-weight: 500;
}

/* Forms & Inputs */
.lobby-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 32px;
}
.input-field {
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: 1rem;
  font-family: inherit;
  outline: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.input-field:focus {
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 3px rgba(52,152,219,0.15);
}
.input-field::placeholder { color: var(--text-secondary); opacity: 0.7; }

/* Buttons */
.btn {
  padding: 12px 24px;
  border: none;
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all var(--transition-fast);
  text-transform: uppercase;
  letter-spacing: 1px;
  position: relative;
  overflow: hidden;
}
.btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(rgba(255,255,255,0.1), transparent);
  opacity: 0;
  transition: opacity var(--transition-fast);
}
.btn:hover::after { opacity: 1; }
.btn:active { transform: scale(0.97); }
.btn-lg { padding: 14px 28px; font-size: 1.05rem; }
.btn-primary {
  background: linear-gradient(135deg, var(--accent-red), var(--accent-red-dark));
  color: white;
  box-shadow: 0 4px 12px rgba(231,76,60,0.3);
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(231,76,60,0.4); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: none; }
.btn-secondary {
  background: var(--bg-cell);
  color: var(--text-primary);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--bg-cell-hover); border-color: var(--accent-blue); }
.btn-accent {
  background: linear-gradient(135deg, var(--accent-gold), #E6A817);
  color: #1a1a2e;
  font-weight: 700;
}
.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid transparent;
}
.btn-ghost:hover { color: var(--text-primary); border-color: var(--border); }
.btn-danger {
  background: var(--accent-red-dark);
  color: white;
}
.btn-small { padding: 8px 16px; font-size: 0.82rem; }
.btn-icon { min-width: 36px; padding: 8px; font-size: 1.1rem; }
.btn-icon-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.4rem;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
}
.btn-icon-close:hover { color: var(--text-primary); }

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 4px 0;
  color: var(--text-secondary);
  font-size: 0.85rem;
}
.divider::before, .divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}
.join-section {
  display: flex;
  gap: 8px;
}
.join-section .input-field { flex: 1; }

/* Games List */
.games-list { margin-top: 24px; text-align: left; }
.games-list h3 {
  margin-bottom: 10px;
  color: var(--text-secondary);
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 1.5px;
}
.game-item {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  padding: 12px 16px;
  border-radius: var(--radius-md);
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  transition: all var(--transition-fast);
}
.game-item:hover { border-color: var(--accent-blue); background: rgba(52,152,219,0.08); }

/* Rules Summary */
.rules-summary {
  text-align: left;
  margin-top: 8px;
}
.rules-summary h3 {
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  margin-bottom: 12px;
}
.rules-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}
.rule-card {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 14px 12px;
  text-align: center;
  transition: border-color var(--transition-fast);
}
.rule-card:hover { border-color: var(--accent-gold); }
.rule-icon {
  display: block;
  font-size: 1.6rem;
  margin-bottom: 6px;
}
.rule-card strong {
  display: block;
  font-size: 0.85rem;
  color: var(--accent-gold);
  margin-bottom: 2px;
}
.rule-card p {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin: 0;
  line-height: 1.3;
}
.piece-reference {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 0;
}
.piece-reference summary {
  padding: 10px 14px;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 500;
  transition: color var(--transition-fast);
}
.piece-reference summary:hover { color: var(--text-primary); }
.piece-ref-grid {
  padding: 8px 14px 14px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}
.piece-ref-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  padding: 4px 0;
}
.piece-ref-item .ref-symbol {
  width: 28px;
  height: 28px;
  border-radius: 5px;
  background: rgba(108,92,231,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.9rem;
  flex-shrink: 0;
  color: var(--accent-gold);
}
.piece-ref-item .ref-sprite {
  padding: 3px;
}
.piece-ref-item .ref-sprite svg {
  width: 100%;
  height: 100%;
}
.piece-ref-item .ref-info {
  line-height: 1.2;
}
.piece-ref-item .ref-name { font-weight: 600; }
.piece-ref-item .ref-desc { color: var(--text-secondary); font-size: 0.7rem; }

/* ====== WAITING ====== */
.waiting-container {
  text-align: center;
  max-width: 480px;
}
.waiting-icon {
  margin-bottom: 16px;
}
.sword-cross {
  font-size: 3rem;
  animation: swordPulse 2s ease-in-out infinite;
}
@keyframes swordPulse {
  0%, 100% { transform: scale(1) rotate(0deg); opacity: 0.8; }
  50% { transform: scale(1.1) rotate(5deg); opacity: 1; }
}
.waiting-container h2 {
  font-family: 'Cinzel', serif;
  margin-bottom: 4px;
}
.waiting-subtitle {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: 12px;
}
.spinner {
  width: 48px;
  height: 48px;
  border: 3px solid var(--border);
  border-top-color: var(--accent-blue);
  border-right-color: var(--accent-purple);
  border-radius: 50%;
  margin: 20px auto;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.share-link {
  display: flex;
  gap: 8px;
  margin: 16px 0;
}
.share-link .input-field {
  flex: 1;
  font-size: 0.82rem;
  font-family: monospace;
}
.game-code-display {
  color: var(--text-secondary);
  margin-top: 8px;
  margin-bottom: 16px;
}
.game-code-display strong {
  color: var(--accent-gold);
  font-size: 1.3rem;
  letter-spacing: 4px;
  font-family: 'Cinzel', serif;
}

/* ====== BOARD ====== */
.board-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 12px 0;
}
.board-area {
  display: flex;
  align-items: flex-start;
}
.board-labels {
  display: flex;
  font-size: 0.65rem;
  color: var(--text-secondary);
  font-weight: 600;
  opacity: 0.6;
}
.board-labels-top {
  margin-left: 18px;
  gap: 0;
}
.board-labels-top span {
  width: var(--cell-size);
  text-align: center;
  margin: 0 calc(var(--board-gap) / 2);
}
.board-labels-left {
  flex-direction: column;
  margin-right: 4px;
  padding-top: var(--board-gap);
}
.board-labels-left span {
  height: var(--cell-size);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: calc(var(--board-gap) / 2) 0;
  width: 14px;
}
.board {
  display: grid;
  grid-template-columns: repeat(8, var(--cell-size));
  grid-template-rows: repeat(8, var(--cell-size));
  gap: var(--board-gap);
  background: linear-gradient(135deg, #0d1520, #1a1a2e);
  border: 3px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--board-gap);
  box-shadow: var(--shadow-lg), inset 0 0 60px rgba(0,0,0,0.3), 0 0 40px rgba(108,92,231,0.05);
}
.board-small {
  --cell-size: 36px;
}
.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  background: var(--bg-cell);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  transition: all var(--transition-fast);
  user-select: none;
}
.cell:hover { background: var(--bg-cell-hover); }
.cell.lake {
  background: linear-gradient(135deg, #143d5e, var(--bg-lake));
  cursor: default;
  background-image:
    repeating-linear-gradient(45deg, transparent, transparent 4px, rgba(255,255,255,0.03) 4px, rgba(255,255,255,0.03) 8px);
  box-shadow: inset 0 0 12px rgba(0,0,0,0.4);
  position: relative;
  overflow: hidden;
}
.cell.lake::after {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    90deg,
    transparent 0%,
    rgba(52,152,219,0.08) 25%,
    transparent 50%
  );
  background-size: 200% 100%;
  animation: waterShimmer 3s linear infinite;
}
@keyframes waterShimmer {
  from { background-position: 0% 0; }
  to { background-position: 200% 0; }
}
.cell.selected {
  box-shadow: 0 0 0 3px var(--accent-gold), 0 0 15px rgba(245,197,66,0.3);
  z-index: 2;
  animation: cellPulse 1s ease-in-out infinite;
}
@keyframes cellPulse {
  0%, 100% { box-shadow: 0 0 0 3px var(--accent-gold), 0 0 15px rgba(245,197,66,0.3); }
  50% { box-shadow: 0 0 0 3px var(--accent-gold), 0 0 25px rgba(245,197,66,0.5); }
}
.cell.valid-move {
  background: rgba(46, 204, 113, 0.12);
}
.cell.valid-move::after {
  content: '';
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: rgba(46, 204, 113, 0.5);
  animation: dotPulse 1.2s ease-in-out infinite;
}
@keyframes dotPulse {
  0%, 100% { transform: scale(0.8); opacity: 0.5; }
  50% { transform: scale(1.1); opacity: 1; }
}
.cell.valid-attack {
  background: rgba(231, 76, 60, 0.12);
  box-shadow: inset 0 0 10px rgba(231,76,60,0.2);
}
.cell.valid-attack::after {
  content: '';
  position: absolute;
  inset: 2px;
  border: 2px solid rgba(231, 76, 60, 0.6);
  border-radius: 4px;
  animation: attackPulse 0.8s ease-in-out infinite;
}
@keyframes attackPulse {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}
.cell.setup-zone {
  background: rgba(52, 152, 219, 0.1);
  border: 1px dashed rgba(52, 152, 219, 0.25);
}
.cell.setup-zone:hover {
  background: rgba(52, 152, 219, 0.2);
  border-color: rgba(52, 152, 219, 0.5);
}
.cell.has-powerup::before {
  content: '';
  position: absolute;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent-gold);
  box-shadow: 0 0 8px var(--accent-gold);
  animation: powerupGlow 1.5s ease-in-out infinite;
  top: 3px;
  right: 3px;
  z-index: 1;
}
@keyframes powerupGlow {
  0%, 100% { opacity: 0.5; transform: scale(0.8); box-shadow: 0 0 4px var(--accent-gold); }
  50% { opacity: 1; transform: scale(1.2); box-shadow: 0 0 12px var(--accent-gold); }
}
.cell.last-move-from {
  background: rgba(245,197,66,0.08);
}
.cell.last-move-to {
  background: rgba(245,197,66,0.12);
  box-shadow: inset 0 0 8px rgba(245,197,66,0.15);
}
.cell.keyboard-focus {
  box-shadow: 0 0 0 2px var(--accent-purple), 0 0 12px rgba(108,92,231,0.4);
  z-index: 3;
}
.cell.drag-over {
  background: rgba(52, 152, 219, 0.3) !important;
  box-shadow: inset 0 0 12px rgba(52,152,219,0.4);
}
.palette-item[draggable="true"] {
  cursor: grab;
}
.palette-item[draggable="true"]:active {
  cursor: grabbing;
}

/* ====== PIECES ====== */
.piece {
  width: calc(var(--cell-size) - 6px);
  height: calc(var(--cell-size) - 6px);
  border-radius: var(--radius-sm);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  position: relative;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
  z-index: 1;
}
.piece:hover { transform: scale(1.08); }
.piece.red {
  background: linear-gradient(145deg, #e55039, var(--accent-red-dark));
  border: 2px solid rgba(231,76,60,0.7);
  color: white;
  text-shadow: 1px 1px 2px rgba(0,0,0,0.5);
  box-shadow: 0 2px 8px rgba(231,76,60,0.3), inset 0 1px 0 rgba(255,255,255,0.15);
}
.piece.red:hover {
  box-shadow: 0 3px 12px rgba(231,76,60,0.45), inset 0 1px 0 rgba(255,255,255,0.15);
}
.piece.blue {
  background: linear-gradient(145deg, #5dade2, var(--accent-blue-dark));
  border: 2px solid rgba(52,152,219,0.7);
  color: white;
  text-shadow: 1px 1px 2px rgba(0,0,0,0.5);
  box-shadow: 0 2px 8px rgba(52,152,219,0.3), inset 0 1px 0 rgba(255,255,255,0.15);
}
.piece.blue:hover {
  box-shadow: 0 3px 12px rgba(52,152,219,0.45), inset 0 1px 0 rgba(255,255,255,0.15);
}
.piece.hidden {
  background: linear-gradient(145deg, #4a4a5a, #3a3a4a);
  border-color: #5a5a6a;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.06);
}
.piece .piece-sprite {
  width: 70%;
  height: 70%;
  display: flex;
  align-items: center;
  justify-content: center;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.4));
}
.piece .piece-sprite svg {
  width: 100%;
  height: 100%;
}
.piece .piece-sprite-hidden {
  opacity: 0.7;
}
.piece .piece-symbol {
  font-size: 1.3rem;
  line-height: 1;
}
.piece .piece-name {
  font-size: 0.42rem;
  opacity: 0.8;
  margin-top: 0px;
  letter-spacing: 0;
  line-height: 1;
}
.piece .piece-rank {
  position: absolute;
  top: -3px;
  right: -3px;
  background: rgba(0,0,0,0.75);
  color: var(--accent-gold);
  font-size: 0.5rem;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  border: 1px solid rgba(245,197,66,0.4);
  box-shadow: 0 1px 3px rgba(0,0,0,0.5);
}
.piece.has-buff::after {
  content: '';
  position: absolute;
  inset: -3px;
  border-radius: 8px;
  border: 2px solid var(--accent-gold);
  animation: buffGlow 1.5s ease-in-out infinite;
}
@keyframes buffGlow {
  0%, 100% { opacity: 0.4; box-shadow: 0 0 4px var(--accent-gold); }
  50% { opacity: 1; box-shadow: 0 0 12px var(--accent-gold); }
}
.piece.piece-moving {
  animation: pieceSlide 0.3s ease;
  z-index: 10;
}
@keyframes pieceSlide {
  from { transform: scale(1.15); }
  to { transform: scale(1); }
}
.piece.piece-eliminated {
  animation: pieceEliminate 0.4s ease forwards;
}
@keyframes pieceEliminate {
  to { transform: scale(0); opacity: 0; }
}

/* ====== SETUP ====== */
.setup-container {
  text-align: center;
  max-width: 900px;
  width: 100%;
}
.setup-header { margin-bottom: 12px; }
.setup-header h2 {
  font-family: 'Cinzel', serif;
  margin-bottom: 4px;
}
.setup-header p { color: var(--text-secondary); font-size: 0.88rem; }
.setup-progress {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: center;
  margin-top: 8px;
}
.progress-bar {
  width: 120px;
  height: 6px;
  background: var(--bg-cell);
  border-radius: 3px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-blue), var(--accent-green));
  border-radius: 3px;
  transition: width 0.3s ease;
  width: 0%;
}
#setup-count {
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-weight: 500;
}
.setup-layout {
  display: flex;
  gap: 20px;
  justify-content: center;
  align-items: flex-start;
  flex-wrap: wrap;
}
.piece-palette {
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: var(--bg-card);
  padding: 10px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-light);
  min-width: 140px;
  box-shadow: var(--shadow-sm);
}
.palette-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
  font-size: 0.82rem;
  border: 1px solid transparent;
}
.palette-item:hover {
  background: var(--bg-cell-hover);
  border-color: var(--border);
}
.palette-item.selected {
  background: rgba(52,152,219,0.15);
  border-color: var(--accent-blue);
  box-shadow: 0 0 8px rgba(52,152,219,0.2);
}
.palette-item.exhausted {
  opacity: 0.3;
  pointer-events: none;
  text-decoration: line-through;
}
.palette-sprite {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-gold);
  flex-shrink: 0;
}
.palette-sprite svg {
  width: 100%;
  height: 100%;
}
.palette-count {
  margin-left: auto;
  color: var(--text-secondary);
  font-size: 0.72rem;
  font-weight: 600;
  background: var(--bg-cell);
  padding: 1px 6px;
  border-radius: 10px;
}
.piece-info-panel {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 14px;
  min-width: 160px;
  max-width: 180px;
  text-align: left;
  box-shadow: var(--shadow-sm);
}
.piece-info-panel h4 {
  font-size: 0.85rem;
  margin-bottom: 6px;
  color: var(--accent-gold);
}
.piece-info-panel p {
  font-size: 0.78rem;
  color: var(--text-secondary);
  line-height: 1.4;
}
.piece-info-panel .info-rank {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--accent-purple);
}
.piece-info-panel .info-ability {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid var(--border-light);
  font-size: 0.75rem;
  color: var(--accent-green);
}
.setup-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 14px;
}
.status-text {
  color: var(--text-secondary);
  margin-top: 10px;
  font-size: 0.82rem;
  font-weight: 500;
}

/* ====== GAME ====== */
.game-container {
  text-align: center;
  position: relative;
  max-width: 1000px;
  width: 100%;
}
.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  gap: 12px;
}
.player-info {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-card);
  padding: 8px 14px;
  border-radius: var(--radius-md);
  font-size: 0.88rem;
  border: 1px solid var(--border-light);
  transition: all var(--transition-fast);
}
.player-info.active-player {
  border-color: var(--accent-green);
  box-shadow: 0 0 12px rgba(46,204,113,0.15);
}
.player-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.red-dot { background: var(--accent-red); box-shadow: 0 0 6px rgba(231,76,60,0.4); }
.blue-dot { background: var(--accent-blue); box-shadow: 0 0 6px rgba(52,152,219,0.4); }
.piece-count {
  background: var(--bg-cell);
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.78rem;
  color: var(--text-secondary);
  font-weight: 600;
}
.turn-indicator {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-card);
  padding: 6px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  transition: all var(--transition-normal);
}
.turn-indicator.my-turn {
  border-color: var(--accent-green);
  box-shadow: 0 0 15px rgba(46,204,113,0.2);
}
#turn-text {
  font-weight: 600;
  font-size: 0.88rem;
}
.timer-ring {
  position: relative;
  width: 40px;
  height: 40px;
}
.timer-ring svg {
  width: 100%;
  height: 100%;
}
.timer {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--accent-gold);
}
.timer.urgent { color: var(--accent-red); animation: blink 0.5s infinite; }
@keyframes blink { 50% { opacity: 0.4; } }

/* Game Main Layout */
.game-main {
  display: flex;
  gap: 16px;
  justify-content: center;
  align-items: flex-start;
}
.game-sidebar {
  width: 200px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex-shrink: 0;
}
.sidebar-section {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 12px;
  text-align: left;
}
.sidebar-section h4 {
  font-size: 0.78rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 8px;
}
.combat-log {
  max-height: 180px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.combat-log .empty-log {
  color: var(--text-secondary);
  font-size: 0.78rem;
  font-style: italic;
}
.combat-log-entry {
  font-size: 0.75rem;
  padding: 4px 6px;
  border-radius: 4px;
  background: rgba(255,255,255,0.03);
  display: flex;
  align-items: center;
  gap: 4px;
  animation: logSlideIn 0.3s ease;
}
@keyframes logSlideIn {
  from { opacity: 0; transform: translateX(-10px); }
  to { opacity: 1; transform: translateX(0); }
}
.combat-log-entry .log-sprite {
  display: inline-flex;
  width: 18px;
  height: 18px;
  vertical-align: middle;
}
.combat-log-entry .log-sprite svg {
  width: 100%;
  height: 100%;
}
.combat-log-entry .log-result {
  font-weight: 700;
}
.combat-log-entry .log-win { color: var(--accent-green); }
.combat-log-entry .log-lose { color: var(--accent-red); }
.combat-log-entry .log-draw { color: var(--accent-gold); }

.eliminated-pieces { display: flex; flex-direction: column; gap: 6px; }
.eliminated-group { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.elim-label {
  font-size: 0.72rem;
  color: var(--text-secondary);
  width: 100%;
  margin-bottom: 2px;
}
.elim-piece {
  width: 22px;
  height: 22px;
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
  animation: elimAppear 0.3s ease;
}
@keyframes elimAppear {
  from { transform: scale(0); }
  to { transform: scale(1); }
}
.elim-piece.red { background: rgba(231,76,60,0.3); border: 1px solid rgba(231,76,60,0.5); color: #ffa89e; }
.elim-piece.blue { background: rgba(52,152,219,0.3); border: 1px solid rgba(52,152,219,0.5); color: #a3d5f7; }
.elim-sprite {
  display: flex;
  width: 16px;
  height: 16px;
}
.elim-sprite svg {
  width: 100%;
  height: 100%;
}

.game-footer {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-top: 10px;
}

/* ====== COMBAT OVERLAY ====== */
.combat-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.75);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: overlayFadeIn 0.2s;
}
@keyframes overlayFadeIn { from { opacity: 0; } to { opacity: 1; } }
.combat-card {
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 36px 52px;
  display: flex;
  align-items: center;
  gap: 28px;
  animation: combatSlam 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  box-shadow: var(--shadow-lg);
  position: relative;
}
@keyframes combatSlam {
  0% { transform: scale(0.3) rotate(-5deg); opacity: 0; }
  60% { transform: scale(1.05) rotate(1deg); }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}
.combat-piece {
  text-align: center;
  min-width: 80px;
}
.combat-piece-icon {
  width: 64px;
  height: 64px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  font-weight: 700;
  margin: 0 auto 6px;
  border: 2px solid;
  padding: 8px;
  color: white;
}
.combat-piece-icon svg {
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.4));
}
.combat-piece-icon.red-bg {
  background: linear-gradient(135deg, var(--accent-red), var(--accent-red-dark));
  border-color: var(--accent-red);
  box-shadow: 0 0 20px rgba(231,76,60,0.3);
}
.combat-piece-icon.blue-bg {
  background: linear-gradient(135deg, var(--accent-blue), var(--accent-blue-dark));
  border-color: var(--accent-blue);
  box-shadow: 0 0 20px rgba(52,152,219,0.3);
}
.combat-piece-label {
  display: block;
  font-weight: 600;
  font-size: 0.85rem;
}
.combat-vs {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.combat-vs span {
  font-size: 1.3rem;
  font-weight: 900;
  color: var(--accent-gold);
  font-family: 'Cinzel', serif;
}
.combat-swords {
  font-size: 1.8rem;
  animation: swordClash 0.6s ease;
}
@keyframes swordClash {
  0% { transform: rotate(-30deg) scale(0.5); opacity: 0; }
  50% { transform: rotate(10deg) scale(1.2); }
  100% { transform: rotate(0deg) scale(1); opacity: 1; }
}
.combat-result {
  position: absolute;
  bottom: -36px;
  left: 50%;
  transform: translateX(-50%);
  font-weight: 700;
  font-size: 1.1rem;
  white-space: nowrap;
  animation: resultPop 0.3s 0.5s ease both;
  text-shadow: 0 0 10px currentColor;
}
@keyframes resultPop {
  from { opacity: 0; transform: translateX(-50%) translateY(10px) scale(0.8); }
  to { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
}

/* ====== CHAT ====== */
.chat-panel {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 300px;
  max-height: 420px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  z-index: 50;
  box-shadow: var(--shadow-lg);
  animation: chatSlideIn 0.3s ease;
}
@keyframes chatSlideIn {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}
.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-light);
  font-weight: 600;
  font-size: 0.88rem;
}
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 10px 12px;
  max-height: 280px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.chat-msg {
  font-size: 0.82rem;
  padding: 4px 0;
  animation: chatMsgIn 0.2s ease;
}
@keyframes chatMsgIn {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}
.chat-msg .sender {
  font-weight: 600;
}
.chat-msg .sender.red { color: var(--accent-red); }
.chat-msg .sender.blue { color: var(--accent-blue); }
.chat-input-row {
  display: flex;
  gap: 6px;
  padding: 8px 10px;
  border-top: 1px solid var(--border-light);
}
.chat-input-row .input-field {
  flex: 1;
  padding: 8px 10px;
  font-size: 0.82rem;
}

/* ====== GAME OVER ====== */
.gameover-container {
  text-align: center;
  max-width: 600px;
  animation: gameoverAppear 0.6s ease;
}
@keyframes gameoverAppear {
  from { opacity: 0; transform: scale(0.9); }
  to { opacity: 1; transform: scale(1); }
}
.gameover-icon {
  font-size: 4rem;
  margin-bottom: 8px;
  animation: iconBounce 0.6s ease;
}
@keyframes iconBounce {
  0% { transform: scale(0); }
  50% { transform: scale(1.2); }
  100% { transform: scale(1); }
}
.gameover-title {
  font-family: 'Cinzel', serif;
  font-size: 2.2rem;
  margin-bottom: 8px;
}
.gameover-title.victory {
  background: linear-gradient(135deg, var(--accent-gold), #E6A817);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  filter: drop-shadow(0 0 20px rgba(245,197,66,0.3));
}
.gameover-title.defeat {
  color: var(--accent-red);
}
.gameover-message {
  color: var(--text-secondary);
  margin-bottom: 20px;
  font-size: 1.05rem;
}
.gameover-stats {
  display: flex;
  gap: 16px;
  justify-content: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 12px 20px;
  min-width: 90px;
}
.stat-value {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--accent-gold);
  display: block;
}
.stat-label {
  font-size: 0.72rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.gameover-board-section {
  margin-bottom: 20px;
}
.gameover-board-section h4 {
  font-size: 0.82rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 8px;
}
.gameover-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
}

/* ====== TOAST ====== */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--bg-card);
  color: var(--text-primary);
  padding: 10px 20px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  font-size: 0.88rem;
  box-shadow: var(--shadow-md);
  pointer-events: auto;
  animation: toastIn 0.3s ease, toastOut 0.3s ease 2.5s forwards;
  max-width: 320px;
}
@keyframes toastIn {
  from { opacity: 0; transform: translateX(30px); }
  to { opacity: 1; transform: translateX(0); }
}
@keyframes toastOut {
  from { opacity: 1; transform: translateX(0); }
  to { opacity: 0; transform: translateX(30px); }
}
.toast.toast-success { border-left: 3px solid var(--accent-green); }
.toast.toast-error { border-left: 3px solid var(--accent-red); }
.toast.toast-warning { border-left: 3px solid var(--accent-gold); }
.toast.toast-info { border-left: 3px solid var(--accent-blue); }

/* ====== CONFETTI ====== */
.confetti-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 150;
}

/* ====== PIECE TOOLTIP ====== */
.piece[title]:hover::after {
  content: attr(title);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.9);
  color: var(--text-primary);
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 0.68rem;
  white-space: nowrap;
  z-index: 20;
  pointer-events: none;
  font-weight: 500;
}

/* ====== REMATCH BUTTON ====== */
.gameover-actions .btn-lg {
  min-width: 140px;
}

/* ====== SCREEN READER ====== */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border-width: 0;
}

/* ====== SCROLLBAR ====== */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.25); }

/* ====== ACCESSIBILITY ====== */
:focus-visible {
  outline: 2px solid var(--accent-gold);
  outline-offset: 2px;
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ====== RESPONSIVE ====== */
@media (max-width: 900px) {
  .game-sidebar {
    display: none;
  }
  .game-sidebar.sidebar-open {
    display: flex;
    position: fixed;
    right: 0;
    top: 0;
    bottom: 0;
    z-index: 60;
    background: var(--bg-dark);
    padding: 16px;
    width: 240px;
    box-shadow: -4px 0 20px rgba(0,0,0,0.5);
    animation: sidebarSlide 0.3s ease;
  }
  @keyframes sidebarSlide {
    from { transform: translateX(100%); }
    to { transform: translateX(0); }
  }
}

@media (max-width: 768px) {
  :root { --cell-size: min(11vw, 48px); }
  .logo { font-size: 2.2rem; letter-spacing: 6px; }
  .subtitle { font-size: 0.85rem; }
  .rules-grid { grid-template-columns: 1fr; }
  .setup-layout { flex-direction: column; align-items: center; }
  .piece-palette {
    flex-direction: row;
    flex-wrap: wrap;
    min-width: unset;
    width: 100%;
    justify-content: center;
  }
  .palette-item { flex: 0 0 auto; padding: 6px 10px; font-size: 0.75rem; }
  .palette-count { font-size: 0.65rem; padding: 1px 4px; }
  .piece-info-panel { display: none; }
  .game-header { flex-direction: column; align-items: stretch; gap: 8px; }
  .combat-card { padding: 24px 32px; gap: 16px; }
  .chat-panel { width: calc(100% - 20px); right: 10px; bottom: 10px; border-radius: var(--radius-lg); }
  .board-labels { display: none; }
  .gameover-title { font-size: 1.8rem; }
  .btn { min-height: 44px; }
  .cell { min-width: 36px; min-height: 36px; }
}

@media (max-width: 480px) {
  :root { --cell-size: min(11.5vw, 42px); }
  .board { padding: 1px; gap: 1px; border-width: 2px; }
  .piece .piece-name { display: none; }
  .piece .piece-symbol { font-size: 1rem; }
  .piece .piece-rank { width: 12px; height: 12px; font-size: 0.48rem; }
  .combat-card { padding: 16px 20px; flex-direction: column; gap: 12px; }
  .combat-piece-icon { width: 44px; height: 44px; font-size: 1.5rem; }
  .gameover-stats { gap: 8px; }
  .stat-card { padding: 8px 14px; min-width: 70px; }
  .stat-value { font-size: 1.2rem; }
}
