/* Header */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: clamp(2px, calc((var(--avail-h) - 460px) * 0.012), 6px) 8px;
  background: rgba(13, 19, 29, 0.96);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  flex-shrink: 0;
  height: var(--hdr-h);
  gap: 4px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
}

.brand-crest {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: linear-gradient(135deg, #5b21b6, #7c3aed);
  border: 1.5px solid rgba(196, 181, 253, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(124, 58, 237, 0.45);
  flex-shrink: 0;
}
.brand-crest svg {
  width: 15px;
  height: 15px;
  fill: #fff;
}

.brand-text-col {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 1px;
  min-width: 0;
  overflow: hidden;
}

.brand-title {
  font-size: 13.5px;
  font-weight: 900;
  letter-spacing: 0.04em;
  line-height: 1.1;
  text-transform: uppercase;
  white-space: nowrap;
  background: linear-gradient(135deg, #ffffff 35%, #c4b5fd 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 3px;
  flex-shrink: 0;
}

.round-pill {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.15;
}

.nav-btn {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: var(--text-muted);
  width: 31px;
  height: 31px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.18s var(--spring);
}
.nav-btn:active {
  transform: scale(0.92);
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
}

/* Opponents Ribbon */
.opponents-section {
  display: flex;
  align-items: stretch;
  gap: 8px;
  padding: var(--opp-sec-pad-y) 10px;
  overflow-x: auto;
  scrollbar-width: none;
  flex-shrink: 0;
  background: rgba(10, 14, 23, 0.6);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.opponents-section:has(.opp-tray:only-child) {
  justify-content: center;
}
.opponents-section::-webkit-scrollbar { display: none; }

.opp-tray {
  flex: 1 0 auto;
  min-width: clamp(136px, calc(var(--opp-col-w) * 4 + 18px), 196px);
  max-width: clamp(160px, calc(var(--opp-col-w) * 4 + 34px), 210px);
  padding: var(--opp-tray-pad-y) 8px;
  background: linear-gradient(180deg, #182232, #121a27);
  border: 1.5px solid rgba(255, 255, 255, 0.14);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  gap: var(--opp-tray-gap);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.4);
  transition: all 0.25s var(--spring);
  position: relative;
}
.opp-tray:first-child {
  margin-left: auto;
}
.opp-tray:last-child {
  margin-right: auto;
}
.opponents-section:has(.opp-tray:only-child) .opp-tray {
  max-width: clamp(180px, calc(var(--opp-col-w) * 4 + 44px), 240px);
}
.opp-tray.active-turn {
  border-color: var(--gold);
  box-shadow: 0 0 14px var(--gold-glow), 0 4px 10px rgba(0, 0, 0, 0.5);
}
.opp-tray.closer {
  border-color: var(--ruby);
  box-shadow: 0 0 14px rgba(244, 63, 94, 0.45);
  animation: alertPulseBadge 1.4s infinite alternate;
}
.opp-tray.danger-imminent {
  border-color: #ef4444;
  box-shadow: 0 0 14px rgba(239, 68, 68, 0.5);
}
.opp-status-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 15px;
}
.opp-closer-badge {
  font-size: 9.5px;
  font-weight: 900;
  color: #ffe4e6;
  background: rgba(244, 63, 94, 0.45);
  border: 1px solid var(--ruby);
  border-radius: 4px;
  padding: 1px 5px;
  text-align: center;
  letter-spacing: 0.04em;
  line-height: 1.2;
}
.opp-danger-badge {
  font-size: 9px;
  font-weight: 900;
  color: #fee2e2;
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.85), rgba(185, 28, 28, 0.95));
  border: 1px solid #f87171;
  border-radius: 4px;
  padding: 1px 5px;
  text-align: center;
  letter-spacing: 0.04em;
  box-shadow: 0 0 10px rgba(239, 68, 68, 0.45);
  animation: alertPulseBadge 1.2s infinite alternate;
  line-height: 1.2;
}
.opp-warning-badge {
  font-size: 9px;
  font-weight: 800;
  color: #fef3c7;
  background: rgba(245, 158, 11, 0.35);
  border: 1px solid #fbbf24;
  border-radius: 4px;
  padding: 1px 5px;
  text-align: center;
  letter-spacing: 0.02em;
  line-height: 1.2;
}
.opp-count-badge {
  font-size: 9px;
  font-weight: 700;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 4px;
  padding: 1px 5px;
  text-align: center;
  line-height: 1.2;
}
.opp-setup-badge {
  font-size: 9px;
  font-weight: 700;
  color: var(--cyan);
  background: rgba(6, 182, 212, 0.15);
  border: 1px solid rgba(6, 182, 212, 0.3);
  border-radius: 4px;
  padding: 1px 5px;
  text-align: center;
  line-height: 1.2;
}
.opp-action-badge {
  font-size: 9px;
  font-weight: 800;
  color: var(--gold-light);
  background: rgba(245, 158, 11, 0.22);
  border: 1px solid rgba(251, 191, 36, 0.55);
  border-radius: 4px;
  padding: 1px 5px;
  text-align: center;
  line-height: 1.2;
}

.opp-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
}
.opp-profile {
  display: flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
  flex: 1 1 auto;
  overflow: hidden;
}
.opp-avatar-badge {
  width: 18px;
  height: 18px;
  border-radius: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.opp-avatar-badge svg {
  width: 12px;
  height: 12px;
  fill: #fff;
}
.opp-name {
  font-size: 12.5px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}
.opp-score-group {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}
.opp-total-pill {
  font-size: 10px;
  font-weight: 800;
  padding: 1px 5px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--text-muted);
  white-space: nowrap;
}
.opp-total-pill.near-target {
  background: rgba(244, 63, 94, 0.2);
  border-color: rgba(244, 63, 94, 0.55);
  color: #fda4af;
}
.opp-score-pill {
  font-size: 12px;
  font-weight: 800;
  padding: 1px 6px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.1);
  color: var(--gold-light);
}

/* Portrait Playing-Card 3x4 Grid for Opponent Preview (supports row & column compaction) */
.opp-grid {
  display: grid;
  grid-template-columns: repeat(4, var(--opp-col-w));
  grid-template-rows: repeat(3, var(--opp-row-h));
  justify-content: center;
  align-content: center;
  gap: 0;
  width: 100%;
  min-height: calc(3 * var(--opp-row-h));
  perspective: 450px;
}
.opp-mini-card {
  border-radius: 5px;
  height: calc(var(--opp-row-h) - 3px);
  margin: 1.5px;
  background: #222d40;
  border: 1.5px solid rgba(255, 255, 255, 0.28);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.42);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(10.5px, calc(var(--opp-row-h) * 0.36), 15px);
  font-weight: 900;
  letter-spacing: -0.02em;
  text-shadow: none;
  color: #3E2B25;
  line-height: 1;
  position: relative;
  transition: transform 0.2s var(--spring), box-shadow 0.2s ease;
}
.opponents-section:has(.opp-tray:only-child) .opp-mini-card {
  font-size: clamp(11px, calc(var(--opp-row-h) * 0.37), 16.5px);
  border-radius: 6px;
}
.opp-mini-card.mini-collapsed {
  margin: 0 !important;
  border: 0 !important;
  width: 0 !important;
  height: 0 !important;
  overflow: hidden !important;
  opacity: 0 !important;
  pointer-events: none !important;
}
.opp-mini-card.val-neg2,
.opp-mini-card.val-neg1 {
  background: linear-gradient(165deg, #FCF8F0, #EFE4D1);
  color: #5B21B6;
  border-color: #A78BFA;
  box-shadow: inset 0 2.5px 0 #7C3AED, 0 1px 3px rgba(0, 0, 0, 0.35);
}
.opp-mini-card.val-0 {
  background: linear-gradient(165deg, #FCF8F0, #EFE4D1);
  color: #0F766E;
  border-color: #5EEAD4;
  box-shadow: inset 0 2.5px 0 #0D9488, 0 1px 3px rgba(0, 0, 0, 0.35);
}
.opp-mini-card.val-1, .opp-mini-card.val-2, .opp-mini-card.val-3, .opp-mini-card.val-4 {
  background: linear-gradient(165deg, #FCF8F0, #EFE4D1);
  color: #27603A;
  border-color: #86C596;
  box-shadow: inset 0 2.5px 0 #2F6B3F, 0 1px 3px rgba(0, 0, 0, 0.35);
}
.opp-mini-card.val-5, .opp-mini-card.val-6, .opp-mini-card.val-7, .opp-mini-card.val-8 {
  background: linear-gradient(165deg, #FCF8F0, #EFE4D1);
  color: #9A4A0B;
  border-color: #F0B45B;
  box-shadow: inset 0 2.5px 0 #D97706, 0 1px 3px rgba(0, 0, 0, 0.35);
}
.opp-mini-card.val-9, .opp-mini-card.val-10, .opp-mini-card.val-11, .opp-mini-card.val-12 {
  background: linear-gradient(165deg, #FCF8F0, #EFE4D1);
  color: #9F1239;
  border-color: #F4839E;
  box-shadow: inset 0 2.5px 0 #BE123C, 0 1px 3px rgba(0, 0, 0, 0.35);
}
.opp-mini-card.hidden {
  background: repeating-linear-gradient(
    135deg,
    #152033 0px,
    #152033 4px,
    #1c2a42 4px,
    #1c2a42 8px
  );
  border: 1px solid rgba(212, 163, 71, 0.3);
  box-shadow: inset 0 0 0 2px rgba(9, 14, 24, 0.55), 0 2px 4px rgba(0, 0, 0, 0.35);
  color: transparent;
  text-shadow: none;
}
.opp-mini-card.hidden::after {
  content: '◆';
  font-size: 8px;
  color: rgba(245, 158, 11, 0.42);
  line-height: 1;
}
.opp-mini-card.cleared {
  opacity: 0.12;
  background: transparent;
  border: 1px dashed rgba(255, 255, 255, 0.15);
}
.opp-mini-card.opp-mini-clearing {
  box-shadow: 0 0 8px #f59e0b, 0 0 0 1.5px #fbbf24;
  z-index: 3;
  animation: miniClearingPulse 0.44s infinite alternate cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes miniClearingPulse {
  0% { transform: scale(1.02); box-shadow: 0 0 5px #f59e0b; }
  100% { transform: scale(1.14); box-shadow: 0 0 12px #fbbf24; }
}
@keyframes oppMiniFlip {
  0% {
    transform: translateY(0) scale(1) rotateY(0deg);
    animation-timing-function: cubic-bezier(0.42, 0, 0.9, 0.65);
  }
  44% {
    transform: translateY(-4px) scale(1.18) rotateY(90deg);
    box-shadow: 0 0 10px var(--cyan), 0 0 0 1.5px #7dd3fc;
  }
  44.01% {
    transform: translateY(-4px) scale(1.18) rotateY(-90deg);
    box-shadow: 0 0 12px var(--cyan), 0 0 0 1.5px #7dd3fc;
    animation-timing-function: cubic-bezier(0.18, 0.89, 0.32, 1.12);
  }
  100% {
    transform: translateY(0) scale(1) rotateY(0deg);
    box-shadow: 0 0 8px rgba(56, 189, 248, 0.72), 0 0 0 1.5px #7dd3fc;
  }
}
@keyframes oppMiniSwap {
  0% { transform: scale(0.86) translateY(-4px); box-shadow: 0 0 10px var(--gold), 0 0 0 1.5px #fde047; }
  52% { transform: scale(1.15) translateY(0); box-shadow: 0 0 12px var(--gold), 0 0 0 1.5px #fde047; }
  100% { transform: scale(1) translateY(0); box-shadow: 0 0 8px rgba(251, 191, 36, 0.75), 0 0 0 1.5px #fde047; }
}
.opp-mini-card.opp-mini-just-flipped {
  animation: oppMiniFlip 0.48s linear forwards;
  z-index: 4;
}
.opp-mini-card.opp-mini-just-flipped.opp-mini-reveal-end {
  animation-duration: 0.52s;
}
.opp-mini-card.opp-mini-just-swapped {
  animation: oppMiniSwap 0.44s cubic-bezier(0.22, 1, 0.36, 1) forwards;
  z-index: 4;
}
.opp-mini-card.opp-mini-recent-flip {
  box-shadow: 0 0 7px rgba(56, 189, 248, 0.65), 0 0 0 1.5px #7dd3fc;
  z-index: 3;
}
.opp-mini-card.opp-mini-recent-swap {
  box-shadow: 0 0 7px rgba(251, 191, 36, 0.7), 0 0 0 1.5px #fde047;
  z-index: 3;
}
.opp-mini-card.opp-mini-reveal-end {
  box-shadow: 0 0 10px rgba(56, 189, 248, 0.78), 0 0 0 1.5px #bae6fd;
  z-index: 4;
}
@keyframes scoreTickPop {
  0% { transform: scale(1); }
  45% { transform: scale(1.22); color: #fde047; }
  100% { transform: scale(1); }
}
.score-tick {
  display: inline-block;
  animation: scoreTickPop 0.44s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Center Table: Piles & Status */
.table-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(2px, calc((var(--avail-h) - 460px) * 0.015), 8px);
  padding: var(--center-pad-y) 12px;
  flex: 1 1 auto;
  min-height: 0;
  position: relative;
}

.piles-layout {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(22px, calc((var(--avail-w) - 240px) * 0.14 + 18px), 38px);
  width: 100%;
  transition: transform 0.24s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.2s ease, filter 0.2s ease;
}
.piles-layout.piles-holding,
.piles-layout.piles-peeking {
  transform: scale(0.92);
  opacity: 0.24;
  filter: blur(0.8px);
  pointer-events: none;
}

.pile-unit {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(7px, calc((var(--avail-h) - 480px) * 0.01 + 6px), 11px);
  cursor: pointer;
  touch-action: none;
}

.pile-tag {
  font-size: clamp(9.5px, calc(var(--pile-h) * 0.145), 12px);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  white-space: nowrap;
}

/* 3D Stacked Deck Effect - Classic Playing Card Proportions (5:7) */
.pile-deck-stack {
  position: relative;
  height: var(--pile-h);
  width: calc(var(--pile-h) / 1.4);
  perspective: 650px;
}
.pile-deck-stack .card-numeral {
  font-size: clamp(20px, calc(var(--pile-h) * 0.36), 38px);
}
.pile-deck-stack:not(.discard-pile-stack)::before,
.pile-deck-stack:not(.discard-pile-stack)::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 9px;
  background: #151e2c;
  border: 1px solid rgba(255, 255, 255, 0.14);
  pointer-events: none;
  transition: transform 0.2s ease, opacity 0.2s ease;
}
.pile-deck-stack:not(.discard-pile-stack)::before {
  transform: translate(2px, 2px);
  z-index: 1;
}
.pile-deck-stack:not(.discard-pile-stack)::after {
  transform: translate(4px, 4px);
  z-index: 0;
}
.pile-deck-stack[data-deck-depth="1"]::after,
.pile-deck-stack[data-deck-depth="0"]::before,
.pile-deck-stack[data-deck-depth="0"]::after {
  opacity: 0;
}

.pile-deck-stack .game-card {
  position: relative;
  z-index: 2;
}

/* Organic Thrown-Cards Discard Pile */
.discard-pile-stack {
  --pile-scatter: clamp(0.45, calc((var(--pile-h) - 46px) / 48px), 1);
}
.discard-pile-stack::before {
  content: "";
  position: absolute;
  inset: -4px -7px -5px -7px;
  border-radius: 16px;
  background: radial-gradient(ellipse at center, rgba(2, 6, 14, 0.42) 0%, rgba(2, 6, 14, 0.14) 56%, transparent 78%);
  pointer-events: none;
  z-index: 0;
  opacity: 0;
  transition: opacity 0.22s ease;
}
.discard-pile-stack.has-thrown-pile::before {
  opacity: 1;
}

.discard-underlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
}

.discard-underlay .discard-underlay-card {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  transform-origin: center center;
  transform:
    translate(
      calc(var(--throw-x, 0px) * var(--pile-scatter, 1)),
      calc(var(--throw-y, 0px) * var(--pile-scatter, 1))
    )
    rotate(var(--throw-rot, 0deg));
  filter: brightness(var(--depth-dim, 0.82)) saturate(0.92);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.56), 0 1px 2px rgba(0, 0, 0, 0.4);
  transition: transform 0.22s cubic-bezier(0.22, 1, 0.36, 1), filter 0.22s ease;
}
.discard-underlay .discard-underlay-card .card-numeral {
  opacity: 0.72;
}

.discard-pile-stack #discardPileCard {
  z-index: 8;
  transform-origin: center center;
}
.discard-pile-stack #discardPileCard:not(.empty-pile-slot) {
  transform:
    translate(
      calc(var(--throw-x, 0px) * var(--pile-scatter, 1)),
      calc(var(--throw-y, 0px) * var(--pile-scatter, 1))
    )
    rotate(var(--throw-rot, 0deg));
}
.discard-pile-stack.has-thrown-pile #discardPileCard:not(.empty-pile-slot):not(.pulse-glow) {
  box-shadow: 0 9px 20px rgba(0, 0, 0, 0.62), 0 2px 5px rgba(0, 0, 0, 0.44);
}
.discard-pile-stack.has-thrown-pile #discardPileCard.pulse-glow:not(.empty-pile-slot) {
  box-shadow: 0 0 18px rgba(245, 158, 11, 0.48), 0 9px 20px rgba(0, 0, 0, 0.62);
}
.discard-pile-stack #discardPileCard.empty-pile-slot {
  transform: none;
}

.pile-counter {
  position: absolute;
  top: -6px;
  right: -8px;
  background: linear-gradient(135deg, #1e293b, #0f172a);
  border: 1.5px solid rgba(255, 255, 255, 0.22);
  border-radius: 999px;
  padding: 1px 7px;
  font-size: 11px;
  font-weight: 800;
  color: #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,0.6);
  z-index: 12;
}
