/**
 * Live match sync overlay — shown while room / clocks arm.
 */
.tmj-live-sync {
  position: fixed;
  inset: 0;
  z-index: 12050;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(0, 8, 4, 0.78);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  font-family: "Courier New", Courier, monospace;
  color: #cfe8d8;
  animation: tmj-live-sync-in 0.22s ease;
  pointer-events: all;
}

/*
 * Mobile battle shell: sit above promo (200k) + battle chrome.
 * CRITICAL: only when NOT [hidden]. Earlier display:flex !important
 * beat el.style.display='none' and left an invisible full-screen
 * pointer-events trap after Fight — froze the whole app.
 */
html body.m-body-battle .tmj-live-sync:not([hidden]),
html body.m-body-chess .tmj-live-sync:not([hidden]),
html body.m-live-syncing .tmj-live-sync:not([hidden]),
.tmj-live-sync.tmj-live-sync--mobile:not([hidden]) {
  z-index: 300000 !important;
  position: fixed !important;
  inset: 0 !important;
  display: flex !important;
  visibility: visible !important;
  opacity: 1 !important;
  pointer-events: all !important;
  transform: none !important;
  max-height: none !important;
  overflow: auto !important;
  -webkit-overflow-scrolling: touch;
  padding:
    max(12px, env(safe-area-inset-top, 0px))
    12px
    max(12px, env(safe-area-inset-bottom, 0px)) !important;
}

/* Hard dismiss — must win over any flex !important above */
html body .tmj-live-sync[hidden],
html body .tmj-live-sync.is-dismissed,
html body.m-body-battle .tmj-live-sync[hidden],
html body.m-body-chess .tmj-live-sync[hidden],
html body .tmj-live-sync--mobile[hidden],
html body .tmj-live-sync--mobile.is-dismissed {
  display: none !important;
  visibility: hidden !important;
  opacity: 0 !important;
  pointer-events: none !important;
  z-index: -1 !important;
  inset: auto !important;
  width: 0 !important;
  height: 0 !important;
  overflow: hidden !important;
}

/*
 * LiveKernel slim: NEVER allow prestage overlay on live match.
 * (Invisible flex trap = hand cursor + frozen UI.)
 */
html body.is-live-mode .tmj-live-sync,
html body.is-live-mode #tmj-sync-ui,
html body.is-live-playable .tmj-live-sync,
html body[data-live-phase] .tmj-live-sync {
  display: none !important;
  visibility: hidden !important;
  opacity: 0 !important;
  pointer-events: none !important;
  z-index: -1 !important;
  cursor: default !important;
  width: 0 !important;
  height: 0 !important;
}
html body.is-live-mode,
html body.is-live-playable {
  cursor: default !important;
}

html body.m-body-battle .tmj-live-sync__card,
.tmj-live-sync--mobile .tmj-live-sync__card {
  width: min(440px, 96vw) !important;
  max-height: min(86dvh, 640px) !important;
  overflow-y: auto !important;
  -webkit-overflow-scrolling: touch;
}

.tmj-live-sync__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 10px;
}
.tmj-live-sync__actions[hidden] {
  display: none !important;
}
.tmj-live-sync__actions a,
.tmj-live-sync__actions button,
.tmj-live-sync__skip {
  appearance: none;
  border: 1px solid rgba(0, 255, 136, 0.4);
  background: rgba(0, 28, 14, 0.95);
  color: #9fffc4;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  padding: 10px 14px;
  border-radius: 10px;
  min-height: 44px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.tmj-live-sync__actions a.is-primary,
.tmj-live-sync__skip {
  background: linear-gradient(165deg, #1dff8a, #008a48);
  color: #03140a;
  border-color: #00ff88;
}
.tmj-live-sync[hidden] {
  display: none !important;
}
.tmj-live-sync.is-done {
  animation: tmj-live-sync-out 0.35s ease forwards;
  pointer-events: none;
}
@keyframes tmj-live-sync-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}
@keyframes tmj-live-sync-out {
  to {
    opacity: 0;
  }
}

.tmj-live-sync__card {
  width: min(440px, 94vw);
  max-height: min(88vh, 620px);
  overflow: hidden; /* auto-scroll log only — no card scrollbar */
  padding: 18px 16px 14px;
  border-radius: 12px;
  border: 1px solid rgba(0, 255, 136, 0.42);
  background: linear-gradient(
    160deg,
    rgba(0, 22, 12, 0.98),
    rgba(0, 12, 8, 0.96)
  );
  box-shadow: 0 0 40px rgba(0, 255, 136, 0.16),
    inset 0 0 24px rgba(0, 40, 20, 0.35);
  text-align: center;
}

.tmj-live-sync__kicker {
  font-size: 0.72rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: #6a9a7a;
  margin-bottom: 8px;
}

.tmj-live-sync__title {
  font-size: 1.15rem;
  font-weight: 700;
  color: #9fffc4;
  margin: 0 0 10px;
  text-shadow: 0 0 12px rgba(0, 255, 136, 0.25);
}

.tmj-live-sync__detail {
  font-size: 0.88rem;
  line-height: 1.45;
  color: #a8c8b4;
  margin: 0 0 16px;
  min-height: 2.6em;
}

.tmj-live-sync__steps {
  list-style: none;
  margin: 0 0 16px;
  padding: 0;
  text-align: left;
}
.tmj-live-sync__steps li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 0.82rem;
  color: #6a8a72;
  margin-bottom: 4px;
}
.tmj-live-sync__steps li.is-done {
  color: #7adb9a;
}
.tmj-live-sync__steps li.is-active {
  color: #c8ffe0;
  background: rgba(0, 255, 136, 0.08);
  border: 1px solid rgba(0, 255, 136, 0.18);
}
.tmj-live-sync__steps li.is-wait {
  color: #556655;
}
.tmj-live-sync__dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 1px solid rgba(0, 255, 136, 0.35);
  background: transparent;
}
.tmj-live-sync__steps li.is-done .tmj-live-sync__dot {
  background: #00cc66;
  border-color: #00ff88;
  box-shadow: 0 0 8px rgba(0, 255, 136, 0.5);
}
.tmj-live-sync__steps li.is-active .tmj-live-sync__dot {
  border-color: #00ff88;
  animation: tmj-live-sync-pulse 0.9s ease infinite;
}
@keyframes tmj-live-sync-pulse {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(0, 255, 136, 0.45);
  }
  50% {
    box-shadow: 0 0 0 6px rgba(0, 255, 136, 0);
  }
}

.tmj-live-sync__bar {
  height: 4px;
  border-radius: 2px;
  background: rgba(0, 40, 20, 0.9);
  overflow: hidden;
  margin-bottom: 12px;
}
.tmj-live-sync__bar-fill {
  height: 100%;
  width: 8%;
  border-radius: 2px;
  background: linear-gradient(90deg, #00aa55, #00ff88);
  transition: width 0.35s ease;
  box-shadow: 0 0 10px rgba(0, 255, 136, 0.4);
}

.tmj-live-sync__meta {
  font-size: 0.72rem;
  color: #4a6a55;
  letter-spacing: 0.04em;
}

.tmj-live-sync.is-err .tmj-live-sync__card {
  border-color: rgba(255, 90, 90, 0.5);
}
.tmj-live-sync.is-err .tmj-live-sync__title {
  color: #ffaaaa;
}

/* Fail actions (Back to lobby / Find live / Retry) */
.tmj-live-sync__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin: 10px 0 4px;
}
.tmj-live-sync__actions a,
.tmj-live-sync__actions button {
  appearance: none;
  border: 1px solid rgba(0, 255, 136, 0.45);
  background: rgba(0, 40, 20, 0.85);
  color: #9fffc4;
  font: 700 0.78rem/1 "Courier New", monospace;
  padding: 10px 14px;
  border-radius: 8px;
  text-decoration: none;
  cursor: pointer;
}
.tmj-live-sync__actions a.is-primary,
.tmj-live-sync__actions button.is-primary {
  background: linear-gradient(165deg, #1dff8a, #008a48);
  color: #03140a;
  border-color: #00ff88;
}

/* While overlay is up, reduce accidental input under the card */
body.is-live-syncing #main-grid {
  pointer-events: none;
  filter: brightness(0.85);
}

/* Fight countdown numeral */
.tmj-live-sync__fight {
  font-size: clamp(3.2rem, 12vw, 5rem);
  font-weight: 800;
  line-height: 1;
  color: #9fffc4;
  text-shadow: 0 0 28px rgba(0, 255, 136, 0.55);
  margin: 4px 0 10px;
  letter-spacing: 0.06em;
  animation: tmj-fight-pop 0.35s ease;
}
.tmj-live-sync__fight.is-go {
  color: #ffee88;
  text-shadow: 0 0 32px rgba(255, 220, 80, 0.65);
  font-size: clamp(2.4rem, 10vw, 3.6rem);
}
@keyframes tmj-fight-pop {
  from {
    transform: scale(0.6);
    opacity: 0.2;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}
.tmj-live-sync.is-fight .tmj-live-sync__steps {
  opacity: 0.75;
}

/* Debug log */
.tmj-live-sync__log-wrap {
  margin-top: 14px;
  text-align: left;
  border: 1px solid rgba(0, 255, 136, 0.18);
  border-radius: 8px;
  background: rgba(0, 8, 4, 0.75);
  overflow: hidden;
}
.tmj-live-sync__log-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 10px;
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #5a8a6a;
  border-bottom: 1px solid rgba(0, 255, 136, 0.12);
}
.tmj-live-sync__log-copy {
  font-family: inherit;
  font-size: 0.68rem;
  padding: 2px 8px;
  border-radius: 4px;
  border: 1px solid rgba(0, 255, 136, 0.35);
  background: rgba(0, 40, 20, 0.8);
  color: #9fffc4;
  cursor: pointer;
}
.tmj-live-sync__log-copy:hover {
  background: rgba(0, 60, 30, 0.95);
}
.tmj-live-sync__log {
  margin: 0;
  padding: 6px 8px;
  max-height: 56px;
  overflow: hidden; /* JS keeps latest lines in view; no scrollbar chrome */
  font-size: 0.58rem;
  line-height: 1.3;
  color: #7a9a82;
  white-space: pre-wrap;
  word-break: break-word;
  scrollbar-width: none;
}
.tmj-live-sync__log::-webkit-scrollbar {
  display: none;
  width: 0;
  height: 0;
}
