#game-hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 5;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

#game-hud[hidden] {
  display: none !important;
}

#game-hud.game-hud-intro-hidden {
  opacity: 0;
  pointer-events: none;
}

#game-hud.game-hud-intro-enter {
  animation: game-hud-intro-reveal 0.45s ease-out forwards;
}

@keyframes game-hud-intro-reveal {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

}

.game-hud-connection-banner {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 1rem;
  border-radius: 0 0 10px 10px;
  font-size: 0.85rem;
  font-weight: 600;
  color: #1a1a1a;
  background: rgba(255, 255, 255, 0.92);
  pointer-events: auto;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.game-hud-connection-banner--warning {
  background: rgba(255, 193, 7, 0.92);
}

.game-hud-connection-banner--error {
  background: rgba(220, 53, 69, 0.92);
  color: #fff;
}

.game-hud-connection-banner__retry {
  border: none;
  border-radius: 6px;
  padding: 0.2rem 0.6rem;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.9);
  color: #1a1a1a;
}

#game-hud-top,
#game-hud-status,
#game-hud-dock,
.game-hud-top-inner,
.game-hud-scores,
.game-hud-top-actions,
.glass-icon-btn,
.glass-pill,
.glass-status-pill,
.glass-chip,
.game-hud-chip-row,
#game-hud-modal,
.glass-modal,
.glass-popover {
  pointer-events: auto;
}

.game-hud-top {
  padding: calc(8px + env(safe-area-inset-top)) 12px 4px;
}

.game-hud-top-inner {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.game-hud-top-inner {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.game-hud-scoreboard-row {
  flex: 1;
  min-width: 0;
}

.game-hud-scoreboard {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  width: 100%;
}

.scoreboard-player {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 10px;
  border-radius: 12px;
  background: var(--hud-glass-bg);
  backdrop-filter: var(--hud-glass-blur);
  -webkit-backdrop-filter: var(--hud-glass-blur);
  border: 1px solid var(--hud-glass-border);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
  min-width: 0;
}

.scoreboard-player--remote {
  justify-self: start;
}

.scoreboard-player--local {
  justify-self: end;
}

.scoreboard-player--active {
  border-color: rgba(255, 209, 102, 0.45);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.12),
    0 0 12px rgba(255, 209, 102, 0.15);
}

.scoreboard-player-label {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--hud-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.scoreboard-player-score {
  font-size: 1rem;
  font-weight: 700;
  color: var(--hud-accent-gold);
  line-height: 1;
}

.scoreboard-target {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--hud-glass-border);
}

.scoreboard-target-value {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--hud-text-muted);
  white-space: nowrap;
}

.game-hud-actions-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-shrink: 0;
}

.game-hud-scores {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

.game-hud-top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.glass-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--hud-glass-bg);
  backdrop-filter: var(--hud-glass-blur);
  -webkit-backdrop-filter: var(--hud-glass-blur);
  border: 1px solid var(--hud-glass-border);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.1),
    0 4px 16px rgba(0, 0, 0, 0.15);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--hud-text);
}

.glass-pill--active {
  border-color: rgba(255, 209, 102, 0.45);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.14),
    0 0 16px rgba(255, 209, 102, 0.15);
}

.glass-pill-label {
  opacity: 0.85;
  font-weight: 500;
}

.glass-pill-score {
  color: var(--hud-accent-gold);
}

.glass-pill-target {
  font-size: 0.8rem;
  color: var(--hud-text-muted);
  font-weight: 500;
}

.glass-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

#game-hud-status {
  padding: 0 16px 4px;
}

.glass-status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: min(100%, 640px);
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(15, 47, 31, 0.45);
  backdrop-filter: var(--hud-glass-blur);
  -webkit-backdrop-filter: var(--hud-glass-blur);
  border: 1px solid var(--hud-glass-border);
  font-size: 0.82rem;
  color: #d8f3dc;
  line-height: 1.35;
}

.glass-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #6c757d;
  flex-shrink: 0;
}

.glass-status-dot--active {
  background: var(--hud-accent-green);
  box-shadow: 0 0 6px rgba(82, 183, 136, 0.8);
}

.game-hud-dock {
  margin-top: auto;
  padding: 0 12px calc(12px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.game-hud-dock-hint {
  margin: 0;
  font-size: 0.78rem;
  color: var(--hud-text-muted);
  text-align: center;
}

.game-hud-chip-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: min(100%, 640px);
  width: 100%;
  justify-content: center;
  padding-bottom: 4px;
  scrollbar-width: none;
}

.game-hud-chip-row::-webkit-scrollbar {
  display: none;
}

.glass-chip {
  flex-shrink: 0;
  white-space: nowrap;
}

.game-hud-capture-picker-title {
  margin: 0 0 12px;
  font-size: 1rem;
  text-align: center;
}

.game-hud-capture-picker-options {
  flex-direction: column;
  align-items: stretch;
  overflow-x: visible;
}

.game-hud-capture-picker-options .glass-chip {
  white-space: normal;
  text-align: center;
  min-height: 44px;
}

.game-hud-capture-picker-cancel {
  display: flex;
  justify-content: center;
  margin-top: 10px;
}

#game-hud-modal {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  padding-top: calc(24px + env(safe-area-inset-top));
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
  background:
    radial-gradient(
      ellipse at center,
      rgba(15, 47, 31, 0.35) 0%,
      var(--ui-overlay-bg) 72%
    );
  backdrop-filter: blur(8px) saturate(1.2);
  -webkit-backdrop-filter: blur(8px) saturate(1.2);
  pointer-events: auto;
}

#game-hud-modal:empty {
  display: none;
  pointer-events: none;
}

.glass-modal {
  position: relative;
  width: min(100%, 400px);
  max-height: min(70vh, 520px);
  overflow-y: auto;
  padding: 24px 22px;
  border-radius: var(--ui-radius-lg);
  background: var(--hud-glass-bg);
  backdrop-filter: var(--hud-glass-blur);
  -webkit-backdrop-filter: var(--hud-glass-blur);
  border: 1px solid var(--hud-glass-border);
  box-shadow: var(--ui-shadow-panel);
  display: flex;
  flex-direction: column;
  gap: 14px;
  animation: ui-panel-enter 0.42s var(--ui-ease-out) forwards;
}

.glass-modal::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  padding: 1px;
  background: linear-gradient(
    145deg,
    rgba(255, 209, 102, 0.28),
    rgba(255, 255, 255, 0.06) 40%,
    rgba(255, 209, 102, 0.12)
  );
  -webkit-mask:
    linear-gradient(#fff 0 0) content-box,
    linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
}

.glass-modal-title {
  margin: 0 0 4px;
  font-family: "Cinzel", serif;
  font-size: 1.25rem;
  letter-spacing: 0.05em;
  color: var(--hud-accent-gold);
  text-shadow: 0 1px 8px rgba(255, 209, 102, 0.2);
}

.glass-modal-desc {
  margin: 0;
  font-family: "Lora", Georgia, serif;
  font-size: 0.9rem;
  color: #d8f3dc;
  line-height: 1.45;
}

.glass-modal-breakdown {
  font-size: 0.85rem;
  color: var(--hud-text-muted);
  line-height: 1.5;
}

.hud-breakdown {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px 14px;
  border-radius: var(--ui-radius-md);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.hud-breakdown-title {
  display: block;
  margin-bottom: 4px;
  color: var(--hud-accent-gold);
  font-family: "Cinzel", serif;
}

.hud-breakdown-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding: 4px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.hud-breakdown-row:last-child {
  border-bottom: none;
  font-weight: 600;
  color: var(--hud-text);
}

.hud-breakdown-label {
  flex-shrink: 0;
  color: var(--hud-text-muted);
}

.hud-breakdown-values {
  text-align: right;
  color: var(--hud-text);
}

.glass-modal-hand {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 8px 0;
}

.glass-modal-hand-card {
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

.glass-modal-bazzica-type {
  color: var(--hud-accent-gold);
  font-weight: 600;
}

.glass-modal-joker-note {
  font-size: 0.82rem;
  font-style: italic;
  color: var(--hud-accent-gold);
}

.glass-modal-breakdown {
  font-size: 0.85rem;
  color: var(--hud-text-muted);
  line-height: 1.5;
}

.glass-modal-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 4px;
}

.glass-modal-actions .glass-chip {
  justify-content: center;
}

.glass-modal-actions--coin {
  flex-direction: column;
  align-items: stretch;
  gap: 12px;
}

.glass-chip--coin {
  width: 100%;
  min-width: 0;
  padding: 14px 24px;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  gap: 12px;
}

.glass-chip-coin-preview {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border-radius: 50%;
  object-fit: cover;
  background: radial-gradient(circle at 35% 30%, #2d6a4f 0%, #1b4332 100%);
}

#game-hud-popover,
#game-hud-chat-popover,
.game-hud-chat-layer,
.chat-bubble,
.chat-picker-popover,
.chat-picker-emote-btn {
  pointer-events: auto;
}

#game-hud-popover {
  position: absolute;
  top: calc(56px + env(safe-area-inset-top));
  right: 12px;
  z-index: 6;
  max-width: min(320px, calc(100vw - 24px));
}

#game-hud-popover[hidden] {
  display: none;
}

#game-hud-chat-popover {
  position: absolute;
  top: calc(56px + env(safe-area-inset-top));
  right: 56px;
  z-index: 8;
  max-width: min(280px, calc(100vw - 24px));
}

#game-hud-chat-popover[hidden] {
  display: none;
}

.game-hud-chat-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 7;
  overflow: visible;
}

.chat-bubble {
  position: absolute;
  pointer-events: none;
}

.chat-bubble-inner {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 56px;
  min-height: 56px;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(15, 47, 31, 0.88);
  backdrop-filter: var(--hud-glass-blur);
  -webkit-backdrop-filter: var(--hud-glass-blur);
  border: 2px solid rgba(255, 209, 102, 0.5);
  box-shadow:
    0 8px 24px rgba(0, 0, 0, 0.5),
    0 0 12px rgba(255, 209, 102, 0.15);
  transform-origin: center top;
}

.chat-bubble--phrase {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--hud-text);
  white-space: nowrap;
  border-radius: 14px;
}

.chat-bubble-emote {
  display: block;
  width: 48px;
  height: 48px;
}

.chat-bubble-emoji,
.chat-picker-emoji {
  display: block;
  font-size: 1.75rem;
  line-height: 1;
}

.chat-picker-emoji {
  font-size: 1.5rem;
}

.chat-picker-popover {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chat-picker-title {
  margin: 0;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--hud-text-muted);
}

.chat-picker-emotes {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.chat-picker-emote-btn {
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-picker-phrases {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chat-picker-phrase-chip:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.chat-picker-cooldown {
  margin: 0;
  font-size: 0.75rem;
  color: var(--hud-accent-gold);
  text-align: center;
}

.glass-icon-btn--cooldown {
  opacity: 0.55;
}

.glass-icon-btn--cooldown:disabled {
  cursor: not-allowed;
}

.glass-popover {
  padding: 14px 16px;
  border-radius: 14px;
  background: var(--hud-glass-bg);
  backdrop-filter: var(--hud-glass-blur);
  -webkit-backdrop-filter: var(--hud-glass-blur);
  border: 1px solid var(--hud-glass-border);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  font-size: 0.85rem;
  color: var(--hud-text-muted);
  line-height: 1.5;
}

#game-hud.game-hud-busy .game-hud-chip-row,
#game-hud.game-hud-busy .glass-modal {
  pointer-events: none;
}

@media (min-width: 768px) {
  .game-hud-top {
    padding-left: 20px;
    padding-right: 20px;
  }

  .game-hud-top-inner {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
  }

  .glass-status-pill {
    font-size: 0.88rem;
  }

  .game-hud-dock {
    padding-left: 20px;
    padding-right: 20px;
  }
}

@media (max-width: 767px) {
  .glass-status-text {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  #game-hud-popover,
  #game-hud-chat-popover {
    top: auto;
    bottom: calc(
      var(--mobile-actions-height, 80px) + 12px + env(safe-area-inset-bottom)
    );
    left: 12px;
    right: 12px;
    max-width: none;
    z-index: 8;
  }

  #game-hud-chat-popover {
    right: 12px;
  }

  .glass-popover {
    max-height: min(50vh, 360px);
    overflow-y: auto;
  }
}

/* Match VS intro overlay (after coin toss) */
.match-vs-overlay {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(12px, 4vw, 32px);
  padding: 16px clamp(12px, 4vw, 28px);
  background: radial-gradient(
    ellipse at center,
    rgba(8, 28, 22, 0.72) 0%,
    rgba(4, 16, 12, 0.88) 55%,
    rgba(2, 10, 8, 0.94) 100%
  );
  pointer-events: none;
}

.match-vs-side {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  flex: 1 1 0;
  min-width: 0;
  max-width: 42%;
}

.match-vs-side--local {
  align-items: flex-end;
  text-align: right;
}

.match-vs-side--opponent {
  align-items: flex-start;
  text-align: left;
}

.match-vs-avatar-wrap {
  position: relative;
  width: clamp(72px, 22vw, 128px);
  height: clamp(72px, 22vw, 128px);
  border-radius: 50%;
  padding: 3px;
  background: linear-gradient(
    135deg,
    rgba(255, 209, 102, 0.9) 0%,
    rgba(201, 162, 39, 0.55) 50%,
    rgba(255, 232, 163, 0.85) 100%
  );
  box-shadow:
    0 0 24px rgba(255, 209, 102, 0.35),
    0 8px 28px rgba(0, 0, 0, 0.45);
  transform-origin: center center;
}

.match-vs-avatar-wrap--opening,
.match-vs-avatar-wrap--will-open {
  box-shadow:
    0 0 32px rgba(255, 209, 102, 0.55),
    0 0 48px rgba(255, 209, 102, 0.25),
    0 8px 28px rgba(0, 0, 0, 0.45);
}

.match-vs-avatar {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  display: block;
  border: 2px solid rgba(27, 67, 50, 0.85);
  background: rgba(12, 40, 32, 0.9);
}

.match-vs-name {
  font-family: "Lora", Georgia, serif;
  font-size: clamp(0.85rem, 3.2vw, 1.1rem);
  font-weight: 600;
  color: #f5f0e6;
  letter-spacing: 0.03em;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}

.match-vs-badges {
  justify-content: center;
  max-width: 100%;
}

.match-vs-badges .player-badge-label {
  display: none;
}

.match-vs-badge {
  flex: 0 0 auto;
  font-family: "Cinzel", "Times New Roman", serif;
  font-size: clamp(2rem, 10vw, 3.5rem);
  font-weight: 700;
  letter-spacing: 0.12em;
  line-height: 1;
  background: linear-gradient(
    135deg,
    #ffe8a3 0%,
    #ffd166 35%,
    #c9a227 70%,
    #f5e6c8 100%
  );
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 18px rgba(255, 209, 102, 0.45))
    drop-shadow(0 4px 12px rgba(0, 0, 0, 0.5));
  transform-origin: center center;
}

@media (max-width: 480px) {
  .match-vs-overlay {
    gap: 8px;
  }

  .match-vs-side {
    max-width: 38%;
  }
}
