:root{
  --preview-bg: transparent;
  --room-gap: 10px;
  /* default palette tuned for overlay on a black/transparent background */
  --title-color: #ffffff;
  --past-color: #b6b6b6;
  --next-color: #55aaff;
  --current-color: #3ee27a;
  --warn-color: #ff4747;
  --text-shadow: 0 2px 6px rgba(0,0,0,.9), 0 0 4px rgba(0,0,0,.7);
}

*{ box-sizing: border-box; }

html,body{
  margin:0; padding:0; width:100%; height:100%;
  font-family:'Segoe UI', Arial, sans-serif;
  overflow:hidden;
  background:transparent;
  display:flex;
  align-items:center;
  justify-content:center;
}

#bgFill{
  position:fixed;
  inset:0;
  background:var(--preview-bg);
  -webkit-mask-image:url(#bgHoleMask);
  mask-image:url(#bgHoleMask);
  pointer-events:none;
  z-index:0;
}

#stage{
  position:relative;
  z-index:1;
  width:min(100vw, 177.78vh);
  height:min(100vh, 56.25vw);
  aspect-ratio:16/9;
  margin:0 auto;
  display:flex;
  flex-direction:column;
  justify-content:space-between;
  padding:10px 0;
  color:var(--title-color);
}

#stage.bg-transparent{ background:transparent; }

/* white background is for preview/testing only — swap to a dark-on-light palette.
   The actual fill color is painted by .videoFrame's box-shadow "hole punch" below,
   not by #stage itself, so the inside of each video frame is never colored. */
#stage.bg-white{
  background:transparent;
  --title-color: #111111;
  --past-color: #777777;
  --next-color: #1a56d6;
  --current-color: #1a8a3d;
  --warn-color: #d61a1a;
  --text-shadow: 0 1px 3px rgba(0,0,0,.25), 0 0 2px rgba(0,0,0,.15);
}

#gearBtn{
  position:absolute;
  top:10px; left:14px;
  width:34px; height:34px;
  border-radius:50%;
  border:none;
  background:rgba(0,0,0,.15);
  color:#fff;
  font-size:18px;
  cursor:pointer;
  opacity:.25;
  transition:opacity .2s;
  z-index:50;
}
#gearBtn:hover{ opacity:1; }

#creditTag{
  position:absolute;
  top:20px; right:20px;
  text-align:right;
  font-size:12px;
  line-height:1.35;
  font-weight:400;
  color:var(--title-color);
  opacity:.4;
  text-shadow:var(--text-shadow);
  z-index:40;
  pointer-events:none;
}

header{
  display:grid;
  grid-template-columns: 1fr auto 1fr;
  align-items:center;
  gap:.6em;
  text-align:center;
  flex:0 0 auto;
}

.headerSide{
  display:flex;
  align-items:center;
  gap:.6em;
  min-width:0;
}
.headerSide.side-left{ justify-content:flex-end; }
.headerSide.side-right{ justify-content:flex-start; }

#titleLabel, #titleDate{
  margin:0;
  font-size:clamp(20px, 2.6vw, 40px);
  font-weight:700;
  letter-spacing:.03em;
  color:var(--title-color);
  text-shadow:var(--text-shadow);
}

header .sep{
  font-size:clamp(20px, 2.6vw, 40px);
  font-weight:350;
  color:var(--title-color);
  opacity:.5;
  text-shadow:var(--text-shadow);
}

#clock{
  display:inline-block;
  width:9ch;
  box-sizing:border-box;
  font-size:clamp(38px, 10vw, 46px);
  font-weight:800;
  color:#e21414;
  background:#b6d7a8;
  border:4px solid #2a7a2a;
  border-radius:16px;
  padding:.01em 0;
  font-variant-numeric: tabular-nums;
  letter-spacing:.02em;
  text-align:center;
}

#stage.bg-white #clock{
  background:rgba(240,255,240,.55);
}

main#rooms{
  flex:1 1 auto;
  display:grid;
  grid-auto-flow:column;
  grid-auto-columns:1fr;
  gap:0;
  align-items:end;
  padding-top:0.1vh;
}

.room{
  display:flex;
  flex-direction:column;
  justify-content:flex-end;
  align-items:center;
  gap:.6vh;
  height:100%;
  min-width:0;
}

.roomTop{
  margin:0;
  width:100%;
  display:flex;
  flex-direction:column;
  align-items:center;
  gap:6px;
}

.frameGroup{
  flex:1 1 0;
  min-height:0;
  width:100%;
  max-width:100%;
  max-height:100%;
  aspect-ratio:9/16;
  margin:0 auto auto;
  box-sizing:border-box;
  border:5px solid #f5b301;
  border-radius:22px;
  overflow:hidden;
  display:flex;
  flex-direction:column;
}

.videoFrame{
  position:relative;
  flex:1 1 auto;
  min-height:0;
  width:100%;
  background:transparent;
  display:flex;
  align-items:center;
  justify-content:center;
}

.countdownOverlay{
  display:none;
  position:absolute;
  inset:0;
  background:rgba(0,0,0,.6);
  align-items:center;
  justify-content:center;
  z-index:5;
}

.countdownOverlay.show{
  display:flex;
}

.countdownNumber{
  color:#ffffff;
  font-weight:900;
  font-size:clamp(48px, 12vw, 140px);
  line-height:1;
  text-shadow:0 4px 14px rgba(0,0,0,.7);
  animation:countdownPulse 1s ease-in-out infinite;
}

@keyframes countdownPulse{
  0%, 100% { transform:scale(1); }
  50% { transform:scale(1.28); }
}

.videoFrame.off{
  background:#808080;
}

.videoFrame.flick{
  animation:tvFlick .5s ease;
}

@keyframes tvFlick{
  0%   { transform:scaleY(1);    filter:brightness(1); }
  42%  { transform:scaleY(.02);  filter:brightness(3); }
  58%  { transform:scaleY(.02);  filter:brightness(3); }
  100% { transform:scaleY(1);    filter:brightness(1); }
}

.videoFrameText{
  display:none;
  color:#1a1a1a;
  font-weight:800;
  font-size:clamp(17px,2.3vw,32px);
  text-align:center;
  padding:0 .4em;
  animation:videoFrameBreathe 2.6s ease-in-out infinite;
}

.videoFrame.off .videoFrameText{
  display:block;
}

@keyframes videoFrameBreathe{
  0%, 100% { opacity:1; }
  50% { opacity:.5; }
}

.room h2{
  margin:0;
  font-size:clamp(16px,1.9vw,30px);
  font-weight:800;
  color:#f5b301;
  text-shadow:var(--text-shadow);
}

.room .kpi{
  flex:0 0 auto;
  width:100%;
  box-sizing:border-box;
  display:flex;
  align-items:center;
  background:#f5b301;
  color:#ffffff;
  font-weight:800;
  font-size:clamp(12px,1.25vw,19px);
  padding:5px 8px;
  white-space:nowrap;
  overflow:hidden;
}

.kpi .kpiPct{
  flex:0 0 auto;
  text-align:left;
}

.kpi .kpiRatio{
  flex:1 1 0;
  min-width:0;
  display:flex;
  align-items:center;
  margin-left:.5em;
  overflow:hidden;
}

.kpiRatio .kpiLeft{
  flex:1 1 0;
  min-width:0;
  text-align:right;
  overflow:hidden;
  text-overflow:ellipsis;
}

.kpiRatio .kpiSep{
  flex:0 0 auto;
  padding:0 .3em;
}

.kpiRatio .kpiRight{
  flex:1 1 0;
  min-width:0;
  text-align:left;
  overflow:hidden;
  text-overflow:ellipsis;
}

.slot{
  width:100%;
  text-align:center;
  font-size:clamp(11px,1.15vw,17px);
  line-height:1.35;
  text-shadow:var(--text-shadow);
  word-break:break-word;
}

.slot .name{
  font-weight:800;
}

.slot .meta{
  font-weight:600;
}

.slot.past{
  color:var(--past-color);
  font-size:clamp(10px,.95vw,14px);
}

.slot.next{
  color:var(--next-color);
}

.slot.current{
  color:var(--current-color);
  font-size:clamp(13px,1.45vw,22px);
  transition:transform .15s, color .15s;
}

.slot.empty{
  color:#999;
  font-style:italic;
}

.slot.current.off{
  color:var(--warn-color);
}

.slot.current.gap{
  color:var(--title-color);
}

.slot.current.warn{
  animation: pulseWarn 1s infinite;
  color:var(--warn-color);
}

@keyframes pulseWarn{
  0%   { transform:scale(1);    opacity:1; }
  50%  { transform:scale(1.18); opacity:.55; }
  100% { transform:scale(1);    opacity:1; }
}

/* ---------- settings modal ---------- */
#settingsOverlay{
  position:fixed; inset:0;
  background:rgba(0,0,0,.55);
  display:flex; align-items:center; justify-content:center;
  z-index:100;
}
#settingsOverlay.hidden{ display:none; }

#settingsPanel{
  position:relative;
  background:#fff;
  color:#222;
  width:min(90vw, 460px);
  max-height:90vh;
  overflow:auto;
  border-radius:12px;
  padding:20px 24px 24px;
  font-family:'Segoe UI', Arial, sans-serif;
  box-shadow:0 10px 40px rgba(0,0,0,.35);
}

#closeSettingsBtn{
  position:absolute;
  top:10px; right:12px;
  width:30px; height:30px;
  border:none;
  border-radius:50%;
  background:#f0f0f0;
  color:#444;
  font-size:20px;
  line-height:1;
  cursor:pointer;
}
#closeSettingsBtn:hover{ background:#e2e2e2; }

#settingsPanel h2{ margin-top:0; }

#settingsPanel label{
  display:block;
  font-size:13px;
  font-weight:600;
  margin:12px 0 4px;
  color:#444;
}

#settingsPanel input[type="text"],
#settingsPanel input[type="number"],
#settingsPanel input[type="password"]{
  width:100%;
  padding:8px 10px;
  font-size:14px;
  border:1px solid #ccc;
  border-radius:6px;
}

#settingsPanel input[type="color"]{
  width:100%;
  height:38px;
  padding:2px;
  border:1px solid #ccc;
  border-radius:6px;
  cursor:pointer;
}

#settingsPanel .checkboxRow{
  display:flex; align-items:center; gap:8px;
  font-weight:600;
}
#settingsPanel .checkboxRow input{ width:auto; }

.btnRow{
  display:flex; gap:10px;
  margin-top:18px;
}

.btnRow button{
  flex:1;
  padding:10px 12px;
  border:none;
  border-radius:8px;
  font-size:14px;
  font-weight:700;
  cursor:pointer;
}

#testSoundBtn{ background:#eee; color:#222; }
#saveSettingsBtn{ background:#1a56d6; color:#fff; }

.hint{
  margin-top:14px;
  font-size:12px;
  color:#777;
}

.cfgError{
  margin:6px 0 0;
  font-size:12px;
  font-weight:700;
  color:#d61a1a;
  min-height:14px;
}
