/* ==========================================================================
   Royal Chess — cinema.css  (v5)
   The cinematic layer over a match: letterbox bars, big move
   callouts (brilliant / blunder / check / fork …), small chips, phase title
   cards, achievement toasts and the achievements gallery.  Driven by Cinema
   in main.js through UI (ui.js).
   ========================================================================== */

.cine {
  position: absolute; inset: 0; z-index: 25;           /* over the board + HUD panels, under the ceremony (30) and modals (40) */
  pointer-events: none; overflow: hidden;
  --lb: 9vh;
}
#app.portrait .cine { --lb: 6vh; }

/* ---- letterbox ---- */
.cine-bar {
  position: absolute; left: 0; right: 0; height: var(--lb);
  background: #000;
  box-shadow: 0 0 40px 10px rgba(0, 0, 0, 0.6);
  transition: transform 0.75s cubic-bezier(.6, 0, .2, 1);
}
.cine-bar.top { top: 0; transform: translateY(-110%); }
.cine-bar.bottom { bottom: 0; transform: translateY(110%); }
.cine.letterbox .cine-bar { transform: none; }

/* v6: no film grain: the picture stays clean (it also forced a blend group over the live 3D canvas) */

/* ---- big callout ---- */
.cine-callout {
  position: absolute; left: 50%; top: 44%;
  transform: translate(-50%, -50%);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  text-align: center; white-space: nowrap;
  opacity: 0;
  --c1: #fffbe6; --c2: #f3d98f; --c3: #b07a2c; --glow: rgba(255, 210, 120, 0.7);
}
.cine-callout.show { animation: coIn 0.6s cubic-bezier(.2, 1.35, .4, 1) both; }
.cine-callout.hide { animation: coOut 0.45s ease-in both; }
.co-title {
  position: relative;
  font-family: var(--font-display); font-weight: 900;
  font-size: clamp(38px, 9vmin, 112px); line-height: 1.02;
  letter-spacing: 0.03em; text-transform: uppercase;
  background: linear-gradient(180deg, var(--c1) 8%, var(--c2) 58%, var(--c3) 96%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 3px 0 rgba(0, 0, 0, 0.65)) drop-shadow(0 0 24px var(--glow));
}
.co-kicker {
  font-family: var(--font-head); font-weight: 800;
  font-size: clamp(11px, 1.9vmin, 17px); letter-spacing: 0.46em; text-transform: uppercase;
  color: var(--c2); filter: drop-shadow(0 2px 3px #000);
}
.co-sub {
  max-width: min(86vw, 760px); white-space: normal;
  font-family: var(--font-body); font-style: italic; font-weight: 600;
  font-size: clamp(16px, 2.6vmin, 27px); color: var(--ivory);
  text-shadow: 0 2px 6px #000, 0 0 14px rgba(0, 0, 0, 0.85);
}
.co-kicker:empty, .co-sub:empty { display: none; }
.co-sweep {
  position: absolute; inset: -10% -30%;
  background: linear-gradient(100deg, transparent 38%, rgba(255, 245, 220, 0.22) 50%, transparent 62%);
  transform: translateX(-130%);
}
.cine-callout.show .co-sweep { animation: coSweep 1.15s 0.28s ease-out both; }
/* transform + opacity only: these run on the compositor, never repainting the big gilded type */
@keyframes coIn {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(1.6); }
  55% { opacity: 1; }
  100% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}
@keyframes coOut { to { opacity: 0; transform: translate(-50%, -62%) scale(0.92); } }
@keyframes coSweep { to { transform: translateX(130%); } }

.cine-callout.brilliant { --c1: #fffdf0; --c2: #ffe08a; --c3: #b8791c; --glow: rgba(64, 224, 208, 0.75); }   /* royal gold, the teal aura of the !! badge */
.cine-callout.great { --c1: #eef5ff; --c2: #8fb8ff; --c3: #3a63b8; --glow: rgba(110, 160, 255, 0.7); }
.cine-callout.mistake { --c1: #fff3df; --c2: #ffb15a; --c3: #b85d14; --glow: rgba(255, 150, 60, 0.65); }
.cine-callout.blunder { --c1: #ffece9; --c2: #ff5a4a; --c3: #8e1410; --glow: rgba(255, 40, 30, 0.8); }
.cine-callout.check { --c1: #fff0ec; --c2: #ff6b5a; --c3: #9e1e14; --glow: rgba(255, 60, 40, 0.6); }
.cine-callout.check .co-title { font-size: clamp(32px, 7vmin, 86px); }
.cine-callout.motif { --c1: #f6f1ff; --c2: #c6a4ff; --c3: #6d3fc0; --glow: rgba(170, 120, 255, 0.75); }
.cine-callout.queen { --c1: #fff8e3; --c2: #ffd77a; --c3: #a8731e; --glow: rgba(255, 200, 90, 0.85); }
.cine-callout.mate { --glow: rgba(255, 215, 120, 0.95); }
.cine-callout.mate .co-title { font-size: clamp(48px, 12.5vmin, 156px); letter-spacing: 0.06em; }
.cine-callout.draw { --c1: #f4f6ff; --c2: #c8d2e6; --c3: #6d7a96; --glow: rgba(200, 215, 255, 0.5); }

/* ---- v6.2 moments of glory ---- */
/* slow motion: the edges darken around the flight of the piece (one pre-rendered layer, opacity only) */
.cine-focus {
  position: absolute; inset: 0; opacity: 0;
  background: radial-gradient(ellipse 62% 58% at 50% 50%, transparent 45%, rgba(12, 5, 2, 0.62) 100%);
  transition: opacity 0.35s ease;
}
.cine.focus .cine-focus { opacity: 1; transition-duration: 0.25s; }

/* the impact: turning rays, a flash and two shock rings on the square (positioned by UI.glory) */
.cine-glory { position: absolute; left: 0; top: 0; width: 0; height: 0; --g: 255, 212, 110; --g2: 255, 246, 220; }
.cine-glory.great { --g: 140, 196, 255; --g2: 236, 246, 255; }
.cine-glory i { position: absolute; left: 0; top: 0; border-radius: 50%; opacity: 0; transform: translate(-50%, -50%) scale(0.2); }
.cg-rays {
  width: 130vmin; height: 130vmin;
  background: repeating-conic-gradient(from 0deg, rgba(var(--g), 0) 0deg 7deg, rgba(var(--g), 0.42) 9deg 11deg, rgba(var(--g), 0) 13deg 20deg);
  -webkit-mask-image: radial-gradient(circle, #000 6%, rgba(0, 0, 0, 0.55) 26%, transparent 62%);
  mask-image: radial-gradient(circle, #000 6%, rgba(0, 0, 0, 0.55) 26%, transparent 62%);
}
.cg-flash {
  width: 46vmin; height: 46vmin;
  background: radial-gradient(circle, rgba(var(--g2), 0.95) 0%, rgba(var(--g), 0.7) 22%, rgba(var(--g), 0.22) 48%, rgba(var(--g), 0) 70%);
}
.cg-ring { width: 18vmin; height: 18vmin; border: 0.9vmin solid rgba(var(--g), 0.95); box-shadow: 0 0 3vmin rgba(var(--g), 0.8), inset 0 0 2vmin rgba(var(--g), 0.6); }
.cg-ring.r2 { border-width: 0.45vmin; border-color: rgba(var(--g2), 0.9); }
.cine-glory.show .cg-rays { animation: cgRays 2.1s cubic-bezier(.15, .8, .3, 1) both; }
.cine-glory.show .cg-flash { animation: cgFlash 0.8s ease-out both; }
.cine-glory.show .cg-ring { animation: cgRing 0.9s cubic-bezier(.1, .7, .3, 1) both; }
.cine-glory.show .cg-ring.r2 { animation-delay: 0.14s; animation-duration: 1.1s; }
@keyframes cgRays {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.3) rotate(0deg); }
  12% { opacity: 1; transform: translate(-50%, -50%) scale(1) rotate(8deg); }
  70% { opacity: 0.75; }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1.25) rotate(46deg); }
}
@keyframes cgFlash {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.2); }
  10% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(2.4); }
}
@keyframes cgRing {
  0% { opacity: 1; transform: translate(-50%, -50%) scale(0.15); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(5.2); }
}

/* the big text slams in with the impact */
.cine-callout.glory.show { animation: coSlam 0.62s cubic-bezier(.2, 1, .3, 1) both; }
.cine-callout.glory .co-title { font-size: clamp(48px, 12.5vmin, 158px); letter-spacing: 0.05em; }
.cine-callout.glory .co-kicker { font-size: clamp(12px, 2.2vmin, 20px); }
@keyframes coSlam {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(3.4); }
  38% { opacity: 1; transform: translate(-50%, -50%) scale(0.93); }
  60% { transform: translate(-50%, -50%) scale(1.045); }
  100% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

/* blunders shudder (v6: no colour-split "broken broadcast" glitch: it read as a rendering fault) */
.cine-callout.blunder.show .co-title { animation: coShake 0.5s 0.3s; }
@keyframes coShake { 15% { transform: translateX(-9px); } 35% { transform: translateX(8px); } 55% { transform: translateX(-5px); } 75% { transform: translateX(3px); } }

/* ---- chips: the small verdicts that should not stop the show ---- */
.cine-chips {
  position: absolute; left: 50%; top: 17%;
  transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.cine-chip {
  --q: var(--gold);
  display: inline-flex; align-items: center; gap: 9px;
  padding: 5px 16px 5px 6px; border-radius: 999px;
  font-family: var(--font-head); font-weight: 800;
  font-size: clamp(12px, 1.8vmin, 16px); letter-spacing: 0.14em; text-transform: uppercase;
  color: #fff;
  background: linear-gradient(180deg, rgba(22, 15, 8, 0.94), rgba(8, 6, 4, 0.9));
  border: 1px solid var(--q);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.6), 0 0 16px color-mix(in srgb, var(--q) 45%, transparent);
  animation: chipIn 0.42s cubic-bezier(.2, 1.4, .4, 1) both;
}
.cine-chip b {
  display: inline-grid; place-items: center; min-width: 24px; height: 24px; padding: 0 5px;
  border-radius: 999px; background: var(--q); color: #111; font-size: 12px; letter-spacing: 0;
}
.cine-chip.out { animation: chipOut 0.4s ease-in both; }
.cine-chip.best { --q: #81b64c; } .cine-chip.excellent { --q: #96bc4b; } .cine-chip.inaccuracy { --q: #f0c15c; }
.cine-chip.event { --q: #d9b25f; } .cine-chip.streak { --q: #4fd2c4; }
@keyframes chipIn { from { opacity: 0; transform: translateY(-14px) scale(0.85); } }
@keyframes chipOut { to { opacity: 0; transform: translateY(-10px) scale(0.92); } }

/* ---- phase title card ---- */
.cine-phase {
  position: absolute; left: 50%; top: 29%;
  transform: translate(-50%, -50%);
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  opacity: 0; text-align: center;
}
.cine-phase.show { animation: phIn 3.6s ease both; }
.cine-phase b {
  font-family: var(--font-display); font-weight: 900;
  font-size: clamp(28px, 6.2vmin, 76px); letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--gold-light);
  filter: drop-shadow(0 3px 0 #000) drop-shadow(0 0 20px rgba(255, 200, 120, 0.55));
}
.cine-phase .cp-sub {
  font-family: var(--font-body); font-style: italic; font-weight: 600;
  font-size: clamp(15px, 2.4vmin, 25px); color: var(--ivory);
  text-shadow: 0 2px 6px #000;
}
.cp-line { width: min(62vw, 560px); height: 2px; background: linear-gradient(90deg, transparent, var(--gold-light), transparent); transform: scaleX(0); opacity: 0; }
.cine-phase.show .cp-line { animation: phLine 3.6s ease both; }
.cine-phase.scramble b { color: #ffb4a6; filter: drop-shadow(0 3px 0 #000) drop-shadow(0 0 22px rgba(255, 70, 40, 0.6)); }
.cine-phase.endgame b { color: #d8e4ff; filter: drop-shadow(0 3px 0 #000) drop-shadow(0 0 22px rgba(130, 170, 255, 0.5)); }
@keyframes phIn {
  0% { opacity: 0; transform: translate(-50%, -38%) scale(1.12); }
  14% { opacity: 1; transform: translate(-50%, -50%); }
  82% { opacity: 1; transform: translate(-50%, -50%); }
  100% { opacity: 0; transform: translate(-50%, -58%); }
}
@keyframes phLine { 0% { transform: scaleX(0); opacity: 0; } 22% { transform: scaleX(1); opacity: 1; } 82% { opacity: 1; } 100% { transform: scaleX(1); opacity: 0; } }

/* ---- achievement toasts (above every screen and modal) ---- */
.cine-ach {
  position: absolute; z-index: 60;
  right: calc(14px + var(--safe-right)); top: calc(76px + var(--safe-top));
  display: flex; flex-direction: column; align-items: flex-end; gap: 10px;
  pointer-events: none;
}
.ach-toast {
  position: relative; overflow: hidden;
  display: flex; align-items: center; gap: 12px;
  min-width: 270px; max-width: min(390px, 88vw);
  padding: 10px 18px 10px 10px; border-radius: 12px;
  background: linear-gradient(180deg, rgba(30, 21, 10, 0.97), rgba(10, 7, 4, 0.95));
  border: 1px solid var(--gold);
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.72), 0 0 26px rgba(217, 178, 95, 0.38);
  animation: achIn 0.65s cubic-bezier(.2, 1.3, .4, 1) both;
}
.ach-toast::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(105deg, transparent 35%, rgba(255, 240, 200, 0.35) 50%, transparent 65%);
  transform: translateX(-120%); animation: coSweep 1.2s 0.5s ease-out both;
}
.ach-toast.out { animation: achOut 0.5s ease-in both; }
@keyframes achIn { from { opacity: 0; transform: translateX(60px) scale(0.9); } }
@keyframes achOut { to { opacity: 0; transform: translateX(40px); } }
.ach-medal {
  flex: 0 0 52px; width: 52px; height: 52px; border-radius: 50%;
  display: grid; place-items: center;
  font-family: 'Segoe UI Symbol', 'DejaVu Sans', var(--font-head); font-size: 27px; line-height: 1;
  color: #2a1904;
  background: radial-gradient(circle at 35% 30%, #fff6d4, #f0c862 45%, #a8731e 100%);
  box-shadow: inset 0 -3px 6px rgba(0, 0, 0, 0.35), 0 0 16px rgba(255, 210, 110, 0.55);
}
.ach-medal.img { background: radial-gradient(circle at 40% 35%, #6a1a22, #1c070b 80%); box-shadow: 0 0 0 2px rgba(232, 190, 98, 0.8), 0 0 16px rgba(255, 210, 110, 0.45); }
.ach-medal.img img { width: 42px; height: 42px; }
.ach-toast.wardrobe { border-color: var(--gold-light); background: linear-gradient(180deg, rgba(70, 12, 20, 0.97), rgba(22, 6, 8, 0.95)); }
.ach-text { display: flex; flex-direction: column; min-width: 0; }
.ach-text small { font-family: var(--font-head); font-weight: 800; font-size: 11px; letter-spacing: 0.24em; text-transform: uppercase; color: var(--gold); }
.ach-text b { font-family: var(--font-display); font-weight: 900; font-size: 19px; color: var(--gold-light); }
.ach-text span { font-family: var(--font-body); font-style: italic; font-size: 15px; color: rgba(247, 238, 215, 0.86); }

/* ---- achievements gallery ---- */
.ach-panel { width: min(780px, 94vw); max-height: min(92vh, calc(100vh - 24px)); }
.ach-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(215px, 1fr)); gap: 10px;
  width: 100%; max-height: min(52vh, 480px); overflow-y: auto; overflow-x: hidden; padding: 4px;
  scrollbar-width: thin; scrollbar-color: var(--gold-dark) transparent;
}
.ach-card {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px;
  background: rgba(0, 0, 0, 0.36); border: 1px solid rgba(217, 178, 95, 0.32);
}
.ach-card .ach-medal { flex-basis: 42px; width: 42px; height: 42px; font-size: 22px; }
.ach-card .ach-text b { font-size: 15px; }
.ach-card .ach-text span { font-size: 13.5px; }
.ach-card .ach-text small { font-size: 10px; letter-spacing: 0.14em; color: rgba(217, 178, 95, 0.85); }
.ach-card.locked { opacity: 0.52; border-color: rgba(255, 255, 255, 0.08); }
.ach-card.locked .ach-medal { filter: grayscale(1) brightness(0.55); box-shadow: none; }
.ach-card.fresh { border-color: var(--gold-light); box-shadow: 0 0 16px rgba(255, 220, 140, 0.35); }

/* the 2D board is graded inside the canvas (light pool + vignette); v6 dropped the CSS filter on it */

@media (prefers-reduced-motion: reduce) {
  .cine-callout.show, .cine-callout.hide, .cine-phase.show { animation-duration: 0.01s; }
  .cine-bar { transition-duration: 0.01s; }
  .cine-glory { display: none; }
}
