/* ==========================================================================
   Royal Chess — hud.css
   In-game HUD: player plates (clock, score, captured material, turn glow,
   low-time alarm), buttons, 3D camera controls, toast, view-board bar.
   Plates are positioned by ui.js from the board layout.
   ========================================================================== */

.hud { z-index: 10; pointer-events: none; }
.hud.active { pointer-events: none; }
.hud.active .hud-buttons, .hud.active .view-bar.show, .hud.active .cam-controls.show { pointer-events: auto; }

.hud-player {
  position: absolute;
  width: 250px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: opacity 0.3s ease, transform 0.3s ease;
}
.hud-player.hidden-soft { opacity: 0; transform: scale(0.95); }
#hud-top { left: 12px; top: 12px; }
#hud-bottom { right: 12px; bottom: 12px; flex-direction: column-reverse; }

.hud-plate {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  height: clamp(58px, 9vmin, 84px);
  padding: 0 14px 0 6px;
  border-style: solid;
  border-color: transparent;
  border-width: 14px;
  border-image: url('../assets/images/ui/hud_plate.png') 30 fill / 14px stretch;
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.6));
  transition: filter 0.35s ease, transform 0.35s ease;
}
.hud-plate > * { margin: -12px 0; }
.hud-king { position: relative; align-self: stretch; flex: none; width: clamp(40px, 6vmin, 56px); }
.hud-king img {
  position: absolute; left: 50%; bottom: -6px;
  height: clamp(66px, 10.5vmin, 98px); width: auto;
  transform: translateX(-50%);
  filter: drop-shadow(0 4px 4px rgba(0, 0, 0, 0.7));
}
.hud-text { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.hud-name {
  font-family: var(--font-head);
  font-weight: 800;
  font-size: clamp(11px, 1.7vmin, 15px);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.hud-time { display: flex; align-items: center; gap: 6px; }
.hud-time img { width: clamp(20px, 3vmin, 28px); height: clamp(20px, 3vmin, 28px); }
.hud-time .time {
  font-family: var(--font-head);
  font-weight: 800;
  font-size: clamp(22px, 3.8vmin, 34px);
  color: var(--ivory);
  font-variant-numeric: tabular-nums;
  text-shadow: 0 2px 0 #02120c;
  line-height: 1;
}
.hud-turn { width: 12px; height: 12px; border-radius: 50%; background: #3b4a42; box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.8); flex: none; }

.hud-player.active .hud-plate {
  filter: drop-shadow(0 0 6px rgba(246, 227, 163, 0.95)) drop-shadow(0 0 18px rgba(246, 208, 110, 0.7)) drop-shadow(0 6px 10px rgba(0, 0, 0, 0.6));
  transform: scale(1.03);
}
.hud-player.active .hud-turn {
  background: radial-gradient(circle at 35% 30%, #c9ffe4, #2ad18a 55%, #0c6b44);
  box-shadow: 0 0 10px #3cf0a4;
  animation: turnBlink 1.2s ease-in-out infinite;
}
@keyframes turnBlink { 50% { opacity: 0.45; } }
.hud-player.in-check .hud-plate {
  filter: drop-shadow(0 0 8px rgba(255, 60, 40, 0.95)) drop-shadow(0 0 20px rgba(255, 40, 20, 0.6)) drop-shadow(0 6px 10px rgba(0, 0, 0, 0.6));
}
.hud-player.low-time .time { color: #ff6b5c; animation: lowPulse 0.9s ease-in-out infinite; }
@keyframes lowPulse { 50% { color: #ffd7cf; text-shadow: 0 0 12px rgba(255, 80, 60, 0.9); } }
.hud-player.flagged .time { color: #ff3b2f; }

.hud-extra { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
#hud-bottom .hud-extra { justify-content: flex-end; }
.hud-score {
  display: flex; align-items: center; gap: 6px;
  padding: 3px 14px 3px 8px;
  border-radius: 20px;
  background: linear-gradient(rgba(10, 44, 32, 0.92), rgba(4, 22, 16, 0.92));
  box-shadow: 0 0 0 2px var(--gold-dark), 0 4px 8px rgba(0, 0, 0, 0.5);
  font-family: var(--font-head); font-weight: 800;
  font-size: clamp(14px, 2.2vmin, 19px);
  color: var(--gold-light);
  font-variant-numeric: tabular-nums;
}
.hud-score img { width: 20px; height: 20px; }
.hud-score.hidden-soft { display: none; }
.hud-captured {
  display: flex; align-items: center; gap: 0;
  min-height: 26px;
  padding: 1px 8px;
  border-radius: 14px;
  background: rgba(4, 22, 16, 0.55);
}
.hud-captured:empty { display: none; }
.hud-captured img { height: 26px; margin: -3px -7px; filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.7)); }
.hud-captured .adv { margin-left: 8px; font-family: var(--font-head); font-weight: 800; font-size: 13px; color: var(--gold-light); }

.hud-buttons {
  position: absolute;
  top: calc(12px + var(--safe-top));
  right: calc(12px + var(--safe-right));
  display: flex;
  gap: 8px;
}
.cam-controls {
  position: absolute;
  left: 50%;
  bottom: calc(10px + var(--safe-bottom));
  transform: translate(-50%, 160%);
  display: flex;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 40px;
  background: rgba(4, 22, 16, 0.6);
  box-shadow: 0 0 0 1px rgba(217, 178, 95, 0.4), 0 8px 18px rgba(0, 0, 0, 0.5);
  transition: transform 0.35s cubic-bezier(.2, 1.3, .4, 1);
}
.cam-controls.show { transform: translate(-50%, 0); }
.cam-controls .medal { --medal-small: 40px; }

/* compact plates when the space beside the board is narrow */
.hud-player.compact .hud-plate { gap: 6px; padding: 0 6px 0 2px; height: 58px; }
.hud-player.compact .hud-king { width: 34px; }
.hud-player.compact .hud-king img { height: 64px; }
.hud-player.compact .hud-name { font-size: 10px; letter-spacing: 0.05em; }
.hud-player.compact .hud-time { gap: 4px; }
.hud-player.compact .hud-time img { width: 18px; height: 18px; }
.hud-player.compact .hud-time .time { font-size: 22px; }
.hud-player.compact .hud-turn { display: none; }
.hud-player.compact .hud-score { font-size: 14px; }

/* toast */
.toast {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%) scale(0.6);
  padding: 10px 34px;
  border-radius: 999px;
  font-family: var(--font-display);
  font-weight: 900;
  font-size: clamp(24px, 5vmin, 48px);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #fff3e0;
  background: radial-gradient(ellipse at center, rgba(120, 10, 16, 0.92), rgba(60, 4, 8, 0.85));
  box-shadow: 0 0 0 3px var(--gold), 0 0 0 5px #3a0508, 0 10px 30px rgba(0, 0, 0, 0.7);
  text-shadow: 0 3px 0 #2a0206, 0 0 16px rgba(255, 120, 90, 0.7);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.35s cubic-bezier(.2, 1.6, .4, 1);
  white-space: nowrap;
  z-index: 20;
}
.toast.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.toast.gold { background: radial-gradient(ellipse at center, rgba(16, 80, 58, 0.94), rgba(5, 36, 26, 0.9)); text-shadow: 0 3px 0 #02140d, 0 0 16px rgba(246, 227, 163, 0.6); }
.toast.blue { background: radial-gradient(ellipse at center, rgba(20, 60, 110, 0.94), rgba(8, 26, 52, 0.9)); text-shadow: 0 3px 0 #04101f, 0 0 16px rgba(140, 200, 255, 0.6); }
.toast.small { font-size: clamp(16px, 3vmin, 26px); padding: 8px 22px; }

/* view-board bar */
.view-bar {
  position: absolute;
  left: 50%;
  bottom: calc(10px + var(--safe-bottom));
  transform: translate(-50%, 140%);
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px;
  border-radius: 16px;
  background: rgba(4, 22, 16, 0.88);
  box-shadow: 0 0 0 2px var(--gold-dark), 0 10px 24px rgba(0, 0, 0, 0.7);
  transition: transform 0.35s cubic-bezier(.2, 1.3, .4, 1);
}
.view-bar.show { transform: translate(-50%, 0); }
.view-label { display: flex; align-items: center; gap: 6px; font-family: var(--font-head); font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--gold-light); font-size: 13px; margin-right: 4px; }
.view-label img { width: 22px; height: 22px; }

.portrait .hud-player { max-width: 80vw; }
.portrait .hud-name { letter-spacing: 0.06em; font-size: 12px; }
.portrait #hud-bottom { flex-direction: column; }
.portrait #hud-bottom .hud-extra { justify-content: flex-end; }
.portrait .hud-buttons .medal.small { --medal-small: 38px; }

@media (max-height: 460px) {
  .hud-score { font-size: 13px; padding: 2px 10px 2px 6px; }
  .hud-score img { width: 16px; height: 16px; }
}

/* ==========================================================================
   Match layer: move-quality badges, camera flashes, tension vignette and the
   opening ceremony.  Driven by Match in main.js.
   ========================================================================== */
.bc-badge, .bc-intro { display: none; }

/* move-quality badge (chess.com style), placed on the destination square */
.bc-badge {
  position: absolute; z-index: 3;
  align-items: center; gap: 6px;
  transform: translate(-15px, -50%) scale(0.2);
  transform-origin: 15px 50%;
  opacity: 0; pointer-events: none;
  transition: transform 0.35s cubic-bezier(.2, 1.7, .4, 1), opacity 0.25s ease;
}
.bc-badge.show { display: flex; transform: translate(-15px, -50%) scale(1); opacity: 1; }
.bc-badge.fade { opacity: 0; transform: translate(-15px, -90%) scale(0.9); transition: transform 0.6s ease, opacity 0.6s ease; }
.bc-badge b {
  flex: none; width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center;
  font-family: 'Segoe UI', Arial, sans-serif; font-weight: 900; font-size: 15px; color: #fff;
  background: var(--q, #7fb239);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.9), 0 4px 10px rgba(0, 0, 0, 0.55), 0 0 18px var(--q, #7fb239);
}
.bc-badge span {
  padding: 2px 9px; border-radius: 10px;
  background: rgba(10, 7, 5, 0.85); color: var(--q, #fff);
  font-family: var(--font-head); font-weight: 700; font-size: 12px; letter-spacing: 0.04em; white-space: nowrap;
  box-shadow: 0 0 0 1px var(--q, #fff);
}
.bc-badge.brilliant { --q: #1bb3a6; } .bc-badge.great { --q: #5b8bd6; } .bc-badge.best { --q: #81b64c; }
.bc-badge.excellent { --q: #96bc4b; } .bc-badge.good { --q: #97af8b; } .bc-badge.book { --q: #a88865; }
.bc-badge.inaccuracy { --q: #f0c15c; } .bc-badge.mistake { --q: #e58f2a; } .bc-badge.blunder { --q: #ca3431; }
.bc-badge.brilliant b, .bc-badge.blunder b { animation: bcPulse 0.9s ease-in-out 2; }
@keyframes bcPulse { 50% { transform: scale(1.25); } }

/* camera flashes from the stands */
.bc-flashes { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.bc-flash { position: absolute; width: 90px; height: 90px; margin: -45px 0 0 -45px; border-radius: 50%; background: radial-gradient(circle, rgba(255, 252, 240, 0.7), rgba(255, 240, 210, 0.28) 22%, rgba(255, 255, 255, 0) 62%); animation: bcFlash 0.32s ease-out forwards; opacity: 0.85; }
@keyframes bcFlash { from { opacity: 0.85; transform: scale(0.6); } to { opacity: 0; transform: scale(1.4); } }
.bc-whiteout { position: absolute; inset: 0; background: #fff; opacity: 0; animation: bcWhite 0.5s ease-out; pointer-events: none; }
@keyframes bcWhite { 10% { opacity: 0.12; } }

/* tension vignette: --t 0..1 tightens the light, .danger tints it red and pulses */
.bc-vignette {
  position: absolute; inset: 0; pointer-events: none; opacity: 0;
  --t: 0;
  background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0) calc(62% - var(--t) * 22%), rgba(0, 0, 0, calc(0.25 + var(--t) * 0.5)) 100%);
  transition: opacity 1.2s ease;
}
.hud.bc-atmo .bc-vignette { opacity: 1; }
.bc-vignette.danger { background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0) calc(58% - var(--t) * 20%), rgba(120, 0, 0, calc(0.3 + var(--t) * 0.45)) 100%); animation: bcDanger 0.9s ease-in-out infinite; }
@keyframes bcDanger { 50% { opacity: 0.72; } }   /* opacity only: a filter pulse repainted the whole screen every frame */

/* opening ceremony */
.bc-intro {
  position: absolute; inset: 0; z-index: 30;
  place-items: center;
  background: radial-gradient(ellipse at center, rgba(12, 8, 4, 0.74), rgba(0, 0, 0, 0.92));
  backdrop-filter: blur(3px);
  pointer-events: auto; cursor: pointer;
  animation: bcFadeIn 0.5s ease-out;
}
.bc-intro.show { display: grid; }
.bc-intro.out { opacity: 0; transition: opacity 0.5s ease; }
@keyframes bcFadeIn { from { opacity: 0; } }
.bc-intro-card { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 26px 34px 18px; text-align: center; color: var(--ivory); }
.bc-intro-event { font-family: var(--font-display); font-weight: 900; font-size: clamp(22px, 4.4vmin, 44px); letter-spacing: 0.06em; color: var(--gold-light); text-shadow: 0 3px 0 #2a1a05, 0 0 24px rgba(246, 208, 110, 0.5); animation: bcDrop 0.7s cubic-bezier(.2, 1.3, .4, 1); }
.bc-intro-round { font-family: var(--font-head); letter-spacing: 0.24em; text-transform: uppercase; font-size: clamp(11px, 1.8vmin, 15px); color: var(--gold); }
.bc-intro-players { display: flex; align-items: center; gap: clamp(14px, 4vmin, 48px); margin: 10px 0 6px; }
.bc-intro-player { display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: clamp(120px, 22vmin, 220px); animation: bcSlideL 0.8s cubic-bezier(.2, 1.2, .4, 1); }
#bc-intro-b { animation-name: bcSlideR; }
.bc-intro-player img { height: clamp(90px, 18vmin, 170px); filter: drop-shadow(0 10px 14px rgba(0, 0, 0, 0.7)); }
.bc-intro-player b { font-family: var(--font-head); font-size: clamp(15px, 2.6vmin, 24px); letter-spacing: 0.06em; color: #fff; }
.bc-intro-player small { font-style: italic; font-size: clamp(13px, 1.9vmin, 17px); color: rgba(247, 238, 215, 0.8); }
.bc-intro-player em { font-style: normal; font-family: var(--font-head); font-size: 12px; letter-spacing: 0.1em; color: var(--gold); padding: 1px 8px; border-radius: 9px; box-shadow: 0 0 0 1px rgba(217, 178, 95, 0.5); margin-top: 4px; }
.bc-intro-vs { font-family: var(--font-display); font-weight: 900; font-size: clamp(26px, 5vmin, 52px); color: #c4161c; text-shadow: 0 0 18px rgba(230, 30, 30, 0.6), 0 3px 0 #2a0206; animation: bcVs 0.9s ease-out; }
.bc-intro-call { min-height: 1.4em; font-family: var(--font-head); font-size: clamp(14px, 2.4vmin, 22px); letter-spacing: 0.08em; color: var(--gold-light); }
.bc-intro-call.swap { animation: bcIn 0.5s ease-out; }
.bc-intro-skip { font-size: 13px; color: rgba(247, 238, 215, 0.5); font-style: italic; }
@keyframes bcIn { from { opacity: 0; transform: translateY(10px); } }
@keyframes bcDrop { from { opacity: 0; transform: translateY(-30px) scale(1.15); } }
@keyframes bcSlideL { from { opacity: 0; transform: translateX(-60px); } }
@keyframes bcSlideR { from { opacity: 0; transform: translateX(60px); } }
@keyframes bcVs { 0% { opacity: 0; transform: scale(2.4); } 60% { opacity: 1; transform: scale(0.9); } }
.portrait .bc-intro-player { min-width: 0; }
.portrait .bc-intro-card { padding: 16px 10px; }

.result-acc { display: block; margin-top: 4px; font-family: var(--font-head); font-size: 12px; letter-spacing: 0.06em; color: var(--gold-light); }
