/* =============================================================
   display.css — Player Display Window
   DeGrid · Third Degree Entertainment
   ============================================================= */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* Prevent display:flex/.grid rules from overriding [hidden] */
[hidden] { display: none !important; }

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--primary);
  font-family: 'Exo 2', sans-serif;
}

#host-connection-status {
  position: fixed;
  z-index: 1000;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100vw - 24px);
  padding: 9px 14px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 999px;
  background: rgba(20, 20, 24, 0.92);
  color: #fff;
  font: 600 14px/1.2 system-ui, sans-serif;
  text-align: center;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
}

#host-connection-status[data-state="disconnected"] {
  border-color: #fbbf24;
  color: #fde68a;
}

#display-fullscreen {
  position: fixed;
  z-index: 1000;
  top: 12px;
  right: 12px;
  padding: 9px 14px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 999px;
  background: rgba(20, 20, 24, 0.92);
  color: #fff;
  font: 600 14px/1.2 system-ui, sans-serif;
  cursor: pointer;
}

#display-fullscreen:hover { background: rgba(45, 45, 52, 0.96); }
#display-fullscreen:focus-visible { outline: 3px solid #fbbf24; outline-offset: 3px; }

/* -------------------------------------------------------------
   Grid view
   ------------------------------------------------------------- */
#grid-view {
  position: relative;
  width: 100vw;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--primary);
}

#tv-grid {
  display: grid;
  flex-shrink: 0;
  background: var(--primary);
  /* grid-template-columns / grid-template-rows / gap set by JS fitGrid() */
}

#tv-grid .tv-cell {
  aspect-ratio: unset;
  width: 100%;
  height: 100%;
}

/* Question cells are read-only on display */
#tv-grid .tv-cell--question {
  cursor: default;
}
#tv-grid .tv-cell--question:hover {
  transform: none;
}

/* Blurred question text shown in grid cells on display */
.display-cell-question {
  font-family: 'Exo 2', sans-serif;
  font-weight: 700;
  font-size: clamp(0.35rem, 1.1vw, 1rem);
  text-align: center;
  line-height: 1.35;
  color: inherit;
  filter: blur(5px);
  user-select: none;
  padding: 0 6%;
  word-break: break-word;
  pointer-events: none;
}

/* -------------------------------------------------------------
   Side panels — fill dead space beside the grid
   ------------------------------------------------------------- */

.side-panel {
  position: absolute;
  top: 0;
  bottom: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

#panel-left  { left: 0; }
#panel-right { right: 0; }

/* Each quadrant takes equal half the panel height */
.panel-quad {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  position: relative;
  min-height: 0;
}

.side-panel img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

/* QR panel */
.panel-qr-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  height: 100%;
}

.panel-qr-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  background: #fff;
  border-radius: 8px;
}

.panel-qr-wrap canvas,
.panel-qr-wrap img {
  display: block;
  width: 200px !important;
  height: 200px !important;
}

.panel-qr-label {
  font-family: 'Exo 2', sans-serif;
  font-weight: 900;
  font-size: clamp(1rem, 3vw, 2rem);
  letter-spacing: 0.25em;
  color: #ffffff;
  text-align: center;
  text-shadow: 0 2px 8px rgba(0,0,0,0.8);
  padding: 6px 0 0;
}

.side-panel-text {
  padding: 24px 16px;
  font-family: 'Exo 2', sans-serif;
  /* font-size driven by JS via --panel-w custom property */
  font-size: clamp(14px, calc(var(--panel-w, 160px) * 0.075), 40px);
  font-weight: 600;
  line-height: 1.5;
  color: #ffffff;
  text-shadow:
    -1px -1px 0 #000,
     1px -1px 0 #000,
    -1px  1px 0 #000,
     1px  1px 0 #000,
     0 2px 8px rgba(0,0,0,0.55);
  word-break: break-word;
  white-space: pre-wrap;
  overflow-y: auto;
}

.panel-text-big {
  font-size: 1.65em;
  line-height: 1.2;
}

/* -------------------------------------------------------------
   Full-screen image overlay
   ------------------------------------------------------------- */

#image-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 500ms ease;
}

#image-overlay:not([hidden]) {
  opacity: 1;
}

#image-overlay img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

/* -------------------------------------------------------------
   Stage — fixed overlay for expanded cell
   ------------------------------------------------------------- */
#stage {
  position: fixed;
  inset: 0;
  z-index: 50;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

#stage[hidden] {
  display: none;
}

#stage-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  opacity: 0;
  transition: opacity 400ms ease;
}

#stage-backdrop.visible {
  opacity: 1;
}

/* Category label above expanded cell */
#stage-label {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  font-family: 'Exo 2', sans-serif;
  font-weight: 900;
  font-size: clamp(1.2rem, 3vw, 2.2rem);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #ffffff;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.8);
  white-space: nowrap;
  opacity: 0;
  transition: opacity 300ms ease 250ms; /* delay until cell is mostly in place */
  z-index: 52;
  /* top set by JS based on stage cell position */
}

#stage-label.visible {
  opacity: 1;
}

/* Countdown timer — shown below stage cell */
#stage-timer {
  position: fixed;
  bottom: 5vh;
  left: 50%;
  transform: translateX(-50%);
  font-family: 'Exo 2', sans-serif;
  font-weight: 900;
  font-size: clamp(3rem, 8vw, 6rem);
  color: #86efac;
  text-shadow: 0 2px 16px rgba(0,0,0,0.8);
  z-index: 52;
  pointer-events: none;
  line-height: 1;
  transition: color 300ms ease;
}

#stage-timer.urgent  { color: #f87171; }
#stage-timer.expired { color: #ef4444; }

/* The expanded TV cell — positioned & sized by JS */
#stage-cell {
  position: fixed;
  z-index: 51;
  /* left, top, width, height all set by JS */
  /* aspect-ratio intentionally not set — JS controls size */
  aspect-ratio: unset;
  transition: left 400ms ease-out,
              top  400ms ease-out,
              width  400ms ease-out,
              height 400ms ease-out;
}

#stage-cell.returning {
  transition: left 350ms ease-out,
              top  350ms ease-out,
              width  350ms ease-out,
              height 350ms ease-out;
}

/* Screen content in expanded state */
#stage-cell .tv-screen {
  justify-content: center;
  gap: 12px;
  padding: 10%;
}

#stage-question {
  font-family: 'Exo 2', sans-serif;
  font-weight: 700;
  font-size: clamp(0.9rem, 2.2vw, 1.8rem); /* JS overrides this after expansion */
  text-align: center;
  line-height: 1.3;
  color: inherit;
  filter: blur(8px);
  transition: filter 600ms ease;
  width: 100%;
  word-break: break-word;
  hyphens: auto;
}

#stage-question.revealed {
  filter: blur(0);
}

#stage-image {
  max-width: 90%;
  max-height: 45%;
  object-fit: contain;
  border-radius: 6px;
  opacity: 0;
  transform: scale(0.96);
  transition: opacity 500ms ease, transform 500ms ease;
  flex-shrink: 0;
}

#stage-image.revealed {
  opacity: 1;
  transform: scale(1);
}

#stage-answer {
  font-family: 'Exo 2', sans-serif;
  font-weight: 900;
  font-size: clamp(1.1rem, 2.6vw, 2.2rem);
  text-align: center;
  line-height: 1.25;
  color: inherit;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 400ms ease, transform 400ms ease;
  border-top: 2px solid rgba(255, 255, 255, 0.35);
  padding-top: 10px;
  margin-top: 6px;
  width: 90%;
}

#stage-answer.revealed {
  opacity: 1;
  transform: translateY(0);
}

/* =============================================================
   QR code overlay — pushed from host so players can join
   ============================================================= */

#qr-overlay {
  position: fixed;
  inset: 0;
  z-index: 201;
  background: rgba(10, 10, 20, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 400ms ease;
}

#qr-overlay:not([hidden]) {
  opacity: 1;
}

#qr-overlay-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(10px, 2vh, 20px);
}

#qr-overlay-title {
  font-family: 'Exo 2', sans-serif;
  font-weight: 900;
  font-size: clamp(1.6rem, 4vw, 3rem);
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--lb-accent, #f97316);
  text-shadow: 0 2px 16px rgba(0,0,0,0.4);
}

#qr-overlay-code {
  background: #fff;
  border-radius: 12px;
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#qr-overlay-code canvas,
#qr-overlay-code img {
  display: block;
  width: 300px !important;
  height: 300px !important;
}

#qr-overlay-url {
  font-family: 'Exo 2', sans-serif;
  font-size: clamp(0.7rem, 1.5vw, 1.1rem);
  color: #94a3b8;
  letter-spacing: 0.04em;
}

#qr-overlay-room {
  font-family: 'Exo 2', sans-serif;
  font-weight: 900;
  font-size: clamp(2rem, 6vw, 4rem);
  letter-spacing: 0.3em;
  color: #ffffff;
  text-shadow: 0 2px 20px rgba(255,255,255,0.3);
}

/* =============================================================
   Leaderboard in side panel
   ============================================================= */

.side-panel-leaderboard {
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;           /* fill panel or panel-quad height */
  min-height: 0;     /* allow shrinking for scroll */
  overflow-y: auto;
  scrollbar-width: none; /* hide scrollbar — JS drives scrolling */
}
.side-panel-leaderboard::-webkit-scrollbar { display: none; }

.side-lb-title {
  font-family: 'Exo 2', sans-serif;
  font-weight: 900;
  font-size: clamp(0.7rem, 1.8vw, 1.1rem);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--lb-accent, #f97316);
  margin-bottom: 8px;
  text-align: center;
}

.side-lb-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  background: rgba(255,255,255,0.06);
  font-family: 'Exo 2', sans-serif;
}

.side-lb-rank {
  font-weight: 700;
  font-size: clamp(0.6rem, 1.4vw, 0.9rem);
  color: #64748b;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
}

.side-lb-item:nth-child(2) .side-lb-rank { color: #fbbf24; }
.side-lb-item:nth-child(3) .side-lb-rank { color: #94a3b8; }
.side-lb-item:nth-child(4) .side-lb-rank { color: #b45309; }

.side-lb-name {
  flex: 1;
  font-size: clamp(0.65rem, 1.5vw, 0.95rem);
  font-weight: 600;
  color: #e2e8f0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.side-lb-score {
  font-weight: 900;
  font-size: clamp(0.75rem, 1.8vw, 1.1rem);
  color: var(--lb-accent, #f97316);
  flex-shrink: 0;
}

/* =============================================================
   Leaderboard overlay — full-screen, pushed from host
   ============================================================= */

#leaderboard-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(10, 10, 20, 0.96);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 500ms ease;
}

#leaderboard-overlay:not([hidden]) {
  opacity: 1;
}

#lb-overlay-inner {
  width: min(90vw, 800px);
  display: flex;
  flex-direction: column;
  gap: 0;
}

#lb-overlay-title {
  font-family: 'Exo 2', sans-serif;
  font-weight: 900;
  font-size: clamp(1.6rem, 4vw, 3rem);
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--lb-accent, #f97316);
  text-align: center;
  margin-bottom: clamp(16px, 3vh, 32px);
  text-shadow: 0 2px 16px rgba(0,0,0,0.4);
}

.lb-overlay-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: clamp(6px, 1.2vh, 12px);
}

.lb-overlay-item {
  display: flex;
  align-items: center;
  gap: clamp(10px, 2vw, 24px);
  padding: clamp(10px, 1.8vh, 18px) clamp(14px, 2.5vw, 28px);
  border-radius: 10px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.08);
  animation: lbItemIn 400ms ease both;
}

.lb-overlay-item:nth-child(1) { animation-delay: 60ms;  background: rgba(251,191,36,0.12); border-color: rgba(251,191,36,0.3); }
.lb-overlay-item:nth-child(2) { animation-delay: 120ms; background: rgba(148,163,184,0.10); border-color: rgba(148,163,184,0.25); }
.lb-overlay-item:nth-child(3) { animation-delay: 180ms; background: rgba(180,83,9,0.12);   border-color: rgba(180,83,9,0.3); }
.lb-overlay-item:nth-child(n+4) { animation-delay: calc(180ms + (var(--i, 0) * 60ms)); }

@keyframes lbItemIn {
  from { opacity: 0; transform: translateX(-20px); }
  to   { opacity: 1; transform: translateX(0); }
}

.lb-overlay-rank {
  font-family: 'Exo 2', sans-serif;
  font-weight: 900;
  font-size: clamp(1rem, 2.5vw, 1.8rem);
  color: #475569;
  width: clamp(28px, 4vw, 48px);
  text-align: center;
  flex-shrink: 0;
}

.lb-overlay-item:nth-child(1) .lb-overlay-rank { color: #fbbf24; }
.lb-overlay-item:nth-child(2) .lb-overlay-rank { color: #94a3b8; }
.lb-overlay-item:nth-child(3) .lb-overlay-rank { color: #b45309; }

.lb-overlay-name {
  flex: 1;
  font-family: 'Exo 2', sans-serif;
  font-weight: 700;
  font-size: clamp(1rem, 2.8vw, 2rem);
  color: #e2e8f0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lb-overlay-score {
  font-family: 'Exo 2', sans-serif;
  font-weight: 900;
  font-size: clamp(1.2rem, 3vw, 2.2rem);
  color: var(--lb-accent, #f97316);
  flex-shrink: 0;
}
